From: Adam Simpkins <adam@adamsimpkins.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Adam Simpkins <adam@adamsimpkins.net>
Subject: [PATCH 2/2] graph API: don't print branch lines for uninteresting merge parents
Date: Fri, 23 May 2008 19:24:11 -0700 [thread overview]
Message-ID: <1211595851-11992-3-git-send-email-adam@adamsimpkins.net> (raw)
In-Reply-To: <1211595851-11992-2-git-send-email-adam@adamsimpkins.net>
Previously, the graphing code printed lines coming out of a merge commit
for all of its parents, even if some of them were uninteresting. Now it
only prints lines for interesting commits.
For example, for a merge commit where only the first parent is
interesting, the code now prints:
* merge commit
* interesting child
instead of:
M merge commit
|\
* interesting child
---
graph.c | 57 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/graph.c b/graph.c
index 400f014..add7e44 100644
--- a/graph.c
+++ b/graph.c
@@ -55,9 +55,11 @@ struct git_graph {
*/
struct commit *commit;
/*
- * The number of parents this commit has.
- * (Stored so we don't have to walk over them each time we need
- * this number)
+ * The number of interesting parents that this commit has.
+ *
+ * Note that this is not the same as the actual number of parents.
+ * This count excludes parents that won't be printed in the graph
+ * output, as determined by graph_is_interesting().
*/
int num_parents;
/*
@@ -180,6 +182,18 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
sizeof(int) * 2 * graph->column_capacity);
}
+/*
+ * Returns 1 if the commit will be printed in the graph output,
+ * and 0 otherwise.
+ */
+static int graph_is_interesting(struct commit *commit)
+{
+ /*
+ * Uninteresting and pruned commits won't be printed
+ */
+ return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
+}
+
static void graph_insert_into_new_columns(struct git_graph *graph,
struct commit *commit,
int *mapping_index)
@@ -187,13 +201,10 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
int i;
/*
- * Ignore uinteresting and pruned commits
+ * Ignore uinteresting commits
*/
- if (commit->object.flags & (UNINTERESTING | TREESAME))
- {
- *mapping_index += 2;
+ if (!graph_is_interesting(commit))
return;
- }
/*
* If the commit is already in the new_columns list, we don't need to
@@ -231,8 +242,8 @@ static void graph_update_width(struct git_graph *graph,
int max_cols = graph->num_columns + graph->num_parents;
/*
- * Even if the current commit has no parents, it still takes up a
- * column for itself.
+ * Even if the current commit has no parents to be printed, it
+ * still takes up a column for itself.
*/
if (graph->num_parents < 1)
max_cols++;
@@ -316,6 +327,7 @@ static void graph_update_columns(struct git_graph *graph)
}
if (col_commit == graph->commit) {
+ int old_mapping_idx = mapping_idx;
seen_this = 1;
for (parent = graph->commit->parents;
parent;
@@ -324,6 +336,14 @@ static void graph_update_columns(struct git_graph *graph)
parent->item,
&mapping_idx);
}
+ /*
+ * We always need to increment mapping_idx by at
+ * least 2, even if it has no interesting parents.
+ * The current commit always takes up at least 2
+ * spaces.
+ */
+ if (mapping_idx == old_mapping_idx)
+ mapping_idx += 2;
} else {
graph_insert_into_new_columns(graph, col_commit,
&mapping_idx);
@@ -353,11 +373,13 @@ void graph_update(struct git_graph *graph, struct commit *commit)
graph->commit = commit;
/*
- * Count how many parents this commit has
+ * Count how many interesting parents this commit has
*/
graph->num_parents = 0;
- for (parent = commit->parents; parent; parent = parent->next)
- graph->num_parents++;
+ for (parent = commit->parents; parent; parent = parent->next) {
+ if (graph_is_interesting(parent->item))
+ graph->num_parents++;
+ }
/*
* Call graph_update_columns() to update
@@ -543,6 +565,15 @@ 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)
strbuf_addch(sb, 'M');
else
--
1.5.5.1.359.gebc23.dirty
next prev parent reply other threads:[~2008-05-24 2:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-23 20:42 bug in "git log --graph" at the tail end? Junio C Hamano
2008-05-23 21:02 ` Reece Dunn
2008-05-24 1:05 ` Adam Simpkins
2008-05-24 1:39 ` Junio C Hamano
2008-05-24 2:24 ` [PATCH 0/2] fix "log --graph" issues with uninteresting parents Adam Simpkins
2008-05-24 2:24 ` [PATCH 1/2] graph API: fix graph mis-alignment after uninteresting commits Adam Simpkins
2008-05-24 2:24 ` Adam Simpkins [this message]
2008-05-24 18:25 ` [PATCH 2/2] graph API: don't print branch lines for uninteresting merge parents Teemu Likonen
2008-05-24 20:52 ` [PATCH 0/1] graph API: always print 'M' for merge commits Adam Simpkins
2008-05-24 20:52 ` [PATCH 1/1] " Adam Simpkins
2008-05-24 22:21 ` Adam Simpkins
2008-05-25 1:28 ` [PATCH 0/1] " Junio C Hamano
2008-05-25 6:29 ` Teemu Likonen
2008-05-25 6:49 ` Adam Simpkins
2008-05-24 22:21 ` [PATCH 2/2] graph API: don't print branch lines for uninteresting merge parents Adam Simpkins
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=1211595851-11992-3-git-send-email-adam@adamsimpkins.net \
--to=adam@adamsimpkins.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).