Browse Source

Move additional have enumeration to Repository

This permits the repository implementation to know what its
alternates concept means, and avoids needing to expose finer details
about the ObjectDatabase to network code like the RefAdvertiser.

Change-Id: Ic6d173f300cb72de34519c7607cf7b0ff3ea6882
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
5309244713
  1. 25
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  2. 19
      org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java

25
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -1021,6 +1021,31 @@ public class Repository {
return name;
}
/**
* Objects known to exist but not expressed by {@link #getAllRefs()}.
* <p>
* When a repository borrows objects from another repository, it can
* advertise that it safely has that other repository's references, without
* exposing any other details about the other repository. This may help
* a client trying to push changes avoid pushing more than it needs to.
*
* @return unmodifiable collection of other known objects.
*/
public Set<ObjectId> getAdditionalHaves() {
HashSet<ObjectId> r = new HashSet<ObjectId>();
for (ObjectDatabase d : objectDatabase.getAlternates()) {
if (d instanceof AlternateRepositoryDatabase) {
Repository repo;
repo = ((AlternateRepositoryDatabase) d).getRepository();
for (Ref ref : repo.getAllRefs().values())
r.add(ref.getObjectId());
r.addAll(repo.getAdditionalHaves());
}
}
return r;
}
/**
* Get a ref by name.
*

19
org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java

@ -49,13 +49,11 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import org.eclipse.jgit.lib.AlternateRepositoryDatabase;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefComparator;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevFlag;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevTag;
@ -217,19 +215,8 @@ public abstract class RefAdvertiser {
* advertisement record.
*/
public void includeAdditionalHaves() throws IOException {
additionalHaves(walk.getRepository().getObjectDatabase());
}
private void additionalHaves(final ObjectDatabase db) throws IOException {
if (db instanceof AlternateRepositoryDatabase)
additionalHaves(((AlternateRepositoryDatabase) db).getRepository());
for (ObjectDatabase alt : db.getAlternates())
additionalHaves(alt);
}
private void additionalHaves(final Repository alt) throws IOException {
for (final Ref r : alt.getAllRefs().values())
advertiseHave(r.getObjectId());
for (ObjectId id : walk.getRepository().getAdditionalHaves())
advertiseHave(id);
}
/** @return true if no advertisements have been sent yet. */

Loading…
Cancel
Save