]> source.dussan.org Git - jgit.git/commitdiff
CommitGraphLoader: receive readChangedPaths as parameter 97/1178197/3
authorXing Huang <xingkhuang@google.com>
Tue, 12 Mar 2024 21:24:10 +0000 (16:24 -0500)
committerIvan Frade <ifrade@google.com>
Tue, 12 Mar 2024 22:55:56 +0000 (22:55 +0000)
commitGraph.readChangedPaths controls the read of bloom filter
chunks from commit graph. CommitGraphLoader uses SystemReader
to read this conf, so it only sees its value when it is set in
$XDG_CONFIG_HOME/jgit/config (and not, for example, in the repo
config).

Pass the readChangedPaths value to the method that reads the commit
graph. Callers should read the value from the right configuration.

This change is a noop, but allows to move callers to the new method
progressively. Follow up changes will remove the previous method and
its usages.

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

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphLoader.java

index 867d522e0850d34b287011710994f3f6bbb59801..7e9220dc0df6e7bf7795af69aba6c6ea8930d111 100644 (file)
@@ -98,6 +98,46 @@ public class CommitGraphLoader {
         */
        public static CommitGraph read(InputStream fd)
                        throws CommitGraphFormatException, IOException {
+
+               boolean readChangedPathFilters;
+               try {
+                       readChangedPathFilters = SystemReader.getInstance().getJGitConfig()
+                                       .getBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION,
+                                                       ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS,
+                                                       false);
+               } catch (ConfigInvalidException e) {
+                       // Use the default value if, for some reason, the config couldn't be
+                       // read.
+                       readChangedPathFilters = false;
+               }
+
+               return read(fd, readChangedPathFilters);
+       }
+
+       /**
+        * Read an existing commit-graph file from a buffered stream.
+        * <p>
+        * The format of the file will be automatically detected and a proper access
+        * implementation for that format will be constructed and returned to the
+        * caller. The file may or may not be held open by the returned instance.
+        *
+        * @param fd
+        *            stream to read the commit-graph file from. The stream must be
+        *            buffered as some small IOs are performed against the stream.
+        *            The caller is responsible for closing the stream.
+        *
+        * @param readChangedPathFilters
+        *            enable reading bloom filter chunks.
+        *
+        * @return a copy of the commit-graph file in memory
+        * @throws CommitGraphFormatException
+        *             the commit-graph file's format is different from we expected.
+        * @throws java.io.IOException
+        *             the stream cannot be read.
+        */
+       public static CommitGraph read(InputStream fd,
+                       boolean readChangedPathFilters)
+                       throws CommitGraphFormatException, IOException {
                byte[] hdr = new byte[8];
                IO.readFully(fd, hdr, 0, hdr.length);
 
@@ -142,17 +182,6 @@ public class CommitGraphLoader {
                        chunks.add(new ChunkSegment(id, offset));
                }
 
-               boolean readChangedPathFilters;
-               try {
-                       readChangedPathFilters = SystemReader.getInstance()
-                                       .getJGitConfig()
-                                       .getBoolean(ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION,
-                                               ConfigConstants.CONFIG_KEY_READ_CHANGED_PATHS, false);
-               } catch (ConfigInvalidException e) {
-                       // Use the default value if, for some reason, the config couldn't be read.
-                       readChangedPathFilters = false;
-               }
-
                CommitGraphBuilder builder = CommitGraphBuilder.builder();
                for (int i = 0; i < numberOfChunks; i++) {
                        long chunkOffset = chunks.get(i).offset;