git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [QUESTION] how to quickly find an oid in the git repository
@ 2021-05-30  6:53 ZheNing Hu
  2021-05-30 20:54 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: ZheNing Hu @ 2021-05-30  6:53 UTC (permalink / raw)
  To: Git List
  Cc: Junio C Hamano, Christian Couder, Hariom verma, Felipe Contreras,
	Phillip Wood

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QUESTION] how to quickly find an oid in the git repository
  2021-05-30  6:53 [QUESTION] how to quickly find an oid in the git repository ZheNing Hu
@ 2021-05-30 20:54 ` Jeff King
  2021-05-31 11:30   ` ZheNing Hu
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2021-05-30 20:54 UTC (permalink / raw)
  To: ZheNing Hu
  Cc: Git List, Junio C Hamano, Christian Couder, Hariom verma,
	Felipe Contreras, Phillip Wood

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [QUESTION] how to quickly find an oid in the git repository
  2021-05-30 20:54 ` Jeff King
@ 2021-05-31 11:30   ` ZheNing Hu
  0 siblings, 0 replies; 3+ messages in thread
From: ZheNing Hu @ 2021-05-31 11:30 UTC (permalink / raw)
  To: Jeff King
  Cc: Git List, Junio C Hamano, Christian Couder, Hariom verma,
	Felipe Contreras, Phillip Wood

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-31 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-30  6:53 [QUESTION] how to quickly find an oid in the git repository ZheNing Hu
2021-05-30 20:54 ` Jeff King
2021-05-31 11:30   ` ZheNing Hu

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).