Skip to content

Commit eef985e

Browse files
committed
Merge branch 'jt/unparse-commit-upon-graft-change'
Updating the graft information invalidates the list of parents of in-core commit objects that used to be in the graft file. * jt/unparse-commit-upon-graft-change: commit,shallow: unparse commits if grafts changed
2 parents 1a7f6be + 4d4e49f commit eef985e

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

commit.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ int commit_graft_pos(struct repository *r, const struct object_id *oid)
120120
commit_graft_oid_access);
121121
}
122122

123+
static void unparse_commit(struct repository *r, const struct object_id *oid)
124+
{
125+
struct commit *c = lookup_commit(r, oid);
126+
127+
if (!c->object.parsed)
128+
return;
129+
free_commit_list(c->parents);
130+
c->parents = NULL;
131+
c->object.parsed = 0;
132+
}
133+
123134
int register_commit_graft(struct repository *r, struct commit_graft *graft,
124135
int ignore_dups)
125136
{
@@ -145,6 +156,7 @@ int register_commit_graft(struct repository *r, struct commit_graft *graft,
145156
(r->parsed_objects->grafts_nr - pos - 1) *
146157
sizeof(*r->parsed_objects->grafts));
147158
r->parsed_objects->grafts[pos] = graft;
159+
unparse_commit(r, &graft->oid);
148160
return 0;
149161
}
150162

@@ -253,8 +265,10 @@ void reset_commit_grafts(struct repository *r)
253265
{
254266
int i;
255267

256-
for (i = 0; i < r->parsed_objects->grafts_nr; i++)
268+
for (i = 0; i < r->parsed_objects->grafts_nr; i++) {
269+
unparse_commit(r, &r->parsed_objects->grafts[i]->oid);
257270
free(r->parsed_objects->grafts[i]);
271+
}
258272
r->parsed_objects->grafts_nr = 0;
259273
r->parsed_objects->commit_graft_prepared = 0;
260274
}

shallow.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ int commit_shallow_file(struct repository *r, struct shallow_lock *lk)
9797
{
9898
int res = commit_lock_file(&lk->lock);
9999
reset_repository_shallow(r);
100+
101+
/*
102+
* Update in-memory data structures with the new shallow information,
103+
* including unparsing all commits that now have grafts.
104+
*/
105+
is_repository_shallow(r);
106+
100107
return res;
101108
}
102109

t/t5537-fetch-shallow.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,24 @@ test_expect_success 'fetch --update-shallow' '
164164
test_expect_success 'fetch --update-shallow into a repo with submodules' '
165165
git init a-submodule &&
166166
test_commit -C a-submodule foo &&
167+
168+
test_when_finished "rm -rf repo-with-sub" &&
167169
git init repo-with-sub &&
168170
git -C repo-with-sub submodule add ../a-submodule a-submodule &&
169171
git -C repo-with-sub commit -m "added submodule" &&
170172
git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/*
171173
'
172174

175+
test_expect_success 'fetch --update-shallow a commit that is also a shallow point into a repo with submodules' '
176+
test_when_finished "rm -rf repo-with-sub" &&
177+
git init repo-with-sub &&
178+
git -C repo-with-sub submodule add ../a-submodule a-submodule &&
179+
git -C repo-with-sub commit -m "added submodule" &&
180+
181+
SHALLOW=$(cat shallow/.git/shallow) &&
182+
git -C repo-with-sub fetch --update-shallow ../shallow/.git "$SHALLOW":refs/heads/a-shallow
183+
'
184+
173185
test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
174186
(
175187
cd shallow &&

0 commit comments

Comments
 (0)