Subject: [PATCH 5/5] Implement 'l' command to display summaries.

From: William Pursell <[email-masked]>
Date: Thu, 27 Nov 2008 21:10:34 +0000

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