Skip to content

Commit 39816d6

Browse files
angavrilovpaulusmack
authored andcommitted
gitk: Add option to specify the default commit on command line
Other GUI tools may need to start gitk and make it automatically select a certain commit. This adds a new command-line option --select-commit=id to make that possible. Signed-off-by: Alexander Gavrilov <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent df75e86 commit 39816d6

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

gitk

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,12 @@ proc stop_rev_list {view} {
418418
}
419419

420420
proc reset_pending_select {selid} {
421-
global pending_select mainheadid
421+
global pending_select mainheadid selectheadid
422422

423423
if {$selid ne {}} {
424424
set pending_select $selid
425+
} elseif {$selectheadid ne {}} {
426+
set pending_select $selectheadid
425427
} else {
426428
set pending_select $mainheadid
427429
}
@@ -1609,6 +1611,7 @@ proc getcommit {id} {
16091611
proc readrefs {} {
16101612
global tagids idtags headids idheads tagobjid
16111613
global otherrefids idotherrefs mainhead mainheadid
1614+
global selecthead selectheadid
16121615

16131616
foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
16141617
catch {unset $v}
@@ -1655,6 +1658,12 @@ proc readrefs {} {
16551658
set mainhead [string range $thehead 11 end]
16561659
}
16571660
}
1661+
set selectheadid {}
1662+
if {$selecthead ne {}} {
1663+
catch {
1664+
set selectheadid [exec git rev-parse --verify $selecthead]
1665+
}
1666+
}
16581667
}
16591668

16601669
# skip over fake commits
@@ -9865,6 +9874,9 @@ if {![file isdirectory $gitdir]} {
98659874
exit 1
98669875
}
98679876

9877+
set selecthead {}
9878+
set selectheadid {}
9879+
98689880
set revtreeargs {}
98699881
set cmdline_files {}
98709882
set i 0
@@ -9876,6 +9888,9 @@ foreach arg $argv {
98769888
set cmdline_files [lrange $argv [expr {$i + 1}] end]
98779889
break
98789890
}
9891+
"--select-commit=*" {
9892+
set selecthead [string range $arg 16 end]
9893+
}
98799894
"--argscmd=*" {
98809895
set revtreeargscmd [string range $arg 10 end]
98819896
}
@@ -9886,6 +9901,10 @@ foreach arg $argv {
98869901
incr i
98879902
}
98889903

9904+
if {$selecthead eq "HEAD"} {
9905+
set selecthead {}
9906+
}
9907+
98899908
if {$i >= [llength $argv] && $revtreeargs ne {}} {
98909909
# no -- on command line, but some arguments (other than --argscmd)
98919910
if {[catch {

0 commit comments

Comments
 (0)