add core.usereplacerefs config option

We can already disable replace refs using a command line option or environment variable, but those are awkward to apply universally. Let's add a config option to do the same thing. That raises the question of why one might want to do so universally. The answer is that replace refs violate the immutability of objects. For instance, if you wanted to cache the diff between commit XYZ and its parent, then in theory that never changes; the hash XYZ represents the total state. But replace refs violate that; pushing up a new ref may create a completely new diff. The obvious "if it hurts, don't do it" answer is not to create replace refs if you're doing this kind of caching. But for a site hosting arbitrary repositories, they may want to allow users to share replace refs with each other, but not actually respect them on the site (because the caching is more important than the replace feature). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 18, 2018 at 16:45 UTC da4398d6a03eb2cf857aa63190e9bf60305befd2
3 files changed +16
Documentation/config.txt
+5
@@ -911,6 +911,11 @@ core.commitGraph::
911 Enable git commit graph feature. Allows reading from the
912 commit-graph file.
913
914 +core.useReplaceRefs::
915 + If set to `false`, behave as if the `--no-replace-objects`
916 + option was given on the command line. See linkgit:git[1] and
917 + linkgit:git-replace[1] for more information.
918 +
919 core.sparseCheckout::
920 Enable "sparse checkout" feature. See section "Sparse checkout" in
921 linkgit:git-read-tree[1] for more information.
config.c
+5
@@ -1347,6 +1347,11 @@ static int git_default_core_config(const char *var, const char *value)
1347 var, value);
1348 }
1349
1350 + if (!strcmp(var, "core.usereplacerefs")) {
1351 + read_replace_refs = git_config_bool(var, value);
1352 + return 0;
1353 + }
1354 +
1355 /* Add other config variables here and to Documentation/config.txt. */
1356 return 0;
1357 }
t/t6050-replace.sh
+6
@@ -113,6 +113,12 @@ test_expect_success 'test GIT_NO_REPLACE_OBJECTS env variable' '
113 GIT_NO_REPLACE_OBJECTS=1 git show $HASH2 | grep "A U Thor"
114 '
115
116 +test_expect_success 'test core.usereplacerefs config option' '
117 + test_config core.usereplacerefs false &&
118 + git cat-file commit $HASH2 | grep "author A U Thor" &&
119 + git show $HASH2 | grep "A U Thor"
120 +'
121 +
122 cat >tag.sig <<EOF
123 object $HASH2
124 type commit