git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] gitk: parse arbitrary commit-ish in SHA1 field

From
Thomas Rast <trast@student.ethz.ch>
Date
Aug 13, 2009, 07:25 UTC
Message-ID
<c3c4afa39354da6df5a0b17ee43eb4e8dfcfb099.1250148240.git.trast@student.ethz.ch>
In-Reply-To
<7vtz0fndak.fsf@alter.siamese.dyndns.org>

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.

Add code to call out to git rev-parse --verify with the string entered if all other methods of interpreting it failed. (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 <trast@student.ethz.ch>
---
Junio C Hamano wrote:
> > +     } else {
> > +         if {[catch {set id [exec git rev-parse $sha1string]}]} {
> 
> "--verify", or "--no-flags --revs-only"?
Indeed, thanks.
 gitk |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/gitk b/gitk
index 4604c83..e50b666 100755
--- a/gitk
+++ b/gitk
@@ -7906,6 +7906,11 @@ proc gotocommit {} {
 		}
 		set id [lindex $matches 0]
 	    }
+	} else {
+	    if {[catch {set id [exec git rev-parse --verify $sha1string]}]} {
+		error_popup [mc "Revision %s is not known" $sha1string]
+		return
+	    }
 	}
     }
     if {[commitinview $id $curview]} {
@@ -7915,7 +7920,7 @@ proc gotocommit {} {
     if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} {
 	set msg [mc "SHA1 id %s is not known" $sha1string]
     } else {
-	set msg [mc "Tag/Head %s is not known" $sha1string]
+	set msg [mc "Revision %s is not in the current view" $sha1string]
     }
     error_popup $msg
 }
-- 
1.6.4.269.g0449d
Previous: Junio C HamanoNext: Paul Mackerras
Message 3 of 4 in “gitk: parse arbitrary commit-ish in SHA1 field”
  1. gitk: parse arbitrary commit-ish in SHA1 fieldThomas Rast, Aug 8, 2009
  2. Junio C HamanoAug 11, 2009
  3. gitk: parse arbitrary commit-ish in SHA1 fieldThomas Rast, Aug 13, 2009
  4. Paul MackerrasAug 13, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.