Skip to content

Commit 94dd91a

Browse files
committed
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. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 7f596c1 commit 94dd91a

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

commit-graph.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ static struct commit_graph *alloc_commit_graph(void)
6060

6161
static int commit_graph_compatible(struct repository *r)
6262
{
63+
prepare_commit_graft(r);
64+
if (r->parsed_objects && r->parsed_objects->grafts_nr)
65+
return 0;
66+
if (is_repository_shallow(r))
67+
return 0;
68+
6369
prepare_replace_object(r);
6470
if (hashmap_get_size(&r->objects->replace_map->map))
6571
return 0;

commit.c

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,42 @@ 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+
git replace --graft HEAD~1 HEAD~3 &&
293+
git -c core.commitGraph=false log >expect &&
294+
git -c core.commitGraph=true log >actual &&
295+
test_cmp expect actual &&
296+
git commit-graph write --reachable &&
297+
git -c core.commitGraph=false --no-replace-objects log >expect &&
298+
git -c core.commitGraph=true --no-replace-objects log >actual &&
299+
test_cmp expect actual &&
300+
rm -rf .git/objects/info/commit-graph &&
301+
git commit-graph write --reachable &&
302+
test_path_is_missing .git/objects/info/commit-graph
303+
)
304+
'
305+
306+
test_expect_success 'replace-objects invalidates commit-graph' '
307+
cd "$TRASH_DIRECTORY" &&
308+
test_when_finished rm -rf shallow &&
309+
git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
310+
(
311+
cd shallow &&
312+
git commit-graph write --reachable &&
313+
test_path_is_missing .git/objects/info/commit-graph &&
314+
git fetch origin --unshallow &&
315+
git commit-graph write --reachable &&
316+
test_path_is_file .git/objects/info/commit-graph
317+
)
318+
'
319+
284320
# the verify tests below expect the commit-graph to contain
285321
# exactly the commits reachable from the commits/8 branch.
286322
# If the file changes the set of commits in the list, then the

0 commit comments

Comments
 (0)