From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCHv2 5/9] rev-list/log: factor out revision mark generation
Date: Mon, 7 Mar 2011 13:31:39 +0100 [thread overview]
Message-ID: <bc30fe8d0aa63a46b6dcaee365dbb6addf11909f.1299499429.git.git@drmicha.warpmail.net> (raw)
In-Reply-To: <cover.1299499429.git.git@drmicha.warpmail.net>
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>
---
builtin/rev-list.c | 14 ++------------
graph.c | 17 ++---------------
log-tree.c | 28 ++++------------------------
pretty.c | 6 +-----
revision.c | 17 +++++++++++++++++
revision.h | 1 +
6 files changed, 27 insertions(+), 56 deletions(-)
diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index ba27d39..f458cb7 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -64,18 +64,8 @@ static void show_commit(struct commit *commit, void *data)
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);
diff --git a/graph.c b/graph.c
index f1a63c2..ef2e24e 100644
--- 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 b46ed3b..1257040 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -380,18 +380,8 @@ void show_log(struct rev_info *opt)
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);
@@ -448,18 +438,8 @@ void show_log(struct rev_info *opt)
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 8549934..f21a30c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -859,11 +859,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
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 1fcaeb7..49d9ba8 100644
--- a/revision.c
+++ b/revision.c
@@ -2263,3 +2263,20 @@ struct commit *get_revision(struct rev_info *revs)
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 d2ffde1..0e4b35e 100644
--- 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);
--
1.7.4.1.299.g567d7.dirty
next prev parent reply other threads:[~2011-03-07 12:35 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-07 12:31 [PATCHv2 0/9] --left/right-only and --cherry-mark Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 1/9] revlist.c: introduce --left/right-only for unsymmetric picking Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 2/9] t6007: Make sure we test --cherry-pick Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 3/9] rev-list: documentation and test for --left/right-only Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 4/9] rev-list: --left/right-only are mutually exclusive Michael J Gruber
2011-03-07 12:31 ` Michael J Gruber [this message]
2011-03-07 12:31 ` [PATCHv2 6/9] revision.c: introduce --cherry-mark Michael J Gruber
2011-03-09 21:29 ` Junio C Hamano
2011-03-10 8:23 ` [PATCHv2+ " Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 7/9] rev-list: documentation and test for --cherry-mark Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 8/9] log --cherry: a synonym Michael J Gruber
2011-03-07 12:31 ` [PATCHv2 9/9] t6007: test rev-list --cherry Michael J Gruber
2011-03-09 21:49 ` [PATCHv2 0/9] --left/right-only and --cherry-mark Junio C Hamano
2011-03-10 8:08 ` Michael J Gruber
2011-03-10 9:56 ` Junio C Hamano
2011-03-10 10:48 ` Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 00/10] " Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 01/10] revlist.c: introduce --left/right-only for unsymmetric picking Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 02/10] t6007: Make sure we test --cherry-pick Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 03/10] rev-list: documentation and test for --left/right-only Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 04/10] rev-list: --left/right-only are mutually exclusive Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 05/10] rev-list/log: factor out revision mark generation Michael J Gruber
2011-03-10 14:44 ` [PATCHv3 06/10] revision.c: introduce --cherry-mark Michael J Gruber
2011-03-10 14:45 ` [PATCHv3 07/10] rev-list: documentation and test for --cherry-mark Michael J Gruber
2011-03-10 14:45 ` [PATCHv3 08/10] log --cherry: a synonym Michael J Gruber
2011-03-10 14:45 ` [PATCHv3 09/10] t6007: test rev-list --cherry Michael J Gruber
2011-03-10 14:45 ` [PATCHv3 10/10] git-log: put space after commit mark Michael J Gruber
2011-03-10 18:22 ` [PATCHv2 0/9] --left/right-only and --cherry-mark Junio C Hamano
2011-03-11 7:52 ` Michael J Gruber
2011-03-11 8:02 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc30fe8d0aa63a46b6dcaee365dbb6addf11909f.1299499429.git.git@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).