aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java71
1 files changed, 39 insertions, 32 deletions
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..796cb745a1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java
@@ -44,8 +44,11 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE;
+
import java.io.IOException;
import java.io.InputStream;
+import java.io.Writer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -69,27 +72,31 @@ 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 {
+ private static final String PFX_REMOTE = "remote: ";
+
static final int CH_DATA = 1;
static final int CH_PROGRESS = 2;
static final int CH_ERROR = 3;
- private static Pattern P_UNBOUNDED = Pattern.compile(
- "^([\\w ]+): (\\d+)( |, done)?.*", Pattern.DOTALL);
+ private static Pattern P_UNBOUNDED = Pattern
+ .compile("^([\\w ]+): +(\\d+)(?:, done\\.)? *[\r\n]$");
- private static Pattern P_BOUNDED = Pattern.compile(
- "^([\\w ]+):.*\\((\\d+)/(\\d+)\\).*", Pattern.DOTALL);
+ private static Pattern P_BOUNDED = Pattern
+ .compile("^([\\w ]+): +\\d+% +\\( *(\\d+)/ *(\\d+)\\)(?:, done\\.)? *[\r\n]$");
- private final PacketLineIn pckIn;
+ private final InputStream rawIn;
- private final InputStream in;
+ private final PacketLineIn pckIn;
private final ProgressMonitor monitor;
+ private final Writer messages;
+
private String progressBuffer = "";
private String currentTask;
@@ -102,11 +109,12 @@ 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,
+ final Writer messageStream) {
+ rawIn = in;
+ pckIn = new PacketLineIn(rawIn);
+ monitor = progress;
+ messages = messageStream;
currentTask = "";
}
@@ -116,7 +124,7 @@ class SideBandInputStream extends InputStream {
if (eof)
return -1;
available--;
- return in.read();
+ return rawIn.read();
}
@Override
@@ -126,7 +134,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 +155,8 @@ class SideBandInputStream extends InputStream {
return;
}
- channel = in.read();
- available -= 5; // length header plus channel indicator
+ channel = rawIn.read() & 0xff;
+ available -= HDR_SIZE; // length header plus channel indicator
if (available == 0)
continue;
@@ -157,18 +165,17 @@ class SideBandInputStream extends InputStream {
return;
case CH_PROGRESS:
progress(readString(available));
-
continue;
case CH_ERROR:
eof = true;
- throw new TransportException("remote: " + readString(available));
+ throw new TransportException(PFX_REMOTE + readString(available));
default:
throw new PackProtocolException("Invalid channel " + channel);
}
}
}
- private void progress(String pkt) {
+ private void progress(String pkt) throws IOException {
pkt = progressBuffer + pkt;
for (;;) {
final int lf = pkt.indexOf('\n');
@@ -183,16 +190,13 @@ class SideBandInputStream extends InputStream {
else
break;
- final String msg = pkt.substring(0, s);
- if (doProgressLine(msg))
- pkt = pkt.substring(s + 1);
- else
- break;
+ doProgressLine(pkt.substring(0, s + 1));
+ pkt = pkt.substring(s + 1);
}
progressBuffer = pkt;
}
- private boolean doProgressLine(final String msg) {
+ private void doProgressLine(final String msg) throws IOException {
Matcher matcher;
matcher = P_BOUNDED.matcher(msg);
@@ -201,13 +205,12 @@ class SideBandInputStream extends InputStream {
if (!currentTask.equals(taskname)) {
currentTask = taskname;
lastCnt = 0;
- final int tot = Integer.parseInt(matcher.group(3));
- monitor.beginTask(currentTask, tot);
+ beginTask(Integer.parseInt(matcher.group(3)));
}
final int cnt = Integer.parseInt(matcher.group(2));
monitor.update(cnt - lastCnt);
lastCnt = cnt;
- return true;
+ return;
}
matcher = P_UNBOUNDED.matcher(msg);
@@ -216,20 +219,24 @@ class SideBandInputStream extends InputStream {
if (!currentTask.equals(taskname)) {
currentTask = taskname;
lastCnt = 0;
- monitor.beginTask(currentTask, ProgressMonitor.UNKNOWN);
+ beginTask(ProgressMonitor.UNKNOWN);
}
final int cnt = Integer.parseInt(matcher.group(2));
monitor.update(cnt - lastCnt);
lastCnt = cnt;
- return true;
+ return;
}
- return false;
+ messages.write(msg);
+ }
+
+ private void beginTask(final int totalWorkUnits) {
+ monitor.beginTask(PFX_REMOTE + currentTask, totalWorkUnits);
}
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);
}
}