Skip to content

Commit 20fd6d5

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: not compatible with grafts
Augment commit_graph_compatible(r) to return false when the given repository r has commit grafts or is a shallow clone. Test that in these situations we ignore existing commit-graph files and we do not write new commit-graph files. Helped-by: Jakub Narebski <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d653824 commit 20fd6d5

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

commit-graph.c

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ static int commit_graph_compatible(struct repository *r)
6868
return 0;
6969
}
7070

71+
prepare_commit_graft(r);
72+
if (r->parsed_objects && r->parsed_objects->grafts_nr)
73+
return 0;
74+
if (is_repository_shallow(r))
75+
return 0;
76+
7177
return 1;
7278
}
7379

commit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ static int read_graft_file(struct repository *r, const char *graft_file)
209209
return 0;
210210
}
211211

212-
static void prepare_commit_graft(struct repository *r)
212+
void prepare_commit_graft(struct repository *r)
213213
{
214214
char *graft_file;
215215

commit.h

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
202202

203203
struct commit_graft *read_graft_line(struct strbuf *line);
204204
int register_commit_graft(struct repository *r, struct commit_graft *, int);
205+
void prepare_commit_graft(struct repository *r);
205206
struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
206207

207208
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);

t/t5318-commit-graph.sh

+38
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,44 @@ test_expect_success 'replace-objects invalidates commit-graph' '
281281
)
282282
'
283283

284+
test_expect_success 'commit grafts invalidate commit-graph' '
285+
cd "$TRASH_DIRECTORY" &&
286+
test_when_finished rm -rf graft &&
287+
git clone full graft &&
288+
(
289+
cd graft &&
290+
git commit-graph write --reachable &&
291+
test_path_is_file .git/objects/info/commit-graph &&
292+
H1=$(git rev-parse --verify HEAD~1) &&
293+
H3=$(git rev-parse --verify HEAD~3) &&
294+
echo "$H1 $H3" >.git/info/grafts &&
295+
git -c core.commitGraph=false log >expect &&
296+
git -c core.commitGraph=true log >actual &&
297+
test_cmp expect actual &&
298+
git commit-graph write --reachable &&
299+
git -c core.commitGraph=false --no-replace-objects log >expect &&
300+
git -c core.commitGraph=true --no-replace-objects log >actual &&
301+
test_cmp expect actual &&
302+
rm -rf .git/objects/info/commit-graph &&
303+
git commit-graph write --reachable &&
304+
test_path_is_missing .git/objects/info/commit-graph
305+
)
306+
'
307+
308+
test_expect_success 'replace-objects invalidates commit-graph' '
309+
cd "$TRASH_DIRECTORY" &&
310+
test_when_finished rm -rf shallow &&
311+
git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
312+
(
313+
cd shallow &&
314+
git commit-graph write --reachable &&
315+
test_path_is_missing .git/objects/info/commit-graph &&
316+
git fetch origin --unshallow &&
317+
git commit-graph write --reachable &&
318+
test_path_is_file .git/objects/info/commit-graph
319+
)
320+
'
321+
284322
# the verify tests below expect the commit-graph to contain
285323
# exactly the commits reachable from the commits/8 branch.
286324
# If the file changes the set of commits in the list, then the

0 commit comments

Comments
 (0)