{"thread":{"id":"55802","subject":"[QUESTION] how to quickly find an oid in the git repository","startedAt":"2021-05-30T06:53:40Z","lastAt":"2021-05-31T11:30:52Z","messageCount":3,"participants":["ZheNing Hu","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"425906","messageId":"CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A@mail.gmail.com","threadId":"55802","inReplyTo":null,"subject":"[QUESTION] how to quickly find an oid in the git repository","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-05-30T06:53:24Z","receivedAt":"2021-05-30T06:53:40Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"When I tried to make cat-file --batch use ref-filter logic,\nI encountered this problem:\n\nget_oid_with_context() does not really let me know\nif an oid is in the git repository. E.g.\n\nget_oid_with_context(the_repository,\n\"0000000000000000000000000000000000000000\",...)\n\nwill return FOUND. (I really want it to tell me MISSING_OBJECT\nor something else)\n\nOn the other hand, oid_object_info_extended() will parse an object\nin depth, using it will seriously affect performance. So I want to know\nif there is a function that can quickly find the oid? I searched in\n`object-name.c`, `object-file.c`, and there seems to be no clue...\n\n--\nZheNing Hu\n"},{"id":"425936","messageId":"YLP7kuFNfVZK+xCK@coredump.intra.peff.net","threadId":"55802","inReplyTo":"CAOLTT8SS8Wypho7eCCGH7LtOLwM6tWCzp8mGGEVASBC80MwJ5A@mail.gmail.com","subject":"Re: [QUESTION] how to quickly find an oid in the git repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-05-30T20:54:42Z","receivedAt":"2021-05-30T20:54:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, May 30, 2021 at 02:53:24PM +0800, ZheNing Hu wrote:\n\n> When I tried to make cat-file --batch use ref-filter logic,\n> I encountered this problem:\n> \n> get_oid_with_context() does not really let me know\n> if an oid is in the git repository. E.g.\n> \n> get_oid_with_context(the_repository,\n> \"0000000000000000000000000000000000000000\",...)\n> \n> will return FOUND. (I really want it to tell me MISSING_OBJECT\n> or something else)\n\nRight, it's purely a name->oid lookup.\n\n> On the other hand, oid_object_info_extended() will parse an object\n> in depth, using it will seriously affect performance. So I want to know\n> if there is a function that can quickly find the oid? I searched in\n> `object-name.c`, `object-file.c`, and there seems to be no clue...\n\nYou should be able to use oid_object_info_extended() here. It will try\nto do as little work as possible to fulfill the items requested in the\nobject_info struct. So a blank one (or even passing NULL) will return an\nerror if the object doesn't exist, but not otherwise.\n\nThere's also has_object_file(), which is essentially a wrapper for this.\n\n-Peff\n"},{"id":"425997","messageId":"CAOLTT8Rsy-XRys6fv3EbUJSUbHFCG4=w9uR7Bz8N8u8PWHgPhw@mail.gmail.com","threadId":"55802","inReplyTo":"YLP7kuFNfVZK+xCK@coredump.intra.peff.net","subject":"Re: [QUESTION] how to quickly find an oid in the git repository","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2021-05-31T11:30:35Z","receivedAt":"2021-05-31T11:30:52Z","isPatch":false,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Jeff King <peff@peff.net> 于2021年5月31日周一 上午4:54写道：\n\n> > On the other hand, oid_object_info_extended() will parse an object\n> > in depth, using it will seriously affect performance. So I want to know\n> > if there is a function that can quickly find the oid? I searched in\n> > `object-name.c`, `object-file.c`, and there seems to be no clue...\n>\n> You should be able to use oid_object_info_extended() here. It will try\n> to do as little work as possible to fulfill the items requested in the\n> object_info struct. So a blank one (or even passing NULL) will return an\n> error if the object doesn't exist, but not otherwise.\n>\n> There's also has_object_file(), which is essentially a wrapper for this.\n>\n\nThis is exactly what I want. It seems that the real performance problem\nis not because of the use of oid_object_info_extended(), but the possible\ncopy of the object data in it.\n\n> -Peff\n\nThanks!\n--\nZheNing Hu\n"}]}