From: William Pursell <bill.pursell@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: summaries in git add --patch
Date: Fri, 28 Nov 2008 06:42:17 +0000 [thread overview]
Message-ID: <492F92C9.7030301@gmail.com> (raw)
In-Reply-To: <7viqq8adsf.fsf@gitster.siamese.dyndns.org>
Here's a new patch. Instead of displaying the summary and then
the current hunk, it implements a 'goto' command. It prints the
summary and then prompts for the index of the hunk to jump to.
By not printing the current hunk, the list should typically
stay on screen. Also, the summary is optional, so:
g -- bring up summary and prompt for index
g3 -- jump to hunk 3
commit 510edf7c28fcc571f29106e32f2570d5f2e04fc3
Author: William Pursell <bill.pursell@gmail.com>
Date: Fri Nov 28 06:22:36 2008 +0000
Implement 'g' command (goto) in add --patch
This command prints a summary of the hunks in the current
file and prompts the user for an index of the hunk to make
current.
Signed-off-by: William Pursell <bill.pursell@gmail.com>
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b0223c3..e6d73a0 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -553,7 +553,7 @@ sub parse_diff {
for (my $i = 0; $i < @diff; $i++) {
if ($diff[$i] =~ /^@@ /) {
- push @hunk, { TEXT => [], DISPLAY => [] };
+ push @hunk, { TEXT => [], DISPLAY => [], SUMMARY => $diff[$i] };
}
push @{$hunk[-1]{TEXT}}, $diff[$i];
push @{$hunk[-1]{DISPLAY}},
@@ -685,6 +685,7 @@ sub split_hunk {
(($n_cnt != 1) ? ",$n_cnt" : '') .
" @@\n");
my $display_head = $head;
+ $hunk->{SUMMARY} = $head;
unshift @{$hunk->{TEXT}}, $head;
if ($diff_use_color) {
$display_head = colored($fraginfo_color, $head);
@@ -783,6 +784,7 @@ sub edit_hunk_loop {
$newhunk,
@{$hunk}[$ix+1..$#{$hunk}])) {
$newhunk->{DISPLAY} = [color_diff(@{$text})];
+ $newhunk->{SUMMARY} = $$text[0];
return $newhunk;
}
else {
@@ -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
@@ -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} ? "+" : "-";
+ }
+ printf "%s%3d: %s",
+ $status,
+ $i + 1,
+ $hunk[$i]{SUMMARY};
+ }
+ printf "goto which hunk? ";
+ $response = <STDIN>;
+ chomp $response;
+ $$ri = $response - 1;
+}
+
sub patch_update_file {
my ($ix, $num);
my $path = shift;
@@ -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/?]? ";
my $line = <STDIN>;
if ($line) {
if ($line =~ /^y/i) {
@@ -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;
+ }
+ next;
+ }
elsif ($line =~ /^d/i) {
while ($ix < $num) {
if (!defined $hunk[$ix]{USE}) {
--
William Pursell
next prev parent reply other threads:[~2008-11-28 6:43 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 [this message]
2008-11-28 7:24 ` Junio C Hamano
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=492F92C9.7030301@gmail.com \
--to=bill.pursell@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).