package org.eclipse.jgit.internal.storage.dfs;
import java.io.IOException;
-import java.security.MessageDigest;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
out.update(block, ptr, cnt);
}
- void write(PackOutputStream out, long pos, int cnt, MessageDigest digest)
+ void write(PackOutputStream out, long pos, int cnt)
throws IOException {
- int ptr = (int) (pos - start);
- out.write(block, ptr, cnt);
- if (digest != null)
- digest.update(block, ptr, cnt);
+ out.write(block, (int) (pos - start), cnt);
}
void check(Inflater inf, byte[] tmp, long pos, int cnt)
return ((DfsObjectRepresentation) rep).pack == pack;
}
- void copyAsIs(PackOutputStream out, boolean validate, DfsReader ctx)
- throws IOException {
- pack.copyPackAsIs(out, validate, ctx);
+ void copyAsIs(PackOutputStream out, DfsReader ctx) throws IOException {
+ pack.copyPackAsIs(out, ctx);
}
}
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
-import java.security.MessageDigest;
import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.Set;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
return dstbuf;
}
- void copyPackAsIs(PackOutputStream out, boolean validate, DfsReader ctx)
+ void copyPackAsIs(PackOutputStream out, DfsReader ctx)
throws IOException {
- MessageDigest md = initCopyPack(out, validate, ctx);
- long p;
- if (cache.shouldCopyThroughCache(length))
- p = copyPackThroughCache(out, ctx, md);
- else
- p = copyPackBypassCache(out, ctx, md);
- verifyPackChecksum(p, md, ctx);
- }
-
- private MessageDigest initCopyPack(PackOutputStream out, boolean validate,
- DfsReader ctx) throws IOException {
// If the length hasn't been determined yet, pin to set it.
- if (length == -1)
+ if (length == -1) {
ctx.pin(this, 0);
- if (!validate) {
ctx.unpin();
- return null;
}
-
- int hdrlen = 12;
- byte[] buf = out.getCopyBuffer();
- int n = ctx.copy(this, 0, buf, 0, hdrlen);
- ctx.unpin();
- if (n != hdrlen)
- throw packfileIsTruncated();
- MessageDigest md = Constants.newMessageDigest();
- md.update(buf, 0, hdrlen);
- return md;
+ if (cache.shouldCopyThroughCache(length))
+ copyPackThroughCache(out, ctx);
+ else
+ copyPackBypassCache(out, ctx);
}
- private long copyPackThroughCache(PackOutputStream out, DfsReader ctx,
- MessageDigest md) throws IOException {
+ private void copyPackThroughCache(PackOutputStream out, DfsReader ctx)
+ throws IOException {
long position = 12;
long remaining = length - (12 + 20);
while (0 < remaining) {
DfsBlock b = cache.getOrLoad(this, position, ctx);
int ptr = (int) (position - b.start);
int n = (int) Math.min(b.size() - ptr, remaining);
- b.write(out, position, n, md);
+ b.write(out, position, n);
position += n;
remaining -= n;
}
- return position;
}
- private long copyPackBypassCache(PackOutputStream out, DfsReader ctx,
- MessageDigest md) throws IOException {
+ private long copyPackBypassCache(PackOutputStream out, DfsReader ctx)
+ throws IOException {
try (ReadableChannel rc = ctx.db.openFile(packDesc, PACK)) {
ByteBuffer buf = newCopyBuffer(out, rc);
if (ctx.getOptions().getStreamPackBufferSize() > 0)
if (b != null) {
int ptr = (int) (position - b.start);
int n = (int) Math.min(b.size() - ptr, remaining);
- b.write(out, position, n, md);
+ b.write(out, position, n);
position += n;
remaining -= n;
rc.position(position);
else if (n > remaining)
n = (int) remaining;
out.write(buf.array(), 0, n);
- if (md != null)
- md.update(buf.array(), 0, n);
position += n;
remaining -= n;
}
return ByteBuffer.wrap(copyBuf, 0, bs);
}
- private void verifyPackChecksum(long position, MessageDigest md,
- DfsReader ctx) throws IOException {
- if (md != null) {
- byte[] buf = new byte[20];
- byte[] actHash = md.digest();
- if (ctx.copy(this, position, buf, 0, 20) != 20)
- throw packfileIsTruncated();
- if (!Arrays.equals(actHash, buf)) {
- invalid = true;
- throw new IOException(MessageFormat.format(
- JGitText.get().packfileCorruptionDetected,
- getPackName()));
- }
- }
- }
-
void copyAsIs(PackOutputStream out, DfsObjectToPack src,
boolean validate, DfsReader ctx) throws IOException,
StoredObjectRepresentationNotAvailableException {
// and we have it pinned. Write this out without copying.
//
out.writeHeader(src, inflatedLength);
- quickCopy.write(out, dataOffset, (int) dataLength, null);
+ quickCopy.write(out, dataOffset, (int) dataLength);
} else if (dataLength <= buf.length) {
// Tiny optimization: Lots of objects are very small deltas or
out.writeObject(otp);
}
- public void copyPackAsIs(PackOutputStream out, CachedPack pack,
- boolean validate) throws IOException {
- ((DfsCachedPack) pack).copyAsIs(out, validate, this);
+ public void copyPackAsIs(PackOutputStream out, CachedPack pack)
+ throws IOException {
+ ((DfsCachedPack) pack).copyAsIs(out, this);
}
/**
package org.eclipse.jgit.internal.storage.file;
import java.io.IOException;
-import java.security.MessageDigest;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
}
@Override
- void write(PackOutputStream out, long pos, int cnt, MessageDigest digest)
+ void write(PackOutputStream out, long pos, int cnt)
throws IOException {
int ptr = (int) (pos - start);
out.write(array, ptr, cnt);
- if (digest != null)
- digest.update(array, ptr, cnt);
}
void check(Inflater inf, byte[] tmp, long pos, int cnt)
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.security.MessageDigest;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
}
@Override
- void write(PackOutputStream out, long pos, int cnt, MessageDigest digest)
+ void write(PackOutputStream out, long pos, int cnt)
throws IOException {
final ByteBuffer s = buffer.slice();
s.position((int) (pos - start));
int n = Math.min(cnt, buf.length);
s.get(buf, 0, n);
out.write(buf, 0, n);
- if (digest != null)
- digest.update(buf, 0, n);
cnt -= n;
}
}
package org.eclipse.jgit.internal.storage.file;
import java.io.IOException;
-import java.security.MessageDigest;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
*/
protected abstract int copy(int pos, byte[] dstbuf, int dstoff, int cnt);
- abstract void write(PackOutputStream out, long pos, int cnt,
- MessageDigest md) throws IOException;
+ abstract void write(PackOutputStream out, long pos, int cnt)
+ throws IOException;
final int setInput(long pos, Inflater inf) throws DataFormatException {
return setInput((int) (pos - start), inf);
return cnt;
}
- void copyAsIs(PackOutputStream out, boolean validate, WindowCursor wc)
+ void copyAsIs(PackOutputStream out, WindowCursor wc)
throws IOException {
for (PackFile pack : getPacks())
- pack.copyPackAsIs(out, validate, wc);
+ pack.copyPackAsIs(out, wc);
}
@Override
return dstbuf;
}
- void copyPackAsIs(PackOutputStream out, boolean validate, WindowCursor curs)
+ void copyPackAsIs(PackOutputStream out, WindowCursor curs)
throws IOException {
// Pin the first window, this ensures the length is accurate.
curs.pin(this, 0);
- curs.copyPackAsIs(this, length, validate, out);
+ curs.copyPackAsIs(this, length, out);
}
final void copyAsIs(PackOutputStream out, LocalObjectToPack src,
// and we have it pinned. Write this out without copying.
//
out.writeHeader(src, inflatedLength);
- quickCopy.write(out, dataOffset, (int) dataLength, null);
+ quickCopy.write(out, dataOffset, (int) dataLength);
} else if (dataLength <= buf.length) {
// Tiny optimization: Lots of objects are very small deltas or
package org.eclipse.jgit.internal.storage.file;
import java.io.IOException;
-import java.security.MessageDigest;
-import java.text.MessageFormat;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.StoredObjectRepresentationNotAvailableException;
-import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.internal.storage.pack.CachedPack;
import org.eclipse.jgit.internal.storage.pack.ObjectReuseAsIs;
import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
return cnt - need;
}
- public void copyPackAsIs(PackOutputStream out, CachedPack pack,
- boolean validate) throws IOException {
- ((LocalCachedPack) pack).copyAsIs(out, validate, this);
+ public void copyPackAsIs(PackOutputStream out, CachedPack pack)
+ throws IOException {
+ ((LocalCachedPack) pack).copyAsIs(out, this);
}
- void copyPackAsIs(final PackFile pack, final long length, boolean validate,
+ void copyPackAsIs(final PackFile pack, final long length,
final PackOutputStream out) throws IOException {
- MessageDigest md = null;
- if (validate) {
- md = Constants.newMessageDigest();
- byte[] buf = out.getCopyBuffer();
- pin(pack, 0);
- if (window.copy(0, buf, 0, 12) != 12) {
- pack.setInvalid();
- throw new IOException(MessageFormat.format(
- JGitText.get().packfileIsTruncated, pack.getPackFile()
- .getPath()));
- }
- md.update(buf, 0, 12);
- }
-
long position = 12;
long remaining = length - (12 + 20);
while (0 < remaining) {
int ptr = (int) (position - window.start);
int n = (int) Math.min(window.size() - ptr, remaining);
- window.write(out, position, n, md);
+ window.write(out, position, n);
position += n;
remaining -= n;
}
-
- if (md != null) {
- byte[] buf = new byte[20];
- byte[] actHash = md.digest();
-
- pin(pack, position);
- if (window.copy(position, buf, 0, 20) != 20) {
- pack.setInvalid();
- throw new IOException(MessageFormat.format(
- JGitText.get().packfileIsTruncated, pack.getPackFile()
- .getPath()));
- }
- if (!Arrays.equals(actHash, buf)) {
- pack.setInvalid();
- throw new IOException(MessageFormat.format(
- JGitText.get().packfileCorruptionDetected, pack
- .getPackFile().getPath()));
- }
- }
}
/**
* stream to append the pack onto.
* @param pack
* the cached pack to send.
- * @param validate
- * if true the representation must be validated and not be
- * corrupt before being reused. If false, validation may be
- * skipped as it will be performed elsewhere in the processing
- * pipeline.
* @throws IOException
* the pack cannot be read, or stream did not accept a write.
*/
- public abstract void copyPackAsIs(PackOutputStream out, CachedPack pack,
- boolean validate) throws IOException;
+ public abstract void copyPackAsIs(PackOutputStream out, CachedPack pack)
+ throws IOException;
/**
* Obtain the available cached packs that match the bitmap and update
stats.reusedObjects += pack.getObjectCount();
stats.reusedDeltas += deltaCnt;
stats.totalDeltas += deltaCnt;
- reuseSupport.copyPackAsIs(out, pack, reuseValidate);
+ reuseSupport.copyPackAsIs(out, pack);
}
writeChecksum(out);
out.flush();
false);
BitmapBuilder needBitmap = wantBitmap.andNot(haveBitmap);
- if (useCachedPacks && reuseSupport != null
+ if (useCachedPacks && reuseSupport != null && !reuseValidate
&& (excludeInPacks == null || excludeInPacks.length == 0))
cachedPacks.addAll(
reuseSupport.getCachedPacksAndUpdate(needBitmap));