# [PATCH RESEND] Teach gitk to display dirty submodules correctly

4 messages from 2010-04-09 to 2010-04-19. Participants: Jens Lehmann, Paul Mackerras, Junio C Hamano.
Thread: https://gitlist.dev/t/23400

## Jens Lehmann, 2010-04-09 20:16

Subject: [PATCH RESEND] Teach gitk to display dirty submodules correctly
Message-ID: <4BBF8B2A.5090208@web.de>
URL: https://gitlist.dev/e/4BBF8B2A.5090208%40web.de

```
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.

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

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(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 1f36a3e..36a9dcf 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -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]
 }

-- 
1.7.0.2.448.g45e29

```

## Paul Mackerras, 2010-04-17 08:56

Subject: Re: [PATCH RESEND] Teach gitk to display dirty submodules correctly
Message-ID: <20100417085600.GD6681@brick.ozlabs.ibm.com>
URL: https://gitlist.dev/e/20100417085600.GD6681%40brick.ozlabs.ibm.com
In-Reply-To: <4BBF8B2A.5090208@web.de>

```
On Fri, Apr 09, 2010 at 10:16:42PM +0200, Jens Lehmann wrote:

> 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.
> 
> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---

Thanks, applied.

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

Paul.

```

## Junio C Hamano, 2010-04-17 16:53

Subject: Re: [PATCH RESEND] Teach gitk to display dirty submodules correctly
Message-ID: <7vzl122f6k.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzl122f6k.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20100417085600.GD6681@brick.ozlabs.ibm.com>

```
Paul Mackerras <paulus@samba.org> writes:

> 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(-)

```

## Paul Mackerras, 2010-04-19 01:10

Subject: Re: [PATCH RESEND] Teach gitk to display dirty submodules correctly
Message-ID: <20100419011032.GB4386@brick.ozlabs.ibm.com>
URL: https://gitlist.dev/e/20100419011032.GB4386%40brick.ozlabs.ibm.com
In-Reply-To: <7vzl122f6k.fsf@alter.siamese.dyndns.org>

```
On Sat, Apr 17, 2010 at 09:53:55AM -0700, Junio C Hamano wrote:

> Thanks.  Is it a good time to pull?

Yes, I think so, thanks.

Paul.

```
