git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
William Pursell <bill.pursell@gmail.com>
Date
Nov 27, 2008, 21:10 UTC
Message-ID
<492F0CCA.20905@gmail.com>
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
Message 1 of 1 in “Implement 'l' command to display summaries.”
  1. 5/5 Implement 'l' command to display summaries.William Pursell, Nov 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.