Skip to contentSkip to conversation

Teach gitk to display dirty submodules correctly

PATCH RESEND Applied Jens Lehmann 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 Teach gitk to display dirty submodules correctly

Since recently "git diff --submodule" prints out extra lines when the submodule contains untracked or modified files. Show all those lines of one submodule under the same header.

Also for newly added or removed submodules the submodule name contained trailing garbage because the extraction of the name was not done right.

---

I didn't receive a response in the last two weeks, so here is a resend.

No need to test for the version of the underlying git here, as the string "Submodule" does not appear in the diff output when older git versions are used and the changed code is not executed at all in this case (except for setting the new "currdiffsubmod" variable to the empty string, but that doesn't have any negative side effects).

 gitk-git/gitk |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)
gitk-git/gitk +21 -8
index 1f36a3e..36a9dcf 100644
@@ -7501,7 +7501,7 @@ proc getblobdiffs {ids} {
     global ignorespace
     global limitdiffs vfilelimit curview
     global diffencoding targetline diffnparents
-    global git_version
+    global git_version currdiffsubmod
 
     set textconv {}
     if {[package vcompare $git_version "1.6.1"] >= 0} {
@@ -7528,6 +7528,7 @@ proc getblobdiffs {ids} {
     set diffencoding [get_path_encoding {}]
     fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
     set blobdifffd($ids) $bdf
+    set currdiffsubmod ""
     filerun $bdf [list getblobdiffline $bdf $diffids]
 }
 
@@ -7598,7 +7599,7 @@ proc getblobdiffline {bdf ids} {
     global diffnexthead diffnextnote difffilestart
     global ctext_file_names ctext_file_lines
     global diffinhdr treediffs mergemax diffnparents
-    global diffencoding jump_to_here targetline diffline
+    global diffencoding jump_to_here targetline diffline currdiffsubmod
 
     set nr 0
     $ctext conf -state normal
@@ -7679,19 +7680,30 @@ proc getblobdiffline {bdf ids} {
 
 	} elseif {![string compare -length 10 "Submodule " $line]} {
 	    # start of a new submodule
-	    if {[string compare [$ctext get "end - 4c" end] "\n \n\n"]} {
+	    if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
+		set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
+	    } else {
+		set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
+	    }
+	    if {$currdiffsubmod != $fname} {
 		$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
+	    if {$currdiffsubmod != $fname} {
+		lappend ctext_file_lines $fname
+		makediffhdr $fname $ids
+		set currdiffsubmod $fname
+		$ctext insert end "\n$line\n" filesep
+	    } else {
+		$ctext insert end "$line\n" filesep
+	    }
 	} elseif {![string compare -length 3 "  >" $line]} {
+	    set $currdiffsubmod ""
 	    set line [encoding convertfrom $diffencoding $line]
 	    $ctext insert end "$line\n" dresult
 	} elseif {![string compare -length 3 "  <" $line]} {
+	    set $currdiffsubmod ""
 	    set line [encoding convertfrom $diffencoding $line]
 	    $ctext insert end "$line\n" d0
 	} elseif {$diffinhdr} {
@@ -8527,7 +8539,7 @@ proc do_cmp_commits {a b} {
 }
 
 proc diffcommits {a b} {
-    global diffcontext diffids blobdifffd diffinhdr
+    global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
 
     set tmpdir [gitknewtmpdir]
     set fna [file join $tmpdir "commit-[string range $a 0 7]"]
@@ -8548,6 +8560,7 @@ proc diffcommits {a b} {
     set diffids [list commits $a $b]
     set blobdifffd($diffids) $fd
     set diffinhdr 0
+    set currdiffsubmod ""
     filerun $fd [list getblobdiffline $fd $diffids]
 }
 
Signature · 1 line
1.7.0.2.448.g45e29
#1 lore raw
Quoted 9 lines · Jens Lehmann

Since recently "git diff --submodule" prints out extra lines when the submodule contains untracked or modified files. Show all those lines of one submodule under the same header.

Also for newly added or removed submodules the submodule name contained trailing garbage because the extraction of the name was not done right.

---

Thanks, applied.

I changed the subject line to "gitk: Display dirty submodules correctly" to fit in with the usual style.

Paul.

#2 lore raw
Quoted 1 line · Paul Mackerras

Thanks, applied.

Thanks. Is it a good time to pull?

Here are the list of things that I would be getting if I did so:

Jens Lehmann (2):
gitk: Add Ctrl-W shortcut for closing the active window
gitk: Display dirty submodules correctly

Jonathan Nieder (2):
gitk: Add comments to explain encode_view_opts and decode_view_opts
gitk: Don't clobber "Remember this view" setting

Mark Hills (4):
gitk: Remove forced use of sans-serif font
gitk: Set the font for all spinbox widgets
gitk: Set the font for all listbox widgets
gitk: Use consistent font for all text input fields

Pat Thoyts (3):
gitk: Avoid calling tk_setPalette on Windows
gitk: Add emacs editor variable block
gitk: Fix display of copyright symbol

 gitk-git/gitk     |   72 ++++++++++++++++++++++++++++++++--------------------
 gitk-git/po/de.po |    4 +-
 gitk-git/po/es.po |    4 +-
 gitk-git/po/fr.po |    4 +-
 gitk-git/po/hu.po |    4 +-
 gitk-git/po/it.po |    4 +-
 gitk-git/po/ja.po |    4 +-
 gitk-git/po/ru.po |    4 +-
 gitk-git/po/sv.po |    4 +-
 9 files changed, 60 insertions(+), 44 deletions(-)
#3 lore raw
Quoted 1 line · Junio C Hamano

Thanks. Is it a good time to pull?

Yes, I think so, thanks.

Paul.