summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2019-01-22 13:17:12 -0800
committerJonathan Tan <jonathantanmy@google.com>2019-07-16 10:05:18 -0700
commitc1ed69de4ae53d04a27c5c10c00371eefc1774fd (patch)
treece77168c41f9b9035eaadf5efcd22e72a7d52419 /org.eclipse.jgit
parente5f7d5a136a9948aa16ca074540efc94dc8b1815 (diff)
downloadjgit-c1ed69de4ae53d04a27c5c10c00371eefc1774fd.tar.gz
jgit-c1ed69de4ae53d04a27c5c10c00371eefc1774fd.zip
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>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java49
1 files changed, 28 insertions, 21 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 37ecead8b9..37ea8698c0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -278,8 +278,6 @@ public class UploadPack {
private PacketLineIn pckIn;
- private PacketLineOut pckOut;
-
private OutputStream msgOut = NullOutputStream.INSTANCE;
/**
@@ -753,6 +751,7 @@ public class UploadPack {
*/
public void upload(InputStream input, OutputStream output,
@Nullable OutputStream messages) throws IOException {
+ PacketLineOut pckOut = null;
try {
rawIn = input;
if (messages != null)
@@ -778,9 +777,9 @@ public class UploadPack {
pckIn = new PacketLineIn(rawIn);
pckOut = new PacketLineOut(rawOut);
if (useProtocolV2()) {
- serviceV2();
+ serviceV2(pckOut);
} else {
- service();
+ service(pckOut);
}
} catch (UploadPackInternalServerErrorException err) {
// UploadPackInternalServerErrorException is a special exception
@@ -972,7 +971,7 @@ public class UploadPack {
return RefDatabase.findRef(getAdvertisedOrDefaultRefs(), name);
}
- private void service() throws IOException {
+ private void service(PacketLineOut pckOut) throws IOException {
boolean sendPack = false;
// If it's a non-bidi request, we need to read the entire request before
// writing a response. Buffer the response until then.
@@ -1028,7 +1027,7 @@ public class UploadPack {
if (!req.getClientShallowCommits().isEmpty())
walk.assumeShallow(req.getClientShallowCommits());
- sendPack = negotiate(req, accumulator);
+ sendPack = negotiate(req, accumulator, pckOut);
accumulator.timeNegotiating += System.currentTimeMillis()
- negotiateStart;
@@ -1054,11 +1053,11 @@ public class UploadPack {
if (sendPack) {
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);
LsRefsV2Request req = parser.parseLsRefsRequest(pckIn);
protocolV2Hook.onLsRefs(req);
@@ -1103,7 +1102,7 @@ public class UploadPack {
return result;
}
- private void fetchV2() throws IOException {
+ private void fetchV2(PacketLineOut pckOut) throws IOException {
// Depending on the requestValidator, #processHaveLines may
// require that advertised be set. Set it only in the required
// circumstances (to avoid a full ref lookup in the case that
@@ -1214,7 +1213,7 @@ public class UploadPack {
req.getClientCapabilities().contains(OPTION_INCLUDE_TAG)
? db.getRefDatabase().getRefsByPrefix(R_TAGS)
: null,
- unshallowCommits, deepenNots);
+ unshallowCommits, deepenNots, pckOut);
// sendPack invokes pckOut.end() for us, so we do not
// need to invoke it here.
} else {
@@ -1227,7 +1226,7 @@ public class UploadPack {
* Returns true if this is the last command and we should tear down the
* connection.
*/
- private boolean serveOneCommandV2() throws IOException {
+ private boolean serveOneCommandV2(PacketLineOut pckOut) throws IOException {
String command;
try {
command = pckIn.readString();
@@ -1242,11 +1241,11 @@ public class UploadPack {
return true;
}
if (command.equals("command=" + COMMAND_LS_REFS)) { //$NON-NLS-1$
- lsRefsV2();
+ lsRefsV2(pckOut);
return false;
}
if (command.equals("command=" + COMMAND_FETCH)) { //$NON-NLS-1$
- fetchV2();
+ fetchV2(pckOut);
return false;
}
throw new PackProtocolException(MessageFormat
@@ -1269,7 +1268,7 @@ public class UploadPack {
return caps;
}
- private void serviceV2() throws IOException {
+ private void serviceV2(PacketLineOut pckOut) throws IOException {
if (biDirectionalPipe) {
// Just like in service(), the capability advertisement
// is sent only if this is a bidirectional pipe. (If
@@ -1282,14 +1281,14 @@ public class UploadPack {
}
pckOut.end();
- while (!serveOneCommandV2()) {
+ while (!serveOneCommandV2(pckOut)) {
// Repeat until an empty command or EOF.
}
return;
}
try {
- serveOneCommandV2();
+ serveOneCommandV2(pckOut);
} finally {
while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) {
// Discard until EOF.
@@ -1585,7 +1584,8 @@ public class UploadPack {
}
private boolean negotiate(FetchRequest req,
- PackStatistics.Accumulator accumulator)
+ PackStatistics.Accumulator accumulator,
+ PacketLineOut pckOut)
throws IOException {
okToGiveUp = Boolean.FALSE;
@@ -2063,6 +2063,8 @@ public class UploadPack {
* shallow commits on the client that are now becoming unshallow
* @param deepenNots
* objects that the client specified using --shallow-exclude
+ * @param pckOut
+ * output writer
* @throws IOException
* if an error occurred while generating or writing the pack.
*/
@@ -2070,14 +2072,15 @@ public class UploadPack {
FetchRequest req,
@Nullable Collection<Ref> allTags,
List<ObjectId> unshallowCommits,
- List<ObjectId> deepenNots) throws IOException {
+ List<ObjectId> deepenNots,
+ PacketLineOut pckOut) throws IOException {
Set<String> caps = req.getClientCapabilities();
boolean sideband = caps.contains(OPTION_SIDE_BAND)
|| caps.contains(OPTION_SIDE_BAND_64K);
if (sideband) {
try {
sendPack(true, req, accumulator, allTags, unshallowCommits,
- deepenNots);
+ deepenNots, pckOut);
} catch (ServiceMayNotContinueException err) {
String message = err.getMessage();
if (message == null) {
@@ -2101,7 +2104,8 @@ public class UploadPack {
throw new UploadPackInternalServerErrorException(err);
}
} 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
* @param deepenNots
* objects that the client specified using --shallow-exclude
+ * @param pckOut
+ * output writer
* @throws IOException
* if an error occurred while generating or writing the pack.
*/
@@ -2140,7 +2146,8 @@ public class UploadPack {
PackStatistics.Accumulator accumulator,
@Nullable Collection<Ref> allTags,
List<ObjectId> unshallowCommits,
- List<ObjectId> deepenNots) throws IOException {
+ List<ObjectId> deepenNots,
+ PacketLineOut pckOut) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
OutputStream packOut = rawOut;