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:
parent
479fcf9e32
commit
5309244713
|
@ -1021,6 +1021,31 @@ public String getBranch() throws IOException {
|
||||||
return name;
|
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.
|
* Get a ref by name.
|
||||||
*
|
*
|
||||||
|
|
|
@ -49,13 +49,11 @@
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.AlternateRepositoryDatabase;
|
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
import org.eclipse.jgit.lib.AnyObjectId;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
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.Ref;
|
||||||
import org.eclipse.jgit.lib.RefComparator;
|
import org.eclipse.jgit.lib.RefComparator;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
|
||||||
import org.eclipse.jgit.revwalk.RevFlag;
|
import org.eclipse.jgit.revwalk.RevFlag;
|
||||||
import org.eclipse.jgit.revwalk.RevObject;
|
import org.eclipse.jgit.revwalk.RevObject;
|
||||||
import org.eclipse.jgit.revwalk.RevTag;
|
import org.eclipse.jgit.revwalk.RevTag;
|
||||||
|
@ -217,19 +215,8 @@ public void advertiseHave(AnyObjectId id) throws IOException {
|
||||||
* advertisement record.
|
* advertisement record.
|
||||||
*/
|
*/
|
||||||
public void includeAdditionalHaves() throws IOException {
|
public void includeAdditionalHaves() throws IOException {
|
||||||
additionalHaves(walk.getRepository().getObjectDatabase());
|
for (ObjectId id : walk.getRepository().getAdditionalHaves())
|
||||||
}
|
advertiseHave(id);
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true if no advertisements have been sent yet. */
|
/** @return true if no advertisements have been sent yet. */
|
||||||
|
|
Loading…
Reference in New Issue