From: Junio C Hamano <gitster@pobox.com>
To: William Pursell <bill.pursell@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: summaries in git add --patch
Date: Thu, 27 Nov 2008 23:24:35 -0800 [thread overview]
Message-ID: <7v8wr48g98.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <492F92C9.7030301@gmail.com> (William Pursell's message of "Fri, 28 Nov 2008 06:42:17 +0000")
William Pursell <bill.pursell@gmail.com> writes:
> Here's a new patch. Instead of displaying the summary and then
> the current hunk, it implements a 'goto' command.
I take it that this is for discussion not for immediate inclusion.
> @@ -799,6 +801,7 @@ sub help_patch_cmd {
> y - stage this hunk
> n - do not stage this hunk
> a - stage this and all the remaining hunks in the file
> +g - select a hunk to jump to
> d - do not stage this hunk nor any of the remaining hunks in the file
> j - leave this hunk undecided, see next undecided hunk
> J - leave this hunk undecided, see next hunk
Since you took 'g' after "go to", help text should also say "go to",
instead of "jump to" for the mnemonics value, iow, to help people
remember.
> @@ -836,6 +839,27 @@ sub patch_update_cmd {
> }
> }
>
> +sub select_new_hunk {
> + my $ri = shift;
> + my @hunk = @_;
> + my ($i, $response);
> + print " '+' stage, '-' don't stage\n";
> + for ( $i = 0; $i < @hunk; $i++ ) {
> + my $status = " ";
> + if( defined $hunk[$i]{USE} ) {
> + $status = $hunk[$i]{USE} ? "+" : "-";
> + }
Style.
(1) SP between language construct and open parenthesis, as opposed to
no extra SP between function name and open parenthesis;
(2) No extra SP around what is enclosed in parentheses.
> + printf "%s%3d: %s",
> + $status,
> + $i + 1,
> + $hunk[$i]{SUMMARY};
> + }
I think this "for ()" loop part, including the comment about +/- notation,
should be separated into a function so that you can implement a separate
"l"ist command like you did in the other patch, using the same function.
> + printf "goto which hunk? ";
> + $response = <STDIN>;
> + chomp $response;
> + $$ri = $response - 1;
What happens when $response is (1) a non number, (2) outside range (both
negative and positive), or (3) EOF?
Sending ref to scalar and returning the value by assigning is a bad taste.
Why shouldn't this function just return an integer to be assigned to $ix
by the caller? If you want to use pass-by-ref to show off your Perl-fu, I
think \@hunk would be what you would want to for performance reasons.
> @@ -919,7 +943,7 @@ sub patch_update_file {
> for (@{$hunk[$ix]{DISPLAY}}) {
> print;
> }
> - print colored $prompt_color, "Stage this hunk [y/n/a/d$other/?]? ";
> + print colored $prompt_color, "Stage this hunk [y/n/a/d/g$other/?]? ";
When there is only one hunk, we do not give j nor k. Should we give g in
such a case? Why?
> @@ -937,6 +961,16 @@ sub patch_update_file {
> }
> next;
> }
> + elsif ($line =~ /^g/) {
> + chomp ($line);
> + if ($line =~ /^g$/) {
> + select_new_hunk (\$ix, @hunk);
> + }
> + else {
> + $ix = (substr $line, 1) - 1;
> + }
The same "input validation" issue exists here. it would make sense to:
- Make choose_hunk(@hunk) that calls list_hunks(@hunk) that gives the
summary, reads one line, and returns that line;
- Make the caller here to look like this:
elsif ($line =~ s/^g//) {
chomp($line);
if ($line eq '') {
$line = choose_hunk(@hunk);
}
if ($line !~ /^\d+$/) {
print STDERR "Eh '$line', what number is that?\n";
next;
} elsif (0 < $line && $line <= $num) {
$ix = $line - 1;
} else {
print STDERR "Sorry, you have only $num hunks\n";
}
}
> + next;
> + }
> elsif ($line =~ /^d/i) {
> while ($ix < $num) {
> if (!defined $hunk[$ix]{USE}) {
>
>
> --
> William Pursell
next prev parent reply other threads:[~2008-11-28 7:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-27 21:10 summaries in git add --patch William Pursell
2008-11-27 21:27 ` Jakub Narebski
2008-11-28 0:34 ` Junio C Hamano
2008-11-28 4:36 ` William Pursell
2008-11-28 6:42 ` William Pursell
2008-11-28 7:24 ` Junio C Hamano [this message]
2008-11-29 0:22 ` William Pursell
2008-12-03 2:15 ` Junio C Hamano
2008-12-03 20:38 ` summaries in git add --patch[PATCH 1/2] William Pursell
2008-12-03 23:22 ` Junio C Hamano
2008-12-04 6:55 ` William Pursell
2008-12-04 8:47 ` Junio C Hamano
2008-12-04 10:43 ` William Pursell
2008-12-05 2:23 ` Junio C Hamano
2008-12-03 20:39 ` summaries in git add --patch[PATCH 2/2] William Pursell
2008-12-03 23:23 ` Junio C Hamano
2008-12-04 6:56 ` William Pursell
2008-12-04 9:00 ` Junio C Hamano
2008-12-04 10:43 ` William Pursell
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=7v8wr48g98.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=bill.pursell@gmail.com \
--cc=git@vger.kernel.org \
/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).