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>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2019-04-06 18:34:29 +07:00 committed by Junio C Hamano
parent d8984c532a
commit 567009033f
2 changed files with 16 additions and 6 deletions

21
refs.c
View File

@ -603,9 +603,11 @@ int expand_ref(struct repository *repo, const char *str, int len,
return refs_found; return refs_found;
} }
int dwim_log(const char *str, int len, struct object_id *oid, char **log) int repo_dwim_log(struct repository *r, const char *str, int len,
struct object_id *oid, char **log)
{ {
char *last_branch = substitute_branch_name(the_repository, &str, &len); struct ref_store *refs = get_main_ref_store(r);
char *last_branch = substitute_branch_name(r, &str, &len);
const char **p; const char **p;
int logs_found = 0; int logs_found = 0;
struct strbuf path = STRBUF_INIT; struct strbuf path = STRBUF_INIT;
@ -617,13 +619,15 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
strbuf_reset(&path); strbuf_reset(&path);
strbuf_addf(&path, *p, len, str); strbuf_addf(&path, *p, len, str);
ref = resolve_ref_unsafe(path.buf, RESOLVE_REF_READING, ref = refs_resolve_ref_unsafe(refs, path.buf,
&hash, NULL); RESOLVE_REF_READING,
&hash, NULL);
if (!ref) if (!ref)
continue; continue;
if (reflog_exists(path.buf)) if (refs_reflog_exists(refs, path.buf))
it = path.buf; it = path.buf;
else if (strcmp(ref, path.buf) && reflog_exists(ref)) else if (strcmp(ref, path.buf) &&
refs_reflog_exists(refs, ref))
it = ref; it = ref;
else else
continue; continue;
@ -639,6 +643,11 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
return logs_found; return logs_found;
} }
int dwim_log(const char *str, int len, struct object_id *oid, char **log)
{
return repo_dwim_log(the_repository, str, len, oid, log);
}
static int is_per_worktree_ref(const char *refname) static int is_per_worktree_ref(const char *refname)
{ {
return !strcmp(refname, "HEAD") || return !strcmp(refname, "HEAD") ||

1
refs.h
View File

@ -150,6 +150,7 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix);
int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
int repo_dwim_log(struct repository *r, const char *str, int len, struct object_id *oid, char **ref);
int dwim_ref(const char *str, int len, struct object_id *oid, char **ref); int dwim_ref(const char *str, int len, struct object_id *oid, char **ref);
int dwim_log(const char *str, int len, struct object_id *oid, char **ref); int dwim_log(const char *str, int len, struct object_id *oid, char **ref);