Skip to content

Commit a1d383c

Browse files
jlehmannpaulusmack
authored andcommitted
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 <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent e7d516b commit a1d383c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

gitk

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7509,7 +7509,7 @@ proc getblobdiffs {ids} {
75097509
global ignorespace
75107510
global limitdiffs vfilelimit curview
75117511
global diffencoding targetline diffnparents
7512-
global git_version
7512+
global git_version currdiffsubmod
75137513

75147514
set textconv {}
75157515
if {[package vcompare $git_version "1.6.1"] >= 0} {
@@ -7536,6 +7536,7 @@ proc getblobdiffs {ids} {
75367536
set diffencoding [get_path_encoding {}]
75377537
fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
75387538
set blobdifffd($ids) $bdf
7539+
set currdiffsubmod ""
75397540
filerun $bdf [list getblobdiffline $bdf $diffids]
75407541
}
75417542

@@ -7606,7 +7607,7 @@ proc getblobdiffline {bdf ids} {
76067607
global diffnexthead diffnextnote difffilestart
76077608
global ctext_file_names ctext_file_lines
76087609
global diffinhdr treediffs mergemax diffnparents
7609-
global diffencoding jump_to_here targetline diffline
7610+
global diffencoding jump_to_here targetline diffline currdiffsubmod
76107611

76117612
set nr 0
76127613
$ctext conf -state normal
@@ -7687,19 +7688,30 @@ proc getblobdiffline {bdf ids} {
76877688

76887689
} elseif {![string compare -length 10 "Submodule " $line]} {
76897690
# 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} {
76917697
$ctext insert end "\n"; # Add newline after commit message
76927698
}
76937699
set curdiffstart [$ctext index "end - 1c"]
76947700
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+
}
76997709
} elseif {![string compare -length 3 " >" $line]} {
7710+
set $currdiffsubmod ""
77007711
set line [encoding convertfrom $diffencoding $line]
77017712
$ctext insert end "$line\n" dresult
77027713
} elseif {![string compare -length 3 " <" $line]} {
7714+
set $currdiffsubmod ""
77037715
set line [encoding convertfrom $diffencoding $line]
77047716
$ctext insert end "$line\n" d0
77057717
} elseif {$diffinhdr} {
@@ -8535,7 +8547,7 @@ proc do_cmp_commits {a b} {
85358547
}
85368548

85378549
proc diffcommits {a b} {
8538-
global diffcontext diffids blobdifffd diffinhdr
8550+
global diffcontext diffids blobdifffd diffinhdr currdiffsubmod
85398551

85408552
set tmpdir [gitknewtmpdir]
85418553
set fna [file join $tmpdir "commit-[string range $a 0 7]"]
@@ -8556,6 +8568,7 @@ proc diffcommits {a b} {
85568568
set diffids [list commits $a $b]
85578569
set blobdifffd($diffids) $fd
85588570
set diffinhdr 0
8571+
set currdiffsubmod ""
85598572
filerun $fd [list getblobdiffline $fd $diffids]
85608573
}
85618574

0 commit comments

Comments
 (0)