summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 24852d9)
raw | patch | inline | side by side (parent: 24852d9)
author | Michael J Gruber <git@drmicha.warpmail.net> | |
Mon, 7 Mar 2011 12:31:39 +0000 (13:31 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 9 Mar 2011 21:50:54 +0000 (13:50 -0800) |
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>
'>', '-') 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>
builtin/rev-list.c | patch | blob | history | |
graph.c | patch | blob | history | |
log-tree.c | patch | blob | history | |
pretty.c | patch | blob | history | |
revision.c | patch | blob | history | |
revision.h | patch | blob | history |
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ba27d39f977f2807cddb6e18364837b9fd50e970..f458cb7587c7d40cf93d42d73379fac485ee3889 100644 (file)
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
if (info->header_prefix)
fputs(info->header_prefix, stdout);
- 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->graph)
+ fputs(get_revision_mark(revs, commit), stdout);
if (revs->abbrev_commit && revs->abbrev)
fputs(find_unique_abbrev(commit->object.sha1, revs->abbrev),
stdout);
index f1a63c2241a30cce0141b87b5e8005b1a899a8ef..ef2e24e85a41dc97cf00bb7b19985ec01b8662bf 100644 (file)
--- a/graph.c
+++ b/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
- * come from the left side, and '>' for commits from the right
- * side.
+ * get_revision_mark() handles all other cases without assert()
*/
- if (graph->revs && graph->revs->left_right) {
- if (graph->commit->object.flags & SYMMETRIC_LEFT)
- strbuf_addch(sb, '<');
- else
- strbuf_addch(sb, '>');
- return;
- }
-
- /*
- * Print '*' in all other cases
- */
- strbuf_addch(sb, '*');
+ strbuf_addstr(sb, get_revision_mark(graph->revs, graph->commit));
}
/*
diff --git a/log-tree.c b/log-tree.c
index b46ed3baef7d9d9971a3886d700059217fbe974a..12570403110cf579b0b9373fda6f80b34488b2d4 100644 (file)
--- a/log-tree.c
+++ b/log-tree.c
if (!opt->verbose_header) {
graph_show_commit(opt->graph);
- 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('>');
- }
- }
+ if (!opt->graph)
+ fputs(get_revision_mark(opt, commit), stdout);
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit), stdout);
if (opt->print_parents)
show_parents(commit, abbrev_commit);
if (opt->commit_format != CMIT_FMT_ONELINE)
fputs("commit ", stdout);
- 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('>');
- }
- }
+ if (!opt->graph)
+ fputs(get_revision_mark(opt, commit), stdout);
fputs(find_unique_abbrev(commit->object.sha1, abbrev_commit),
stdout);
if (opt->print_parents)
diff --git a/pretty.c b/pretty.c
index 85499347514ec3e1d62d6caa9f53b886c556e345..f21a30ccca66e31130edf85a935f350a8b73a4ad 100644 (file)
--- a/pretty.c
+++ b/pretty.c
c->abbrev_parent_hashes.off;
return 1;
case 'm': /* left/right/bottom */
- strbuf_addch(sb, (commit->object.flags & BOUNDARY)
- ? '-'
- : (commit->object.flags & SYMMETRIC_LEFT)
- ? '<'
- : '>');
+ strbuf_addstr(sb, get_revision_mark(NULL, commit));
return 1;
case 'd':
format_decoration(sb, commit);
diff --git a/revision.c b/revision.c
index 1fcaeb79024665910099ea4cd377ed5cd9a5a707..0de1608d045d6fec757dd77f9c432938483ea5d3 100644 (file)
--- a/revision.c
+++ b/revision.c
graph_update(revs->graph, 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 "";
+}
diff --git a/revision.h b/revision.h
index d2ffde1ce67a555ec6ac8b00b3b225a7bdad2319..0e4b35e8e54ba9b6c574a7d6b628d1fe9a325ca6 100644 (file)
--- a/revision.h
+++ b/revision.h
@@ -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 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_tree_uninteresting(struct tree *tree);