Merge "Fix ReceivePack connectivity validation with alternates"
This commit is contained in:
commit
2b42869912
|
@ -166,6 +166,9 @@ public class ReceivePack {
|
||||||
/** The refs we advertised as existing at the start of the connection. */
|
/** The refs we advertised as existing at the start of the connection. */
|
||||||
private Map<String, Ref> refs;
|
private Map<String, Ref> refs;
|
||||||
|
|
||||||
|
/** All SHA-1s shown to the client, which can be possible edges. */
|
||||||
|
private Set<ObjectId> advertisedHaves;
|
||||||
|
|
||||||
/** Capabilities requested by the client. */
|
/** Capabilities requested by the client. */
|
||||||
private Set<String> enabledCapablities;
|
private Set<String> enabledCapablities;
|
||||||
|
|
||||||
|
@ -208,6 +211,7 @@ public ReceivePack(final Repository into) {
|
||||||
refFilter = RefFilter.DEFAULT;
|
refFilter = RefFilter.DEFAULT;
|
||||||
preReceive = PreReceiveHook.NULL;
|
preReceive = PreReceiveHook.NULL;
|
||||||
postReceive = PostReceiveHook.NULL;
|
postReceive = PostReceiveHook.NULL;
|
||||||
|
advertisedHaves = new HashSet<ObjectId>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ReceiveConfig {
|
private static class ReceiveConfig {
|
||||||
|
@ -251,9 +255,28 @@ public final RevWalk getRevWalk() {
|
||||||
|
|
||||||
/** @return all refs which were advertised to the client. */
|
/** @return all refs which were advertised to the client. */
|
||||||
public final Map<String, Ref> getAdvertisedRefs() {
|
public final Map<String, Ref> getAdvertisedRefs() {
|
||||||
|
if (refs == null) {
|
||||||
|
refs = refFilter.filter(db.getAllRefs());
|
||||||
|
|
||||||
|
Ref head = refs.get(Constants.HEAD);
|
||||||
|
if (head != null && head.isSymbolic())
|
||||||
|
refs.remove(Constants.HEAD);
|
||||||
|
|
||||||
|
for (Ref ref : refs.values()) {
|
||||||
|
if (ref.getObjectId() != null)
|
||||||
|
advertisedHaves.add(ref.getObjectId());
|
||||||
|
}
|
||||||
|
advertisedHaves.addAll(db.getAdditionalHaves());
|
||||||
|
}
|
||||||
return refs;
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return the set of objects advertised as present in this repository. */
|
||||||
|
public final Set<ObjectId> getAdvertisedObjects() {
|
||||||
|
getAdvertisedRefs();
|
||||||
|
return advertisedHaves;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if this instance will validate all referenced, but not
|
* @return true if this instance will validate all referenced, but not
|
||||||
* supplied by the client, objects are reachable from another
|
* supplied by the client, objects are reachable from another
|
||||||
|
@ -629,7 +652,7 @@ private void service() throws IOException {
|
||||||
sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
|
sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
|
||||||
pckOut.flush();
|
pckOut.flush();
|
||||||
} else
|
} else
|
||||||
refs = refFilter.filter(db.getAllRefs());
|
getAdvertisedRefs();
|
||||||
if (advertiseError != null)
|
if (advertiseError != null)
|
||||||
return;
|
return;
|
||||||
recvCommands();
|
recvCommands();
|
||||||
|
@ -707,12 +730,9 @@ public void sendAdvertisedRefs(final RefAdvertiser adv) throws IOException {
|
||||||
adv.advertiseCapability(CAPABILITY_REPORT_STATUS);
|
adv.advertiseCapability(CAPABILITY_REPORT_STATUS);
|
||||||
if (allowOfsDelta)
|
if (allowOfsDelta)
|
||||||
adv.advertiseCapability(CAPABILITY_OFS_DELTA);
|
adv.advertiseCapability(CAPABILITY_OFS_DELTA);
|
||||||
refs = refFilter.filter(db.getAllRefs());
|
adv.send(getAdvertisedRefs());
|
||||||
final Ref head = refs.remove(Constants.HEAD);
|
for (ObjectId obj : advertisedHaves)
|
||||||
adv.send(refs);
|
adv.advertiseHave(obj);
|
||||||
if (head != null && !head.isSymbolic())
|
|
||||||
adv.advertiseHave(head.getObjectId());
|
|
||||||
adv.includeAdditionalHaves(db);
|
|
||||||
if (adv.isEmpty())
|
if (adv.isEmpty())
|
||||||
adv.advertiseId(ObjectId.zeroId(), "capabilities^{}");
|
adv.advertiseId(ObjectId.zeroId(), "capabilities^{}");
|
||||||
adv.end();
|
adv.end();
|
||||||
|
@ -847,8 +867,8 @@ private void checkConnectivity() throws IOException {
|
||||||
continue;
|
continue;
|
||||||
ow.markStart(ow.parseAny(cmd.getNewId()));
|
ow.markStart(ow.parseAny(cmd.getNewId()));
|
||||||
}
|
}
|
||||||
for (final Ref ref : refs.values()) {
|
for (final ObjectId have : advertisedHaves) {
|
||||||
RevObject o = ow.parseAny(ref.getObjectId());
|
RevObject o = ow.parseAny(have);
|
||||||
ow.markUninteresting(o);
|
ow.markUninteresting(o);
|
||||||
|
|
||||||
if (checkReferencedIsReachable && !baseObjects.isEmpty()) {
|
if (checkReferencedIsReachable && !baseObjects.isEmpty()) {
|
||||||
|
|
|
@ -133,7 +133,6 @@ public void setDerefTags(final boolean deref) {
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link #send(Map)}
|
* <li>{@link #send(Map)}
|
||||||
* <li>{@link #advertiseHave(AnyObjectId)}
|
* <li>{@link #advertiseHave(AnyObjectId)}
|
||||||
* <li>{@link #includeAdditionalHaves(Repository)}
|
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -205,20 +204,6 @@ public void advertiseHave(AnyObjectId id) throws IOException {
|
||||||
advertiseAnyOnce(id, ".have");
|
advertiseAnyOnce(id, ".have");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Include references of alternate repositories as {@code .have} lines.
|
|
||||||
*
|
|
||||||
* @param src
|
|
||||||
* repository to get the additional reachable objects from.
|
|
||||||
* @throws IOException
|
|
||||||
* the underlying output stream failed to write out an
|
|
||||||
* advertisement record.
|
|
||||||
*/
|
|
||||||
public void includeAdditionalHaves(Repository src) throws IOException {
|
|
||||||
for (ObjectId id : src.getAdditionalHaves())
|
|
||||||
advertiseHave(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return true if no advertisements have been sent yet. */
|
/** @return true if no advertisements have been sent yet. */
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return first;
|
return first;
|
||||||
|
|
Loading…
Reference in New Issue