git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Yury Polyanskiy <polyanskiy@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Why not show ORIG_HEAD in git-log --decorate?
Date: Fri, 9 Apr 2010 21:29:03 -0400	[thread overview]
Message-ID: <20100410012903.GA32428@coredump.intra.peff.net> (raw)
In-Reply-To: <s2zea182b21004090907i9af49416za4fdb4650af5ae29@mail.gmail.com>

On Fri, Apr 09, 2010 at 12:07:00PM -0400, Yury Polyanskiy wrote:

> It would be very convenient if after git-pull I could see the new
> merged-in commits in the git-log. The simplest solution for this is to
> simply mark ORIG_HEAD in the output of git-log --decorate (and ideally
> also in gitk).

I think most people do something like:

  gitk HEAD^..ORIG_HEAD

To see everything in ORIG_HEAD that isn't in HEAD^ (the first parent of
HEAD, or what you had just before the pull).

> Just thought to throw in this idea to developers. Perhaps it is not
> that hard to implement.

Marking ORIG_HEAD in git-log is pretty straightforward. If we wanted to
do that, probably MERGE_HEAD and FETCH_HEAD should be marked, too.
I don't really have an opinion, as I don't generally use "git log
--decorate", but the patch for git-log would look something like what is
below (I am not planning on taking it further, but if somebody wants to
think more about the issues, they are welcome to pick it up and work on
it).

gitk would need a separate patch, as it uses a separate mechanism.

diff --git a/log-tree.c b/log-tree.c
index d3ae969..e2034c4 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -43,7 +43,7 @@ void load_ref_decorations(int flags)
 	if (!loaded) {
 		loaded = 1;
 		for_each_ref(add_ref_decoration, &flags);
-		head_ref(add_ref_decoration, &flags);
+		for_each_metaref(add_ref_decoration, &flags);
 	}
 }
 
diff --git a/refs.c b/refs.c
index d3db15a..eef7e13 100644
--- a/refs.c
+++ b/refs.c
@@ -663,6 +663,28 @@ int head_ref(each_ref_fn fn, void *cb_data)
 	return 0;
 }
 
+int for_each_metaref(each_ref_fn fn, void *cb_data)
+{
+	static const char *meta_refs[] = {
+		"HEAD",
+		"ORIG_HEAD",
+		"FETCH_HEAD",
+		"MERGE_HEAD",
+	};
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(meta_refs); i++) {
+		unsigned char sha1[20];
+		int flag;
+		if (resolve_ref(meta_refs[i], sha1, 1, &flag)) {
+			int ret = fn(meta_refs[i], sha1, flag, cb_data);
+			if (ret)
+				return ret;
+		}
+	}
+	return 0;
+}
+
 int for_each_ref(each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref("refs/", fn, 0, 0, cb_data);
diff --git a/refs.h b/refs.h
index 4a18b08..7e72c4d 100644
--- a/refs.h
+++ b/refs.h
@@ -19,6 +19,7 @@ struct ref_lock {
  */
 typedef int each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data);
 extern int head_ref(each_ref_fn, void *);
+extern int for_each_metaref(each_ref_fn, void *);
 extern int for_each_ref(each_ref_fn, void *);
 extern int for_each_ref_in(const char *, each_ref_fn, void *);
 extern int for_each_tag_ref(each_ref_fn, void *);

  reply	other threads:[~2010-04-10  1:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 16:07 Why not show ORIG_HEAD in git-log --decorate? Yury Polyanskiy
2010-04-10  1:29 ` Jeff King [this message]
2010-04-10  9:00   ` Björn Steinbrink
2010-04-10  9:04     ` Jeff King

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=20100410012903.GA32428@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=polyanskiy@gmail.com \
    /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).