git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5/5] Implement 'l' command to display summaries.
@ 2008-11-27 21:10 William Pursell
  0 siblings, 0 replies; only message in thread
From: William Pursell @ 2008-11-27 21:10 UTC (permalink / raw)
  To: git



The summary information is in place to print out
the first added line (NEW), and the first removed
line (OLD), but it seems that just printing the
line number context is adequate.  Perhaps one
could add config options to print OLD and NEW,
but this seems good enough for now.
---
  git-add--interactive.perl |   25 ++++++++++++++++++++++++-
  1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index ae785e2..6a3d97d 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -824,6 +824,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
+l - print a brief summary of all the hunks in the file
  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
@@ -861,6 +862,24 @@ sub patch_update_cmd {
  	}
  }

+sub display_summaries {
+	my $index = shift;
+	my @hunk = @_;
+	my $i = 0;
+	print "'*' indicates current hunk.  '+' stage, '-' don't stage\n";
+	for ( ; $i < @hunk; $i++ ) {
+		my $status = " ";
+		if( defined $hunk[$i]{USE} ) {
+			$status = $hunk[$i]{USE} ? "+" : "-";
+		}
+		printf "%s%d%s: %s",
+			$i == $index ? "*" : " ",
+			$i,
+			$status,
+			$hunk[$i]{SUMMARY}{LINE};
+	}
+}
+
  sub patch_update_file {
  	my ($ix, $num);
  	my $path = shift;
@@ -904,7 +923,7 @@ sub patch_update_file {

  	while (1) {
  		my ($commands, $undecided, $i);
-		$commands = 'ynad';
+		$commands = 'ynald';

  		if ($num <= $ix) {
  			$ix = 0;
@@ -961,6 +980,10 @@ sub patch_update_file {
  				}
  				next;
  			}
+			elsif ($line =~ /^l/i) {
+				display_summaries ($ix, @hunk);
+				next;
+			}
  			elsif ($line =~ /^d/i) {
  				while ($ix < $num) {
  					if (!defined $hunk[$ix]{USE}) {
-- 
1.6.0.4.782.geea74.dirty


-- 
William Pursell

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-27 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-27 21:10 [PATCH 5/5] Implement 'l' command to display summaries William Pursell

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).