login
Header Space

 
 

Re: [PATCH] log --reflog: use dwim_log

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Nicolas Pitre <nico@...>
Cc: <git@...>, Johannes Schindelin <Johannes.Schindelin@...>
Date: Friday, February 9, 2007 - 3:19 am

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 <junkio@cox.net> writes:

 > Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
 >
 >> Since "git log origin/master" uses dwim_log() to match
 >> "refs/remotes/origin/master", it makes sense to do that for
 >> "git log --reflog", too.
 >
 > This is a bit sad.
 >
 > When there is remotes/origin/HEAD symref that points at
 > remotes/origin/master (and usually there is, in a repository
 > initialized with the current git-clone), you can say "git log
 > origin".  Even with this patch, I do not think dwim_log would
 > allow you to say "git log -g origin" to mean "git log -g
 > origin/master".

 I think there should be a cleaner way to fix this, but at least
 this seems to work.

 sha1_name.c |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index f79a7c9..09c63ed 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];
+		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;
 }

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [BUG] Empty reflogs and "git log -g", Jakub Narebski, (Thu Feb 8, 3:37 pm)
Re: [BUG] Empty reflogs and "git log -g", Johannes Schindelin, (Thu Feb 8, 3:46 pm)
Re: [BUG] Empty reflogs and "git log -g", Junio C Hamano, (Thu Feb 8, 7:18 pm)
[PATCH] log --reflog: use dwim_log, Johannes Schindelin, (Thu Feb 8, 8:28 pm)
Re: [PATCH] log --reflog: use dwim_log, Junio C Hamano, (Thu Feb 8, 11:43 pm)
Re: [PATCH] log --reflog: use dwim_log, Junio C Hamano, (Fri Feb 9, 3:19 am)
[PATCH] for_each_reflog_ent: be forgiving about missing mess..., Johannes Schindelin, (Thu Feb 8, 7:59 pm)
speck-geostationary