Skip to content

Commit 7f1978c

Browse files
committed
Merge branch 'jt/unparse-commit-upon-graft-change' into seen
* jt/unparse-commit-upon-graft-change: commit,shallow: unparse commits if grafts changed
2 parents b379ec4 + 9809814 commit 7f1978c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,15 @@ test_expect_success 'fetch --update-shallow into a repo with submodules' '
170170
git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/*
171171
'
172172

173+
test_expect_success 'fetch --update-shallow a commit that is also a shallow point into a repo with submodules' '
174+
git init repo-with-unreachable-upstream-shallow &&
175+
git -C repo-with-unreachable-upstream-shallow submodule add ../a-submodule a-submodule &&
176+
git -C repo-with-unreachable-upstream-shallow commit -m "added submodule" &&
177+
178+
SHALLOW=$(cat shallow/.git/shallow) &&
179+
git -C repo-with-unreachable-upstream-shallow fetch --update-shallow ../shallow/.git "$SHALLOW":refs/heads/a-shallow
180+
'
181+
173182
test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' '
174183
(
175184
cd shallow &&

0 commit comments

Comments
 (0)