"git status" and "git branch" let the user know when the HEAD is
detached, while "git log --decorate" does not.

Change the decoration by a detached HEAD to "detached HEAD". This can be
seen as giving more information about the decoration item itself in the
same way as we prefix tags by "tag: ".

Signed-off-by: Michael J Gruber <g...@drmicha.warpmail.net>
---
This turned out to be easy to do, though I am still undecided.
Personally, I like to think of refs as objects (and have implemented refname
objects in the past), but that view is not too popular.

So, maybe the analogy between ref peeling and symref resolving (for HEAD) is
not that strong after all. They are both indirections, though different 
technically.

The RFC patch only checks HEAD for being a symref, the output is analogous to 
the summary of "git commit".

 log-tree.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/log-tree.c b/log-tree.c
index 7f0890e..2eac4b6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -118,8 +118,14 @@ static int add_ref_decoration(const char *refname, const 
unsigned char *sha1, in
                type = DECORATION_REF_TAG;
        else if (!strcmp(refname, "refs/stash"))
                type = DECORATION_REF_STASH;
-       else if (!strcmp(refname, "HEAD"))
+       else if (!strcmp(refname, "HEAD")) {
+               char *junk_sha1[20];
+               char *head;
                type = DECORATION_REF_HEAD;
+               head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
+               if (!strcmp(head, "HEAD"))
+                       refname = "detached HEAD";
+       }
 
        if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
                refname = prettify_refname(refname);
-- 
2.3.0.136.g92a3b58

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to