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

Re: rev-parse, unknown arguments and extended sha1's

From
Linus Torvalds <torvalds@osdl.org>
Date
Jun 24, 2005, 17:32 UTC
Message-ID
<Pine.LNX.4.58.0506241026490.11175@ppc970.osdl.org>
In-Reply-To
<Pine.LNX.4.58.0506240941520.11175@ppc970.osdl.org>
On Fri, 24 Jun 2005, Linus Torvalds wrote:
Show 5 quoted lines
> 
> Anyway, I think I'll make git-rev-parse have some option to "error out if 
> the result is anything but a single revision number", since this is really 
> the only reason for git-rev-parse in the first place: to make readable 
> scripts.
How about something like
	rev=$(git-rev-parse --default HEAD --revs-only --verify "$@") || exit 1
which now should work correctly.

In particular, the "--default" field is now expanded properly as a revision, instead of just output raw, so the "HEAD" actually gets translated into its SHA1 representation (and this also means that you can now use SHA1 expressions in "default", ie you don't need to do two git-rev-parse phases to do "--default HEAD^" etc).

The "--verify" thing then checks that the end result isn't a revision argument (ie "--max-age=.." isn't accepted), and that there's exactly one revision in the result (ie no ranges or multiple revisions some other way).

So now you shouldn't need to check the result any more. You know that if it worked, "rev" will be a nice SHA1 (of course, it might still be an _invalid_ SHA1, that's a different issue. But it's at least syntactically ok)

		Linus
Previous: Linus Torvalds
Message 5 of 5 in “rev-parse, unknown arguments and extended sha1's”
  1. Sven VerdoolaegeJun 24, 2005
  2. Linus TorvaldsJun 24, 2005
  3. Sven VerdoolaegeJun 24, 2005
  4. Linus TorvaldsJun 24, 2005
  5. Linus TorvaldsJun 24, 2005

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.