Browse Source

gitk: Fix compare-commits function when we have local changes

This fixes a bug in the compare-commits function added in commit
010509f2 ("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 <paulus@samba.org>
maint
Paul Mackerras 16 years ago
parent
commit
6f63fc18b6
  1. 66
      gitk

66
gitk

@ -6489,6 +6489,17 @@ proc setlink {id lk} { @@ -6489,6 +6489,17 @@ proc setlink {id lk} {
}
}

proc appendshortlink {id {pre {}} {post {}}} {
global ctext linknum

$ctext insert end $pre
$ctext tag delete link$linknum
$ctext insert end [string range $id 0 7] link$linknum
$ctext insert end $post
setlink $id link$linknum
incr linknum
}

proc makelink {id} {
global pendinglinks

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

if {![info exists patchids($id)]} {
set x [exec git diff-tree -p --root $id | git patch-id]
set patchids($id) [lindex $x 0]
set cmd [diffcmd [list $id] {-p --root}]
# trim off the initial "|"
set cmd [lrange $cmd 1 end]
if {[catch {
set x [eval exec $cmd | git patch-id]
set patchids($id) [lindex $x 0]
}]} {
set patchids($id) "error"
}
}
return $patchids($id)
}
@ -8140,18 +8158,16 @@ proc do_cmp_commits {a b} { @@ -8140,18 +8158,16 @@ proc do_cmp_commits {a b} {
clear_ctext
init_flist {}
for {set i 0} {$i < 100} {incr i} {
set shorta [string range $a 0 7]
set shortb [string range $b 0 7]
set skipa 0
set skipb 0
if {[llength $parents($curview,$a)] > 1} {
appendwithlinks [mc "Skipping merge commit %s\n" $shorta] {}
appendshortlink $a [mc "Skipping merge commit "] "\n"
set skipa 1
} else {
set patcha [getpatchid $a]
}
if {[llength $parents($curview,$b)] > 1} {
appendwithlinks [mc "Skipping merge commit %s\n" $shortb] {}
appendshortlink $b [mc "Skipping merge commit "] "\n"
set skipb 1
} else {
set patchb [getpatchid $b]
@ -8159,39 +8175,51 @@ proc do_cmp_commits {a b} { @@ -8159,39 +8175,51 @@ proc do_cmp_commits {a b} {
if {!$skipa && !$skipb} {
set heada [lindex $commitinfo($a) 0]
set headb [lindex $commitinfo($b) 0]
if {$patcha eq "error"} {
appendshortlink $a [mc "Error getting patch ID for "] \
[mc " - stopping\n"]
break
}
if {$patchb eq "error"} {
appendshortlink $b [mc "Error getting patch ID for "] \
[mc " - stopping\n"]
break
}
if {$patcha eq $patchb} {
if {$heada eq $headb} {
appendwithlinks [mc "Commit %s == %s %s\n" \
$shorta $shortb $heada] {}
appendshortlink $a [mc "Commit "]
appendshortlink $b " == " " $heada\n"
} else {
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
appendwithlinks [mc " is the same patch as\n"] {}
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
appendshortlink $a [mc "Commit "] " $heada\n"
appendshortlink $b [mc " is the same patch as\n "] \
" $headb\n"
}
set skipa 1
set skipb 1
} else {
$ctext insert end "\n"
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
appendwithlinks [mc " differs from\n"] {}
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
appendwithlinks [mc "- stopping\n"]
appendshortlink $a [mc "Commit "] " $heada\n"
appendshortlink $b [mc " differs from\n "] \
" $headb\n"
$ctext insert end [mc "- stopping\n"]
break
}
}
if {$skipa} {
if {[llength $children($curview,$a)] != 1} {
$ctext insert end "\n"
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
$shorta [llength $children($curview,$a)]] {}
appendshortlink $a [mc "Commit "] \
[mc " has %s children - stopping\n" \
[llength $children($curview,$a)]]
break
}
set a [lindex $children($curview,$a) 0]
}
if {$skipb} {
if {[llength $children($curview,$b)] != 1} {
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
$shortb [llength $children($curview,$b)]] {}
appendshortlink $b [mc "Commit "] \
[mc " has %s children - stopping\n" \
[llength $children($curview,$b)]]
break
}
set b [lindex $children($curview,$b) 0]

Loading…
Cancel
Save