THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

commit-graph: close under reachability

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@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tags/v2.18.0-rc0
Derrick Stolee Junio C Hamano 1 year ago
parent
commit
4f2542b49e
1 changed files with 45 additions and 0 deletions
  1. +45
    -0
      commit-graph.c

+ 45
- 0
commit-graph.c View File

@@ -367,6 +367,50 @@ static int add_packed_commits(const struct object_id *oid,
return 0;
}

static void add_missing_parents(struct packed_oid_list *oids, struct commit *commit)
{
struct commit_list *parent;
for (parent = commit->parents; parent; parent = parent->next) {
if (!(parent->item->object.flags & UNINTERESTING)) {
ALLOC_GROW(oids->list, oids->nr + 1, oids->alloc);
oidcpy(&oids->list[oids->nr], &(parent->item->object.oid));
oids->nr++;
parent->item->object.flags |= UNINTERESTING;
}
}
}

static void close_reachable(struct packed_oid_list *oids)
{
int i;
struct commit *commit;

for (i = 0; i < oids->nr; i++) {
commit = lookup_commit(&oids->list[i]);
if (commit)
commit->object.flags |= UNINTERESTING;
}

/*
* As this loop runs, oids->nr may grow, but not more
* than the number of missing commits in the reachable
* closure.
*/
for (i = 0; i < oids->nr; i++) {
commit = lookup_commit(&oids->list[i]);

if (commit && !parse_commit(commit))
add_missing_parents(oids, commit);
}

for (i = 0; i < oids->nr; i++) {
commit = lookup_commit(&oids->list[i]);

if (commit)
commit->object.flags &= ~UNINTERESTING;
}
}

void write_commit_graph(const char *obj_dir)
{
struct packed_oid_list oids;
@@ -390,6 +434,7 @@ void write_commit_graph(const char *obj_dir)
ALLOC_ARRAY(oids.list, oids.alloc);

for_each_packed_object(add_packed_commits, &oids, 0);
close_reachable(&oids);

QSORT(oids.list, oids.nr, commit_compare);



Loading…
Cancel
Save