git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-mv.perl: use stderr for error output and cleanup

From
Alex Riesen <raa.lkml@gmail.com>
Date
Jan 5, 2006, 11:49 UTC
Message-ID
<81b0412b0601050349s6bec1a36jc410fd315fbbc4c@mail.gmail.com>
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
It is cleaned up in the "Perl' meaning" of process: trivial loops
replaced with map{}
Subject: [PATCH] use stderr for error output and cleanup
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 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; $_; } <F>;
 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
Next: Junio C Hamano
Message 1 of 14 in “git-mv.perl: use stderr for error output and cleanup”
  1. git-mv.perl: use stderr for error output and cleanupAlex Riesen, Jan 5, 2006
  2. Junio C HamanoJan 6, 2006
  3. Randal L. SchwartzJan 6, 2006
  4. Linus TorvaldsJan 6, 2006
  5. Randal L. SchwartzJan 6, 2006
  6. Linus TorvaldsJan 7, 2006
  7. Junio C HamanoJan 7, 2006
  8. Alex RiesenJan 7, 2006
  9. Junio C HamanoJan 7, 2006
  10. Alex RiesenJan 10, 2006
  11. Randal L. SchwartzJan 7, 2006
  12. Junio C HamanoJan 7, 2006
  13. Andreas EricssonJan 8, 2006
  14. Alex RiesenJan 10, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.