Re: [PATCH 1/4] Suppress spurious linefeeds in git-add--interactive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



El 22/11/2007, a las 9:59, Jeff King escribió:

On Thu, Nov 22, 2007 at 01:02:50AM +0100, Wincent Colaiuta wrote:

+	return undef if ($#diff == -1);

Style nit: I think the rest of the code generally uses (and I prefer)
"@diff" to get the number of elements. So:

 return undef unless @diff;

or I might even have written

 my @diff = ...
   or return undef;

but perhaps I am the only one who finds $#array comparisons to -1 hard
on the eyes.

No, I agree with you; it does read nicer. I'm not a real Perl programmer, so everything I do I have to do it with a copy of "Programming Perl" next to me to find out how to do things. It's handy to have advice from people more familiar with the idioms. Will incorporate something like this into the series:

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index a5a07bc..0a8f0a9 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -60,7 +60,7 @@ sub list_modified {
 		defined run_cmd_pipe(qw(git ls-files
 			                --exclude-standard --), $_)
 	} @ARGV;
-	return if $#tracked == -1 && $#ARGV != -1;
+	return if !@tracked && @ARGV;

 	for (run_cmd_pipe(qw(git diff-index --cached
 			     --numstat --summary HEAD --), @tracked)) {
@@ -340,8 +340,8 @@ sub add_untracked_cmd {

 sub parse_diff {
 	my ($path) = @_;
-	my @diff = run_cmd_pipe(qw(git diff-files -p --), $path);
-	return undef if ($#diff == -1);
+	my @diff = run_cmd_pipe(qw(git diff-files -p --), $path)
+	    or return undef;
 	my (@hunk) = { TEXT => [] };

 	for (@diff) {



Cheers,
Wincent

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux