Преглед изворни кода

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>
tags/v5.3.0.201901161700-m1
Jonathan Nieder пре 5 година
родитељ
комит
d2bab65470

+ 38
- 0
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…
Откажи
Сачувај