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

Re: [QUESTION] how to quickly find an oid in the git repository

From
Jeff King <peff@peff.net>
Date
May 30, 2021, 20:54 UTC
Message-ID
<YLP7kuFNfVZK+xCK@coredump.intra.peff.net>
In-Reply-To
<CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A@mail.gmail.com>
On Sun, May 30, 2021 at 02:53:24PM +0800, ZheNing Hu wrote:
Show 11 quoted lines
> When I tried to make cat-file --batch use ref-filter logic,
> I encountered this problem:
> 
> get_oid_with_context() does not really let me know
> if an oid is in the git repository. E.g.
> 
> get_oid_with_context(the_repository,
> "0000000000000000000000000000000000000000",...)
> 
> will return FOUND. (I really want it to tell me MISSING_OBJECT
> or something else)
Right, it's purely a name->oid lookup.
> On the other hand, oid_object_info_extended() will parse an object
> in depth, using it will seriously affect performance. So I want to know
> if there is a function that can quickly find the oid? I searched in
> `object-name.c`, `object-file.c`, and there seems to be no clue...

You should be able to use oid_object_info_extended() here. It will try to do as little work as possible to fulfill the items requested in the object_info struct. So a blank one (or even passing NULL) will return an error if the object doesn't exist, but not otherwise.

There's also has_object_file(), which is essentially a wrapper for this.
-Peff
Previous: ZheNing HuNext: ZheNing Hu
Message 2 of 3 in “[QUESTION] how to quickly find an oid in the git repository”
  1. ZheNing HuMay 30, 2021
  2. Jeff KingMay 30, 2021
  3. ZheNing HuMay 31, 2021

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.