]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: make repo_dwim_log() accept a NULL oid
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 23 Aug 2021 11:36:08 +0000 (13:36 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 25 Aug 2021 20:27:37 +0000 (13:27 -0700)
Change the repo_dwim_log() function initially added as dwim_log() in
eb3a48221fd (log --reflog: use dwim_log, 2007-02-09) to accept a NULL
oid parameter. The refs_resolve_ref_unsafe() function it invokes
already deals with it, but it didn't.

This allows for a bit more clarity in a reflog-walk.c codepath added
in f2eba66d4d1 (Enable HEAD@{...} and make it independent from the
current branch, 2007-02-03). We'll shortly use this in
builtin/reflog.c as well.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reflog-walk.c
refs.c

index e9cd3283694decbc6ea8e72c5681766129df793d..8ac4b284b6b6857a0a6d1f79eed563135771a291 100644 (file)
@@ -158,10 +158,9 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
                }
                reflogs = read_complete_reflog(branch);
                if (!reflogs || reflogs->nr == 0) {
-                       struct object_id oid;
                        char *b;
                        int ret = dwim_log(branch, strlen(branch),
-                                          &oid, &b);
+                                          NULL, &b);
                        if (ret > 1)
                                free(b);
                        else if (ret == 1) {
diff --git a/refs.c b/refs.c
index 8b9f7c3a80a0f615e33a7d14cd505c27c3304491..d963543675992a8195de5eacb8c5dfcd81a8630e 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -698,7 +698,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
                strbuf_addf(&path, *p, len, str);
                ref = refs_resolve_ref_unsafe(refs, path.buf,
                                              RESOLVE_REF_READING,
-                                             &hash, NULL);
+                                             oid ? &hash : NULL, NULL);
                if (!ref)
                        continue;
                if (refs_reflog_exists(refs, path.buf))
@@ -710,7 +710,8 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
                        continue;
                if (!logs_found++) {
                        *log = xstrdup(it);
-                       oidcpy(oid, &hash);
+                       if (oid)
+                               oidcpy(oid, &hash);
                }
                if (!warn_ambiguous_refs)
                        break;