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[PATCH 1/2]
Date: Wed, 03 Dec 2008 20:38:59 +0000 [thread overview]
Message-ID: <4936EE63.209@gmail.com> (raw)
In-Reply-To: <7vskp6j95x.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
> One thing I will not do after such a discussion, unless I am really really
> interested in having the new feature personally myself, is to go back to
> the discussion thread and assemble the pieces together to make the final
> series of patches for inclusion. The responsibility for doing that lies
> on the original contributor.
>
That is a perfectly reasonable policy, and I did not intend
to suggest that you should do that work. My apologies if
it seemed that way. Here is the first of 2 patches to
implement the 'g' command. I believe it is complete, but
I am not much for user interface. It works for me, but it
could be improved upon. (For example, I took your suggestion
and disallowed 'g' when there is only one hunk, but the
behavior feels clunky, although it is similar to an invalid
k/j entry.)
From de169b0062ae21f085d1309b4dd7da369029ae7d Mon Sep 17 00:00:00 2001
From: William Pursell <bill.pursell@gmail.com>
Date: Wed, 3 Dec 2008 20:25:31 +0000
Subject: [PATCH 1/2] Add subroutine to display one-line summary of hunks.
This commit implements a rather simple-minded mechanism
to display a one-line summary of the hunks in an array ref.
The display consists of the line numbers and the first
changed line, truncated to 80 characters. 20 lines are
displayed at a time, and the index of the first undisplayed
line is returned, allowing the caller to display more if
desired. (The 20 and 80 should be made configurable.)
Signed-off-by: William Pursell <bill.pursell@gmail.com>
---
git-add--interactive.perl | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b0223c3..daf8d5d 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -836,6 +836,45 @@ sub patch_update_cmd {
}
}
+# Generate a one line summary of a hunk.
+sub summarize_hunk {
+ my $rhunk = shift;
+ my $summary = $rhunk->{TEXT}[0];
+
+ # Keep the line numbers, discard extra context.
+ $summary =~ s/(@@.*@@).*/$1 /s;
+
+ # Add some user context. (Just take first changed line.)
+ for my $line (@{$rhunk->{TEXT}}) {
+ if ($line =~ m/^[+-]/) {
+ $summary .= $line;
+ last;
+ }
+ }
+
+ return substr ($summary, 0, 80);
+}
+
+
+# Print a one-line summary of each hunk in the array ref in
+# the first argument, starting wih the index in the 2nd.
+sub display_hunks {
+ my ($hunks, $i) = @_;
+ my $ctr = 0;
+ $i = 0 if not $i;
+ for (; $i < @$hunks && $ctr < 20; $i++, $ctr++) {
+ my $status = " ";
+ if (defined $hunks->[$i]{USE}) {
+ $status = $hunks->[$i]{USE} ? "+" : "-";
+ }
+ printf "%s%2d: %s",
+ $status,
+ $i + 1,
+ summarize_hunk ($hunks->[$i]);
+ }
+ return $i;
+}
+
sub patch_update_file {
my ($ix, $num);
my $path = shift;
--
1.6.1.rc1.37.g83daf.dirty
--
William Pursell
next prev parent reply other threads:[~2008-12-03 20:41 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
2008-11-29 0:22 ` William Pursell
2008-12-03 2:15 ` Junio C Hamano
2008-12-03 20:38 ` William Pursell [this message]
2008-12-03 23:22 ` summaries in git add --patch[PATCH 1/2] 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=4936EE63.209@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).