Skip to contentSkip to conversation

grep: avoid using oid_to_hex() with parse_object_or_die()

PATCH In review René Scharfe 3 participants 3 messages Jul 28, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 grep: avoid using oid_to_hex() with parse_object_or_die()

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.

---
 builtin/grep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/grep.c +1 -1
index a5056f395a..5975cf5ef2 100644
@@ -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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · René Scharfe

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.

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

#2 lore raw
Quoted 8 lines · Matheus Tavares Bernardino
Quoted 7 lines · René Scharfe

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.

Quoted 6 lines
Quoted 1 line

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

Yup, makes sense. Thanks, both.