summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2023-01-18 17:39:19 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2023-01-23 17:19:14 +0100
commitcd3fc7a2995c06cf2425f51758094e039c938559 (patch)
tree1d7d96ea014697116a55976f2dbd97c7a35805d2 /org.eclipse.jgit
parent2011fe06d2cbc15159342b263704f95a39f937c4 (diff)
downloadjgit-cd3fc7a2995c06cf2425f51758094e039c938559.tar.gz
jgit-cd3fc7a2995c06cf2425f51758094e039c938559.zip
Speedup GC listing objects referenced from reflogs
GC needs to get a ReflogReader for all existing refs to list all objects referenced from reflogs. The existing Repository#getReflogReader method accepts the ref name and then resolves the Ref to create a ReflogReader. GC calling that for a huge number of Refs one by one is very slow. GC first gets all Refs in bulk and then calls getReflogReader for each of them. Fix this by adding another getReflogReader method to Repository which accepts a Ref directly. This speeds up running JGit gc on a mirror clone of the Gerrit repository from 15:36 min to 1:08 min. The repository used in this test had 45k refs, 275k commits and 1.2m git objects. Change-Id: I474897fdc6652923e35d461c065a29f54d9949f4
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/.settings/.api_filters32
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java16
4 files changed, 36 insertions, 24 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index 87deace396..27b322c91b 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jgit" version="2">
+ <resource path="META-INF/MANIFEST.MF">
+ <filter id="924844039">
+ <message_arguments>
+ <message_argument value="5.13.2"/>
+ <message_argument value="5.13.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
<filter id="1142947843">
<message_arguments>
@@ -8,11 +16,11 @@
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/jgit/storage/pack/PackConfig.java" type="org.eclipse.jgit.storage.pack.PackConfig">
- <filter id="336658481">
+ <resource path="src/org/eclipse/jgit/lib/Repository.java" type="org.eclipse.jgit.lib.Repository">
+ <filter id="1142947843">
<message_arguments>
- <message_argument value="org.eclipse.jgit.storage.pack.PackConfig"/>
- <message_argument value="DEFAULT_SEARCH_FOR_REUSE_TIMEOUT"/>
+ <message_argument value="5.13.2"/>
+ <message_argument value="getReflogReader(Ref)"/>
</message_arguments>
</filter>
</resource>
@@ -24,22 +32,6 @@
</message_arguments>
</filter>
</resource>
- <resource path="src/org/eclipse/jgit/transport/ProtocolV2Hook.java" type="org.eclipse.jgit.transport.ProtocolV2Hook">
- <filter id="404000815">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.transport.ProtocolV2Hook"/>
- <message_argument value="onObjectInfo(ObjectInfoRequest)"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/transport/SshConstants.java" type="org.eclipse.jgit.transport.SshConstants">
- <filter id="1142947843">
- <message_arguments>
- <message_argument value="5.11.1"/>
- <message_argument value="PUBKEY_ACCEPTED_ALGORITHMS"/>
- </message_arguments>
- </filter>
- </resource>
<resource path="src/org/eclipse/jgit/util/sha1/SHA1.java" type="org.eclipse.jgit.util.sha1.SHA1">
<filter id="337764418">
<message_arguments>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
index fecced1ae6..90ee8def5c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
@@ -31,6 +31,7 @@ import java.util.Locale;
import java.util.Objects;
import java.util.Set;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.attributes.AttributesNode;
@@ -525,6 +526,12 @@ public class FileRepository extends Repository {
return new ReflogReaderImpl(this, ref.getName());
}
+ @Override
+ public @NonNull ReflogReader getReflogReader(@NonNull Ref ref)
+ throws IOException {
+ return new ReflogReaderImpl(this, ref.getName());
+ }
+
/** {@inheritDoc} */
@Override
public AttributesNodeProvider createAttributesNodeProvider() {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
index 40c075ec5e..a14bb411ff 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
@@ -1019,10 +1019,7 @@ public class GC {
* @throws IOException
*/
private Set<ObjectId> listRefLogObjects(Ref ref, long minTime) throws IOException {
- ReflogReader reflogReader = repo.getReflogReader(ref.getName());
- if (reflogReader == null) {
- return Collections.emptySet();
- }
+ ReflogReader reflogReader = repo.getReflogReader(ref);
List<ReflogEntry> rlEntries = reflogReader
.getReverseEntries();
if (rlEntries == null || rlEntries.isEmpty())
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 1e8a6c9175..d3b3c6e8a2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -1692,6 +1692,22 @@ public abstract class Repository implements AutoCloseable {
throws IOException;
/**
+ * Get the reflog reader. Subclasses should override this method and provide
+ * a more efficient implementation.
+ *
+ * @param ref
+ * a Ref
+ * @return a {@link org.eclipse.jgit.lib.ReflogReader} for the supplied ref,
+ * or {@code null} if the ref does not exist.
+ * @throws IOException
+ * @since 5.13.2
+ */
+ public @Nullable ReflogReader getReflogReader(@NonNull Ref ref)
+ throws IOException {
+ return getReflogReader(ref.getName());
+ }
+
+ /**
* Return the information stored in the file $GIT_DIR/MERGE_MSG. In this
* file operations triggering a merge will store a template for the commit
* message of the merge commit.