From: Alex Riesen <raa.lkml@gmail.com>
To: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: [PATCH] git-mv.perl: use stderr for error output and cleanup
Date: Thu, 5 Jan 2006 12:49:45 +0100 [thread overview]
Message-ID: <81b0412b0601050349s6bec1a36jc410fd315fbbc4c@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2006-01-05 11:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-05 11:49 Alex Riesen [this message]
2006-01-06 22:38 ` [PATCH] git-mv.perl: use stderr for error output and cleanup 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81b0412b0601050349s6bec1a36jc410fd315fbbc4c@mail.gmail.com \
--to=raa.lkml@gmail.com \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).