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

3 messages from 2020-07-28 to 2020-07-28. Participants: René Scharfe, Matheus Tavares Bernardino, Junio C Hamano.
Thread: https://gitlist.dev/t/53942

## René Scharfe, 2020-07-28 21:40

Subject: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
Message-ID: <551da4ae-c75a-0f2b-7786-2fee32939b2b@web.de>
URL: https://gitlist.dev/e/551da4ae-c75a-0f2b-7786-2fee32939b2b%40web.de

```
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(-)

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, 2020-07-28 22:35

Subject: Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
Message-ID: <CAHd-oW68nGch8b3tfas4AUUgA8so-ihwazAf8-W-xQNPi31=Mw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHd-oW68nGch8b3tfas4AUUgA8so-ihwazAf8-W-xQNPi31%3DMw%40mail.gmail.com
In-Reply-To: <551da4ae-c75a-0f2b-7786-2fee32939b2b@web.de>

```
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>

```

## Junio C Hamano, 2020-07-28 22:44

Subject: Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
Message-ID: <xmqq1rkvclak.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqq1rkvclak.fsf%40gitster.c.googlers.com
In-Reply-To: <CAHd-oW68nGch8b3tfas4AUUgA8so-ihwazAf8-W-xQNPi31=Mw@mail.gmail.com>

```
Matheus Tavares Bernardino <matheus.bernardino@usp.br> writes:

> 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.

```
