Subject: [PATCH] use stderr for error output and cleanup Signed-off-by: Alex Riesen --- git-mv.perl | 38 ++++++++++++++------------------------ 1 files changed, 14 insertions(+), 24 deletions(-) 487484f85df999ad949123800e1ab4a24458370b diff --git a/git-mv.perl b/git-mv.perl index 83dc7e4..5e7addf 100755 --- a/git-mv.perl +++ b/git-mv.perl @@ -37,7 +37,7 @@ if (-d $ARGV[$argCount-1]) { # remove any trailing slash $dstDir =~ s/\/$//; @srcArgs = @ARGV[0..$argCount-2]; - + foreach $src (@srcArgs) { $base = $src; $base =~ s/^.*\///; @@ -47,10 +47,9 @@ if (-d $ARGV[$argCount-1]) { } else { if ($argCount != 2) { - print "Error: moving to directory '" + die "Error: moving to directory '" . $ARGV[$argCount-1] - . "' not possible; not exisiting\n"; - exit(1); + . "' not possible; not existing\n"; } @srcArgs = ($ARGV[0]); @dstArgs = ($ARGV[1]); @@ -63,7 +62,7 @@ my (%overwritten, %srcForDst); $/ = "\0"; open(F, 'git-ls-files -z |') - or die "Failed to open pipe from git-ls-files: " . $!; + or die "Failed to open pipe from git-ls-files: $!\n"; @allfiles = map { chomp; $_; } ; close(F); @@ -92,7 +91,7 @@ while(scalar @srcArgs > 0) { if ($opt_f) { # only files can overwrite each other: check both source and destination if (-f $dst && (scalar @srcfiles == 1)) { - print "Warning: $bad; will overwrite!\n"; + warn "Warning: $bad; will overwrite!\n"; $bad = ""; $overwritten{$dst} = 1; } @@ -101,7 +100,7 @@ while(scalar @srcArgs > 0) { } } } - + if (($bad eq "") && ($dst =~ /^$safesrc\//)) { $bad = "can not move directory '$src' into itself"; } @@ -124,11 +123,10 @@ while(scalar @srcArgs > 0) { if ($bad ne "") { if ($opt_k) { - print "Warning: $bad; skipping\n"; + warn "Warning: $bad; skipping\n"; next; } - print "Error: $bad\n"; - exit(1); + die "Error: $bad\n"; } push @srcs, $src; push @dsts, $dst; @@ -146,7 +144,7 @@ while(scalar @srcs > 0) { if (!rename($src,$dst)) { $bad = "renaming '$src' failed: $!"; if ($opt_k) { - print "Warning: skipped: $bad\n"; + warn "Warning: skipped: $bad\n"; $bad = ""; next; } @@ -162,6 +160,7 @@ while(scalar @srcs > 0) { push @deletedfiles, @srcfiles; if (scalar @srcfiles == 1) { # $dst can be a directory with 1 file inside + if ($overwritten{$dst} ==1) { push @changedfiles, $dstfiles[0]; @@ -189,30 +188,21 @@ else { if (@changedfiles) { open(H, "| git-update-index -z --stdin") or die "git-update-index failed to update changed files with code $!\n"; - foreach my $fileName (@changedfiles) { - print H "$fileName\0"; - } + print H map {"$_\0"} @changedfiles; close(H); } if (@addedfiles) { open(H, "| git-update-index --add -z --stdin") or die "git-update-index failed to add new names with code $!\n"; - foreach my $fileName (@addedfiles) { - print H "$fileName\0"; - } + print H map {"$_\0"} @addedfiles; close(H); } if (@deletedfiles) { open(H, "| git-update-index --remove -z --stdin") or die "git-update-index failed to remove old names with code $!\n"; - foreach my $fileName (@deletedfiles) { - print H "$fileName\0"; - } + print H map {"$_\0"} @deletedfiles; close(H); } } -if ($bad ne "") { - print "Error: $bad\n"; - exit(1); -} +die "Error: $bad\n" if $bad ne ""; -- 1.0.GIT