@matheusbsbs / matheus-bagliano / commits / 37a75abc98
Fork 0

graph API: don't print branch lines for uninteresting merge parents

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 Signed-off-by: Adam Simpkins <adam@adamsimpkins.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Adam Simpkins committed May 23, 2008 at 19:24 UTC 37a75abc985a25a0612c2c176ed35d438722752d
1 file changed +44 -13
graph.c
+44 -13
@@ -55,9 +55,11 @@ struct git_graph {
55 */
56 struct commit *commit;
57 /*
58 - * The number of parents this commit has.
59 - * (Stored so we don't have to walk over them each time we need
60 - * this number)
58 + * The number of interesting parents that this commit has.
59 + *
60 + * Note that this is not the same as the actual number of parents.
61 + * This count excludes parents that won't be printed in the graph
62 + * output, as determined by graph_is_interesting().
63 */
64 int num_parents;
65 /*
@@ -180,6 +182,18 @@ static void graph_ensure_capacity(struct git_graph *graph, int num_columns)
182 sizeof(int) * 2 * graph->column_capacity);
183 }
184
185 +/*
186 + * Returns 1 if the commit will be printed in the graph output,
187 + * and 0 otherwise.
188 + */
189 +static int graph_is_interesting(struct commit *commit)
190 +{
191 + /*
192 + * Uninteresting and pruned commits won't be printed
193 + */
194 + return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
195 +}
196 +
197 static void graph_insert_into_new_columns(struct git_graph *graph,
198 struct commit *commit,
199 int *mapping_index)
@@ -187,13 +201,10 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
201 int i;
202
203 /*
190 - * Ignore uinteresting and pruned commits
204 + * Ignore uinteresting commits
205 */
192 - if (commit->object.flags & (UNINTERESTING | TREESAME))
193 - {
194 - *mapping_index += 2;
206 + if (!graph_is_interesting(commit))
207 return;
196 - }
208
209 /*
210 * 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,
242 int max_cols = graph->num_columns + graph->num_parents;
243
244 /*
234 - * Even if the current commit has no parents, it still takes up a
235 - * column for itself.
245 + * Even if the current commit has no parents to be printed, it
246 + * still takes up a column for itself.
247 */
248 if (graph->num_parents < 1)
249 max_cols++;
@@ -316,6 +327,7 @@ static void graph_update_columns(struct git_graph *graph)
327 }
328
329 if (col_commit == graph->commit) {
330 + int old_mapping_idx = mapping_idx;
331 seen_this = 1;
332 for (parent = graph->commit->parents;
333 parent;
@@ -324,6 +336,14 @@ static void graph_update_columns(struct git_graph *graph)
336 parent->item,
337 &mapping_idx);
338 }
339 + /*
340 + * We always need to increment mapping_idx by at
341 + * least 2, even if it has no interesting parents.
342 + * The current commit always takes up at least 2
343 + * spaces.
344 + */
345 + if (mapping_idx == old_mapping_idx)
346 + mapping_idx += 2;
347 } else {
348 graph_insert_into_new_columns(graph, col_commit,
349 &mapping_idx);
@@ -353,11 +373,13 @@ void graph_update(struct git_graph *graph, struct commit *commit)
373 graph->commit = commit;
374
375 /*
356 - * Count how many parents this commit has
376 + * Count how many interesting parents this commit has
377 */
378 graph->num_parents = 0;
359 - for (parent = commit->parents; parent; parent = parent->next)
360 - graph->num_parents++;
379 + for (parent = commit->parents; parent; parent = parent->next) {
380 + if (graph_is_interesting(parent->item))
381 + graph->num_parents++;
382 + }
383
384 /*
385 * Call graph_update_columns() to update
@@ -543,6 +565,15 @@ void graph_output_commit_line(struct git_graph *graph, struct strbuf *sb)
565
566 if (col_commit == graph->commit) {
567 seen_this = 1;
568 + /*
569 + * If the commit has more than 1 interesting
570 + * parent, print 'M' to indicate that it is a
571 + * merge. Otherwise, print '*'.
572 + *
573 + * Note that even if this is actually a merge
574 + * commit, we still print '*' if less than 2 of its
575 + * parents are interesting.
576 + */
577 if (graph->num_parents > 1)
578 strbuf_addch(sb, 'M');
579 else