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>
This commit is contained in:
Shawn O. Pearce 2010-06-18 20:23:06 -07:00
parent 479fcf9e32
commit 5309244713
2 changed files with 28 additions and 16 deletions

View File

@ -1021,6 +1021,31 @@ public String getBranch() throws IOException {
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.
*

View File

@ -49,13 +49,11 @@
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 void advertiseHave(AnyObjectId id) throws IOException {
* 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. */