{"thread":{"id":"53942","subject":"[PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()","startedAt":"2020-07-28T21:40:53Z","lastAt":"2020-07-28T22:44:08Z","messageCount":3,"participants":["René Scharfe","Matheus Tavares Bernardino","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"402253","messageId":"551da4ae-c75a-0f2b-7786-2fee32939b2b@web.de","threadId":"53942","inReplyTo":null,"subject":"[PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-07-28T21:40:38Z","receivedAt":"2020-07-28T21:40:53Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"parse_object_or_die() is passed an object ID and a name to show if the\nobject cannot be parsed.  If the name is NULL then it shows the\nhexadecimal object ID.  Use that feature instead of preparing and\npassing the hexadecimal representation to the function proactively.\nThat's shorter and a bit more efficient.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/grep.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex a5056f395a..5975cf5ef2 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -466,7 +466,7 @@ static int grep_submodule(struct grep_opt *opt,\n \t\tstruct strbuf base = STRBUF_INIT;\n\n \t\tobj_read_lock();\n-\t\tobject = parse_object_or_die(oid, oid_to_hex(oid));\n+\t\tobject = parse_object_or_die(oid, NULL);\n \t\tobj_read_unlock();\n \t\tdata = read_object_with_reference(&subrepo,\n \t\t\t\t\t\t  &object->oid, tree_type,\n--\n2.28.0\n"},{"id":"402263","messageId":"CAHd-oW68nGch8b3tfas4AUUgA8so-ihwazAf8-W-xQNPi31=Mw@mail.gmail.com","threadId":"53942","inReplyTo":"551da4ae-c75a-0f2b-7786-2fee32939b2b@web.de","subject":"Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()","fromName":"Matheus Tavares Bernardino","fromEmail":"matheus.bernardino@usp.br","sentAt":"2020-07-28T22:35:50Z","receivedAt":"2020-07-28T22:36:05Z","isPatch":true,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"On Tue, Jul 28, 2020 at 6:40 PM René Scharfe <l.s.r@web.de> wrote:\n>\n> parse_object_or_die() is passed an object ID and a name to show if the\n> object cannot be parsed.  If the name is NULL then it shows the\n> hexadecimal object ID.  Use that feature instead of preparing and\n> passing the hexadecimal representation to the function proactively.\n> That's shorter and a bit more efficient.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n\nGood catch. And this seems to be the only place where we use\n`parse_object_or_die(oid, oid_to_hex(oid))`.\n\nReviewed-by: Matheus Tavares <matheus.bernardino@usp.br>\n"},{"id":"402266","messageId":"xmqq1rkvclak.fsf@gitster.c.googlers.com","threadId":"53942","inReplyTo":"CAHd-oW68nGch8b3tfas4AUUgA8so-ihwazAf8-W-xQNPi31=Mw@mail.gmail.com","subject":"Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-07-28T22:44:03Z","receivedAt":"2020-07-28T22:44:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:\n\n> On Tue, Jul 28, 2020 at 6:40 PM René Scharfe <l.s.r@web.de> wrote:\n>>\n>> parse_object_or_die() is passed an object ID and a name to show if the\n>> object cannot be parsed.  If the name is NULL then it shows the\n>> hexadecimal object ID.  Use that feature instead of preparing and\n>> passing the hexadecimal representation to the function proactively.\n>> That's shorter and a bit more efficient.\n>>\n>> Signed-off-by: René Scharfe <l.s.r@web.de>\n>\n> Good catch. And this seems to be the only place where we use\n> `parse_object_or_die(oid, oid_to_hex(oid))`.\n>\n> Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br>\n\nYup, makes sense.  Thanks, both.\n"}]}