Browse Source

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>
stable-5.0
David Pursehouse 7 years ago
parent
commit
4dcf2f93db
  1. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
  2. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
  3. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
  4. 7
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  5. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java
  6. 5
      org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
  7. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java
  8. 4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
  9. 16
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
  10. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
  11. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
  12. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
  13. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
  14. 4
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java

@ -45,8 +45,6 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -73,7 +71,7 @@ class RevParse extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
if (all) { if (all) {
List<Ref> allRefs = db.getRefDatabase().getRefsByPrefix(ALL); List<Ref> allRefs = db.getRefDatabase().getAllRefs();
for (final Ref r : allRefs) { for (final Ref r : allRefs) {
ObjectId objectId = r.getObjectId(); ObjectId objectId = r.getObjectId();
// getRefs skips dangling symrefs, so objectId should never be // getRefs skips dangling symrefs, so objectId should never be

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java

@ -53,7 +53,6 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.pgm.internal.CLIText; import org.eclipse.jgit.pgm.internal.CLIText;
import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler; import org.eclipse.jgit.pgm.opt.PathTreeFilterHandler;
import org.eclipse.jgit.revwalk.FollowFilter; import org.eclipse.jgit.revwalk.FollowFilter;
@ -170,8 +169,7 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
walk.setRevFilter(AndRevFilter.create(revLimiter)); walk.setRevFilter(AndRevFilter.create(revLimiter));
if (all) { if (all) {
List<Ref> refs = List<Ref> refs = db.getRefDatabase().getAllRefs();
db.getRefDatabase().getRefsByPrefix(RefDatabase.ALL);
for (Ref a : refs) { for (Ref a : refs) {
ObjectId oid = a.getPeeledObjectId(); ObjectId oid = a.getPeeledObjectId();
if (oid == null) if (oid == null)

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java

@ -45,8 +45,6 @@
package org.eclipse.jgit.pgm; package org.eclipse.jgit.pgm;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -67,7 +65,7 @@ class ShowRef extends TextBuiltin {
} }
private Iterable<Ref> getSortedRefs() 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 // TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
// SortedList // SortedList
return RefComparator.sort(all); return RefComparator.sort(all);

7
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -43,8 +43,6 @@
package org.eclipse.jgit.pgm.debug; package org.eclipse.jgit.pgm.debug;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -117,7 +115,7 @@ class RebuildCommitGraph extends TextBuiltin {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
if (!really && !db.getRefDatabase().getRefsByPrefix(ALL).isEmpty()) { if (!really && !db.getRefDatabase().getAllRefs().isEmpty()) {
File directory = db.getDirectory(); File directory = db.getDirectory();
String absolutePath = directory == null ? "null" //$NON-NLS-1$ String absolutePath = directory == null ? "null" //$NON-NLS-1$
: directory.getAbsolutePath(); : directory.getAbsolutePath();
@ -247,8 +245,7 @@ class RebuildCommitGraph extends TextBuiltin {
private void deleteAllRefs() throws Exception { private void deleteAllRefs() throws Exception {
final RevWalk rw = new RevWalk(db); final RevWalk rw = new RevWalk(db);
List<Ref> refs = db.getRefDatabase().getRefsByPrefix(ALL); for (Ref r : db.getRefDatabase().getAllRefs()) {
for (final Ref r : refs) {
if (Constants.HEAD.equals(r.getName())) if (Constants.HEAD.equals(r.getName()))
continue; continue;
final RefUpdate u = db.updateRef(r.getName()); final RefUpdate u = db.updateRef(r.getName());

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildRefTree.java

@ -154,7 +154,7 @@ class RebuildRefTree extends TextBuiltin {
head)); head));
} }
for (Ref r : refdb.getRefsByPrefix(RefDatabase.ALL)) { for (Ref r : refdb.getAllRefs()) {
if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD) if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
|| r.getName().startsWith(txnNamespace)) { || r.getName().startsWith(txnNamespace)) {
continue; continue;

5
org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java

@ -42,8 +42,6 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -274,8 +272,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
* the references could not be accessed * the references could not be accessed
*/ */
public LogCommand all() throws IOException { public LogCommand all() throws IOException {
List<Ref> refs = getRepository().getRefDatabase().getRefsByPrefix(ALL); for (Ref ref : getRepository().getRefDatabase().getAllRefs()) {
for (Ref ref : refs) {
if(!ref.isPeeled()) if(!ref.isPeeled())
ref = getRepository().peel(ref); ref = getRepository().peel(ref);

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java

@ -403,7 +403,7 @@ public class DfsGarbageCollector {
} }
private Collection<Ref> getAllRefs() 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(); List<Ref> addl = refdb.getAdditionalRefs();
if (!addl.isEmpty()) { if (!addl.isEmpty()) {
List<Ref> all = new ArrayList<>(refs.size() + addl.size()); List<Ref> all = new ArrayList<>(refs.size() + addl.size());

4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

@ -1068,7 +1068,7 @@ public class GC {
*/ */
private Collection<Ref> getAllRefs() throws IOException { private Collection<Ref> getAllRefs() throws IOException {
RefDatabase refdb = repo.getRefDatabase(); RefDatabase refdb = repo.getRefDatabase();
Collection<Ref> refs = refdb.getRefsByPrefix(RefDatabase.ALL); Collection<Ref> refs = refdb.getAllRefs();
List<Ref> addl = refdb.getAdditionalRefs(); List<Ref> addl = refdb.getAdditionalRefs();
if (!addl.isEmpty()) { if (!addl.isEmpty()) {
List<Ref> all = new ArrayList<>(refs.size() + addl.size()); List<Ref> all = new ArrayList<>(refs.size() + addl.size());
@ -1376,7 +1376,7 @@ public class GC {
} }
RefDatabase refDb = repo.getRefDatabase(); RefDatabase refDb = repo.getRefDatabase();
for (Ref r : refDb.getRefsByPrefix(RefDatabase.ALL)) { for (Ref r : refDb.getAllRefs()) {
Storage storage = r.getStorage(); Storage storage = r.getStorage();
if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED) if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
ret.numberOfLooseRefs++; ret.numberOfLooseRefs++;

16
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java

@ -391,6 +391,22 @@ public abstract class RefDatabase {
return Collections.unmodifiableList(result); 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. * Get the additional reference-like entities from the repository.
* <p> * <p>

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java

@ -45,8 +45,6 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
@ -439,7 +437,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection
private void markReachable(final Set<ObjectId> have, final int maxTime) private void markReachable(final Set<ObjectId> have, final int maxTime)
throws IOException { throws IOException {
for (Ref r : local.getRefDatabase().getRefsByPrefix(ALL)) { for (Ref r : local.getRefDatabase().getAllRefs()) {
ObjectId id = r.getPeeledObjectId(); ObjectId id = r.getPeeledObjectId();
if (id == null) if (id == null)
id = r.getObjectId(); id = r.getObjectId();

5
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java

@ -47,8 +47,6 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -256,8 +254,7 @@ class BundleFetchConnection extends BaseFetchConnection {
List<Ref> localRefs; List<Ref> localRefs;
try { try {
localRefs = transport.local.getRefDatabase() localRefs = transport.local.getRefDatabase().getAllRefs();
.getRefsByPrefix(ALL);
} catch (IOException e) { } catch (IOException e) {
throw new TransportException(transport.uri, e.getMessage(), e); throw new TransportException(transport.uri, e.getMessage(), e);
} }

3
org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java

@ -47,7 +47,6 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -689,7 +688,7 @@ public abstract class Transport implements AutoCloseable {
private static Collection<RefSpec> expandPushWildcardsFor( private static Collection<RefSpec> expandPushWildcardsFor(
final Repository db, final Collection<RefSpec> specs) final Repository db, final Collection<RefSpec> specs)
throws IOException { throws IOException {
final List<Ref> localRefs = db.getRefDatabase().getRefsByPrefix(ALL); final List<Ref> localRefs = db.getRefDatabase().getAllRefs();
final Collection<RefSpec> procRefs = new LinkedHashSet<>(); final Collection<RefSpec> procRefs = new LinkedHashSet<>();
for (final RefSpec spec : specs) { for (final RefSpec spec : specs) {

8
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

@ -90,7 +90,6 @@ import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.AsyncRevObjectQueue; import org.eclipse.jgit.revwalk.AsyncRevObjectQueue;
import org.eclipse.jgit.revwalk.BitmapWalker; import org.eclipse.jgit.revwalk.BitmapWalker;
@ -776,7 +775,7 @@ public class UploadPack {
private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException { private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException {
if (refs == null) if (refs == null)
setAdvertisedRefs(db.getRefDatabase().getRefs(RefDatabase.ALL)); setAdvertisedRefs(db.getRefDatabase().getRefs(ALL));
return refs; return refs;
} }
@ -1583,7 +1582,7 @@ public class UploadPack {
else if (!wants.isEmpty()) { else if (!wants.isEmpty()) {
Set<ObjectId> refIds = Set<ObjectId> refIds =
refIdSet(up.getRepository().getRefDatabase() refIdSet(up.getRepository().getRefDatabase()
.getRefsByPrefix(ALL)); .getAllRefs());
for (ObjectId obj : wants) { for (ObjectId obj : wants) {
if (!refIds.contains(obj)) if (!refIds.contains(obj))
throw new WantNotValidException(obj); throw new WantNotValidException(obj);
@ -1603,8 +1602,7 @@ public class UploadPack {
public void checkWants(UploadPack up, List<ObjectId> wants) public void checkWants(UploadPack up, List<ObjectId> wants)
throws PackProtocolException, IOException { throws PackProtocolException, IOException {
checkNotAdvertisedWants(up, wants, checkNotAdvertisedWants(up, wants,
refIdSet(up.getRepository().getRefDatabase() refIdSet(up.getRepository().getRefDatabase().getAllRefs()));
.getRefsByPrefix(ALL)));
} }
} }

4
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

@ -44,8 +44,6 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -691,7 +689,7 @@ class WalkFetchConnection extends BaseFetchConnection {
private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException { private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
List<Ref> refs; List<Ref> refs;
try { try {
refs = local.getRefDatabase().getRefsByPrefix(ALL); refs = local.getRefDatabase().getAllRefs();
} catch (IOException e) { } catch (IOException e) {
throw new TransportException(e.getMessage(), e); throw new TransportException(e.getMessage(), e);
} }

Loading…
Cancel
Save