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

[PATCH 4/5] Adding SUMMARY lines to hunks.

From
William Pursell <bill.pursell@gmail.com>
Date
Nov 27, 2008, 21:10 UTC
Message-ID
<492F0CC4.7050805@gmail.com>
The idea is to add a command to allow the hunks to be listed
with a brief summary of each, with an option to determine
what the summary will entail.  The current thought is
to be able to display the line summary, the first new
line, and the first removed line.
---
  git-add--interactive.perl |   27 ++++++++++++++++++++++++++-
  1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 0d51cb2..ae785e2 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -553,7 +553,20 @@ sub parse_diff {

  	for (my $i = 0; $i < @diff; $i++) {
  		if ($diff[$i] =~ /^@@ /) {
-			push @hunk, { TEXT => [], DISPLAY => [] };
+			push @hunk,
+			{ TEXT => [], DISPLAY => [],
+				SUMMARY => {
+					 LINE => $diff[$i],
+					 NEW => undef,
+					 OLD => undef
+				}
+			};
+		}
+		if ($diff[$i] =~ /^\+/ and not $hunk[-1]{SUMMARY}{NEW}) {
+			$hunk[-1]{SUMMARY}{NEW} = $diff[$i];
+		}
+		if ($diff[$i] =~ /^-/ and not $hunk[-1]{SUMMARY}{OLD}) {
+			$hunk[-1]{SUMMARY}{OLD} = $diff[$i];
  		}
  		push @{$hunk[-1]{TEXT}}, $diff[$i];
  		push @{$hunk[-1]{DISPLAY}},
@@ -613,6 +626,11 @@ sub split_hunk {
  		my $this = +{
  			TEXT => [],
  			DISPLAY => [],
+			SUMMARY => {
+				 LINE => undef,
+				 NEW => undef,
+				 OLD => undef
+			},
  			OLD => $o_ofs,
  			NEW => $n_ofs,
  			OCNT => 0,
@@ -658,6 +676,12 @@ sub split_hunk {
  				push @split, $this;
  				redo OUTER;
  			}
+			if ($line =~ /\+/ and not $this->{SUMMARY}{NEW}) {
+				$this->{SUMMARY}{NEW} = $line;
+			}
+			if ($line =~ /-/ and not $this->{SUMMARY}{OLD}) {
+				$this->{SUMMARY}{OLD} = $line;
+			}
  			push @{$this->{TEXT}}, $line;
  			push @{$this->{DISPLAY}}, $display;
  			$this->{ADDDEL}++;
@@ -685,6 +709,7 @@ sub split_hunk {
  			    (($n_cnt != 1) ? ",$n_cnt" : '') .
  			    " @@\n");
  		my $display_head = $head;
+		$hunk->{SUMMARY}{LINE} = $head;
  		unshift @{$hunk->{TEXT}}, $head;
  		if ($diff_use_color) {
  			$display_head = colored($fraginfo_color, $head);
-- 
1.6.0.4.782.geea74.dirty


-- 
William Pursell
Message 1 of 1 in “Adding SUMMARY lines to hunks.”
  1. 4/5 Adding SUMMARY lines to hunks.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.