Skip to content

Commit 9bf3acf

Browse files
trastpaulusmack
authored andcommitted
gitk: Parse arbitrary commit-ish in SHA1 field
We only accepted either SHA1s or heads/tags that have been read. This meant the user could not, e.g., enter HEAD to go back to the current commit. This adds code to call out to git rev-parse --verify if all other methods of interpreting the string the user entered fail. (git-rev-parse alone is not enough as we really want a single revision.) The error paths change slighly, because we now know from the rev-parse invocation whether the expression was valid at all. The previous "unknown" path is now only triggered if the revision does exist, but is not in the current view display. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 2b1fbf9 commit 9bf3acf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gitk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7909,6 +7909,11 @@ proc gotocommit {} {
79097909
}
79107910
set id [lindex $matches 0]
79117911
}
7912+
} else {
7913+
if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
7914+
error_popup [mc "Revision %s is not known" $sha1string]
7915+
return
7916+
}
79127917
}
79137918
}
79147919
if {[commitinview $id $curview]} {
@@ -7918,7 +7923,7 @@ proc gotocommit {} {
79187923
if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
79197924
set msg [mc "SHA1 id %s is not known" $sha1string]
79207925
} else {
7921-
set msg [mc "Tag/Head %s is not known" $sha1string]
7926+
set msg [mc "Revision %s is not in the current view" $sha1string]
79227927
}
79237928
error_popup $msg
79247929
}

0 commit comments

Comments
 (0)