diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2022-06-06 10:54:37 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-06-06 11:50:34 -0700 |
commit | 4d4e49fff17122e0eec185857fa87d526174859f (patch) | |
tree | 987539eb1a4cd50d6321b409e75779c61db130ee /commit.c | |
parent | 2668e3608e47494f2f10ef2b6e69f08a84816bcb (diff) | |
download | git-4d4e49fff17122e0eec185857fa87d526174859f.tar.gz |
commit,shallow: unparse commits if grafts changed
When a commit is parsed, it pretends to have a different (possibly
empty) list of parents if there is graft information for that commit.
But there is a bug that could occur when a commit is parsed, the graft
information is updated (for example, when a shallow file is rewritten),
and the same commit is subsequently used: the parents of the commit do
not conform to the updated graft information, but the information at the
time of parsing.
This is usually not an issue, as a commit is usually introduced into the
repository at the same time as its graft information. That means that
when we try to parse that commit, we already have its graft information.
But it is an issue when fetching a shallow point directly into a
repository with submodules. The function
assign_shallow_commits_to_refs() parses all sought objects (including
the shallow point, which we are directly fetching). In update_shallow()
in fetch-pack.c, assign_shallow_commits_to_refs() is called before
commit_shallow_file(), which means that the shallow point would have
been parsed before graft information is updated. Once a commit is
parsed, it is no longer sensitive to any graft information updates. This
parsed commit is subsequently used when we do a revision walk to search
for submodules to fetch, meaning that the commit is considered to have
parents even though it is a shallow point (and therefore should be
treated as having no parents).
Therefore, whenever graft information is updated, mark the commits that
were previously grafts and the commits that are newly grafts as
unparsed.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r-- | commit.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -120,6 +120,17 @@ int commit_graft_pos(struct repository *r, const struct object_id *oid) commit_graft_oid_access); } +static void unparse_commit(struct repository *r, const struct object_id *oid) +{ + struct commit *c = lookup_commit(r, oid); + + if (!c->object.parsed) + return; + free_commit_list(c->parents); + c->parents = NULL; + c->object.parsed = 0; +} + int register_commit_graft(struct repository *r, struct commit_graft *graft, int ignore_dups) { @@ -145,6 +156,7 @@ int register_commit_graft(struct repository *r, struct commit_graft *graft, (r->parsed_objects->grafts_nr - pos - 1) * sizeof(*r->parsed_objects->grafts)); r->parsed_objects->grafts[pos] = graft; + unparse_commit(r, &graft->oid); return 0; } @@ -253,8 +265,10 @@ void reset_commit_grafts(struct repository *r) { int i; - for (i = 0; i < r->parsed_objects->grafts_nr; i++) + for (i = 0; i < r->parsed_objects->grafts_nr; i++) { + unparse_commit(r, &r->parsed_objects->grafts[i]->oid); free(r->parsed_objects->grafts[i]); + } r->parsed_objects->grafts_nr = 0; r->parsed_objects->commit_graft_prepared = 0; } |