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>tags/v5.0.0.201805151920-m7
@@ -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.errors.IncorrectObjectTypeException; | |||
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 @@ abstract class RevWalkTextBuiltin extends TextBuiltin { | |||
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 @@ class ShowRef extends TextBuiltin { | |||
} | |||
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 @@ class RebuildCommitGraph extends TextBuiltin { | |||
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 @@ class RebuildRefTree extends TextBuiltin { | |||
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 class LogCommand extends GitCommand<Iterable<RevCommit>> { | |||
* 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 class DfsGarbageCollector { | |||
} | |||
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 @@ public class GC { | |||
*/ | |||
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 class GC { | |||
} | |||
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 abstract class RefDatabase { | |||
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 @@ public abstract class BasePackFetchConnection extends BasePackConnection | |||
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 @@ class BundleFetchConnection extends BaseFetchConnection { | |||
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 abstract class Transport implements AutoCloseable { | |||
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.ObjectId; | |||
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 class UploadPack { | |||
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 class UploadPack { | |||
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 class UploadPack { | |||
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 @@ class WalkFetchConnection extends BaseFetchConnection { | |||
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); | |||
} |