@matheusbsbs / matheus-bagliano / commits / 1df2d656cc
Fork 0

rev-list/log: factor out revision mark generation

Currently, we have identical code for generating revision marks ('<', '>', '-') in 5 places. Factor out the code to a single function get_revision_mark() for easier maintenance and extensibility. Note that the check for !!revs in graph.c (which gets removed effectively by this patch) is superfluous. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Mar 7, 2011 at 13:31 UTC 1df2d656cc442dc057e30b6fb130967e5ae19654
6 files changed +26 -56
builtin/rev-list.c
+2 -12
@@ -64,18 +64,8 @@ static void show_commit(struct commit *commit, void *data)
64 if (info->header_prefix)
65 fputs(info->header_prefix, stdout);
66
67 - if (!revs->graph) {
68 - if (commit->object.flags & BOUNDARY)
69 - putchar('-');
70 - else if (commit->object.flags & UNINTERESTING)
71 - putchar('^');
72 - else if (revs->left_right) {
73 - if (commit->object.flags & SYMMETRIC_LEFT)
74 - putchar('<');
75 - else
76 - putchar('>');
77 - }
78 - }
67 + if (!revs->graph)
68 + fputs(get_revision_mark(revs, commit), stdout);
69 if (revs->abbrev_commit && revs->abbrev)
70 fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
71 stdout);
graph.c
+2 -15
@@ -798,22 +798,9 @@ static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb)
798 }
799
800 /*
801 - * If revs->left_right is set, print '<' for commits that
802 - * come from the left side, and '>' for commits from the right
803 - * side.
801 + * get_revision_mark() handles all other cases without assert()
802 */
805 - if (graph->revs && graph->revs->left_right) {
806 - if (graph->commit->object.flags & SYMMETRIC_LEFT)
807 - strbuf_addch(sb, '<');
808 - else
809 - strbuf_addch(sb, '>');
810 - return;
811 - }
812 -
813 - /*
814 - * Print '*' in all other cases
815 - */
816 - strbuf_addch(sb, '*');
803 + strbuf_addstr(sb, get_revision_mark(graph->revs, graph->commit));
804 }
805
806 /*
log-tree.c
+4 -24
@@ -380,18 +380,8 @@ void show_log(struct rev_info *opt)
380 if (!opt->verbose_header) {
381 graph_show_commit(opt->graph);
382
383 - if (!opt->graph) {
384 - if (commit->object.flags & BOUNDARY)
385 - putchar('-');
386 - else if (commit->object.flags & UNINTERESTING)
387 - putchar('^');
388 - else if (opt->left_right) {
389 - if (commit->object.flags & SYMMETRIC_LEFT)
390 - putchar('<');
391 - else
392 - putchar('>');
393 - }
394 - }
383 + if (!opt->graph)
384 + fputs(get_revision_mark(opt, commit), stdout);
385 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
386 if (opt->print_parents)
387 show_parents(commit, abbrev_commit);
@@ -448,18 +438,8 @@ void show_log(struct rev_info *opt)
438 if (opt->commit_format != CMIT_FMT_ONELINE)
439 fputs("commit ", stdout);
440
451 - if (!opt->graph) {
452 - if (commit->object.flags & BOUNDARY)
453 - putchar('-');
454 - else if (commit->object.flags & UNINTERESTING)
455 - putchar('^');
456 - else if (opt->left_right) {
457 - if (commit->object.flags & SYMMETRIC_LEFT)
458 - putchar('<');
459 - else
460 - putchar('>');
461 - }
462 - }
441 + if (!opt->graph)
442 + fputs(get_revision_mark(opt, commit), stdout);
443 fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
444 stdout);
445 if (opt->print_parents)
pretty.c
+1 -5
@@ -859,11 +859,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
859 c->abbrev_parent_hashes.off;
860 return 1;
861 case 'm': /* left/right/bottom */
862 - strbuf_addch(sb, (commit->object.flags & BOUNDARY)
863 - ? '-'
864 - : (commit->object.flags & SYMMETRIC_LEFT)
865 - ? '<'
866 - : '>');
862 + strbuf_addstr(sb, get_revision_mark(NULL, commit));
863 return 1;
864 case 'd':
865 format_decoration(sb, commit);
revision.c
+16
@@ -2263,3 +2263,19 @@ struct commit *get_revision(struct rev_info *revs)
2263 graph_update(revs->graph, c);
2264 return c;
2265 }
2266 +
2267 +char *get_revision_mark(const struct rev_info *revs, const struct commit *commit)
2268 +{
2269 + if (commit->object.flags & BOUNDARY)
2270 + return "-";
2271 + else if (commit->object.flags & UNINTERESTING)
2272 + return "^";
2273 + else if (!revs || revs->left_right) {
2274 + if (commit->object.flags & SYMMETRIC_LEFT)
2275 + return "<";
2276 + else
2277 + return ">";
2278 + } else if (revs->graph)
2279 + return "*";
2280 + return "";
2281 +}
revision.h
+1
@@ -165,6 +165,7 @@ extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,
165
166 extern int prepare_revision_walk(struct rev_info *revs);
167 extern struct commit *get_revision(struct rev_info *revs);
168 +extern char *get_revision_mark(const struct rev_info *revs, const struct commit *commit);
169
170 extern void mark_parents_uninteresting(struct commit *commit);
171 extern void mark_tree_uninteresting(struct tree *tree);