refs.c: add repo_dwim_log()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 6, 2019 at 18:34 UTC 567009033f7ef4619c890f0e07d7e0b67136e1b1
2 files changed +16 -6
refs.c
+15 -6
@@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
603 return refs_found;
604 }
605
606 -int dwim_log(const char *str, int len, struct object_id *oid, char **log)
606 +int repo_dwim_log(struct repository *r, const char *str, int len,
607 + struct object_id *oid, char **log)
608 {
608 - char *last_branch = substitute_branch_name(the_repository, &str, &len);
609 + struct ref_store *refs = get_main_ref_store(r);
610 + char *last_branch = substitute_branch_name(r, &str, &len);
611 const char **p;
612 int logs_found = 0;
613 struct strbuf path = STRBUF_INIT;
@@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
619
620 strbuf_reset(&path);
621 strbuf_addf(&path, *p, len, str);
620 - ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING,
621 - &hash, NULL);
622 + ref = refs_resolve_ref_unsafe(refs, path.buf,
623 + RESOLVE_REF_READING,
624 + &hash, NULL);
625 if (!ref)
626 continue;
624 - if (reflog_exists(path.buf))
627 + if (refs_reflog_exists(refs, path.buf))
628 it = path.buf;
626 - else if (strcmp(ref, path.buf) && reflog_exists(ref))
629 + else if (strcmp(ref, path.buf) &&
630 + refs_reflog_exists(refs, ref))
631 it = ref;
632 else
633 continue;
@@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
643 return logs_found;
644 }
645
646 +int dwim_log(const char *str, int len, struct object_id *oid, char **log)
647 +{
648 + return repo_dwim_log(the_repository, str, len, oid, log);
649 +}
650 +
651 static int is_per_worktree_ref(const char *refname)
652 {
653 return !strcmp(refname, "HEAD") ||
refs.h
+1
@@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
150
151 int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
152 int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
153 +int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
154 int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
155 int dwim_log(const char *str, int len, struct object_id *oid, char **ref);
156