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>
This commit is contained in:
parent
24852d9171
commit
1df2d656cc
@ -64,18 +64,8 @@ static void show_commit(struct commit *commit, void *data)
|
|||||||
if (info->header_prefix)
|
if (info->header_prefix)
|
||||||
fputs(info->header_prefix, stdout);
|
fputs(info->header_prefix, stdout);
|
||||||
|
|
||||||
if (!revs->graph) {
|
if (!revs->graph)
|
||||||
if (commit->object.flags & BOUNDARY)
|
fputs(get_revision_mark(revs, commit), stdout);
|
||||||
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)
|
if (revs->abbrev_commit && revs->abbrev)
|
||||||
fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
|
fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
|
||||||
stdout);
|
stdout);
|
||||||
|
17
graph.c
17
graph.c
@ -798,22 +798,9 @@ static void graph_output_commit_char(struct git_graph *graph, struct strbuf *sb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If revs->left_right is set, print '<' for commits that
|
* get_revision_mark() handles all other cases without assert()
|
||||||
* come from the left side, and '>' for commits from the right
|
|
||||||
* side.
|
|
||||||
*/
|
*/
|
||||||
if (graph->revs && graph->revs->left_right) {
|
strbuf_addstr(sb, get_revision_mark(graph->revs, graph->commit));
|
||||||
if (graph->commit->object.flags & SYMMETRIC_LEFT)
|
|
||||||
strbuf_addch(sb, '<');
|
|
||||||
else
|
|
||||||
strbuf_addch(sb, '>');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Print '*' in all other cases
|
|
||||||
*/
|
|
||||||
strbuf_addch(sb, '*');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
28
log-tree.c
28
log-tree.c
@ -380,18 +380,8 @@ void show_log(struct rev_info *opt)
|
|||||||
if (!opt->verbose_header) {
|
if (!opt->verbose_header) {
|
||||||
graph_show_commit(opt->graph);
|
graph_show_commit(opt->graph);
|
||||||
|
|
||||||
if (!opt->graph) {
|
if (!opt->graph)
|
||||||
if (commit->object.flags & BOUNDARY)
|
fputs(get_revision_mark(opt, commit), stdout);
|
||||||
putchar('-');
|
|
||||||
else if (commit->object.flags & UNINTERESTING)
|
|
||||||
putchar('^');
|
|
||||||
else if (opt->left_right) {
|
|
||||||
if (commit->object.flags & SYMMETRIC_LEFT)
|
|
||||||
putchar('<');
|
|
||||||
else
|
|
||||||
putchar('>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
|
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
|
||||||
if (opt->print_parents)
|
if (opt->print_parents)
|
||||||
show_parents(commit, abbrev_commit);
|
show_parents(commit, abbrev_commit);
|
||||||
@ -448,18 +438,8 @@ void show_log(struct rev_info *opt)
|
|||||||
if (opt->commit_format != CMIT_FMT_ONELINE)
|
if (opt->commit_format != CMIT_FMT_ONELINE)
|
||||||
fputs("commit ", stdout);
|
fputs("commit ", stdout);
|
||||||
|
|
||||||
if (!opt->graph) {
|
if (!opt->graph)
|
||||||
if (commit->object.flags & BOUNDARY)
|
fputs(get_revision_mark(opt, commit), stdout);
|
||||||
putchar('-');
|
|
||||||
else if (commit->object.flags & UNINTERESTING)
|
|
||||||
putchar('^');
|
|
||||||
else if (opt->left_right) {
|
|
||||||
if (commit->object.flags & SYMMETRIC_LEFT)
|
|
||||||
putchar('<');
|
|
||||||
else
|
|
||||||
putchar('>');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
|
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
|
||||||
stdout);
|
stdout);
|
||||||
if (opt->print_parents)
|
if (opt->print_parents)
|
||||||
|
6
pretty.c
6
pretty.c
@ -859,11 +859,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
|
|||||||
c->abbrev_parent_hashes.off;
|
c->abbrev_parent_hashes.off;
|
||||||
return 1;
|
return 1;
|
||||||
case 'm': /* left/right/bottom */
|
case 'm': /* left/right/bottom */
|
||||||
strbuf_addch(sb, (commit->object.flags & BOUNDARY)
|
strbuf_addstr(sb, get_revision_mark(NULL, commit));
|
||||||
? '-'
|
|
||||||
: (commit->object.flags & SYMMETRIC_LEFT)
|
|
||||||
? '<'
|
|
||||||
: '>');
|
|
||||||
return 1;
|
return 1;
|
||||||
case 'd':
|
case 'd':
|
||||||
format_decoration(sb, commit);
|
format_decoration(sb, commit);
|
||||||
|
16
revision.c
16
revision.c
@ -2263,3 +2263,19 @@ struct commit *get_revision(struct rev_info *revs)
|
|||||||
graph_update(revs->graph, c);
|
graph_update(revs->graph, c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *get_revision_mark(const struct rev_info *revs, const struct commit *commit)
|
||||||
|
{
|
||||||
|
if (commit->object.flags & BOUNDARY)
|
||||||
|
return "-";
|
||||||
|
else if (commit->object.flags & UNINTERESTING)
|
||||||
|
return "^";
|
||||||
|
else if (!revs || revs->left_right) {
|
||||||
|
if (commit->object.flags & SYMMETRIC_LEFT)
|
||||||
|
return "<";
|
||||||
|
else
|
||||||
|
return ">";
|
||||||
|
} else if (revs->graph)
|
||||||
|
return "*";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
@ -165,6 +165,7 @@ extern int handle_revision_arg(const char *arg, struct rev_info *revs,int flags,
|
|||||||
|
|
||||||
extern int prepare_revision_walk(struct rev_info *revs);
|
extern int prepare_revision_walk(struct rev_info *revs);
|
||||||
extern struct commit *get_revision(struct rev_info *revs);
|
extern struct commit *get_revision(struct rev_info *revs);
|
||||||
|
extern char *get_revision_mark(const struct rev_info *revs, const struct commit *commit);
|
||||||
|
|
||||||
extern void mark_parents_uninteresting(struct commit *commit);
|
extern void mark_parents_uninteresting(struct commit *commit);
|
||||||
extern void mark_tree_uninteresting(struct tree *tree);
|
extern void mark_tree_uninteresting(struct tree *tree);
|
||||||
|
Loading…
Reference in New Issue
Block a user