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 <jnareb@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 20, 2018 at 18:24 UTC 20fd6d57996e33c30b6bb030329523d0116f15ec
4 files changed +46 -1
commit-graph.c
+6
@@ -68,6 +68,12 @@ static int commit_graph_compatible(struct repository *r)
68 return 0;
69 }
70
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 +
77 return 1;
78 }
79
commit.c
+1 -1
@@ -209,7 +209,7 @@ static int read_graft_file(struct repository *r, const char *graft_file)
209 return 0;
210 }
211
212 -static void prepare_commit_graft(struct repository *r)
212 +void prepare_commit_graft(struct repository *r)
213 {
214 char *graft_file;
215
commit.h
+1
@@ -202,6 +202,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
202
203 struct commit_graft *read_graft_line(struct strbuf *line);
204 int register_commit_graft(struct repository *r, struct commit_graft *, int);
205 +void prepare_commit_graft(struct repository *r);
206 struct commit_graft *lookup_commit_graft(struct repository *r, const struct object_id *oid);
207
208 extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
t/t5318-commit-graph.sh
+38
@@ -281,6 +281,44 @@ test_expect_success 'replace-objects invalidates commit-graph' '
281 )
282 '
283
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 +
322 # the verify tests below expect the commit-graph to contain
323 # exactly the commits reachable from the commits/8 branch.
324 # If the file changes the set of commits in the list, then the