refs: make repo_dwim_log() accept a NULL oid
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>
Ævar Arnfjörð Bjarmason committed
Aug 23, 2021 at 13:36 UTC
6f45ec88d2168013b00b46d8593524ca5b6c0acb
2 files changed
+4
-4
reflog-walk.c
+1
-2
@@ -158,10 +158,9 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
158
}
159
reflogs = read_complete_reflog(branch);
160
if (!reflogs || reflogs->nr == 0) {
161
- struct object_id oid;
161
char *b;
162
int ret = dwim_log(branch, strlen(branch),
164
- &oid, &b);
163
+ NULL, &b);
164
if (ret > 1)
165
free(b);
166
else if (ret == 1) {
refs.c
+3
-2
@@ -698,7 +698,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
698
strbuf_addf(&path, *p, len, str);
699
ref = refs_resolve_ref_unsafe(refs, path.buf,
700
RESOLVE_REF_READING,
701
- &hash, NULL);
701
+ oid ? &hash : NULL, NULL);
702
if (!ref)
703
continue;
704
if (refs_reflog_exists(refs, path.buf))
@@ -710,7 +710,8 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
710
continue;
711
if (!logs_found++) {
712
*log = xstrdup(it);
713
- oidcpy(oid, &hash);
713
+ if (oid)
714
+ oidcpy(oid, &hash);
715
}
716
if (!warn_ambiguous_refs)
717
break;