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

[PATCH v2] gitk: Use the --submodule option for displaying diffs when available

From
Jens Lehmann <jens.lehmann@web.de>
Date
Oct 28, 2009, 11:40 UTC
Message-ID
<4AE82DBD.5070202@web.de>
In-Reply-To
<19175.49800.697048.349753@drongo.ozlabs.ibm.com>

Instead of just showing not-quite-helpful SHA-1 pairs in the diff display of a submodule gitk will display the first lines of the corresponding commit messages (similar to the output of 'git submodule summary') when the underlying git installation supports this. That makes it much easier to evaluate the changes, as it eliminates the need to start a gitk inside the submodule and use the superprojects hashes there to find out what the commits are about.

This patch applies to 'next' - which will be 1.6.6 or 1.7.0 when merged - and uses the new --submodule option of git diff when a version of 1.6.6 or higher is detected to achieve a more human readable output of submodule differences in gitk.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---

Thanks for the review of the first version of this patch. I tried to address all the issues raised and moved the additions of the --submodule flag to the getblobdiffs procedure, where the --textconv flag is handled too.

 gitk-git/gitk |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index a0214b7..b06cac7 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7343,7 +7343,11 @@ proc getblobdiffs {ids} {
     if {[package vcompare $git_version "1.6.1"] >= 0} {
 	set textconv "--textconv"
     }
-    set cmd [diffcmd $ids "-p $textconv -C --cc --no-commit-id -U$diffcontext"]
+    set submodule {}
+    if {[package vcompare $git_version "1.6.6"] >= 0} {
+	set submodule "--submodule"
+    }
+    set cmd [diffcmd $ids "-p $textconv $submodule  -C --cc --no-commit-id -U$diffcontext"]
     if {$ignorespace} {
 	append cmd " -w"
     }
@@ -7481,6 +7485,21 @@ proc getblobdiffline {bdf ids} {
 	    set diffnparents [expr {[string length $ats] - 1}]
 	    set diffinhdr 0

+	} elseif {![string compare -length 10 "Submodule " $line]} {
+	    # start of a new submodule
+	    if {[string compare [$ctext get "end - 4c" end] "\n \n\n"]} {
+		$ctext insert end "\n";     # Add newline after commit message
+	    }
+	    set curdiffstart [$ctext index "end - 1c"]
+	    lappend ctext_file_names ""
+	    set fname [string range $line 10 [expr [string last " " $line] - 1]]
+	    lappend ctext_file_lines $fname
+	    makediffhdr $fname $ids
+	    $ctext insert end "\n$line\n" filesep
+	} elseif {![string compare -length 3 "  >" $line]} {
+	    $ctext insert end "$line\n" dresult
+	} elseif {![string compare -length 3 "  <" $line]} {
+	    $ctext insert end "$line\n" d0
 	} elseif {$diffinhdr} {
 	    if {![string compare -length 12 "rename from " $line]} {
 		set fname [string range $line [expr 6 + [string first " from " $line] ] end]
-- 
1.6.5.2.182.g3d976.dirty
Previous: Paul MackerrasNext: Paul Mackerras
Message 4 of 6 in “gitk: Use the --submodule option for diffs”
  1. gitk: Use the --submodule option for diffsJens Lehmann, Oct 27, 2009
  2. Johannes SchindelinOct 27, 2009
  3. Paul MackerrasOct 28, 2009
  4. gitk: Use the --submodule option for displaying diffs when availableJens Lehmann, Oct 28, 2009
  5. Paul MackerrasNov 3, 2009
  6. Junio C HamanoOct 28, 2009

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.