summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sha1_name.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/sha1_name.c b/sha1_name.c
index f79a7c9..a7efa96 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -275,16 +275,29 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
*log = NULL;
for (p = ref_fmt; *p; p++) {
struct stat st;
- char *path = mkpath(*p, len, str);
+ unsigned char hash[20];
+ char path[PATH_MAX];
+ const char *ref, *it;
+
+ strcpy(path, mkpath(*p, len, str));
+ ref = resolve_ref(path, hash, 0, NULL);
+ if (!ref)
+ continue;
if (!stat(git_path("logs/%s", path), &st) &&
- S_ISREG(st.st_mode)) {
- if (!logs_found++) {
- *log = xstrdup(path);
- resolve_ref(path, sha1, 0, NULL);
- }
- if (!warn_ambiguous_refs)
- break;
+ S_ISREG(st.st_mode))
+ it = path;
+ else if (strcmp(ref, path) &&
+ !stat(git_path("logs/%s", ref), &st) &&
+ S_ISREG(st.st_mode))
+ it = ref;
+ else
+ continue;
+ if (!logs_found++) {
+ *log = xstrdup(it);
+ hashcpy(sha1, hash);
}
+ if (!warn_ambiguous_refs)
+ break;
}
return logs_found;
}