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

[PATCH 4/6] gitweb: Create special from-file/to-file header for combined diff

From
Jakub Narebski <jnareb@gmail.com>
Date
Jun 8, 2007, 11:29 UTC
Message-ID
<20070608112747.3594.81616.stgit@roke.D-201>
In-Reply-To
<20070608112337.3594.93976.stgit@roke.D-201>

Instead of using default, diff(1) like from-file/to-file header for combined diff (for a merge commit), which looks like:

  --- a/git-gui/git-gui.sh
  +++ b/_git-gui/git-gui.sh_

(where _link_ denotes [hidden] hyperlink), create from-file(n)/to-file header, using "--- <n>/_<filename>_" for each of parents, e.g.:

  --- 1/_git-gui/git-gui.sh_
  --- 2/_git-gui.sh_
  +++ b/_git-gui/git-gui.sh_
Test it on one of merge commits involving rename, e.g.
  95f97567c1887d77f3a46b42d8622c76414d964d (rename at top)
  5bac4a671907604b5fb4e24ff682d5b0e8431931 (file from one branch)
This is mainly meant to easier see renames in a merge commit.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Junio and Pasky likes this, and were source of inspiration for
the next patch.
 gitweb/gitweb.perl |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index aee4f23..13114bc 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1064,19 +1064,35 @@ sub format_diff_from_to_header {
 
 	$line = $from_line;
 	#assert($line =~ m/^---/) if DEBUG;
-	# no extra formatting "^--- /dev/null"
-	if ($line =~ m!^--- "?a/!) {
-		if (!$diffinfo->{'nparents'} && # multiple 'from'
-		    $from->{'href'}) {
-			$line = '--- a/' .
-			        $cgi->a({-href=>$from->{'href'}, -class=>"path"},
-			                esc_path($from->{'file'}));
-		} else {
-			$line = '--- a/' .
-			        esc_path($from->{'file'});
+	# no extra formatting for "^--- /dev/null"
+	if (! $diffinfo->{'nparents'}) {
+		# ordinary (single parent) diff
+		if ($line =~ m!^--- "?a/!) {
+			if ($from->{'href'}) {
+				$line = '--- a/' .
+				        $cgi->a({-href=>$from->{'href'}, -class=>"path"},
+				                esc_path($from->{'file'}));
+			} else {
+				$line = '--- a/' .
+				        esc_path($from->{'file'});
+			}
+		}
+		$result .= qq!<div class="diff from_file">$line</div>\n!;
+
+	} else {
+		# combined diff (merge commit)
+		for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
+			if ($from->{'href'}[$i]) {
+				$line = '--- ' .
+				        ($i+1) . "/" .
+				        $cgi->a({-href=>$from->{'href'}[$i], -class=>"path"},
+				                esc_path($from->{'file'}[$i]));
+			} else {
+				$line = '--- /dev/null';
+			}
+			$result .= qq!<div class="diff from_file">$line</div>\n!;
 		}
 	}
-	$result .= qq!<div class="diff from_file">$line</div>\n!;
 
 	$line = $to_line;
 	#assert($line =~ m/^\+\+\+/) if DEBUG;
Previous: Jakub NarebskiNext: Jakub Narebski
Message 5 of 8 in “gitweb: 'commitdiff' view improvements”
  1. 0/6 gitweb: 'commitdiff' view improvementsJakub Narebski, Jun 8, 2007
  2. 1/6 gitweb: Provide links to commitdiff to each parent in 'commitdiff' viewJakub Narebski, Jun 8, 2007
  3. 2/6 gitweb: Improve "next" link in commitdiff viewJakub Narebski, Jun 8, 2007
  4. 3/6 gitweb: Split git_patchset_body into separate subroutinesJakub Narebski, Jun 8, 2007
  5. 4/6 gitweb: Create special from-file/to-file header for combined diffJakub Narebski, Jun 8, 2007
  6. 5/6 gitweb: Add links to blobdiffs in from-file/to-file header for mergesJakub Narebski, Jun 8, 2007
  7. 6/6 gitweb: '--cc' for merges in 'commitdiff' viewJakub Narebski, Jun 8, 2007
  8. Junio C HamanoJun 11, 2007

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.