Browse Source

UploadPack: remove pckOut instance field

It is difficult to track what's happening with the pckOut instance
field, so replace it with a local variable in #upload instead.

Change-Id: Ibd9225b28334b7133eccdc6d82b26fc96cbde299
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
stable-5.5
Jonathan Tan 6 years ago
parent
commit
c1ed69de4a
  1. 49
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

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

@ -278,8 +278,6 @@ public class UploadPack {
private PacketLineIn pckIn; private PacketLineIn pckIn;
private PacketLineOut pckOut;
private OutputStream msgOut = NullOutputStream.INSTANCE; private OutputStream msgOut = NullOutputStream.INSTANCE;
/** /**
@ -753,6 +751,7 @@ public class UploadPack {
*/ */
public void upload(InputStream input, OutputStream output, public void upload(InputStream input, OutputStream output,
@Nullable OutputStream messages) throws IOException { @Nullable OutputStream messages) throws IOException {
PacketLineOut pckOut = null;
try { try {
rawIn = input; rawIn = input;
if (messages != null) if (messages != null)
@ -778,9 +777,9 @@ public class UploadPack {
pckIn = new PacketLineIn(rawIn); pckIn = new PacketLineIn(rawIn);
pckOut = new PacketLineOut(rawOut); pckOut = new PacketLineOut(rawOut);
if (useProtocolV2()) { if (useProtocolV2()) {
serviceV2(); serviceV2(pckOut);
} else { } else {
service(); service(pckOut);
} }
} catch (UploadPackInternalServerErrorException err) { } catch (UploadPackInternalServerErrorException err) {
// UploadPackInternalServerErrorException is a special exception // UploadPackInternalServerErrorException is a special exception
@ -972,7 +971,7 @@ public class UploadPack {
return RefDatabase.findRef(getAdvertisedOrDefaultRefs(), name); return RefDatabase.findRef(getAdvertisedOrDefaultRefs(), name);
} }
private void service() throws IOException { private void service(PacketLineOut pckOut) throws IOException {
boolean sendPack = false; boolean sendPack = false;
// If it's a non-bidi request, we need to read the entire request before // If it's a non-bidi request, we need to read the entire request before
// writing a response. Buffer the response until then. // writing a response. Buffer the response until then.
@ -1028,7 +1027,7 @@ public class UploadPack {
if (!req.getClientShallowCommits().isEmpty()) if (!req.getClientShallowCommits().isEmpty())
walk.assumeShallow(req.getClientShallowCommits()); walk.assumeShallow(req.getClientShallowCommits());
sendPack = negotiate(req, accumulator); sendPack = negotiate(req, accumulator, pckOut);
accumulator.timeNegotiating += System.currentTimeMillis() accumulator.timeNegotiating += System.currentTimeMillis()
- negotiateStart; - negotiateStart;
@ -1054,11 +1053,11 @@ public class UploadPack {
if (sendPack) { if (sendPack) {
sendPack(accumulator, req, refs == null ? null : refs.values(), sendPack(accumulator, req, refs == null ? null : refs.values(),
unshallowCommits, Collections.emptyList()); unshallowCommits, Collections.emptyList(), pckOut);
} }
} }
private void lsRefsV2() throws IOException { private void lsRefsV2(PacketLineOut pckOut) throws IOException {
ProtocolV2Parser parser = new ProtocolV2Parser(transferConfig); ProtocolV2Parser parser = new ProtocolV2Parser(transferConfig);
LsRefsV2Request req = parser.parseLsRefsRequest(pckIn); LsRefsV2Request req = parser.parseLsRefsRequest(pckIn);
protocolV2Hook.onLsRefs(req); protocolV2Hook.onLsRefs(req);
@ -1103,7 +1102,7 @@ public class UploadPack {
return result; return result;
} }
private void fetchV2() throws IOException { private void fetchV2(PacketLineOut pckOut) throws IOException {
// Depending on the requestValidator, #processHaveLines may // Depending on the requestValidator, #processHaveLines may
// require that advertised be set. Set it only in the required // require that advertised be set. Set it only in the required
// circumstances (to avoid a full ref lookup in the case that // circumstances (to avoid a full ref lookup in the case that
@ -1214,7 +1213,7 @@ public class UploadPack {
req.getClientCapabilities().contains(OPTION_INCLUDE_TAG) req.getClientCapabilities().contains(OPTION_INCLUDE_TAG)
? db.getRefDatabase().getRefsByPrefix(R_TAGS) ? db.getRefDatabase().getRefsByPrefix(R_TAGS)
: null, : null,
unshallowCommits, deepenNots); unshallowCommits, deepenNots, pckOut);
// sendPack invokes pckOut.end() for us, so we do not // sendPack invokes pckOut.end() for us, so we do not
// need to invoke it here. // need to invoke it here.
} else { } else {
@ -1227,7 +1226,7 @@ public class UploadPack {
* Returns true if this is the last command and we should tear down the * Returns true if this is the last command and we should tear down the
* connection. * connection.
*/ */
private boolean serveOneCommandV2() throws IOException { private boolean serveOneCommandV2(PacketLineOut pckOut) throws IOException {
String command; String command;
try { try {
command = pckIn.readString(); command = pckIn.readString();
@ -1242,11 +1241,11 @@ public class UploadPack {
return true; return true;
} }
if (command.equals("command=" + COMMAND_LS_REFS)) { //$NON-NLS-1$ if (command.equals("command=" + COMMAND_LS_REFS)) { //$NON-NLS-1$
lsRefsV2(); lsRefsV2(pckOut);
return false; return false;
} }
if (command.equals("command=" + COMMAND_FETCH)) { //$NON-NLS-1$ if (command.equals("command=" + COMMAND_FETCH)) { //$NON-NLS-1$
fetchV2(); fetchV2(pckOut);
return false; return false;
} }
throw new PackProtocolException(MessageFormat throw new PackProtocolException(MessageFormat
@ -1269,7 +1268,7 @@ public class UploadPack {
return caps; return caps;
} }
private void serviceV2() throws IOException { private void serviceV2(PacketLineOut pckOut) throws IOException {
if (biDirectionalPipe) { if (biDirectionalPipe) {
// Just like in service(), the capability advertisement // Just like in service(), the capability advertisement
// is sent only if this is a bidirectional pipe. (If // is sent only if this is a bidirectional pipe. (If
@ -1282,14 +1281,14 @@ public class UploadPack {
} }
pckOut.end(); pckOut.end();
while (!serveOneCommandV2()) { while (!serveOneCommandV2(pckOut)) {
// Repeat until an empty command or EOF. // Repeat until an empty command or EOF.
} }
return; return;
} }
try { try {
serveOneCommandV2(); serveOneCommandV2(pckOut);
} finally { } finally {
while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) { while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) {
// Discard until EOF. // Discard until EOF.
@ -1585,7 +1584,8 @@ public class UploadPack {
} }
private boolean negotiate(FetchRequest req, private boolean negotiate(FetchRequest req,
PackStatistics.Accumulator accumulator) PackStatistics.Accumulator accumulator,
PacketLineOut pckOut)
throws IOException { throws IOException {
okToGiveUp = Boolean.FALSE; okToGiveUp = Boolean.FALSE;
@ -2063,6 +2063,8 @@ public class UploadPack {
* shallow commits on the client that are now becoming unshallow * shallow commits on the client that are now becoming unshallow
* @param deepenNots * @param deepenNots
* objects that the client specified using --shallow-exclude * objects that the client specified using --shallow-exclude
* @param pckOut
* output writer
* @throws IOException * @throws IOException
* if an error occurred while generating or writing the pack. * if an error occurred while generating or writing the pack.
*/ */
@ -2070,14 +2072,15 @@ public class UploadPack {
FetchRequest req, FetchRequest req,
@Nullable Collection<Ref> allTags, @Nullable Collection<Ref> allTags,
List<ObjectId> unshallowCommits, List<ObjectId> unshallowCommits,
List<ObjectId> deepenNots) throws IOException { List<ObjectId> deepenNots,
PacketLineOut pckOut) throws IOException {
Set<String> caps = req.getClientCapabilities(); Set<String> caps = req.getClientCapabilities();
boolean sideband = caps.contains(OPTION_SIDE_BAND) boolean sideband = caps.contains(OPTION_SIDE_BAND)
|| caps.contains(OPTION_SIDE_BAND_64K); || caps.contains(OPTION_SIDE_BAND_64K);
if (sideband) { if (sideband) {
try { try {
sendPack(true, req, accumulator, allTags, unshallowCommits, sendPack(true, req, accumulator, allTags, unshallowCommits,
deepenNots); deepenNots, pckOut);
} catch (ServiceMayNotContinueException err) { } catch (ServiceMayNotContinueException err) {
String message = err.getMessage(); String message = err.getMessage();
if (message == null) { if (message == null) {
@ -2101,7 +2104,8 @@ public class UploadPack {
throw new UploadPackInternalServerErrorException(err); throw new UploadPackInternalServerErrorException(err);
} }
} else { } else {
sendPack(false, req, accumulator, allTags, unshallowCommits, deepenNots); sendPack(false, req, accumulator, allTags, unshallowCommits, deepenNots,
pckOut);
} }
} }
@ -2132,6 +2136,8 @@ public class UploadPack {
* shallow commits on the client that are now becoming unshallow * shallow commits on the client that are now becoming unshallow
* @param deepenNots * @param deepenNots
* objects that the client specified using --shallow-exclude * objects that the client specified using --shallow-exclude
* @param pckOut
* output writer
* @throws IOException * @throws IOException
* if an error occurred while generating or writing the pack. * if an error occurred while generating or writing the pack.
*/ */
@ -2140,7 +2146,8 @@ public class UploadPack {
PackStatistics.Accumulator accumulator, PackStatistics.Accumulator accumulator,
@Nullable Collection<Ref> allTags, @Nullable Collection<Ref> allTags,
List<ObjectId> unshallowCommits, List<ObjectId> unshallowCommits,
List<ObjectId> deepenNots) throws IOException { List<ObjectId> deepenNots,
PacketLineOut pckOut) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE; ProgressMonitor pm = NullProgressMonitor.INSTANCE;
OutputStream packOut = rawOut; OutputStream packOut = rawOut;

Loading…
Cancel
Save