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

3 messages from 2021-05-30 to 2021-05-31. Participants: ZheNing Hu, Jeff King.
Thread: https://gitlist.dev/t/55802

## ZheNing Hu, 2021-05-30 06:53

Subject: [QUESTION] how to quickly find an oid in the git repository
Message-ID: <CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A@mail.gmail.com>
URL: https://gitlist.dev/e/CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A%40mail.gmail.com

```
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)

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...

--
ZheNing Hu

```

## Jeff King, 2021-05-30 20:54

Subject: Re: [QUESTION] how to quickly find an oid in the git repository
Message-ID: <YLP7kuFNfVZK+xCK@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YLP7kuFNfVZK%2BxCK%40coredump.intra.peff.net
In-Reply-To: <CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A@mail.gmail.com>

```
On Sun, May 30, 2021 at 02:53:24PM +0800, ZheNing Hu wrote:

> 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

```

## ZheNing Hu, 2021-05-31 11:30

Subject: Re: [QUESTION] how to quickly find an oid in the git repository
Message-ID: <CAOLTT8Rsy-XRys6fv3EbUJSUbHFCG4=w9uR7Bz8N8u8PWHgPhw@mail.gmail.com>
URL: https://gitlist.dev/e/CAOLTT8Rsy-XRys6fv3EbUJSUbHFCG4%3Dw9uR7Bz8N8u8PWHgPhw%40mail.gmail.com
In-Reply-To: <YLP7kuFNfVZK+xCK@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> 于2021年5月31日周一 上午4:54写道：

> > 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.
>

This is exactly what I want. It seems that the real performance problem
is not because of the use of oid_object_info_extended(), but the possible
copy of the object data in it.

> -Peff

Thanks!
--
ZheNing Hu

```
