Browse Source

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>
stable-4.7
Zhen Chen 8 years ago
parent
commit
d6b354f60f
  1. 9
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java

9
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()); rc.setReadAheadBytes(ctx.getOptions().getStreamPackBufferSize());
long position = 12; long position = 12;
long remaining = length - (12 + 20); long remaining = length - (12 + 20);
boolean packHeadSkipped = false;
while (0 < remaining) { while (0 < remaining) {
DfsBlock b = cache.get(key, alignToBlock(position)); DfsBlock b = cache.get(key, alignToBlock(position));
if (b != null) { if (b != null) {
@ -508,6 +509,7 @@ public final class DfsPackFile {
position += n; position += n;
remaining -= n; remaining -= n;
rc.position(position); rc.position(position);
packHeadSkipped = true;
continue; continue;
} }
@ -517,7 +519,14 @@ public final class DfsPackFile {
throw packfileIsTruncated(); throw packfileIsTruncated();
else if (n > remaining) else if (n > remaining)
n = (int) remaining; n = (int) remaining;
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); out.write(buf.array(), 0, n);
}
position += n; position += n;
remaining -= n; remaining -= n;
} }

Loading…
Cancel
Save