summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2016-01-21 00:32:17 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2016-01-21 00:32:17 -0500
commit8fe9a8baf53ed5c45c697669808d04423702e496 (patch)
treec320dae4c98ed307dde372dfeef4a0f55b4a867d /org.eclipse.jgit/src
parent8d0551dd64d026c161a82ce4d9ed2222b5a4b4be (diff)
parent14dfa70520ddf06422df1d943c7bd955a23e46bc (diff)
downloadjgit-8fe9a8baf53ed5c45c697669808d04423702e496.tar.gz
jgit-8fe9a8baf53ed5c45c697669808d04423702e496.zip
Merge changes from topic 'reftree'
* changes: debug-rebuild-ref-tree: Copy HEAD into RefTree debug-rebuild-ref-tree: Add --enable flag to turn the database on RefTreeDatabase: Allow ORIG_HEAD, etc. on non-bare repositories RefTreeDatabase: Expose bootstrap refs in getAdditionalRefs
Diffstat (limited to 'org.eclipse.jgit/src')
-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.java43
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeNames.java35
4 files changed, 57 insertions, 44 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..df93ce88af 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
@@ -43,10 +43,13 @@
package org.eclipse.jgit.internal.storage.reftree;
+import static org.eclipse.jgit.lib.Constants.HEAD;
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;
@@ -187,12 +190,19 @@ public class RefTreeDatabase extends RefDatabase {
@Override
public Ref getRef(String name) throws IOException {
- return findRef(getRefs(ALL), name);
+ String[] needle = new String[SEARCH_PATH.length];
+ for (int i = 0; i < SEARCH_PATH.length; i++) {
+ needle[i] = SEARCH_PATH[i] + name;
+ }
+ return firstExactRef(needle);
}
@Override
public Ref exactRef(String name) throws IOException {
- if (conflictsWithBootstrap(name)) {
+ if (!repo.isBare() && name.indexOf('/') < 0 && !HEAD.equals(name)) {
+ // Pass through names like MERGE_HEAD, ORIG_HEAD, FETCH_HEAD.
+ return bootstrap.exactRef(name);
+ } else if (conflictsWithBootstrap(name)) {
return null;
}
@@ -250,7 +260,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
@@ -293,6 +319,9 @@ public class RefTreeDatabase extends RefDatabase {
@Override
public RefUpdate newUpdate(String name, boolean detach) throws IOException {
+ if (!repo.isBare() && name.indexOf('/') < 0 && !HEAD.equals(name)) {
+ return bootstrap.newUpdate(name, detach);
+ }
if (conflictsWithBootstrap(name)) {
return new AlwaysFailUpdate(this, name);
}
@@ -327,7 +356,13 @@ public class RefTreeDatabase extends RefDatabase {
return true;
} else if (txnCommitted.equals(name)) {
return true;
- } else if (name.length() > txnCommitted.length()
+ }
+
+ if (name.indexOf('/') < 0 && !HEAD.equals(name)) {
+ return true;
+ }
+
+ if (name.length() > txnCommitted.length()
&& name.charAt(txnCommitted.length()) == '/'
&& name.startsWith(txnCommitted)) {
return true;
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() {
}
}