Skip to content

Commit 010509f

Browse files
committed
gitk: Add a command to compare two strings of commits
This adds a row context menu command to compare this commit and its descendants with the marked commit and its descendants. The results are shown in the bottom-left pane. Commits are compared by checking whether their headlines are the same and their patches have the same patch ID as generated by git patch-id. Merges are ignored and skipped over (as long as they have one descendant). If two commits have the same patch ID then the process will continue and compare their descendants, as long as they both have exactly one descendant. If either commit has 0 or 2 or more descendants, the comparison stops there. There is currently a limit of 100 comparisons. This can be useful for checking whether one string of commits is just a rebased version of another string of commits. Mark the end of one string (i.e. the oldest commit in the string) and invoke "Compare with marked commit" on the end of the other string. As this is implemented, the UI will be unresponsive while the results are being generated. This should be fixed. Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent b9fdba7 commit 010509f

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

gitk

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,7 @@ proc makewindow {} {
23622362
{mc "Mark this commit" command markhere}
23632363
{mc "Return to mark" command gotomark}
23642364
{mc "Find descendant of this and mark" command find_common_desc}
2365+
{mc "Compare with marked commit" command compare_commits}
23652366
}
23662367
$rowctxmenu configure -tearoff 0
23672368

@@ -8037,9 +8038,11 @@ proc rowmenu {x y id} {
80378038
if {[info exists markedid] && $markedid ne $id} {
80388039
$menu entryconfigure 9 -state normal
80398040
$menu entryconfigure 10 -state normal
8041+
$menu entryconfigure 11 -state normal
80408042
} else {
80418043
$menu entryconfigure 9 -state disabled
80428044
$menu entryconfigure 10 -state disabled
8045+
$menu entryconfigure 11 -state disabled
80438046
}
80448047
} else {
80458048
set menu $fakerowmenu
@@ -8103,6 +8106,92 @@ proc find_common_desc {} {
81038106
#puts "took [expr {$t2-$t1}]ms"
81048107
}
81058108

8109+
proc compare_commits {} {
8110+
global markedid rowmenuid curview children
8111+
8112+
if {![info exists markedid]} return
8113+
if {![commitinview $markedid $curview]} return
8114+
addtohistory [list do_cmp_commits $markedid $rowmenuid]
8115+
do_cmp_commits $markedid $rowmenuid
8116+
}
8117+
8118+
proc getpatchid {id} {
8119+
global patchids
8120+
8121+
if {![info exists patchids($id)]} {
8122+
set x [exec git diff-tree -p --root $id | git patch-id]
8123+
set patchids($id) [lindex $x 0]
8124+
}
8125+
return $patchids($id)
8126+
}
8127+
8128+
proc do_cmp_commits {a b} {
8129+
global ctext curview parents children patchids commitinfo
8130+
8131+
$ctext conf -state normal
8132+
clear_ctext
8133+
init_flist {}
8134+
for {set i 0} {$i < 100} {incr i} {
8135+
set shorta [string range $a 0 7]
8136+
set shortb [string range $b 0 7]
8137+
set skipa 0
8138+
set skipb 0
8139+
if {[llength $parents($curview,$a)] > 1} {
8140+
appendwithlinks [mc "Skipping merge commit %s\n" $shorta] {}
8141+
set skipa 1
8142+
} else {
8143+
set patcha [getpatchid $a]
8144+
}
8145+
if {[llength $parents($curview,$b)] > 1} {
8146+
appendwithlinks [mc "Skipping merge commit %s\n" $shortb] {}
8147+
set skipb 1
8148+
} else {
8149+
set patchb [getpatchid $b]
8150+
}
8151+
if {!$skipa && !$skipb} {
8152+
set heada [lindex $commitinfo($a) 0]
8153+
set headb [lindex $commitinfo($b) 0]
8154+
if {$patcha eq $patchb} {
8155+
if {$heada eq $headb} {
8156+
appendwithlinks [mc "Commit %s == %s %s\n" \
8157+
$shorta $shortb $heada] {}
8158+
} else {
8159+
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
8160+
appendwithlinks [mc " is the same patch as\n"] {}
8161+
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
8162+
}
8163+
set skipa 1
8164+
set skipb 1
8165+
} else {
8166+
$ctext insert end "\n"
8167+
appendwithlinks [mc "Commit %s %s\n" $shorta $heada] {}
8168+
appendwithlinks [mc " differs from\n"] {}
8169+
appendwithlinks [mc " %s %s\n" $shortb $headb] {}
8170+
appendwithlinks [mc "- stopping\n"]
8171+
break
8172+
}
8173+
}
8174+
if {$skipa} {
8175+
if {[llength $children($curview,$a)] != 1} {
8176+
$ctext insert end "\n"
8177+
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
8178+
$shorta [llength $children($curview,$a)]] {}
8179+
break
8180+
}
8181+
set a [lindex $children($curview,$a) 0]
8182+
}
8183+
if {$skipb} {
8184+
if {[llength $children($curview,$b)] != 1} {
8185+
appendwithlinks [mc "Commit %s has %s children - stopping\n" \
8186+
$shortb [llength $children($curview,$b)]] {}
8187+
break
8188+
}
8189+
set b [lindex $children($curview,$b) 0]
8190+
}
8191+
}
8192+
$ctext conf -state disabled
8193+
}
8194+
81068195
proc diffvssel {dirn} {
81078196
global rowmenuid selectedline
81088197

0 commit comments

Comments
 (0)