GC: disable writing commit-graph for shallow repos
In shallow repos, GC writes to the commit-graph that shallow commits do not have parents. This won't be true after a "git fetch --unshallow" (and before another GC). Do not write the commit-graph from shallow clones of a repo. The commit-graph must have the real metadata of commits and that is not available in a shallow view of the repo. Change-Id: Ic9f2358ddaa607c74f4dbf289c9bf2a2f0af9ce0 Signed-off-by: kylezhao <kylezhao@tencent.com>
This commit is contained in:
parent
8ef58089a8
commit
05e5e9907c
|
@ -58,6 +58,25 @@ public void testWriteEmptyRepo() throws Exception {
|
|||
assertFalse(graphFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteShallowRepo() throws Exception {
|
||||
StoredConfig config = repo.getConfig();
|
||||
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||
ConfigConstants.CONFIG_COMMIT_GRAPH, true);
|
||||
config.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null,
|
||||
ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true);
|
||||
|
||||
RevCommit tip = commitChain(2);
|
||||
TestRepository.BranchBuilder bb = tr.branch("refs/heads/master");
|
||||
bb.update(tip);
|
||||
repo.getObjectDatabase().setShallowCommits(Collections.singleton(tip));
|
||||
|
||||
gc.writeCommitGraph(Collections.singleton(tip));
|
||||
File graphFile = new File(repo.getObjectsDirectory(),
|
||||
Constants.INFO_COMMIT_GRAPH);
|
||||
assertFalse(graphFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteWhenGc() throws Exception {
|
||||
StoredConfig config = repo.getConfig();
|
||||
|
|
|
@ -913,6 +913,9 @@ void writeCommitGraph(@NonNull Set<? extends ObjectId> wants)
|
|||
if (!repo.getConfig().get(CoreConfig.KEY).enableCommitGraph()) {
|
||||
return;
|
||||
}
|
||||
if (repo.getObjectDatabase().getShallowCommits().size() > 0) {
|
||||
return;
|
||||
}
|
||||
checkCancelled();
|
||||
if (wants.isEmpty()) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue