summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2018-12-28 15:57:51 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2018-12-28 15:57:51 -0500
commit2f9ebeacc8a73444976e1ba888dd83801e6b6306 (patch)
treecfd85468d294c456c01c4f01e8b754f69d68f2c1 /org.eclipse.jgit
parentb4e415f8a993a0fff34eaeb2010864a63a6737c6 (diff)
parentc1954f6c366121f971699573322a2669c7dd9430 (diff)
downloadjgit-2f9ebeacc8a73444976e1ba888dd83801e6b6306.tar.gz
jgit-2f9ebeacc8a73444976e1ba888dd83801e6b6306.zip
Merge changes Id3bb9443,I1be1948b
* changes: RefDatabase: Introduce findRef synonym for getRef RefDirectory: Look up several exact refs in one shot
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java27
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java38
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java4
6 files changed, 57 insertions, 48 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java
index a884346842..8b2a03d4c5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java
@@ -107,20 +107,6 @@ public abstract class DfsRefDatabase extends RefDatabase {
/** {@inheritDoc} */
@Override
- public Ref getRef(String needle) throws IOException {
- RefCache curr = read();
- for (String prefix : SEARCH_PATH) {
- Ref ref = curr.ids.get(prefix + needle);
- if (ref != null) {
- ref = resolve(ref, 0, curr.ids);
- return ref;
- }
- }
- return null;
- }
-
- /** {@inheritDoc} */
- @Override
public List<Ref> getAdditionalRefs() {
return Collections.emptyList();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
index 0e0a6ef5e4..83394bb92c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
@@ -229,18 +229,6 @@ public class DfsReftableDatabase extends DfsRefDatabase {
/** {@inheritDoc} */
@Override
- public Ref getRef(String needle) throws IOException {
- for (String prefix : SEARCH_PATH) {
- Ref ref = exactRef(prefix + needle);
- if (ref != null) {
- return ref;
- }
- }
- return null;
- }
-
- /** {@inheritDoc} */
- @Override
public Map<String, Ref> getRefs(String prefix) throws IOException {
RefList.Builder<Ref> all = new RefList.Builder<>();
lock.lock();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index dcf30c713e..a4729bba48 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -74,6 +74,7 @@ import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -352,11 +353,31 @@ public class RefDirectory extends RefDatabase {
/** {@inheritDoc} */
@Override
- public Ref getRef(String needle) throws IOException {
+ @NonNull
+ public Map<String, Ref> exactRef(String... refs) throws IOException {
try {
RefList<Ref> packed = getPackedRefs();
- for (String prefix : SEARCH_PATH) {
- Ref ref = readAndResolve(prefix + needle, packed);
+ Map<String, Ref> result = new HashMap<>(refs.length);
+ for (String name : refs) {
+ Ref ref = readAndResolve(name, packed);
+ if (ref != null) {
+ result.put(name, ref);
+ }
+ }
+ return result;
+ } finally {
+ fireRefsChanged();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ @Nullable
+ public Ref firstExactRef(String... refs) throws IOException {
+ try {
+ RefList<Ref> packed = getPackedRefs();
+ for (String name : refs) {
+ Ref ref = readAndResolve(name, packed);
if (ref != null) {
return ref;
}
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 27daaf0bb2..ddd05b3e54 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
@@ -206,16 +206,6 @@ public class RefTreeDatabase extends RefDatabase {
/** {@inheritDoc} */
@Override
- public Ref getRef(String name) throws IOException {
- 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);
- }
-
- /** {@inheritDoc} */
- @Override
public Ref exactRef(String name) throws IOException {
if (!repo.isBare() && name.indexOf('/') < 0 && !HEAD.equals(name)) {
// Pass through names like MERGE_HEAD, ORIG_HEAD, FETCH_HEAD.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
index 73c7b1c613..877792097c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
@@ -69,10 +69,10 @@ public abstract class RefDatabase {
/**
* Order of prefixes to search when using non-absolute references.
* <p>
- * The implementation's {@link #getRef(String)} method must take this search
- * space into consideration when locating a reference by name. The first
- * entry in the path is always {@code ""}, ensuring that absolute references
- * are resolved without further mangling.
+ * {@link #findRef(String)} takes this search space into consideration
+ * when locating a reference by name. The first entry in the path is
+ * always {@code ""}, ensuring that absolute references are resolved
+ * without further mangling.
*/
protected static final String[] SEARCH_PATH = { "", //$NON-NLS-1$
Constants.R_REFS, //
@@ -257,6 +257,23 @@ public abstract class RefDatabase {
}
/**
+ * Compatibility synonym for {@link #findRef(String)}.
+ *
+ * @param name
+ * the name of the reference. May be a short name which must be
+ * searched for using the standard {@link #SEARCH_PATH}.
+ * @return the reference (if it exists); else {@code null}.
+ * @throws IOException
+ * the reference space cannot be accessed.
+ * @deprecated Use {@link #findRef(String)} instead.
+ */
+ @Deprecated
+ @Nullable
+ public final Ref getRef(String name) throws IOException {
+ return findRef(name);
+ }
+
+ /**
* Read a single reference.
* <p>
* Aside from taking advantage of {@link #SEARCH_PATH}, this method may be
@@ -272,14 +289,21 @@ public abstract class RefDatabase {
* @return the reference (if it exists); else {@code null}.
* @throws java.io.IOException
* the reference space cannot be accessed.
+ * @since 5.3
*/
@Nullable
- public abstract Ref getRef(String name) throws IOException;
+ public final Ref findRef(String name) throws IOException {
+ String[] names = new String[SEARCH_PATH.length];
+ for (int i = 0; i < SEARCH_PATH.length; i++) {
+ names[i] = SEARCH_PATH[i] + name;
+ }
+ return firstExactRef(names);
+ }
/**
* Read a single reference.
* <p>
- * Unlike {@link #getRef}, this method expects an unshortened reference
+ * Unlike {@link #findRef}, this method expects an unshortened reference
* name and does not search using the standard {@link #SEARCH_PATH}.
*
* @param name
@@ -469,7 +493,7 @@ public abstract class RefDatabase {
* <p>
* The result list includes non-ref items such as MERGE_HEAD and
* FETCH_RESULT cast to be refs. The names of these refs are not returned by
- * <code>getRefs()</code> but are accepted by {@link #getRef(String)}
+ * <code>getRefs()</code> but are accepted by {@link #findRef(String)}
* and {@link #exactRef(String)}.
*
* @return a list of additional refs
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 b72b7629f3..ce51c14c2c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -849,7 +849,7 @@ public abstract class Repository implements AutoCloseable {
return ObjectId.fromString(revstr);
if (Repository.isValidRefName("x/" + revstr)) { //$NON-NLS-1$
- Ref r = getRefDatabase().getRef(revstr);
+ Ref r = getRefDatabase().findRef(revstr);
if (r != null)
return r.getObjectId();
}
@@ -1087,7 +1087,7 @@ public abstract class Repository implements AutoCloseable {
*/
@Nullable
public final Ref findRef(String name) throws IOException {
- return getRefDatabase().getRef(name);
+ return getRefDatabase().findRef(name);
}
/**