@matheusbsbs / matheus-bagliano / commits / a1d383c5ab
Fork 0

gitk: 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. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Paul Mackerras <paulus@samba.org>

Jens Lehmann committed Apr 9, 2010 at 22:16 UTC a1d383c5ab90ec19c8a77158f65e5ea7d61fb42c
1 file changed +21 -8
gitk
+21 -8
@@ -7509,7 +7509,7 @@ proc getblobdiffs {ids} {
7509 global ignorespace
7510 global limitdiffs vfilelimit curview
7511 global diffencoding targetline diffnparents
7512 - global git_version
7512 + global git_version currdiffsubmod
7513
7514 set textconv {}
7515 if {[package vcompare $git_version "1.6.1"] >= 0} {
@@ -7536,6 +7536,7 @@ proc getblobdiffs {ids} {
7536 set diffencoding [get_path_encoding {}]
7537 fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
7538 set blobdifffd($ids) $bdf
7539 + set currdiffsubmod ""
7540 filerun $bdf [list getblobdiffline $bdf $diffids]
7541 }
7542
@@ -7606,7 +7607,7 @@ proc getblobdiffline {bdf ids} {
7607 global diffnexthead diffnextnote difffilestart
7608 global ctext_file_names ctext_file_lines
7609 global diffinhdr treediffs mergemax diffnparents
7609 - global diffencoding jump_to_here targetline diffline
7610 + global diffencoding jump_to_here targetline diffline currdiffsubmod
7611
7612 set nr 0
7613 $ctext conf -state normal
@@ -7687,19 +7688,30 @@ proc getblobdiffline {bdf ids} {
7688
7689 } elseif {![string compare -length 10 "Submodule " $line]} {
7690 # start of a new submodule
7690 - if {[string compare [$ctext get "end - 4c" end] "\n \n\n"]} {
7691 + if {[regexp -indices "\[0-9a-f\]+\\.\\." $line nameend]} {
7692 + set fname [string range $line 10 [expr [lindex $nameend 0] - 2]]
7693 + } else {
7694 + set fname [string range $line 10 [expr [string first "contains " $line] - 2]]
7695 + }
7696 + if {$currdiffsubmod != $fname} {
7697 $ctext insert end "\n"; # Add newline after commit message
7698 }
7699 set curdiffstart [$ctext index "end - 1c"]
7700 lappend ctext_file_names ""
7695 - set fname [string range $line 10 [expr [string last " " $line] - 1]]
7696 - lappend ctext_file_lines $fname
7697 - makediffhdr $fname $ids
7698 - $ctext insert end "\n$line\n" filesep
7701 + if {$currdiffsubmod != $fname} {
7702 + lappend ctext_file_lines $fname
7703 + makediffhdr $fname $ids
7704 + set currdiffsubmod $fname
7705 + $ctext insert end "\n$line\n" filesep
7706 + } else {
7707 + $ctext insert end "$line\n" filesep
7708 + }
7709 } elseif {![string compare -length 3 " >" $line]} {
7710 + set $currdiffsubmod ""
7711 set line [encoding convertfrom $diffencoding $line]
7712 $ctext insert end "$line\n" dresult
7713 } elseif {![string compare -length 3 " <" $line]} {
7714 + set $currdiffsubmod ""
7715 set line [encoding convertfrom $diffencoding $line]
7716 $ctext insert end "$line\n" d0
7717 } elseif {$diffinhdr} {
@@ -8535,7 +8547,7 @@ proc do_cmp_commits {a b} {
8547 }
8548
8549 proc diffcommits {a b} {
8538 - global diffcontext diffids blobdifffd diffinhdr
8550 + global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
8551
8552 set tmpdir [gitknewtmpdir]
8553 set fna [file join $tmpdir "commit-[string range $a 0 7]"]
@@ -8556,6 +8568,7 @@ proc diffcommits {a b} {
8568 set diffids [list commits $a $b]
8569 set blobdifffd($diffids) $fd
8570 set diffinhdr 0
8571 + set currdiffsubmod ""
8572 filerun $fd [list getblobdiffline $fd $diffids]
8573 }
8574