diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2007-04-16 16:05:10 -0700 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-04-16 16:51:11 -0700 |
commit | ca135e7acc06f7d24ead732d2a1a531428da7135 (patch) | |
tree | 5a56e061f15602736847ec608839619cf377e09c /builtin-log.c | |
parent | a59b276e18f3d4a548caf549e05188cb1bd3a709 (diff) | |
download | git-ca135e7acc06f7d24ead732d2a1a531428da7135.tar.gz |
Add support for "commit name decorations" to log family of commands
This adds "--decorate" as a log option, which prints out the ref names
of any commits that are shown.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-log.c')
-rw-r--r-- | builtin-log.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/builtin-log.c b/builtin-log.c index 469949457f..38bf52f100 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -13,16 +13,43 @@ #include "tag.h" #include "reflog-walk.h" #include "patch-ids.h" +#include "refs.h" static int default_show_root = 1; /* this is in builtin-diff.c */ void add_head(struct rev_info *revs); +static void add_name_decoration(const char *prefix, const char *name, struct object *obj) +{ + int plen = strlen(prefix); + int nlen = strlen(name); + struct name_decoration *res = xmalloc(sizeof(struct name_decoration) + plen + nlen); + memcpy(res->name, prefix, plen); + memcpy(res->name + plen, name, nlen + 1); + res->next = add_decoration(&name_decoration, obj, res); +} + +static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data) +{ + struct object *obj = parse_object(sha1); + if (!obj) + return 0; + add_name_decoration("", refname, obj); + while (obj->type == OBJ_TAG) { + obj = ((struct tag *)obj)->tagged; + if (!obj) + break; + add_name_decoration("tag: ", refname, obj); + } + return 0; +} + static void cmd_log_init(int argc, const char **argv, const char *prefix, struct rev_info *rev) { int i; + int decorate = 0; rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; @@ -39,8 +66,11 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, git_log_output_encoding = xstrdup(arg); else git_log_output_encoding = ""; - } - else + } else if (!strcmp(arg, "--decorate")) { + if (!decorate) + for_each_ref(add_ref_decoration, NULL); + decorate = 1; + } else die("unrecognized argument: %s", arg); } } |