aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhen Chen <czhen@google.com>2017-01-13 22:02:37 -0800
committerZhen Chen <czhen@google.com>2017-01-13 22:10:42 -0800
commitd6b354f60f1a5fd4719908e2ae820c16022e99ce (patch)
treea17c2aa052130456fccfc831bfd9ed1bb14faa3c
parent55c629a9f39e3560ecb3682b95a5049a3bc2ea89 (diff)
downloadjgit-d6b354f60f1a5fd4719908e2ae820c16022e99ce.tar.gz
jgit-d6b354f60f1a5fd4719908e2ae820c16022e99ce.zip
Skip pack header bytes in DfsPackFile
The 12 bytes `PACK...` header is written in PackWriter before reading CachedPack files. In DfsPackFile#copyPackBypassCache, the header was not skipped when the first block is not in cache. Change-Id: Ibbe2e564d36b79922a936657f286addb1044d237 Signed-off-by: Zhen Chen <czhen@google.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
index 4eabb03163..a3d79ecb63 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java
@@ -499,6 +499,7 @@ public final class DfsPackFile {
rc.setReadAheadBytes(ctx.getOptions().getStreamPackBufferSize());
long position = 12;
long remaining = length - (12 + 20);
+ boolean packHeadSkipped = false;
while (0 < remaining) {
DfsBlock b = cache.get(key, alignToBlock(position));
if (b != null) {
@@ -508,6 +509,7 @@ public final class DfsPackFile {
position += n;
remaining -= n;
rc.position(position);
+ packHeadSkipped = true;
continue;
}
@@ -517,7 +519,14 @@ public final class DfsPackFile {
throw packfileIsTruncated();
else if (n > remaining)
n = (int) remaining;
- out.write(buf.array(), 0, n);
+
+ if (!packHeadSkipped) {
+ // Need skip the 'PACK' header for the first read
+ out.write(buf.array(), 12, n - 12);
+ packHeadSkipped = true;
+ } else {
+ out.write(buf.array(), 0, n);
+ }
position += n;
remaining -= n;
}