From 7528f27dd677bed65d758667a621034b853595b4 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Sun, 25 May 2008 00:07:21 -0700 Subject: [PATCH] log --graph --left-right: show left/right information in place of '*' With the --graph option, the graph already outputs 'o' instead of '*' for boundary commits. Make it emit '<' or '>' when --left-right is specified. (This change also disables the '^' prefix for UNINTERESTING commits. The graph code currently doesn't print anything special for these commits, since it assumes no UNINTERESTING, non-BOUNDARY commits are displayed. This is potentially a bug if UNINTERESTING non-BOUNDARY commits can actually be displayed via some code path.) [jc: squashed the left-right change from Dscho and Adam's fixup into one] Signed-off-by: Adam Simpkins Signed-off-by: Junio C Hamano --- Documentation/technical/api-history-graph.txt | 2 +- builtin-rev-list.c | 21 ++++++---- graph.c | 22 +++++----- graph.h | 2 +- log-tree.c | 41 +++++++++++-------- revision.c | 2 +- 6 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Documentation/technical/api-history-graph.txt b/Documentation/technical/api-history-graph.txt index ce1c08ee8..e9559790a 100644 --- a/Documentation/technical/api-history-graph.txt +++ b/Documentation/technical/api-history-graph.txt @@ -115,7 +115,7 @@ Sample usage ------------ struct commit *commit; -struct git_graph *graph = graph_init(); +struct git_graph *graph = graph_init(opts); while ((commit = get_revision(opts)) != NULL) { graph_update(graph, commit); diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 54d55cc3a..b47452740 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -65,15 +65,18 @@ static void show_commit(struct commit *commit) printf("%lu ", commit->date); if (header_prefix) fputs(header_prefix, stdout); - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (revs.left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); + + if (!revs.graph) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (revs.left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } } if (revs.abbrev_commit && revs.abbrev) fputs(find_unique_abbrev(commit->object.sha1, revs.abbrev), diff --git a/graph.c b/graph.c index add7e4477..dc2c1ec5d 100644 --- a/graph.c +++ b/graph.c @@ -54,6 +54,8 @@ struct git_graph { * The commit currently being processed */ struct commit *commit; + /* The rev-info used for the current traversal */ + struct rev_info *revs; /* * The number of interesting parents that this commit has. * @@ -127,10 +129,11 @@ struct git_graph { int *new_mapping; }; -struct git_graph *graph_init(void) +struct git_graph *graph_init(struct rev_info *opt) { struct git_graph *graph = xmalloc(sizeof(struct git_graph)); graph->commit = NULL; + graph->revs = opt; graph->num_parents = 0; graph->expansion_row = 0; graph->state = GRAPH_PADDING; @@ -565,16 +568,13 @@ void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb) if (col_commit == graph->commit) { seen_this = 1; - /* - * If the commit has more than 1 interesting - * parent, print 'M' to indicate that it is a - * merge. Otherwise, print '*'. - * - * Note that even if this is actually a merge - * commit, we still print '*' if less than 2 of its - * parents are interesting. - */ - if (graph->num_parents > 1) + + if (graph->revs && graph->revs->left_right) { + if (graph->commit->object.flags & SYMMETRIC_LEFT) + strbuf_addch(sb, '<'); + else + strbuf_addch(sb, '>'); + } else if (graph->num_parents > 1) strbuf_addch(sb, 'M'); else strbuf_addch(sb, '*'); diff --git a/graph.h b/graph.h index a7748a5b2..eab4e3dab 100644 --- a/graph.h +++ b/graph.h @@ -8,7 +8,7 @@ struct git_graph; * Create a new struct git_graph. * The graph should be freed with graph_release() when no longer needed. */ -struct git_graph *graph_init(); +struct git_graph *graph_init(struct rev_info *opt); /* * Destroy a struct git_graph and free associated memory. diff --git a/log-tree.c b/log-tree.c index 1474d1f5d..5505606ed 100644 --- a/log-tree.c +++ b/log-tree.c @@ -228,15 +228,17 @@ void show_log(struct rev_info *opt) if (!opt->verbose_header) { graph_show_commit(opt->graph); - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); + if (!opt->graph) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); if (opt->print_parents) @@ -293,15 +295,18 @@ void show_log(struct rev_info *opt) fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); if (opt->commit_format != CMIT_FMT_ONELINE) fputs("commit ", stdout); - if (commit->object.flags & BOUNDARY) - putchar('-'); - else if (commit->object.flags & UNINTERESTING) - putchar('^'); - else if (opt->left_right) { - if (commit->object.flags & SYMMETRIC_LEFT) - putchar('<'); - else - putchar('>'); + + if (!opt->graph) { + if (commit->object.flags & BOUNDARY) + putchar('-'); + else if (commit->object.flags & UNINTERESTING) + putchar('^'); + else if (opt->left_right) { + if (commit->object.flags & SYMMETRIC_LEFT) + putchar('<'); + else + putchar('>'); + } } fputs(diff_unique_abbrev(commit->object.sha1, abbrev_commit), stdout); diff --git a/revision.c b/revision.c index 7142cf96c..1341f3d12 100644 --- a/revision.c +++ b/revision.c @@ -1205,7 +1205,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch if (!prefixcmp(arg, "--graph")) { revs->topo_order = 1; revs->rewrite_parents = 1; - revs->graph = graph_init(); + revs->graph = graph_init(revs); continue; } if (!strcmp(arg, "--root")) { -- 2.30.2