Skip to content

Commit 6f63fc1

Browse files
committed
gitk: Fix compare-commits function when we have local changes
This fixes a bug in the compare-commits function added in commit 010509f ("gitk: Add a command to compare two strings of commits") where gitk would show an error dialog if the comparison of commits got to a fake commit (one showing local changes). It extends getpatchid to handle these fake commits by using [diffcmd] to get the git diff command variant to use, and also handles the situation where an error occurs. Now that we can have the fake commit IDs showing up, which are 00..00 and 00..01, the short ID is ambiguous. To make sure the links point to the right commit, this adds a new [appendshortlink] procedure which takes the full link destination, and uses that rather than appendwithlinks. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 478afad commit 6f63fc1

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

gitk

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6489,6 +6489,17 @@ proc setlink {id lk} {
64896489
}
64906490
}
64916491

6492+
proc appendshortlink {id {pre {}} {post {}}} {
6493+
global ctext linknum
6494+
6495+
$ctext insert end $pre
6496+
$ctext tag delete link$linknum
6497+
$ctext insert end [string range $id 0 7] link$linknum
6498+
$ctext insert end $post
6499+
setlink $id link$linknum
6500+
incr linknum
6501+
}
6502+
64926503
proc makelink {id} {
64936504
global pendinglinks
64946505

@@ -8127,8 +8138,15 @@ proc getpatchid {id} {
81278138
global patchids
81288139

81298140
if {![info exists patchids($id)]} {
8130-
set x [exec git diff-tree -p --root $id | git patch-id]
8131-
set patchids($id) [lindex $x 0]
8141+
set cmd [diffcmd [list $id] {-p --root}]
8142+
# trim off the initial "|"
8143+
set cmd [lrange $cmd 1 end]
8144+
if {[catch {
8145+
set x [eval exec $cmd | git patch-id]
8146+
set patchids($id) [lindex $x 0]
8147+
}]} {
8148+
set patchids($id) "error"
8149+
}
81328150
}
81338151
return $patchids($id)
81348152
}
@@ -8140,58 +8158,68 @@ proc do_cmp_commits {a b} {
81408158
clear_ctext
81418159
init_flist {}
81428160
for {set i 0} {$i < 100} {incr i} {
8143-
set shorta [string range $a 0 7]
8144-
set shortb [string range $b 0 7]
81458161
set skipa 0
81468162
set skipb 0
81478163
if {[llength $parents($curview,$a)] > 1} {
8148-
appendwithlinks [mc "Skipping merge commit %s\n" $shorta] {}
8164+
appendshortlink $a [mc "Skipping merge commit "] "\n"
81498165
set skipa 1
81508166
} else {
81518167
set patcha [getpatchid $a]
81528168
}
81538169
if {[llength $parents($curview,$b)] > 1} {
8154-
appendwithlinks [mc "Skipping merge commit %s\n" $shortb] {}
8170+
appendshortlink $b [mc "Skipping merge commit "] "\n"
81558171
set skipb 1
81568172
} else {
81578173
set patchb [getpatchid $b]
81588174
}
81598175
if {!$skipa && !$skipb} {
81608176
set heada [lindex $commitinfo($a) 0]
81618177
set headb [lindex $commitinfo($b) 0]
8178+
if {$patcha eq "error"} {
8179+
appendshortlink $a [mc "Error getting patch ID for "] \
8180+
[mc " - stopping\n"]
8181+
break
8182+
}
8183+
if {$patchb eq "error"} {
8184+
appendshortlink $b [mc "Error getting patch ID for "] \
8185+
[mc " - stopping\n"]
8186+
break
8187+
}
81628188
if {$patcha eq $patchb} {
81638189
if {$heada eq $headb} {
8164-
appendwithlinks [mc "Commit %s == %s %s\n" \
8165-
$shorta $shortb $heada] {}
8190+
appendshortlink $a [mc "Commit "]
8191+
appendshortlink $b " == " " $heada\n"
81668192
} else {
8167-
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
8168-
appendwithlinks [mc " is the same patch as\n"] {}
8169-
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
8193+
appendshortlink $a [mc "Commit "] " $heada\n"
8194+
appendshortlink $b [mc " is the same patch as\n "] \
8195+
" $headb\n"
81708196
}
81718197
set skipa 1
81728198
set skipb 1
81738199
} else {
81748200
$ctext insert end "\n"
8175-
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
8176-
appendwithlinks [mc " differs from\n"] {}
8177-
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
8178-
appendwithlinks [mc "- stopping\n"]
8201+
appendshortlink $a [mc "Commit "] " $heada\n"
8202+
appendshortlink $b [mc " differs from\n "] \
8203+
" $headb\n"
8204+
$ctext insert end [mc "- stopping\n"]
81798205
break
81808206
}
81818207
}
81828208
if {$skipa} {
81838209
if {[llength $children($curview,$a)] != 1} {
81848210
$ctext insert end "\n"
8185-
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
8186-
$shorta [llength $children($curview,$a)]] {}
8211+
appendshortlink $a [mc "Commit "] \
8212+
[mc " has %s children - stopping\n" \
8213+
[llength $children($curview,$a)]]
81878214
break
81888215
}
81898216
set a [lindex $children($curview,$a) 0]
81908217
}
81918218
if {$skipb} {
81928219
if {[llength $children($curview,$b)] != 1} {
8193-
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
8194-
$shortb [llength $children($curview,$b)]] {}
8220+
appendshortlink $b [mc "Commit "] \
8221+
[mc " has %s children - stopping\n" \
8222+
[llength $children($curview,$b)]]
81958223
break
81968224
}
81978225
set b [lindex $children($curview,$b) 0]

0 commit comments

Comments
 (0)