aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandInputStreamTest.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java23
4 files changed, 56 insertions, 7 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandInputStreamTest.java
index 497f584b5f..7ac83195fb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandInputStreamTest.java
@@ -79,6 +79,8 @@ public class SideBandInputStreamTest {
init(packet("message"));
assertTrue(sideband.read() < 0);
assertEquals("", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message\n", messages.toString());
}
@Test
@@ -128,6 +130,8 @@ public class SideBandInputStreamTest {
init(packet("message 0%\rmessage 100%"));
assertTrue(sideband.read() < 0);
assertEquals("message 0%\r", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\rmessage 100%\n", messages.toString());
}
@Test
@@ -135,6 +139,8 @@ public class SideBandInputStreamTest {
init(packet("message 0%\nmessage 100%"));
assertTrue(sideband.read() < 0);
assertEquals("message 0%\n", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\nmessage 100%\n", messages.toString());
}
@Test
@@ -142,6 +148,8 @@ public class SideBandInputStreamTest {
init(packet("message 0%\r\nmessage 100%"));
assertTrue(sideband.read() < 0);
assertEquals("message 0%\r\n", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\r\nmessage 100%\n", messages.toString());
}
@Test
@@ -152,6 +160,8 @@ public class SideBandInputStreamTest {
assertEquals("", messages.toString());
assertTrue(sideband.read() < 0);
assertEquals("message 0%\r", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\rmessage 100%\n", messages.toString());
}
@Test
@@ -162,6 +172,8 @@ public class SideBandInputStreamTest {
assertEquals("", messages.toString());
assertTrue(sideband.read() < 0);
assertEquals("message 0%\n", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\nmessage 100%\n", messages.toString());
}
@Test
@@ -172,6 +184,8 @@ public class SideBandInputStreamTest {
assertEquals("", messages.toString());
assertTrue(sideband.read() < 0);
assertEquals("message 0%\r\n", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\r\nmessage 100%\n", messages.toString());
}
@Test
@@ -197,6 +211,9 @@ public class SideBandInputStreamTest {
assertEquals("message 0%\r", messages.toString());
assertTrue(sideband.read() < 0);
assertEquals("message 0%\rmessage 10%\r", messages.toString());
+ sideband.drainMessages();
+ assertEquals("message 0%\rmessage 10%\rmessage 100%\n",
+ messages.toString());
}
private String packet(String data) {
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 f48e1e68cc..3f167ccce2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2008, 2010 Google Inc.
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2008, 2020 Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -1004,9 +1004,12 @@ public abstract class BasePackFetchConnection extends BasePackConnection
OutputStream outputStream) throws IOException {
onReceivePack();
InputStream input = in;
- if (sideband)
- input = new SideBandInputStream(input, monitor, getMessageWriter(),
- outputStream);
+ SideBandInputStream sidebandIn = null;
+ if (sideband) {
+ sidebandIn = new SideBandInputStream(input, monitor,
+ getMessageWriter(), outputStream);
+ input = sidebandIn;
+ }
try (ObjectInserter ins = local.newObjectInserter()) {
PackParser parser = ins.newPackParser(input);
@@ -1015,6 +1018,10 @@ public abstract class BasePackFetchConnection extends BasePackConnection
parser.setLockMessage(lockMessage);
packLock = parser.parse(monitor);
ins.flush();
+ } finally {
+ if (sidebandIn != null) {
+ sidebandIn.drainMessages();
+ }
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java
index b87a85d934..b7be59d6f8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -194,10 +194,11 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen
// the other data channels.
//
int b = in.read();
- if (0 <= b)
+ if (0 <= b) {
throw new TransportException(uri, MessageFormat.format(
JGitText.get().expectedEOFReceived,
Character.valueOf((char) b)));
+ }
}
}
} catch (TransportException e) {
@@ -205,6 +206,9 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen
} catch (Exception e) {
throw new TransportException(uri, e.getMessage(), e);
} finally {
+ if (in instanceof SideBandInputStream) {
+ ((SideBandInputStream) in).drainMessages();
+ }
close();
}
}
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 8a8d977ed3..96c7be5b97 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -28,6 +28,8 @@ import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.RawParseUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Unmultiplexes the data portion of a side-band channel.
@@ -46,6 +48,10 @@ import org.eclipse.jgit.util.RawParseUtils;
* @since 4.11
*/
public class SideBandInputStream extends InputStream {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SideBandInputStream.class);
+
static final int CH_DATA = 1;
static final int CH_PROGRESS = 2;
static final int CH_ERROR = 3;
@@ -210,6 +216,21 @@ public class SideBandInputStream extends InputStream {
monitor.beginTask(remote(currentTask), totalWorkUnits);
}
+ /**
+ * Forces any buffered progress messages to be written.
+ */
+ void drainMessages() {
+ if (!progressBuffer.isEmpty()) {
+ try {
+ progress("\n"); //$NON-NLS-1$
+ } catch (IOException e) {
+ // Just log; otherwise this IOException might hide a real
+ // TransportException
+ LOG.error(e.getMessage(), e);
+ }
+ }
+ }
+
private static String remote(String msg) {
String prefix = JGitText.get().prefixRemote;
StringBuilder r = new StringBuilder(prefix.length() + msg.length() + 1);