diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-02-09 09:14:00 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-03-12 16:08:13 -0800 |
commit | f2dc9f0bfe0bd521a9a2cf446b5210d8c85b583a (patch) | |
tree | e97618f0a810cfc56e9a9a60df44517e1802a91b /org.eclipse.jgit | |
parent | 0af5944cac5e09ee99f242d029c89f924e4dd294 (diff) | |
download | jgit-f2dc9f0bfe0bd521a9a2cf446b5210d8c85b583a.tar.gz jgit-f2dc9f0bfe0bd521a9a2cf446b5210d8c85b583a.zip |
Refactor SideBandInputStream construction
Typically we refer to the raw InputStream (the stream without the
pkt-line headers on it) as rawIn, and the pkt-line header variant
as pckIn. Refactor our fields to reflect that. To ensure these
are actually the same underlying InputStream, we now create our own
PacketLineIn wrapper around the supplied raw InputStream. Its a
very low-cost object since it has only the 4 byte length buffer.
Instead of hardcoding the header length as 5, use the constant from
SideBandOutputStream. This makes it a bit more clear what we are
consuming, exactly here.
Change-Id: Iebd05538042913536b88c3ddc3adc3a86a841cc5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
3 files changed, 20 insertions, 20 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java index 84e55b61ea..dc9c7948b6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import java.io.InputStream; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -609,7 +610,11 @@ abstract class BasePackFetchConnection extends BasePackConnection implements private void receivePack(final ProgressMonitor monitor) throws IOException { final IndexPack ip; - ip = IndexPack.create(local, sideband ? pckIn.sideband(monitor) : in); + InputStream input = in; + if (sideband) + input = new SideBandInputStream(input, monitor); + + ip = IndexPack.create(local, input); ip.setFixThin(thinPack); ip.setObjectChecking(transport.isCheckFetchedObjects()); ip.index(monitor); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index db6abef1ac..1022eb2ee1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -51,7 +51,6 @@ import java.io.InputStream; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.MutableObjectId; -import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; @@ -80,10 +79,6 @@ class PacketLineIn { lenbuffer = new byte[4]; } - InputStream sideband(final ProgressMonitor pm) { - return new SideBandInputStream(this, in, pm); - } - AckNackResult readACK(final MutableObjectId returnedId) throws IOException { final String line = readString(); if (line.length() == 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java index 40a6808d25..7b5422644a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; + import java.io.IOException; import java.io.InputStream; import java.util.regex.Matcher; @@ -69,7 +71,7 @@ import org.eclipse.jgit.util.RawParseUtils; * Channel 3 results in an exception being thrown, as the remote side has issued * an unrecoverable error. * - * @see PacketLineIn#sideband(ProgressMonitor) + * @see SideBandOutputStream */ class SideBandInputStream extends InputStream { static final int CH_DATA = 1; @@ -84,9 +86,9 @@ class SideBandInputStream extends InputStream { private static Pattern P_BOUNDED = Pattern.compile( "^([\\w ]+):.*\\((\\d+)/(\\d+)\\).*", Pattern.DOTALL); - private final PacketLineIn pckIn; + private final InputStream rawIn; - private final InputStream in; + private final PacketLineIn pckIn; private final ProgressMonitor monitor; @@ -102,11 +104,10 @@ class SideBandInputStream extends InputStream { private int available; - SideBandInputStream(final PacketLineIn aPckIn, final InputStream aIn, - final ProgressMonitor aProgress) { - pckIn = aPckIn; - in = aIn; - monitor = aProgress; + SideBandInputStream(final InputStream in, final ProgressMonitor progress) { + rawIn = in; + pckIn = new PacketLineIn(rawIn); + monitor = progress; currentTask = ""; } @@ -116,7 +117,7 @@ class SideBandInputStream extends InputStream { if (eof) return -1; available--; - return in.read(); + return rawIn.read(); } @Override @@ -126,7 +127,7 @@ class SideBandInputStream extends InputStream { needDataPacket(); if (eof) break; - final int n = in.read(b, off, Math.min(len, available)); + final int n = rawIn.read(b, off, Math.min(len, available)); if (n < 0) break; r += n; @@ -147,8 +148,8 @@ class SideBandInputStream extends InputStream { return; } - channel = in.read(); - available -= 5; // length header plus channel indicator + channel = rawIn.read(); + available -= HDR_SIZE; // length header plus channel indicator if (available == 0) continue; @@ -157,7 +158,6 @@ class SideBandInputStream extends InputStream { return; case CH_PROGRESS: progress(readString(available)); - continue; case CH_ERROR: eof = true; @@ -229,7 +229,7 @@ class SideBandInputStream extends InputStream { private String readString(final int len) throws IOException { final byte[] raw = new byte[len]; - IO.readFully(in, raw, 0, len); + IO.readFully(rawIn, raw, 0, len); return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); } } |