Browse Source

Improve native Git transport when following repository

If the client is only following the remote repository and has not
created any new non-common commits, the client will wind up sending
a "have %s" line for each tag in the repository.  For some projects
like git.git, this is 339 tags and growing, resulting in more than
16 KiB needing to be POSTed over 12 HTTP requests.

Teach UploadPack (server side) to always execute the okToGiveUp()
logic at least once per negotiation round to determine if the server
can compute a pack right now.  If it can, shove in an "ACK %s ready"
message to tell the client this and try to prevent receiving ancient
tags in future negotiation rounds.

Teach BasePackFetchConnection (client side) to honor a "ACK %s ready"
from the remote and break out of its SEND_HAVE loop once the remote
knows it can create a pack.  This avoids sending the remaining 307
tags of git.git.

These two changes together reduce the number of HTTP RPCs from 13
down to 3 in order to fetch from git.git over smart HTTP.  If either
side is missing the change, the older behavior (and its 13 RPCs)
is used.

Change-Id: I64736318fd0abf9ee5e56bd0b737707adb580b37
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
9b917ac169
  1. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

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

@ -434,12 +434,13 @@ public abstract class BasePackFetchConnection extends BasePackConnection
int havesSinceLastContinue = 0; int havesSinceLastContinue = 0;
boolean receivedContinue = false; boolean receivedContinue = false;
boolean receivedAck = false; boolean receivedAck = false;
boolean negotiate = true;
if (statelessRPC) if (statelessRPC)
state.writeTo(out, null); state.writeTo(out, null);
negotiateBegin(); negotiateBegin();
SEND_HAVES: for (;;) { SEND_HAVES: while (negotiate) {
final RevCommit c = walk.next(); final RevCommit c = walk.next();
if (c == null) if (c == null)
break SEND_HAVES; break SEND_HAVES;
@ -505,6 +506,8 @@ public abstract class BasePackFetchConnection extends BasePackConnection
receivedAck = true; receivedAck = true;
receivedContinue = true; receivedContinue = true;
havesSinceLastContinue = 0; havesSinceLastContinue = 0;
if (anr == AckNackResult.ACK_READY)
negotiate = false;
break; break;
} }

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

@ -591,9 +591,11 @@ public class UploadPack {
// create a pack at this point, let the client know so it stops // create a pack at this point, let the client know so it stops
// telling us about its history. // telling us about its history.
// //
boolean didOkToGiveUp = false;
for (int i = peerHas.size() - 1; i >= 0; i--) { for (int i = peerHas.size() - 1; i >= 0; i--) {
ObjectId id = peerHas.get(i); ObjectId id = peerHas.get(i);
if (walk.lookupOrNull(id) == null) { if (walk.lookupOrNull(id) == null) {
didOkToGiveUp = true;
if (okToGiveUp()) { if (okToGiveUp()) {
switch (multiAck) { switch (multiAck) {
case OFF: case OFF:
@ -610,6 +612,11 @@ public class UploadPack {
} }
} }
if (multiAck == MultiAck.DETAILED && !didOkToGiveUp && okToGiveUp()) {
ObjectId id = peerHas.get(peerHas.size() - 1);
pckOut.writeString("ACK " + id.name() + " ready\n");
}
peerHas.clear(); peerHas.clear();
return last; return last;
} }

Loading…
Cancel
Save