RefDatabase: Introduce getAllRefs method
Currently to get all refs, callers must use: getRefsByPrefix(ALL) Introduce getAllRefs, which does this, and migrate all existing callers of getRefsByPrefix(ALL). Change-Id: I7b1687c162c8ae836dc7db3ccc7ac847863f691d Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
parent
57f158632d
commit
4dcf2f93db
|
@ -45,8 +45,6 @@
|
|||
|
||||
package org.eclipse.jgit.pgm;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -73,7 +71,7 @@ class RevParse extends TextBuiltin {
|
|||
@Override
|
||||
protected void run() throws Exception {
|
||||
if (all) {
|
||||
List<Ref> allRefs = db.getRefDatabase().getRefsByPrefix(ALL);
|
||||
List<Ref> allRefs = db.getRefDatabase().getAllRefs();
|
||||
for (final Ref r : allRefs) {
|
||||
ObjectId objectId = r.getObjectId();
|
||||
// getRefs skips dangling symrefs, so objectId should never be
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
import org.eclipse.jgit.lib.Constants;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.pgm.internal.CLIText;
|
||||
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
|
||||
import org.eclipse.jgit.revwalk.FollowFilter;
|
||||
|
@ -170,8 +169,7 @@ else if (revLimiter.size() > 1)
|
|||
walk.setRevFilter(AndRevFilter.create(revLimiter));
|
||||
|
||||
if (all) {
|
||||
List<Ref> refs =
|
||||
db.getRefDatabase().getRefsByPrefix(RefDatabase.ALL);
|
||||
List<Ref> refs = db.getRefDatabase().getAllRefs();
|
||||
for (Ref a : refs) {
|
||||
ObjectId oid = a.getPeeledObjectId();
|
||||
if (oid == null)
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
|
||||
package org.eclipse.jgit.pgm;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -67,7 +65,7 @@ protected void run() throws Exception {
|
|||
}
|
||||
|
||||
private Iterable<Ref> getSortedRefs() throws Exception {
|
||||
List<Ref> all = db.getRefDatabase().getRefsByPrefix(ALL);
|
||||
List<Ref> all = db.getRefDatabase().getAllRefs();
|
||||
// TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
|
||||
// SortedList
|
||||
return RefComparator.sort(all);
|
||||
|
|
|
@ -43,8 +43,6 @@
|
|||
|
||||
package org.eclipse.jgit.pgm.debug;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -117,7 +115,7 @@ class RebuildCommitGraph extends TextBuiltin {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
if (!really && !db.getRefDatabase().getRefsByPrefix(ALL).isEmpty()) {
|
||||
if (!really && !db.getRefDatabase().getAllRefs().isEmpty()) {
|
||||
File directory = db.getDirectory();
|
||||
String absolutePath = directory == null ? "null" //$NON-NLS-1$
|
||||
: directory.getAbsolutePath();
|
||||
|
@ -247,8 +245,7 @@ private void detachHead() throws IOException {
|
|||
|
||||
private void deleteAllRefs() throws Exception {
|
||||
final RevWalk rw = new RevWalk(db);
|
||||
List<Ref> refs = db.getRefDatabase().getRefsByPrefix(ALL);
|
||||
for (final Ref r : refs) {
|
||||
for (Ref r : db.getRefDatabase().getAllRefs()) {
|
||||
if (Constants.HEAD.equals(r.getName()))
|
||||
continue;
|
||||
final RefUpdate u = db.updateRef(r.getName());
|
||||
|
|
|
@ -154,7 +154,7 @@ private RefTree rebuild(RefDatabase refdb) throws IOException {
|
|||
head));
|
||||
}
|
||||
|
||||
for (Ref r : refdb.getRefsByPrefix(RefDatabase.ALL)) {
|
||||
for (Ref r : refdb.getAllRefs()) {
|
||||
if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
|
||||
|| r.getName().startsWith(txnNamespace)) {
|
||||
continue;
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
*/
|
||||
package org.eclipse.jgit.api;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -274,8 +272,7 @@ public LogCommand addRange(AnyObjectId since, AnyObjectId until)
|
|||
* the references could not be accessed
|
||||
*/
|
||||
public LogCommand all() throws IOException {
|
||||
List<Ref> refs = getRepository().getRefDatabase().getRefsByPrefix(ALL);
|
||||
for (Ref ref : refs) {
|
||||
for (Ref ref : getRepository().getRefDatabase().getAllRefs()) {
|
||||
if(!ref.isPeeled())
|
||||
ref = getRepository().peel(ref);
|
||||
|
||||
|
|
|
@ -403,7 +403,7 @@ public boolean pack(ProgressMonitor pm) throws IOException {
|
|||
}
|
||||
|
||||
private Collection<Ref> getAllRefs() throws IOException {
|
||||
Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
|
||||
Collection<Ref> refs = refdb.getAllRefs();
|
||||
List<Ref> addl = refdb.getAdditionalRefs();
|
||||
if (!addl.isEmpty()) {
|
||||
List<Ref> all = new ArrayList<>(refs.size() + addl.size());
|
||||
|
|
|
@ -1068,7 +1068,7 @@ private Set<ObjectId> listRefLogObjects(Ref ref, long minTime) throws IOExceptio
|
|||
*/
|
||||
private Collection<Ref> getAllRefs() throws IOException {
|
||||
RefDatabase refdb = repo.getRefDatabase();
|
||||
Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL);
|
||||
Collection<Ref> refs = refdb.getAllRefs();
|
||||
List<Ref> addl = refdb.getAdditionalRefs();
|
||||
if (!addl.isEmpty()) {
|
||||
List<Ref> all = new ArrayList<>(refs.size() + addl.size());
|
||||
|
@ -1376,7 +1376,7 @@ public RepoStatistics getStatistics() throws IOException {
|
|||
}
|
||||
|
||||
RefDatabase refDb = repo.getRefDatabase();
|
||||
for (Ref r : refDb.getRefsByPrefix(RefDatabase.ALL)) {
|
||||
for (Ref r : refDb.getAllRefs()) {
|
||||
Storage storage = r.getStorage();
|
||||
if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
|
||||
ret.numberOfLooseRefs++;
|
||||
|
|
|
@ -391,6 +391,22 @@ public List<Ref> getRefsByPrefix(String prefix) throws IOException {
|
|||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all refs.
|
||||
* <p>
|
||||
* Callers interested in only a portion of the ref hierarchy can call
|
||||
* {@link #getRefsByPrefix} instead.
|
||||
*
|
||||
* @return immutable list of all refs.
|
||||
* @throws java.io.IOException
|
||||
* the reference space cannot be accessed.
|
||||
* @since 5.0
|
||||
*/
|
||||
@NonNull
|
||||
public List<Ref> getAllRefs() throws IOException {
|
||||
return getRefsByPrefix(ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the additional reference-like entities from the repository.
|
||||
* <p>
|
||||
|
|
|
@ -45,8 +45,6 @@
|
|||
|
||||
package org.eclipse.jgit.transport;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
@ -439,7 +437,7 @@ private int maxTimeWanted(final Collection<Ref> wants) {
|
|||
|
||||
private void markReachable(final Set<ObjectId> have, final int maxTime)
|
||||
throws IOException {
|
||||
for (Ref r : local.getRefDatabase().getRefsByPrefix(ALL)) {
|
||||
for (Ref r : local.getRefDatabase().getAllRefs()) {
|
||||
ObjectId id = r.getPeeledObjectId();
|
||||
if (id == null)
|
||||
id = r.getObjectId();
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
|
||||
package org.eclipse.jgit.transport;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -256,8 +254,7 @@ private void verifyPrerequisites() throws TransportException {
|
|||
|
||||
List<Ref> localRefs;
|
||||
try {
|
||||
localRefs = transport.local.getRefDatabase()
|
||||
.getRefsByPrefix(ALL);
|
||||
localRefs = transport.local.getRefDatabase().getAllRefs();
|
||||
} catch (IOException e) {
|
||||
throw new TransportException(transport.uri, e.getMessage(), e);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
package org.eclipse.jgit.transport;
|
||||
|
||||
import static org.eclipse.jgit.lib.Constants.CHARSET;
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -689,7 +688,7 @@ public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
|
|||
private static Collection<RefSpec> expandPushWildcardsFor(
|
||||
final Repository db, final Collection<RefSpec> specs)
|
||||
throws IOException {
|
||||
final List<Ref> localRefs = db.getRefDatabase().getRefsByPrefix(ALL);
|
||||
final List<Ref> localRefs = db.getRefDatabase().getAllRefs();
|
||||
final Collection<RefSpec> procRefs = new LinkedHashSet<>();
|
||||
|
||||
for (final RefSpec spec : specs) {
|
||||
|
|
|
@ -90,7 +90,6 @@
|
|||
import org.eclipse.jgit.lib.ObjectReader;
|
||||
import org.eclipse.jgit.lib.ProgressMonitor;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.RefDatabase;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
|
||||
import org.eclipse.jgit.revwalk.BitmapWalker;
|
||||
|
@ -776,7 +775,7 @@ public PackStatistics getStatistics() {
|
|||
|
||||
private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
|
||||
if (refs == null)
|
||||
setAdvertisedRefs(db.getRefDatabase().getRefs(RefDatabase.ALL));
|
||||
setAdvertisedRefs(db.getRefDatabase().getRefs(ALL));
|
||||
return refs;
|
||||
}
|
||||
|
||||
|
@ -1583,7 +1582,7 @@ public void checkWants(UploadPack up, List<ObjectId> wants)
|
|||
else if (!wants.isEmpty()) {
|
||||
Set<ObjectId> refIds =
|
||||
refIdSet(up.getRepository().getRefDatabase()
|
||||
.getRefsByPrefix(ALL));
|
||||
.getAllRefs());
|
||||
for (ObjectId obj : wants) {
|
||||
if (!refIds.contains(obj))
|
||||
throw new WantNotValidException(obj);
|
||||
|
@ -1603,8 +1602,7 @@ public static final class ReachableCommitTipRequestValidator
|
|||
public void checkWants(UploadPack up, List<ObjectId> wants)
|
||||
throws PackProtocolException, IOException {
|
||||
checkNotAdvertisedWants(up, wants,
|
||||
refIdSet(up.getRepository().getRefDatabase()
|
||||
.getRefsByPrefix(ALL)));
|
||||
refIdSet(up.getRepository().getRefDatabase().getAllRefs()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,6 @@
|
|||
|
||||
package org.eclipse.jgit.transport;
|
||||
|
||||
import static org.eclipse.jgit.lib.RefDatabase.ALL;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -691,7 +689,7 @@ private Collection<WalkRemoteObjectDatabase> expandOneAlternate(
|
|||
private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
|
||||
List<Ref> refs;
|
||||
try {
|
||||
refs = local.getRefDatabase().getRefsByPrefix(ALL);
|
||||
refs = local.getRefDatabase().getAllRefs();
|
||||
} catch (IOException e) {
|
||||
throw new TransportException(e.getMessage(), e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue