Browse Source

Rename RefDatabase#getAllRefs to getRefs

This is easier to type and makes it clearer that it only returns refs
and not the pseudo-refs returned by getAdditionalRefs. It also puts us
in a better position to add a method to the Repository class later
that delegates to this one without colliding with the existing
Repository#getAllRefs method that returns a Map<String, Ref>.

While at it, clarify the javadoc of getRefs and hasRefs to make the
same point.

Suggested-by: David Pursehouse <david.pursehouse@gmail.com>
Change-Id: I23497c66ac7b5e0c987b91efbc9e9cc29924ca66
Signed-off-by: Jonathan Nieder <jrn@google.com>
stable-5.0
Jonathan Nieder 7 years ago
parent
commit
0a35e5f25b
  1. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevParse.java
  2. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java
  3. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/ShowRef.java
  4. 2
      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. 2
      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. 51
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java
  10. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
  11. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java
  12. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
  13. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
  14. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java

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

@ -71,8 +71,7 @@ class RevParse extends TextBuiltin {
@Override
protected void run() throws Exception {
if (all) {
List<Ref> allRefs = db.getRefDatabase().getAllRefs();
for (final Ref r : allRefs) {
for (Ref r : db.getRefDatabase().getRefs()) {
ObjectId objectId = r.getObjectId();
// getRefs skips dangling symrefs, so objectId should never be
// null.

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

@ -169,8 +169,7 @@ abstract class RevWalkTextBuiltin extends TextBuiltin {
walk.setRevFilter(AndRevFilter.create(revLimiter));
if (all) {
List<Ref> refs = db.getRefDatabase().getAllRefs();
for (Ref a : refs) {
for (Ref a : db.getRefDatabase().getRefs()) {
ObjectId oid = a.getPeeledObjectId();
if (oid == null)
oid = a.getObjectId();

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

@ -65,7 +65,7 @@ class ShowRef extends TextBuiltin {
}
private Iterable<Ref> getSortedRefs() throws Exception {
List<Ref> all = db.getRefDatabase().getAllRefs();
List<Ref> all = db.getRefDatabase().getRefs();
// TODO(jrn) check if we can reintroduce fast-path by e.g. implementing
// SortedList
return RefComparator.sort(all);

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

@ -245,7 +245,7 @@ class RebuildCommitGraph extends TextBuiltin {
private void deleteAllRefs() throws Exception {
final RevWalk rw = new RevWalk(db);
for (Ref r : db.getRefDatabase().getAllRefs()) {
for (Ref r : db.getRefDatabase().getRefs()) {
if (Constants.HEAD.equals(r.getName()))
continue;
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));
}
for (Ref r : refdb.getAllRefs()) {
for (Ref r : refdb.getRefs()) {
if (r.getName().equals(txnCommitted) || r.getName().equals(HEAD)
|| r.getName().startsWith(txnNamespace)) {
continue;

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

@ -272,7 +272,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
* the references could not be accessed
*/
public LogCommand all() throws IOException {
for (Ref ref : getRepository().getRefDatabase().getAllRefs()) {
for (Ref ref : getRepository().getRefDatabase().getRefs()) {
if(!ref.isPeeled())
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 {
Collection<Ref> refs = refdb.getAllRefs();
Collection<Ref> refs = refdb.getRefs();
List<Ref> addl = refdb.getAdditionalRefs();
if (!addl.isEmpty()) {
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 {
RefDatabase refdb = repo.getRefDatabase();
Collection<Ref> refs = refdb.getAllRefs();
Collection<Ref> refs = refdb.getRefs();
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.getAllRefs()) {
for (Ref r : refDb.getRefs()) {
Storage storage = r.getStorage();
if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED)
ret.numberOfLooseRefs++;

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

@ -336,6 +336,29 @@ public abstract class RefDatabase {
return null;
}
/**
* Returns all refs.
* <p>
* This includes {@code HEAD}, branches under {@code ref/heads/}, tags
* under {@code refs/tags/}, etc. It does not include pseudo-refs like
* {@code FETCH_HEAD}; for those, see {@link #getAdditionalRefs}.
* <p>
* Symbolic references to a non-existent ref (for example,
* {@code HEAD} pointing to a branch yet to be born) are not included.
* <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> getRefs() throws IOException {
return getRefsByPrefix(ALL);
}
/**
* Get a section of the reference namespace.
*
@ -357,7 +380,7 @@ public abstract class RefDatabase {
/**
* Returns refs whose names start with a given prefix.
* <p>
* The default implementation uses {@link #getRefs}. Implementors of
* The default implementation uses {@link #getRefs(String)}. Implementors of
* {@link RefDatabase} should override this method directly if a better
* implementation is possible.
*
@ -391,24 +414,14 @@ 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);
}
/**
* Check if any refs exist in the ref database.
* <p>
* This uses the same definition of refs as {@link #getRefs()}. In
* particular, returns {@code false} in a new repository with no refs
* under {@code refs/} and {@code HEAD} pointing to a branch yet to be
* born, and returns {@code true} in a repository with no refs under
* {@code refs/} and a detached {@code HEAD} pointing to history.
*
* @return true if the database has refs.
* @throws java.io.IOException
@ -416,7 +429,7 @@ public abstract class RefDatabase {
* @since 5.0
*/
public boolean hasRefs() throws IOException {
return !getAllRefs().isEmpty();
return !getRefs().isEmpty();
}
/**
@ -424,7 +437,7 @@ public abstract class RefDatabase {
* <p>
* The result list includes non-ref items such as MERGE_HEAD and
* FETCH_RESULT cast to be refs. The names of these refs are not returned by
* <code>getRefs(ALL)</code> but are accepted by {@link #getRef(String)}
* <code>getRefs()</code> but are accepted by {@link #getRef(String)}
* and {@link #exactRef(String)}.
*
* @return a list of additional refs

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

@ -437,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().getAllRefs()) {
for (Ref r : local.getRefDatabase().getRefs()) {
ObjectId id = r.getPeeledObjectId();
if (id == null)
id = r.getObjectId();

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

@ -254,7 +254,7 @@ class BundleFetchConnection extends BaseFetchConnection {
List<Ref> localRefs;
try {
localRefs = transport.local.getRefDatabase().getAllRefs();
localRefs = transport.local.getRefDatabase().getRefs();
} catch (IOException e) {
throw new TransportException(transport.uri, e.getMessage(), e);
}

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

@ -688,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().getAllRefs();
final List<Ref> localRefs = db.getRefDatabase().getRefs();
final Collection<RefSpec> procRefs = new LinkedHashSet<>();
for (final RefSpec spec : specs) {

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

@ -1581,8 +1581,7 @@ public class UploadPack {
new ReachableCommitTipRequestValidator().checkWants(up, wants);
else if (!wants.isEmpty()) {
Set<ObjectId> refIds =
refIdSet(up.getRepository().getRefDatabase()
.getAllRefs());
refIdSet(up.getRepository().getRefDatabase().getRefs());
for (ObjectId obj : wants) {
if (!refIds.contains(obj))
throw new WantNotValidException(obj);
@ -1602,7 +1601,7 @@ public class UploadPack {
public void checkWants(UploadPack up, List<ObjectId> wants)
throws PackProtocolException, IOException {
checkNotAdvertisedWants(up, wants,
refIdSet(up.getRepository().getRefDatabase().getAllRefs()));
refIdSet(up.getRepository().getRefDatabase().getRefs()));
}
}

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

@ -689,7 +689,7 @@ class WalkFetchConnection extends BaseFetchConnection {
private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException {
List<Ref> refs;
try {
refs = local.getRefDatabase().getAllRefs();
refs = local.getRefDatabase().getRefs();
} catch (IOException e) {
throw new TransportException(e.getMessage(), e);
}

Loading…
Cancel
Save