]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Add a 'source' decorator for commits
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 27 Oct 2008 19:51:59 +0000 (12:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Nov 2008 08:08:03 +0000 (00:08 -0800)
We already support decorating commits by tags or branches that point to
them, but especially when we are looking at multiple branches together,
we sometimes want to see _how_ we reached a particular commit.

We can abuse the '->util' field in the commit to keep track of that as
we walk the commit lists, and get a reasonably useful view into which
branch or tag first reaches that commit.

Of course, if the commit is reachable through multiple sources (which is
common), our particular choice of "first" reachable is entirely random
and depends on the particular path we happened to follow.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-log.c
builtin-rev-list.c
log-tree.c
log-tree.h
revision.c
revision.h

index a0944f70a4a3aa4f5fb08c4ac4ae7dc31d25d532..176cbce308be8147aa06134c57b846cb8a4761ed 100644 (file)
@@ -56,6 +56,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                if (!strcmp(arg, "--decorate")) {
                        load_ref_decorations();
                        decorate = 1;
+               } else if (!strcmp(arg, "--source")) {
+                       rev->show_source = 1;
                } else
                        die("unrecognized argument: %s", arg);
        }
index 06cdeb7ebe7468911a7bee670bf5ec539185ba54..857742a14f82e049c5b9e8b234dae9e9e1a7dc30 100644 (file)
@@ -100,7 +100,7 @@ static void show_commit(struct commit *commit)
                        children = children->next;
                }
        }
-       show_decorations(commit);
+       show_decorations(&revs, commit);
        if (revs.commit_format == CMIT_FMT_ONELINE)
                putchar(' ');
        else
index cec3c061360e9d33068fdb6c2555b69cc11f6771..cf7947b9c9c37cd0591effc7f3653c1ce2dd723d 100644 (file)
@@ -52,11 +52,13 @@ static void show_parents(struct commit *commit, int abbrev)
        }
 }
 
-void show_decorations(struct commit *commit)
+void show_decorations(struct rev_info *opt, struct commit *commit)
 {
        const char *prefix;
        struct name_decoration *decoration;
 
+       if (opt->show_source && commit->util)
+               printf(" %s", (char *) commit->util);
        decoration = lookup_decoration(&name_decoration, &commit->object);
        if (!decoration)
                return;
@@ -279,7 +281,7 @@ void show_log(struct rev_info *opt)
                fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
                if (opt->print_parents)
                        show_parents(commit, abbrev_commit);
-               show_decorations(commit);
+               show_decorations(opt, commit);
                if (opt->graph && !graph_is_commit_finished(opt->graph)) {
                        putchar('\n');
                        graph_show_remainder(opt->graph);
@@ -352,7 +354,7 @@ void show_log(struct rev_info *opt)
                        printf(" (from %s)",
                               diff_unique_abbrev(parent->object.sha1,
                                                  abbrev_commit));
-               show_decorations(commit);
+               show_decorations(opt, commit);
                printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
                if (opt->commit_format == CMIT_FMT_ONELINE) {
                        putchar(' ');
index 3c8127bb7cc8d27ff1e91ad6c159bc718fb7d9d0..f2a90084ae1874632318c7880e95426eca2682ea 100644 (file)
@@ -12,7 +12,7 @@ int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
 int log_tree_opt_parse(struct rev_info *, const char **, int);
 void show_log(struct rev_info *opt);
-void show_decorations(struct commit *commit);
+void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, const char *name,
                             const char **subject_p,
                             const char **extra_headers_p,
index 2f646deab09c423143185b7f7928ae46ab9f4c97..d45f05a00c8065669c232069caabf35634e6b9c2 100644 (file)
@@ -199,6 +199,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
                        mark_parents_uninteresting(commit);
                        revs->limited = 1;
                }
+               if (revs->show_source && !commit->util)
+                       commit->util = (void *) name;
                return commit;
        }
 
@@ -484,6 +486,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
 
                if (parse_commit(p) < 0)
                        return -1;
+               if (revs->show_source && !p->util)
+                       p->util = commit->util;
                p->object.flags |= left_flag;
                if (!(p->object.flags & SEEN)) {
                        p->object.flags |= SEEN;
index 2fdb2dd0ff3425b68b47aa8fd11155aa881d4a4a..51a48630e8e6c2768042846e7b2f07341b806da0 100644 (file)
@@ -53,6 +53,7 @@ struct rev_info {
                        left_right:1,
                        rewrite_parents:1,
                        print_parents:1,
+                       show_source:1,
                        reverse:1,
                        reverse_output_stage:1,
                        cherry_pick:1,