git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-mv.perl: use stderr for error output and cleanup
@ 2006-01-05 11:49 Alex Riesen
  2006-01-06 22:38 ` Junio C Hamano
  0 siblings, 1 reply; 14+ messages in thread
From: Alex Riesen @ 2006-01-05 11:49 UTC (permalink / raw)
  To: Junio C Hamano, git

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
It is cleaned up in the "Perl' meaning" of process: trivial loops
replaced with map{}

[-- Attachment #2: 0005-use-stderr-for-error-output-and-cleanup.txt --]
[-- Type: text/plain, Size: 3458 bytes --]

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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-01-10 22:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-05 11:49 [PATCH] git-mv.perl: use stderr for error output and cleanup Alex Riesen
2006-01-06 22:38 ` Junio C Hamano
2006-01-06 22:55   ` Randal L. Schwartz
2006-01-06 23:28     ` Linus Torvalds
2006-01-06 23:53       ` Randal L. Schwartz
2006-01-07  0:10         ` Linus Torvalds
2006-01-07  0:46       ` Junio C Hamano
2006-01-07 10:28     ` Alex Riesen
2006-01-07 10:29       ` Junio C Hamano
2006-01-10 22:24         ` Alex Riesen
2006-01-07 10:34       ` Randal L. Schwartz
2006-01-07 21:04         ` Junio C Hamano
2006-01-08  0:07           ` Andreas Ericsson
2006-01-10 22:26         ` Alex Riesen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).