summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2016-01-14 16:11:15 -0800
committerShawn Pearce <spearce@spearce.org>2016-01-15 11:07:19 -0800
commita290b822ab4f0ec9c1e5121235564fadf594a74e (patch)
treed1976ca65a95ff5eb536c35074e7405a2aad559b /org.eclipse.jgit
parentf52581c6a50d841e1939dbd69d174effa63c8c57 (diff)
downloadjgit-a290b822ab4f0ec9c1e5121235564fadf594a74e.tar.gz
jgit-a290b822ab4f0ec9c1e5121235564fadf594a74e.zip
RefTreeDatabase: Expose bootstrap refs in getAdditionalRefs
By showing the bootstrap layer in getAdditionalRefs() garbage collector code can be more RefDatabase agnostic and not care about the special case of RefTree and RefTreeNames for the purposes of building up the roots to GC. Instead they can combine getRefs(ALL) and getAdditionalRefs() and have a clean set of roots. Change-Id: I665cd2456e9316640215b6a08bc728d1356f36d8
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java35
4 files changed, 37 insertions, 41 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
index 784507d88c..33be3b15a8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
@@ -194,7 +194,7 @@ public class DfsGarbageCollector {
refdb.refresh();
objdb.clearCache();
- Collection<Ref> refsBefore = RefTreeNames.allRefs(refdb);
+ Collection<Ref> refsBefore = getAllRefs();
packsBefore = packsToRebuild();
if (packsBefore.isEmpty())
return true;
@@ -235,6 +235,18 @@ public class DfsGarbageCollector {
}
}
+ private Collection<Ref> getAllRefs() throws IOException {
+ Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values();
+ List<Ref> addl = refdb.getAdditionalRefs();
+ if (!addl.isEmpty()) {
+ List<Ref> all = new ArrayList<>(refs.size() + addl.size());
+ all.addAll(refs);
+ all.addAll(addl);
+ return all;
+ }
+ return refs;
+ }
+
private List<DfsPackFile> packsToRebuild() throws IOException {
DfsPackFile[] packs = objdb.getPacks();
List<DfsPackFile> out = new ArrayList<DfsPackFile>(packs.length);
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 2ce0d47348..49f9335aed 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
@@ -629,15 +629,16 @@ public class GC {
}
/**
- * Returns a map of all refs and additional refs (e.g. FETCH_HEAD,
+ * Returns a collection of all refs and additional refs (e.g. FETCH_HEAD,
* MERGE_HEAD, ...)
*
- * @return a map where names of refs point to ref objects
+ * @return a collection of refs pointing to live objects.
* @throws IOException
*/
private Collection<Ref> getAllRefs() throws IOException {
- Collection<Ref> refs = RefTreeNames.allRefs(repo.getRefDatabase());
- List<Ref> addl = repo.getRefDatabase().getAdditionalRefs();
+ RefDatabase refdb = repo.getRefDatabase();
+ Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values();
+ List<Ref> addl = refdb.getAdditionalRefs();
if (!addl.isEmpty()) {
List<Ref> all = new ArrayList<>(refs.size() + addl.size());
all.addAll(refs);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java
index dc60311102..f6fdef1fa5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java
@@ -47,6 +47,8 @@ import static org.eclipse.jgit.lib.Ref.Storage.LOOSE;
import static org.eclipse.jgit.lib.Ref.Storage.PACKED;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -250,7 +252,23 @@ public class RefTreeDatabase extends RefDatabase {
@Override
public List<Ref> getAdditionalRefs() throws IOException {
- return Collections.emptyList();
+ Collection<Ref> txnRefs;
+ if (txnNamespace != null) {
+ txnRefs = bootstrap.getRefs(txnNamespace).values();
+ } else {
+ Ref r = bootstrap.exactRef(txnCommitted);
+ if (r != null && r.getObjectId() != null) {
+ txnRefs = Collections.singleton(r);
+ } else {
+ txnRefs = Collections.emptyList();
+ }
+ }
+
+ List<Ref> otherRefs = bootstrap.getAdditionalRefs();
+ List<Ref> all = new ArrayList<>(txnRefs.size() + otherRefs.size());
+ all.addAll(txnRefs);
+ all.addAll(otherRefs);
+ return all;
}
@Override
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java
index 239a745277..c53d6deb21 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java
@@ -43,14 +43,6 @@
package org.eclipse.jgit.internal.storage.reftree;
-import static org.eclipse.jgit.lib.RefDatabase.ALL;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
/** Magic reference name logic for RefTrees. */
@@ -92,33 +84,6 @@ public class RefTreeNames {
return false;
}
- /**
- * Snapshot all references from a RefTreeDatabase and its bootstrap.
- * <p>
- * There may be name conflicts with multiple {@link Ref} objects containing
- * the same name in the returned collection.
- *
- * @param refdb
- * database instance.
- * @return all known references.
- * @throws IOException
- * references cannot be enumerated.
- */
- public static Collection<Ref> allRefs(RefDatabase refdb)
- throws IOException {
- Collection<Ref> refs = refdb.getRefs(ALL).values();
- if (!(refdb instanceof RefTreeDatabase)) {
- return refs;
- }
-
- RefDatabase bootstrap = ((RefTreeDatabase) refdb).getBootstrap();
- Collection<Ref> br = bootstrap.getRefs(ALL).values();
- List<Ref> all = new ArrayList<>(refs.size() + br.size());
- all.addAll(refs);
- all.addAll(br);
- return all;
- }
-
private RefTreeNames() {
}
}