Add a 'source' decorator for commits
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>
Linus Torvalds committed
Oct 27, 2008 at 12:51 UTC
0f3a290b89b89bb5375cf5019b067e4a99f02620
6 files changed
+14
-5
builtin-log.c
+2
@@ -56,6 +56,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
56
if (!strcmp(arg, "--decorate")) {
57
load_ref_decorations();
58
decorate = 1;
59
+ } else if (!strcmp(arg, "--source")) {
60
+ rev->show_source = 1;
61
} else
62
die("unrecognized argument: %s", arg);
63
}
builtin-rev-list.c
+1
-1
@@ -100,7 +100,7 @@ static void show_commit(struct commit *commit)
100
children = children->next;
101
}
102
}
103
- show_decorations(commit);
103
+ show_decorations(&revs, commit);
104
if (revs.commit_format == CMIT_FMT_ONELINE)
105
putchar(' ');
106
else
log-tree.c
+5
-3
@@ -52,11 +52,13 @@ static void show_parents(struct commit *commit, int abbrev)
52
}
53
}
54
55
-void show_decorations(struct commit *commit)
55
+void show_decorations(struct rev_info *opt, struct commit *commit)
56
{
57
const char *prefix;
58
struct name_decoration *decoration;
59
60
+ if (opt->show_source && commit->util)
61
+ printf(" %s", (char *) commit->util);
62
decoration = lookup_decoration(&name_decoration, &commit->object);
63
if (!decoration)
64
return;
@@ -279,7 +281,7 @@ void show_log(struct rev_info *opt)
281
fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
282
if (opt->print_parents)
283
show_parents(commit, abbrev_commit);
282
- show_decorations(commit);
284
+ show_decorations(opt, commit);
285
if (opt->graph && !graph_is_commit_finished(opt->graph)) {
286
putchar('\n');
287
graph_show_remainder(opt->graph);
@@ -352,7 +354,7 @@ void show_log(struct rev_info *opt)
354
printf(" (from %s)",
355
diff_unique_abbrev(parent->object.sha1,
356
abbrev_commit));
355
- show_decorations(commit);
357
+ show_decorations(opt, commit);
358
printf("%s", diff_get_color_opt(&opt->diffopt, DIFF_RESET));
359
if (opt->commit_format == CMIT_FMT_ONELINE) {
360
putchar(' ');
log-tree.h
+1
-1
@@ -12,7 +12,7 @@ int log_tree_diff_flush(struct rev_info *);
12
int log_tree_commit(struct rev_info *, struct commit *);
13
int log_tree_opt_parse(struct rev_info *, const char **, int);
14
void show_log(struct rev_info *opt);
15
-void show_decorations(struct commit *commit);
15
+void show_decorations(struct rev_info *opt, struct commit *commit);
16
void log_write_email_headers(struct rev_info *opt, const char *name,
17
const char **subject_p,
18
const char **extra_headers_p,
revision.c
+4
@@ -199,6 +199,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
199
mark_parents_uninteresting(commit);
200
revs->limited = 1;
201
}
202
+ if (revs->show_source && !commit->util)
203
+ commit->util = (void *) name;
204
return commit;
205
}
206
@@ -484,6 +486,8 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit,
486
487
if (parse_commit(p) < 0)
488
return -1;
489
+ if (revs->show_source && !p->util)
490
+ p->util = commit->util;
491
p->object.flags |= left_flag;
492
if (!(p->object.flags & SEEN)) {
493
p->object.flags |= SEEN;
revision.h
+1
@@ -53,6 +53,7 @@ struct rev_info {
53
left_right:1,
54
rewrite_parents:1,
55
print_parents:1,
56
+ show_source:1,
57
reverse:1,
58
reverse_output_stage:1,
59
cherry_pick:1,