threads / patch / 53942

patchgrep: avoid using oid_to_hex() with parse_object_or_die()

Subject: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()

## tl;dr

3 messages between Jul 28, 2020 and Jul 28, 2020. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

René Scharfe· Jul 28, 2020, 21:40 UTC · lore

parse_object_or_die() is passed an object ID and a name to show if the object cannot be parsed. If the name is NULL then it shows the hexadecimal object ID. Use that feature instead of preparing and passing the hexadecimal representation to the function proactively. That's shorter and a bit more efficient.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to builtin/grep.c +1 −2
diff --git a/builtin/grep.c b/builtin/grep.c
index a5056f395a..5975cf5ef2 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -466,7 +466,7 @@ static int grep_submodule(struct grep_opt *opt,
 		struct strbuf base = STRBUF_INIT;

 		obj_read_lock();
-		object = parse_object_or_die(oid, oid_to_hex(oid));
+		object = parse_object_or_die(oid, NULL);
 		obj_read_unlock();
 		data = read_object_with_reference(&subrepo,
 						  &object->oid, tree_type,
--
2.28.0
Matheus Tavares Bernardino· Jul 28, 2020, 22:35 UTC · re: René Scharfe · lore

Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()

On Tue, Jul 28, 2020 at 6:40 PM René Scharfe <l.s.r@web.de> wrote:
Show 8 quoted lines
>
> parse_object_or_die() is passed an object ID and a name to show if the
> object cannot be parsed.  If the name is NULL then it shows the
> hexadecimal object ID.  Use that feature instead of preparing and
> passing the hexadecimal representation to the function proactively.
> That's shorter and a bit more efficient.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>

Good catch. And this seems to be the only place where we use `parse_object_or_die(oid, oid_to_hex(oid))`.

Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br>
Junio C Hamano· Jul 28, 2020, 22:44 UTC · re: Matheus Tavares Bernardino · lore

Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()

Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:
Show 14 quoted lines
> On Tue, Jul 28, 2020 at 6:40 PM René Scharfe <l.s.r@web.de> wrote:
>>
>> parse_object_or_die() is passed an object ID and a name to show if the
>> object cannot be parsed.  If the name is NULL then it shows the
>> hexadecimal object ID.  Use that feature instead of preparing and
>> passing the hexadecimal representation to the function proactively.
>> That's shorter and a bit more efficient.
>>
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>
> Good catch. And this seems to be the only place where we use
> `parse_object_or_die(oid, oid_to_hex(oid))`.
>
> Reviewed-by: Matheus Tavares <matheus.bernardino@usp.br>
Yup, makes sense.  Thanks, both.

← back to recent threads