Teach write_commit_graph() to walk all parents from the commits discovered in packfiles. This prevents gaps given by loose objects or previously-missed packfiles. Also automatically add commits from the existing graph file, if it exists. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- commit-graph.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/commit-graph.c b/commit-graph.c index c8fb38f..00bd73a 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -385,6 +385,28 @@ static int if_packed_commit_add_to_list(const struct object_id *oid, return 0; } +static void close_reachable(struct packed_oid_list *oids) +{ + int i; + struct rev_info revs; + struct commit *commit; + init_revisions(&revs, NULL); + for (i = 0; i < oids->nr; i++) { + commit = lookup_commit(&oids->list[i]); + if (commit && !parse_commit(commit)) + revs.commits = commit_list_insert(commit, &revs.commits); + } + + if (prepare_revision_walk(&revs)) + die(_("revision walk setup failed")); + + while ((commit = get_revision(&revs)) != NULL) { + ALLOC_GROW(oids->list, oids->nr + 1, oids->alloc); + oidcpy(&oids->list[oids->nr], &(commit->object.oid)); + (oids->nr)++; + } +} + char *write_commit_graph(const char *obj_dir) { struct packed_oid_list oids; @@ -411,6 +433,7 @@ char *write_commit_graph(const char *obj_dir) ALLOC_ARRAY(oids.list, oids.alloc); for_each_packed_object(if_packed_commit_add_to_list, &oids, 0); + close_reachable(&oids); QSORT(oids.list, oids.nr, commit_compare); -- 2.7.4