threads / patch / 16507

patch, 5 partsAdding SUMMARY lines to hunks.

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

## tl;dr

One message between Nov 27, 2008 and Nov 27, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

William Pursell· Nov 27, 2008, 21:10 UTC · lore
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(-)
Show changes to git-add--interactive.perl +26 −1
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

← back to recent threads