Browse Source

RefDirectory: Look up several exact refs in one shot

Override exactRef(String...) and firstExactRef(String...) with
implementations specific to FileRepository.

The specialized implementations are similar to the generic ones from
RefDatabase, but because these use readRef directly instead of
exactRef, they only need to call fireRefsChanged once.

This will allow replacing RefDirectory#getRef with a generic
implementation that uses firstExactRef without hurting performance.

Change-Id: I1be1948bd6121c1a1e8152e201aab97e7fb308bb
Signed-off-by: Jonathan Nieder <jrn@google.com>
stable-5.3
Jonathan Nieder 6 years ago
parent
commit
d2bab65470
  1. 38
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

38
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;
@ -350,6 +351,43 @@ public class RefDirectory extends RefDatabase {
}
}
/** {@inheritDoc} */
@Override
@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 name : refs) {
Ref ref = readAndResolve(name, packed);
if (ref != null) {
return ref;
}
}
return null;
} finally {
fireRefsChanged();
}
}
/** {@inheritDoc} */
@Override
public Ref getRef(String needle) throws IOException {

Loading…
Cancel
Save