Merge branch 'ds/commit-graph-with-grafts' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Nov 2018 13:57:47 +0000 (22:57 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Nov 2018 13:57:47 +0000 (22:57 +0900)
The recently introduced commit-graph auxiliary data is incompatible
with mechanisms such as replace & grafts that "breaks" immutable
nature of the object reference relationship. Disable optimizations
based on its use (and updating existing commit-graph) when these
incompatible features are in use in the repository.

* ds/commit-graph-with-grafts:
commit-graph: close_commit_graph before shallow walk
commit-graph: not compatible with uninitialized repo
commit-graph: not compatible with grafts
commit-graph: not compatible with replace objects
test-repository: properly init repo
commit-graph: update design document
refs.c: upgrade for_each_replace_ref to be a each_repo_ref_fn callback
refs.c: migrate internal ref iteration to pass thru repository argument

1  2 
builtin/replace.c
commit-graph.c
commit-graph.h
commit.c
commit.h
refs.c
refs.h
replace-object.c
t/t5318-commit-graph.sh
index 4f05791f3e895f78ba511dd6571bd09abab9269c,b5861a0ee91f82f6e7bc7641bec140e0ee3ed06c..17868a92dcfccce335d69854f54f0ef5d3a9ca1b
@@@ -54,11 -55,10 +55,10 @@@ static int show_reference(struct reposi
                        enum object_type obj_type, repl_type;
  
                        if (get_oid(refname, &object))
 -                              return error("Failed to resolve '%s' as a valid ref.", refname);
 +                              return error(_("failed to resolve '%s' as a valid ref"), refname);
  
-                       obj_type = oid_object_info(the_repository, &object,
-                                                  NULL);
-                       repl_type = oid_object_info(the_repository, oid, NULL);
+                       obj_type = oid_object_info(r, &object, NULL);
+                       repl_type = oid_object_info(r, oid, NULL);
  
                        printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type),
                               oid_to_hex(oid), type_name(repl_type));
diff --cc commit-graph.c
Simple merge
diff --cc commit-graph.h
Simple merge
diff --cc commit.c
Simple merge
diff --cc commit.h
Simple merge
diff --cc refs.c
Simple merge
diff --cc refs.h
Simple merge
index 4ec77ce41848311a912256046bd2bf8dc9ee63c0,9821f1477edab21d98bfeb89edd301f6d6257753..e295e87943102c2a1ad903aea1a634d34bf603a0
@@@ -25,8 -26,8 +26,8 @@@ static int register_replace_ref(struct 
        oidcpy(&repl_obj->replacement, oid);
  
        /* Register new object */
-       if (oidmap_put(the_repository->objects->replace_map, repl_obj))
+       if (oidmap_put(r->objects->replace_map, repl_obj))
 -              die("duplicate replace ref: %s", refname);
 +              die(_("duplicate replace ref: %s"), refname);
  
        return 0;
  }
index 0c500f7ca2641a2752f5d4819bb11efcf5f588bf,6aee861f7807f81a069e532908f91e7e7dd224d2..2799969f3e2a15fc636ed042c96d8a846e01ebe8
@@@ -254,11 -254,71 +254,71 @@@ test_expect_success 'check that gc comp
        git config gc.writeCommitGraph true &&
        git gc &&
        cp $objdir/info/commit-graph commit-graph-after-gc &&
 -      ! test_cmp commit-graph-before-gc commit-graph-after-gc &&
 +      ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
        git commit-graph write --reachable &&
 -      test_cmp commit-graph-after-gc $objdir/info/commit-graph
 +      test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
  '
  
+ test_expect_success 'replace-objects invalidates commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf replace &&
+       git clone full replace &&
+       (
+               cd replace &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph &&
+               git replace HEAD~1 HEAD~2 &&
+               git -c core.commitGraph=false log >expect &&
+               git -c core.commitGraph=true log >actual &&
+               test_cmp expect actual &&
+               git commit-graph write --reachable &&
+               git -c core.commitGraph=false --no-replace-objects log >expect &&
+               git -c core.commitGraph=true --no-replace-objects log >actual &&
+               test_cmp expect actual &&
+               rm -rf .git/objects/info/commit-graph &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph
+       )
+ '
+ test_expect_success 'commit grafts invalidate commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf graft &&
+       git clone full graft &&
+       (
+               cd graft &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph &&
+               H1=$(git rev-parse --verify HEAD~1) &&
+               H3=$(git rev-parse --verify HEAD~3) &&
+               echo "$H1 $H3" >.git/info/grafts &&
+               git -c core.commitGraph=false log >expect &&
+               git -c core.commitGraph=true log >actual &&
+               test_cmp expect actual &&
+               git commit-graph write --reachable &&
+               git -c core.commitGraph=false --no-replace-objects log >expect &&
+               git -c core.commitGraph=true --no-replace-objects log >actual &&
+               test_cmp expect actual &&
+               rm -rf .git/objects/info/commit-graph &&
+               git commit-graph write --reachable &&
+               test_path_is_missing .git/objects/info/commit-graph
+       )
+ '
+ test_expect_success 'replace-objects invalidates commit-graph' '
+       cd "$TRASH_DIRECTORY" &&
+       test_when_finished rm -rf shallow &&
+       git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
+       (
+               cd shallow &&
+               git commit-graph write --reachable &&
+               test_path_is_missing .git/objects/info/commit-graph &&
+               git fetch origin --unshallow &&
+               git commit-graph write --reachable &&
+               test_path_is_file .git/objects/info/commit-graph
+       )
+ '
  # the verify tests below expect the commit-graph to contain
  # exactly the commits reachable from the commits/8 branch.
  # If the file changes the set of commits in the list, then the