git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
@ 2020-07-28 21:40 René Scharfe
  2020-07-28 22:35 ` Matheus Tavares Bernardino
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2020-07-28 21:40 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Matheus Tavares

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
  2020-07-28 21:40 [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die() René Scharfe
@ 2020-07-28 22:35 ` Matheus Tavares Bernardino
  2020-07-28 22:44   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Matheus Tavares Bernardino @ 2020-07-28 22:35 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano

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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die()
  2020-07-28 22:35 ` Matheus Tavares Bernardino
@ 2020-07-28 22:44   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2020-07-28 22:44 UTC (permalink / raw)
  To: Matheus Tavares Bernardino; +Cc: René Scharfe, Git Mailing List

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-28 22:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 21:40 [PATCH] grep: avoid using oid_to_hex() with parse_object_or_die() René Scharfe
2020-07-28 22:35 ` Matheus Tavares Bernardino
2020-07-28 22:44   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).