Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Wetherbee2012-06-07 02:29:34 +0000
committerIan Wetherbee2012-06-15 22:16:36 +0000
commitb1e4d6bca251c1919674a46c982965ee12fdcfaa (patch)
treea8ddb0d869f7dd81587c838f85aaee98e0bd348c /org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
parentfe1f1b8f8aba60fdd1ad6f0f72e9c9180978cc60 (diff)
downloadjgit-b1e4d6bca251c1919674a46c982965ee12fdcfaa.tar.gz
jgit-b1e4d6bca251c1919674a46c982965ee12fdcfaa.tar.xz
jgit-b1e4d6bca251c1919674a46c982965ee12fdcfaa.zip
ReceivePack supports InputStream data after pack
When receiving a pack, data buffered after the pack can restored to the InputStream if the stream supports mark and reset. Change-Id: If04915c32c91be28db8df7e8491ed3e9fe0e1608
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java45
1 files changed, 36 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index 6b4bf2a41e..5a7d74de79 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -141,6 +141,8 @@ public abstract class PackParser {
private boolean checkEofAfterPackFooter;
+ private boolean expectDataAfterPackFooter;
+
private long objectCount;
private PackedObjectInfo[] entries;
@@ -305,6 +307,21 @@ public abstract class PackParser {
checkEofAfterPackFooter = b;
}
+ /** @return true if there is data expected after the pack footer. */
+ public boolean isExpectDataAfterPackFooter() {
+ return expectDataAfterPackFooter;
+ }
+
+ /**
+ * @param e
+ * true if there is additional data in InputStream after pack.
+ * This requires the InputStream to support the mark and reset
+ * functions.
+ */
+ public void setExpectDataAfterPackFooter(boolean e) {
+ expectDataAfterPackFooter = e;
+ }
+
/** @return the new objects that were sent by the user */
public ObjectIdSubclassMap<ObjectId> getNewObjectIds() {
if (newObjectIds != null)
@@ -826,6 +843,13 @@ public abstract class PackParser {
}
private void readPackHeader() throws IOException {
+ if (expectDataAfterPackFooter) {
+ if (!in.markSupported())
+ throw new IOException(
+ JGitText.get().inputStreamMustSupportMark);
+ in.mark(buf.length);
+ }
+
final int hdrln = Constants.PACK_SIGNATURE.length + 4 + 4;
final int p = fill(Source.INPUT, hdrln);
for (int k = 0; k < Constants.PACK_SIGNATURE.length; k++)
@@ -851,23 +875,19 @@ public abstract class PackParser {
System.arraycopy(buf, c, srcHash, 0, 20);
use(20);
- // The input stream should be at EOF at this point. We do not support
- // yielding back any remaining buffered data after the pack footer, so
- // protocols that embed a pack stream are required to either end their
- // stream with the pack, or embed the pack with a framing system like
- // the SideBandInputStream does.
-
- if (bAvail != 0)
+ if (bAvail != 0 && !expectDataAfterPackFooter)
throw new CorruptObjectException(MessageFormat.format(
JGitText.get().expectedEOFReceived,
"\\x" + Integer.toHexString(buf[bOffset] & 0xff)));
-
if (isCheckEofAfterPackFooter()) {
int eof = in.read();
if (0 <= eof)
throw new CorruptObjectException(MessageFormat.format(
JGitText.get().expectedEOFReceived,
"\\x" + Integer.toHexString(eof)));
+ } else if (bAvail > 0 && expectDataAfterPackFooter) {
+ in.reset();
+ IO.skipFully(in, bOffset);
}
if (!Arrays.equals(actHash, srcHash))
@@ -1142,7 +1162,14 @@ public abstract class PackParser {
private void sync() throws IOException {
packDigest.update(buf, 0, bOffset);
onStoreStream(buf, 0, bOffset);
- if (bAvail > 0)
+ if (expectDataAfterPackFooter) {
+ if (bAvail > 0) {
+ in.reset();
+ IO.skipFully(in, bOffset);
+ bAvail = 0;
+ }
+ in.mark(buf.length);
+ } else if (bAvail > 0)
System.arraycopy(buf, bOffset, buf, 0, bAvail);
bBase += bOffset;
bOffset = 0;

Back to the top