@matheusbsbs / matheus-bagliano / commits / 40facde06e
Fork 0

reflog: handle $name => remotes/%s/HEAD mapping consistently for logs

When refs/remotes/gfi/master and refs/remotes/gfi/HEAD exist, and the latter is a symref that points at the former, dwim_ref() resolves string "gfi" to "refs/remotes/gfi/master" as expected, but dwim_log() does not understand "gfi@{1.day}" and needs to be told "gfi/master@{1.day}". This is confusing. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 8, 2007 at 23:24 UTC 40facde06e3f9d5231c257e1a7f5b545b563d45f
1 file changed +21 -8
sha1_name.c
+21 -8
@@ -275,16 +275,29 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
275 *log = NULL;
276 for (p = ref_fmt; *p; p++) {
277 struct stat st;
278 - char *path = mkpath(*p, len, str);
278 + unsigned char hash[20];
279 + char path[PATH_MAX];
280 + const char *ref, *it;
281 +
282 + strcpy(path, mkpath(*p, len, str));
283 + ref = resolve_ref(path, hash, 0, NULL);
284 + if (!ref)
285 + continue;
286 if (!stat(git_path("logs/%s", path), &st) &&
280 - S_ISREG(st.st_mode)) {
281 - if (!logs_found++) {
282 - *log = xstrdup(path);
283 - resolve_ref(path, sha1, 0, NULL);
284 - }
285 - if (!warn_ambiguous_refs)
286 - break;
287 + S_ISREG(st.st_mode))
288 + it = path;
289 + else if (strcmp(ref, path) &&
290 + !stat(git_path("logs/%s", ref), &st) &&
291 + S_ISREG(st.st_mode))
292 + it = ref;
293 + else
294 + continue;
295 + if (!logs_found++) {
296 + *log = xstrdup(it);
297 + hashcpy(sha1, hash);
298 }
299 + if (!warn_ambiguous_refs)
300 + break;
301 }
302 return logs_found;
303 }