Skip to content

Commit 6d01e90

Browse files
committed
commit-graph: fix writing first commit-graph during fetch
The previous commit includes a failing test for an issue around fetch.writeCommitGraph and fetching in a repo with a submodule. Here, we fix that bug and set the test to "test_expect_success". The problem arises with this set of commands when the remote repo at <url> has a submodule. Note that --recurse-submodules is not needed to demonstrate the bug. $ git clone <url> test $ cd test $ git -c fetch.writeCommitGraph=true fetch origin Computing commit graph generation numbers: 100% (12/12), done. BUG: commit-graph.c:886: missing parent <hash1> for commit <hash2> Aborted (core dumped) As an initial fix, I converted the code in builtin/fetch.c that calls write_commit_graph_reachable() to instead launch a "git commit-graph write --reachable --split" process. That code worked, but is not how we want the feature to work long-term. That test did demonstrate that the issue must be something to do with internal state of the 'git fetch' process. The write_commit_graph() method in commit-graph.c ensures the commits we plan to write are "closed under reachability" using close_reachable(). This method walks from the input commits, and uses the UNINTERESTING flag to mark which commits have already been visited. This allows the walk to take O(N) time, where N is the number of commits, instead of O(P) time, where P is the number of paths. (The number of paths can be exponential in the number of commits.) However, the UNINTERESTING flag is used in lots of places in the codebase. This flag usually means some barrier to stop a commit walk, such as in revision-walking to compare histories. It is not often cleared after the walk completes because the starting points of those walks do not have the UNINTERESTING flag, and clear_commit_marks() would stop immediately. This is happening during a 'git fetch' call with a remote. The fetch negotiation is comparing the remote refs with the local refs and marking some commits as UNINTERESTING. I tested running clear_commit_marks_many() to clear the UNINTERESTING flag inside close_reachable(), but the tips did not have the flag, so that did nothing. It turns out that the calculate_changed_submodule_paths() method is at fault. Thanks, Peff, for pointing out this detail! More specifically, for each submodule, the collect_changed_submodules() runs a revision walk to essentially do file-history on the list of submodules. That revision walk marks commits UNININTERESTING if they are simplified away by not changing the submodule. Instead, I finally arrived on the conclusion that I should use a flag that is not used in any other part of the code. In commit-reach.c, a number of flags were defined for commit walk algorithms. The REACHABLE flag seemed like it made the most sense, and it seems it was not actually used in the file. The REACHABLE flag was used in early versions of commit-reach.c, but was removed by 4fbcca4 (commit-reach: make can_all_from_reach... linear, 2018-07-20). Add the REACHABLE flag to commit-graph.c and use it instead of UNINTERESTING in close_reachable(). This fixes the bug in manual testing. Reported-by: Johannes Schindelin <[email protected]> Helped-by: Jeff King <[email protected]> Helped-by: Szeder Gábor <[email protected]> Signed-off-by: Derrick Stolee <[email protected]>
1 parent 8150108 commit 6d01e90

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

commit-graph.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
4242
+ GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
4343

44+
/* Remember to update object flag allocation in object.h */
45+
#define REACHABLE (1u<<15)
46+
4447
char *get_commit_graph_filename(const char *obj_dir)
4548
{
4649
char *filename = xstrfmt("%s/info/commit-graph", obj_dir);
@@ -1030,11 +1033,11 @@ static void add_missing_parents(struct write_commit_graph_context *ctx, struct c
10301033
{
10311034
struct commit_list *parent;
10321035
for (parent = commit->parents; parent; parent = parent->next) {
1033-
if (!(parent->item->object.flags & UNINTERESTING)) {
1036+
if (!(parent->item->object.flags & REACHABLE)) {
10341037
ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
10351038
oidcpy(&ctx->oids.list[ctx->oids.nr], &(parent->item->object.oid));
10361039
ctx->oids.nr++;
1037-
parent->item->object.flags |= UNINTERESTING;
1040+
parent->item->object.flags |= REACHABLE;
10381041
}
10391042
}
10401043
}
@@ -1052,7 +1055,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
10521055
display_progress(ctx->progress, i + 1);
10531056
commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
10541057
if (commit)
1055-
commit->object.flags |= UNINTERESTING;
1058+
commit->object.flags |= REACHABLE;
10561059
}
10571060
stop_progress(&ctx->progress);
10581061

@@ -1089,7 +1092,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
10891092
commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
10901093

10911094
if (commit)
1092-
commit->object.flags &= ~UNINTERESTING;
1095+
commit->object.flags &= ~REACHABLE;
10931096
}
10941097
stop_progress(&ctx->progress);
10951098
}

commit-reach.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "commit-reach.h"
1111

1212
/* Remember to update object flag allocation in object.h */
13-
#define REACHABLE (1u<<15)
1413
#define PARENT1 (1u<<16)
1514
#define PARENT2 (1u<<17)
1615
#define STALE (1u<<18)

object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ struct object_array {
6868
* bisect.c: 16
6969
* bundle.c: 16
7070
* http-push.c: 16-----19
71-
* commit-reach.c: 15-------19
71+
* commit-graph.c: 15
72+
* commit-reach.c: 16-----19
7273
* sha1-name.c: 20
7374
* list-objects-filter.c: 21
7475
* builtin/fsck.c: 0--3

t/t5510-fetch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ test_expect_success 'fetch.writeCommitGraph' '
583583
)
584584
'
585585

586-
test_expect_failure 'fetch.writeCommitGraph with submodules' '
586+
test_expect_success 'fetch.writeCommitGraph with submodules' '
587587
git clone dups super &&
588588
(
589589
cd super &&

0 commit comments

Comments
 (0)