git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Nicolas Pitre <nico@cam.org>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] log --reflog: use dwim_log
Date: Thu, 08 Feb 2007 23:19:59 -0800	[thread overview]
Message-ID: <7v4ppvvluo.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vtzxwuhb1.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Thu, 08 Feb 2007 19:43:30 -0800")

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;
 }

      reply	other threads:[~2007-02-09  7:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-08  1:21 [BUG] Empty reflogs and "git log -g" Santi Béjar
2007-02-08  7:25 ` Santi Béjar
2007-02-08 19:36   ` Johannes Schindelin
2007-02-08 19:49     ` Nicolas Pitre
2007-02-08 20:02       ` Johannes Schindelin
2007-02-08 19:22 ` Johannes Schindelin
2007-02-08 19:37   ` Jakub Narebski
2007-02-08 19:46     ` Johannes Schindelin
2007-02-08 23:18       ` Junio C Hamano
2007-02-08 23:59         ` [PATCH] for_each_reflog_ent: be forgiving about missing message Johannes Schindelin
2007-02-09  0:28         ` [PATCH] log --reflog: use dwim_log Johannes Schindelin
2007-02-09  3:43           ` Junio C Hamano
2007-02-09  7:19             ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v4ppvvluo.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=nico@cam.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).