graph API: fix "git log --graph --first-parent"
This change teaches the graph API that only the first parent of each commit is interesting when "--first-parent" was specified. This change also consolidates the graph parent walking logic into two new internal functions, first_interesting_parent() and next_interesting_parent(). A simpler fix would have been to simply break at the end of the 2 existing for loops when graph->revs->first_parent_only is set. However, this change seems nicer, especially if we ever need to add any new loops over the parent list in the future. Signed-off-by: Adam Simpkins <adam@adamsimpkins.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
b7d9681974
commit
a0ebe573a5
64
graph.c
64
graph.c
|
@ -237,18 +237,58 @@ static int graph_is_interesting(struct git_graph *graph, struct commit *commit)
|
||||||
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
|
return (commit->object.flags & (UNINTERESTING | TREESAME)) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct commit_list *next_interesting_parent(struct git_graph *graph,
|
||||||
|
struct commit_list *orig)
|
||||||
|
{
|
||||||
|
struct commit_list *list;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If revs->first_parent_only is set, only the first
|
||||||
|
* parent is interesting. None of the others are.
|
||||||
|
*/
|
||||||
|
if (graph->revs->first_parent_only)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the next interesting commit after orig
|
||||||
|
*/
|
||||||
|
for (list = orig->next; list; list = list->next) {
|
||||||
|
if (graph_is_interesting(graph, list->item))
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct commit_list *first_interesting_parent(struct git_graph *graph)
|
||||||
|
{
|
||||||
|
struct commit_list *parents = graph->commit->parents;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If this commit has no parents, ignore it
|
||||||
|
*/
|
||||||
|
if (!parents)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the first parent is interesting, return it
|
||||||
|
*/
|
||||||
|
if (graph_is_interesting(graph, parents->item))
|
||||||
|
return parents;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Otherwise, call next_interesting_parent() to get
|
||||||
|
* the next interesting parent
|
||||||
|
*/
|
||||||
|
return next_interesting_parent(graph, parents);
|
||||||
|
}
|
||||||
|
|
||||||
static void graph_insert_into_new_columns(struct git_graph *graph,
|
static void graph_insert_into_new_columns(struct git_graph *graph,
|
||||||
struct commit *commit,
|
struct commit *commit,
|
||||||
int *mapping_index)
|
int *mapping_index)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
|
||||||
* Ignore uinteresting commits
|
|
||||||
*/
|
|
||||||
if (!graph_is_interesting(graph, commit))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the commit is already in the new_columns list, we don't need to
|
* If the commit is already in the new_columns list, we don't need to
|
||||||
* add it. Just update the mapping correctly.
|
* add it. Just update the mapping correctly.
|
||||||
|
@ -373,9 +413,9 @@ static void graph_update_columns(struct git_graph *graph)
|
||||||
int old_mapping_idx = mapping_idx;
|
int old_mapping_idx = mapping_idx;
|
||||||
seen_this = 1;
|
seen_this = 1;
|
||||||
graph->commit_index = i;
|
graph->commit_index = i;
|
||||||
for (parent = graph->commit->parents;
|
for (parent = first_interesting_parent(graph);
|
||||||
parent;
|
parent;
|
||||||
parent = parent->next) {
|
parent = next_interesting_parent(graph, parent)) {
|
||||||
graph_insert_into_new_columns(graph,
|
graph_insert_into_new_columns(graph,
|
||||||
parent->item,
|
parent->item,
|
||||||
&mapping_idx);
|
&mapping_idx);
|
||||||
|
@ -420,9 +460,11 @@ void graph_update(struct git_graph *graph, struct commit *commit)
|
||||||
* Count how many interesting parents this commit has
|
* Count how many interesting parents this commit has
|
||||||
*/
|
*/
|
||||||
graph->num_parents = 0;
|
graph->num_parents = 0;
|
||||||
for (parent = commit->parents; parent; parent = parent->next) {
|
for (parent = first_interesting_parent(graph);
|
||||||
if (graph_is_interesting(graph, parent->item))
|
parent;
|
||||||
graph->num_parents++;
|
parent = next_interesting_parent(graph, parent))
|
||||||
|
{
|
||||||
|
graph->num_parents++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue