threads / patch / 52432

patchremote: pass NULL to read_ref_full() because object ID is not needed

Subject: [PATCH] remote: pass NULL to read_ref_full() because object ID is not needed

## tl;dr

2 messages between Dec 11, 2019 and Dec 11, 2019. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Dec 11, 2019, 18:46 UTC · lore

read_ref_full() wraps refs_read_ref_full(), which in turn wraps refs_resolve_ref_unsafe(), which handles a NULL oid pointer of callers not interested in the resolved object ID. Make use of that feature to document that mv() is such a caller.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/remote.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Show changes to builtin/remote.c +1 −3
diff --git a/builtin/remote.c b/builtin/remote.c
index 5591cef775..96bbe828fe 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -693,9 +693,8 @@ static int mv(int argc, const char **argv)
 	for (i = 0; i < remote_branches.nr; i++) {
 		struct string_list_item *item = remote_branches.items + i;
 		int flag = 0;
-		struct object_id oid;

-		read_ref_full(item->string, RESOLVE_REF_READING, &oid, &flag);
+		read_ref_full(item->string, RESOLVE_REF_READING, NULL, &flag);
 		if (!(flag & REF_ISSYMREF))
 			continue;
 		if (delete_ref(NULL, item->string, NULL, REF_NO_DEREF))
--
2.24.1
Derrick Stolee· Dec 11, 2019, 18:57 UTC · re: René Scharfe · lore

Re: [PATCH] remote: pass NULL to read_ref_full() because object ID is not needed

On 12/11/2019 1:46 PM, René Scharfe wrote:
> read_ref_full() wraps refs_read_ref_full(), which in turn wraps
> refs_resolve_ref_unsafe(), which handles a NULL oid pointer of callers
> not interested in the resolved object ID.  Make use of that feature to
> document that mv() is such a caller.
Double-checking the code shows this in refs_resolve_ref_unsafe():
        if (!oid)
                oid = &unused_oid;

where unused_oid is a local struct. Unfortunate that the correct code change doesn't get any performance benefit for sending this message of "I don't need this value".

LGTM.
-Stolee

← back to recent threads