]> source.dussan.org Git - jgit.git/commitdiff
DfsPackFile: get commitGraph.readChangePaths from repo config 98/1178198/8
authorXing Huang <xingkhuang@google.com>
Tue, 12 Mar 2024 21:32:46 +0000 (16:32 -0500)
committerXing Huang <xingkhuang@google.com>
Thu, 14 Mar 2024 16:57:52 +0000 (11:57 -0500)
By default, CommitGraphLoader reads the readChangedPaths flag from
SystemReader ignoring the values set at repo-level.

Read the value of the property from the repo configuration and pass it
to CommitGraphLoader.

Signed-off-by: Xing Huang <xingkhuang@google.com>
Change-Id: I34c807714c5a7573769ba9d611457aa107006244

org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsPackFileTest.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

index 05360dc052bb168030118e9b6de187da743c07d6..dfd273e4011e33bac41334f709e679d1e30e7a29 100644 (file)
@@ -30,6 +30,8 @@ import org.eclipse.jgit.junit.MockSystemReader;
 import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.lib.AnyObjectId;
 import org.eclipse.jgit.lib.BatchRefUpdate;
+import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.NullProgressMonitor;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectIdRef;
@@ -1120,6 +1122,40 @@ public class DfsGarbageCollectorTest {
                assertEquals(1, stats.getChangedPathFiltersComputed());
        }
 
+       @Test
+       public void testReadChangedPathConfigAsFalse() throws Exception {
+               String head = "refs/heads/head1";
+               git.branch(head).commit().message("0").noParents().create();
+               gcWithCommitGraphAndBloomFilter();
+
+               Config repoConfig = odb.getRepository().getConfig();
+               repoConfig.setBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, false);
+
+               DfsPackFile gcPack = odb.getPacks()[0];
+               try (DfsReader reader = odb.newReader()) {
+                       CommitGraph cg = gcPack.getCommitGraph(reader);
+                       assertNull(cg.getChangedPathFilter(0));
+               }
+       }
+
+       @Test
+       public void testReadChangedPathConfigAsTrue() throws Exception {
+               String head = "refs/heads/head1";
+               git.branch(head).commit().message("0").noParents().create();
+               gcWithCommitGraphAndBloomFilter();
+
+               Config repoConfig = odb.getRepository().getConfig();
+               repoConfig.setBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION, null,
+                               ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, true);
+
+               DfsPackFile gcPack = odb.getPacks()[0];
+               try (DfsReader reader = odb.newReader()) {
+                       CommitGraph cg = gcPack.getCommitGraph(reader);
+                       assertNotNull(cg.getChangedPathFilter(0));
+               }
+       }
+
        @Test
        public void objectSizeIdx_reachableBlob_bigEnough_indexed() throws Exception {
                String master = "refs/heads/master";
index 44694acc8d656389c7a3e91696b7128b4c976a8c..d21e51f2761ea6ec3d221a76f7b396ccac7d88d3 100644 (file)
@@ -10,7 +10,9 @@
 
 package org.eclipse.jgit.internal.storage.dfs;
 
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX;
+import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS;
 import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_PACK_SECTION;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -24,6 +26,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.zip.Deflater;
 
+import org.eclipse.jgit.internal.storage.commitgraph.CommitGraph;
 import org.eclipse.jgit.internal.storage.dfs.DfsObjDatabase.PackSource;
 import org.eclipse.jgit.internal.storage.dfs.DfsReader.PackLoadListener;
 import org.eclipse.jgit.internal.storage.file.PackBitmapIndex;
@@ -31,6 +34,7 @@ import org.eclipse.jgit.internal.storage.pack.PackExt;
 import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
 import org.eclipse.jgit.internal.storage.pack.PackWriter;
 import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.junit.TestRng;
 import org.eclipse.jgit.lib.BatchRefUpdate;
 import org.eclipse.jgit.lib.Constants;
@@ -263,6 +267,27 @@ public class DfsPackFileTest {
                assertEquals(2, tal.blockLoadCount);
        }
 
+       @Test
+       public void testExistenceOfBloomFilterAlongWithCommitGraph()
+                       throws Exception {
+               try (TestRepository<InMemoryRepository> repository = new TestRepository<>(
+                               db)) {
+                       repository.branch("/refs/heads/main").commit().add("blob1", "blob1")
+                                       .create();
+               }
+               setReadChangedPaths(true);
+               DfsGarbageCollector gc = new DfsGarbageCollector(db);
+               gc.setWriteCommitGraph(true).setWriteBloomFilter(true)
+                               .pack(NullProgressMonitor.INSTANCE);
+
+               DfsReader reader = db.getObjectDatabase().newReader();
+               CommitGraph cg = db.getObjectDatabase().getPacks()[0]
+                               .getCommitGraph(reader);
+               assertNotNull(cg);
+               assertEquals(1, cg.getCommitCnt());
+               assertNotNull(cg.getChangedPathFilter(0));
+       }
+
        private ObjectId setupPack(int bs, int ps) throws IOException {
                DfsBlockCacheConfig cfg = new DfsBlockCacheConfig().setBlockSize(bs)
                                .setBlockLimit(bs * 100).setStreamRatio(bypassCache ? 0F : 1F);
@@ -298,4 +323,9 @@ public class DfsPackFileTest {
                db.getConfig().setInt(CONFIG_PACK_SECTION, null,
                                CONFIG_KEY_MIN_BYTES_OBJ_SIZE_INDEX, threshold);
        }
+
+       private void setReadChangedPaths(boolean enable) {
+               db.getConfig().setBoolean(CONFIG_COMMIT_GRAPH_SECTION, null,
+                               CONFIG_KEY_READ_CHANGED_PATHS, enable);
+       }
 }
index 42b1d235bf34ba92cff44eaa03de809b4f1ed47c..2e534d580f59597514c843555afa853376642b4c 100644 (file)
@@ -52,10 +52,12 @@ import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
 import org.eclipse.jgit.internal.storage.pack.StoredObjectRepresentation;
 import org.eclipse.jgit.lib.AbbreviatedObjectId;
 import org.eclipse.jgit.lib.AnyObjectId;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectLoader;
 import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
 import org.eclipse.jgit.util.LongList;
 
 /**
@@ -1283,11 +1285,16 @@ public final class DfsPackFile extends BlockBasedFile {
                        DfsStreamKey cgkey) throws IOException {
                ctx.stats.readCommitGraph++;
                long start = System.nanoTime();
+               StoredConfig repoConfig = ctx.db.getRepository().getConfig();
+               boolean readChangedPathFilters = repoConfig.getBoolean(
+                               ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION,
+                               ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, false);
                try (ReadableChannel rc = ctx.db.openFile(desc, COMMIT_GRAPH)) {
                        long size;
                        CommitGraph cg;
                        try {
-                               cg = CommitGraphLoader.read(alignTo8kBlocks(rc));
+                               cg = CommitGraphLoader.read(alignTo8kBlocks(rc),
+                                               readChangedPathFilters);
                        } finally {
                                size = rc.position();
                                ctx.stats.readCommitGraphBytes += size;