Skip to content

Commit

Permalink
Merge branch 'mg/log-decorate-HEAD'
Browse files Browse the repository at this point in the history
The "log --decorate" enhancement in Git 2.4 that shows the commit
at the tip of the current branch e.g. "HEAD -> master", did not
work with --decorate=full.

* mg/log-decorate-HEAD:
  log: do not shorten decoration names too early
  log: decorate HEAD with branch name under --decorate=full, too
  • Loading branch information
gitster committed May 22, 2015
2 parents d1caa58 + 429ad20 commit fd70780
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions log-tree.c
Expand Up @@ -13,6 +13,8 @@
#include "line-log.h"

static struct decoration name_decoration = { "object names" };
static int decoration_loaded;
static int decoration_flags;

static char decoration_colors[][COLOR_MAXLEN] = {
GIT_COLOR_RESET,
Expand Down Expand Up @@ -92,6 +94,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
struct object *obj;
enum decoration_type type = DECORATION_NONE;

assert(cb_data == NULL);

if (starts_with(refname, "refs/replace/")) {
unsigned char original_sha1[20];
if (!check_replace_refs)
Expand Down Expand Up @@ -121,8 +125,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
else if (!strcmp(refname, "HEAD"))
type = DECORATION_REF_HEAD;

if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
refname = prettify_refname(refname);
add_name_decoration(type, refname, obj);
while (obj->type == OBJ_TAG) {
obj = ((struct tag *)obj)->tagged;
Expand All @@ -146,11 +148,11 @@ static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)

void load_ref_decorations(int flags)
{
static int loaded;
if (!loaded) {
loaded = 1;
for_each_ref(add_ref_decoration, &flags);
head_ref(add_ref_decoration, &flags);
if (!decoration_loaded) {
decoration_loaded = 1;
decoration_flags = flags;
for_each_ref(add_ref_decoration, NULL);
head_ref(add_ref_decoration, NULL);
for_each_commit_graft(add_graft_decoration, NULL);
}
}
Expand Down Expand Up @@ -196,7 +198,8 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags);
if (!(rru_flags & REF_ISSYMREF))
return NULL;
if (!skip_prefix(branch_name, "refs/heads/", &branch_name))

if (!starts_with(branch_name, "refs/"))
return NULL;

/* OK, do we have that ref in the list? */
Expand All @@ -209,6 +212,14 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d
return NULL;
}

static void show_name(struct strbuf *sb, const struct name_decoration *decoration)
{
if (decoration_flags == DECORATE_SHORT_REFS)
strbuf_addstr(sb, prettify_refname(decoration->name));
else
strbuf_addstr(sb, decoration->name);
}

/*
* The caller makes sure there is no funny color before calling.
* format_decorations_extended makes sure the same after return.
Expand Down Expand Up @@ -246,7 +257,7 @@ void format_decorations_extended(struct strbuf *sb,
if (decoration->type == DECORATION_REF_TAG)
strbuf_addstr(sb, "tag: ");

strbuf_addstr(sb, decoration->name);
show_name(sb, decoration);

if (current_and_HEAD &&
decoration->type == DECORATION_REF_HEAD) {
Expand All @@ -255,7 +266,7 @@ void format_decorations_extended(struct strbuf *sb,
strbuf_addstr(sb, " -> ");
strbuf_addstr(sb, color_reset);
strbuf_addstr(sb, decorate_get_color(use_color, current_and_HEAD->type));
strbuf_addstr(sb, current_and_HEAD->name);
show_name(sb, current_and_HEAD);
}
strbuf_addstr(sb, color_reset);

Expand Down
2 changes: 1 addition & 1 deletion t/t4013/diff.log_--decorate=full_--all
Expand Up @@ -5,7 +5,7 @@ Date: Mon Jun 26 00:06:00 2006 +0000

Rearranged lines in dir/sub

commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, refs/heads/master)
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD -> refs/heads/master)
Merge: 9a6d494 c7a2ab9
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:04:00 2006 +0000
Expand Down

0 comments on commit fd70780

Please sign in to comment.