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

Re: [Question] git rev-parse verify for non-existent object

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2023, 16:32 UTC
Message-ID
<xmqq1qgl9zgm.fsf@gitster.g>
In-Reply-To
<CAOLTT8TXYpyadp=Z6K44G59iSar5ieyLwmSph4ypwxGo9doHYA@mail.gmail.com>
ZheNing Hu <adlternative@gmail.com> writes:
Show 9 quoted lines
>>       --verify
>>           Verify that exactly one parameter is provided, and that it
>> can be turned into a raw 20-byte SHA-1 that can be used to access the
>> object database. If so, emit it to the standard output;
>>           otherwise, error out.
>>
>
> So why doesn't "git rev-list --verify" check if 20-byte SHA-1 can
>  "access the object database"?
Hysterical Raisins.

"rev-parse" can do many things, and one of them is about expanding strings (like "9e4df4da", "jt/path-filter-fix", "seen~7^2", and "9e4df4da0786797b1d51ed8fd3dfc18970772a91") given from the command line into hexadecimal strings of the full length (they are often called "revision"). "--verify" tells the command that on the command line there must be ONE and only one "revision", give the full length hexadecimal string for it. The command fails if the command line argument cannot be turned into a hexadecimal string of the full length.

Now, among the ones given as examples in the above, "9e4df4da", needs to look at the object database to turn it into a hexadecimal string of the full length, because it is likely to be an abbrevation (although it could be a branch name, too). "jt/path-filter-fix" and "seen~7^2" needs to look at the refs and probably into the object database (to see what the 7th generation grandparent is and what the second parent of that commit is) before they can be turned into hexadecimal strings of the full length.

But "9e4df4da0786797b1d51ed8fd3dfc18970772a91" is already a full hexadecimal, so it is given back as a "revision" without checking if there is such an object in the object database.

Checking if it can be turned into the form that can be used to query the object database, and checking the object database using it to find out if such an object exists, are two distinct steps low-level tool authors, who would want to use the plumbing tools, may need. The current option set allows the separation (and ^{object} suffix lets you do the both at the same time, too).

Previous: ZheNing HuNext: ZheNing Hu
Message 4 of 5 in “[Question] git rev-parse verify for non-existent object”
  1. ZheNing HuAug 2, 2023
  2. Christian CouderAug 2, 2023
  3. ZheNing HuAug 2, 2023
  4. Junio C HamanoAug 2, 2023
  5. ZheNing HuAug 3, 2023

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.