@matheusbsbs / matheus-bagliano / commits / f88961a85f
Fork 0

archimport: remove String::ShellQuote dependency.

use safe_pipe_capture() or system() over backticks where shellquoting may have been necessary. More changes planned, so I'm not touching the parts I'm planning on replacing entirely. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>

Eric Wong committed Nov 23, 2005 at 23:48 UTC f88961a85f14dd3fae4f5204f8187ba5d9a7646e
1 file changed +28 -23
git-archimport.perl
+28 -23
@@ -55,9 +55,8 @@ use warnings;
55 use Getopt::Std;
56 use File::Spec;
57 use File::Temp qw(tempfile tempdir);
58 -use File::Path qw(mkpath);
58 +use File::Path qw(mkpath rmtree);
59 use File::Basename qw(basename dirname);
60 -use String::ShellQuote;
60 use Time::Local;
61 use IO::Socket;
62 use IO::Pipe;
@@ -306,7 +305,7 @@ foreach my $ps (@psets) {
305 unless ($import) { # skip for import
306 if ( -e "$git_dir/refs/heads/$ps->{branch}") {
307 # we know about this branch
309 - `git checkout $ps->{branch}`;
308 + system('git-checkout',$ps->{branch});
309 } else {
310 # new branch! we need to verify a few things
311 die "Branch on a non-tag!" unless $ps->{type} eq 't';
@@ -315,7 +314,7 @@ foreach my $ps (@psets) {
314 unless $branchpoint;
315
316 # find where we are supposed to branch from
318 - `git checkout -b $ps->{branch} $branchpoint`;
317 + system('git-checkout','-b',$ps->{branch},$branchpoint);
318
319 # If we trust Arch with the fact that this is just
320 # a tag, and it does not affect the state of the tree
@@ -344,7 +343,7 @@ foreach my $ps (@psets) {
343 #
344 my $tree;
345
347 - my $commitlog = `tla cat-archive-log -A $ps->{repo} $ps->{id}`;
346 + my $commitlog = safe_pipe_capture($TLA,'cat-archive-log',$ps->{id});
347 die "Error in cat-archive-log: $!" if $?;
348
349 # parselog will git-add/rm files
@@ -422,7 +421,7 @@ foreach my $ps (@psets) {
421 #
422 my @par;
423 if ( -e "$git_dir/refs/heads/$ps->{branch}") {
425 - if (open HEAD, "<$git_dir/refs/heads/$ps->{branch}") {
424 + if (open HEAD, "<","$git_dir/refs/heads/$ps->{branch}") {
425 my $p = <HEAD>;
426 close HEAD;
427 chomp $p;
@@ -437,7 +436,6 @@ foreach my $ps (@psets) {
436 if ($ps->{merges}) {
437 push @par, find_parents($ps);
438 }
440 - my $par = join (' ', @par);
439
440 #
441 # Commit, tag and clean state
@@ -454,7 +452,7 @@ foreach my $ps (@psets) {
452 $commit_rh = 'commit_rh';
453 $commit_wh = 'commit_wh';
454
457 - $pid = open2(*READER, *WRITER, "git-commit-tree $tree $par")
455 + $pid = open2(*READER, *WRITER,'git-commit-tree',$tree,@par)
456 or die $!;
457 print WRITER $logmessage; # write
458 close WRITER;
@@ -469,7 +467,7 @@ foreach my $ps (@psets) {
467 #
468 # Update the branch
469 #
472 - open HEAD, ">$git_dir/refs/heads/$ps->{branch}";
470 + open HEAD, ">","$git_dir/refs/heads/$ps->{branch}";
471 print HEAD $commitid;
472 close HEAD;
473 system('git-update-ref', 'HEAD', "$ps->{branch}");
@@ -483,21 +481,23 @@ foreach my $ps (@psets) {
481 print " + tree $tree\n";
482 print " + commit $commitid\n";
483 $opt_v && print " + commit date is $ps->{date} \n";
486 - $opt_v && print " + parents: $par \n";
484 + $opt_v && print " + parents: ",join(' ',@par),"\n";
485 }
486
487 sub apply_import {
488 my $ps = shift;
489 my $bname = git_branchname($ps->{id});
490
493 - `mkdir -p $tmp`;
491 + mkpath($tmp);
492
495 - `tla get -s --no-pristine -A $ps->{repo} $ps->{id} $tmp/import`;
493 + safe_pipe_capture($TLA,'get','-s','--no-pristine',$ps->{id},"$tmp/import");
494 die "Cannot get import: $!" if $?;
497 - `rsync -v --archive --delete --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/import/* ./`;
495 + system('rsync','-aI','--delete', '--exclude',$git_dir,
496 + '--exclude','.arch-ids','--exclude','{arch}',
497 + "$tmp/import/", './');
498 die "Cannot rsync import:$!" if $?;
499
500 - `rm -fr $tmp/import`;
500 + rmtree("$tmp/import");
501 die "Cannot remove tempdir: $!" if $?;
502
503
@@ -507,10 +507,10 @@ sub apply_import {
507 sub apply_cset {
508 my $ps = shift;
509
510 - `mkdir -p $tmp`;
510 + mkpath($tmp);
511
512 # get the changeset
513 - `tla get-changeset -A $ps->{repo} $ps->{id} $tmp/changeset`;
513 + safe_pipe_capture($TLA,'get-changeset',$ps->{id},"$tmp/changeset");
514 die "Cannot get changeset: $!" if $?;
515
516 # apply patches
@@ -534,17 +534,20 @@ sub apply_cset {
534 $orig =~ s/\.modified$//; # lazy
535 $orig =~ s!^\Q$tmp\E/changeset/patches/!!;
536 #print "rsync -p '$mod' '$orig'";
537 - `rsync -p $mod ./$orig`;
537 + system('rsync','-p',$mod,"./$orig");
538 die "Problem applying binary changes! $!" if $?;
539 }
540 }
541
542 # bring in new files
543 - `rsync --archive --exclude '$git_dir' --exclude '.arch-ids' --exclude '{arch}' $tmp/changeset/new-files-archive/* ./`;
543 + system('rsync','-aI','--exclude',$git_dir,
544 + '--exclude','.arch-ids',
545 + '--exclude', '{arch}',
546 + "$tmp/changeset/new-files-archive/",'./');
547
548 # deleted files are hinted from the commitlog processing
549
547 - `rm -fr $tmp/changeset`;
550 + rmtree("$tmp/changeset");
551 }
552
553
@@ -622,9 +625,9 @@ sub parselog {
625 # tla cat-archive-log will give us filenames with spaces as file\(sp)name - why?
626 # we can assume that any filename with \ indicates some pika escaping that we want to get rid of.
627 if ($t =~ /\\/ ){
625 - $t = `tla escape --unescaped '$t'`;
628 + $t = (safe_pipe_capture($TLA,'escape','--unescaped',$t))[0];
629 }
627 - push (@tmp, shell_quote($t));
630 + push (@tmp, $t);
631 }
632 @$ref = @tmp;
633 }
@@ -827,8 +830,10 @@ sub find_parents {
830 }
831 }
832 }
830 - @parents = keys %parents;
831 - @parents = map { " -p " . ptag($_) } @parents;
833 + @parents = ();
834 + foreach (keys %parents) {
835 + push @parents, '-p', ptag($_);
836 + }
837 return @parents;
838 }
839