Browse Source

Merge changes Id3bb9443,I1be1948b

* changes:
  RefDatabase: Introduce findRef synonym for getRef
  RefDirectory: Look up several exact refs in one shot
stable-5.3
Jonathan Nieder 6 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
2f9ebeacc8
  1. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefDatabaseConflictingNamesTest.java
  2. 14
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java
  3. 12
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java
  4. 27
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  5. 10
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java
  6. 38
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
  7. 4
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefDatabaseConflictingNamesTest.java

@ -99,11 +99,6 @@ public class RefDatabaseConflictingNamesTest {
return null;
}
@Override
public Ref getRef(String name) throws IOException {
return null;
}
@Override
public List<Ref> getAdditionalRefs() throws IOException {
return null;

14
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRefDatabase.java

@ -105,20 +105,6 @@ public abstract class DfsRefDatabase extends RefDatabase {
return ref != null ? resolve(ref, 0, curr.ids) : null;
}
/** {@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() {

12
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReftableDatabase.java

@ -227,18 +227,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 {

27
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();
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 prefix : SEARCH_PATH) {
Ref ref = readAndResolve(prefix + needle, packed);
for (String name : refs) {
Ref ref = readAndResolve(name, packed);
if (ref != null) {
return ref;
}

10
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java

@ -204,16 +204,6 @@ public class RefTreeDatabase extends RefDatabase {
bootstrap.close();
}
/** {@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 {

38
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, //
@ -256,6 +256,23 @@ public abstract class RefDatabase {
return false;
}
/**
* 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>
@ -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

4
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);
}
/**

Loading…
Cancel
Save