import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
-import java.util.zip.CRC32;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
private final PackWriter packWriter;
- private final CRC32 crc = new CRC32();
-
private final MessageDigest md = Constants.newMessageDigest();
private long count;
public void write(final int b) throws IOException {
count++;
out.write(b);
- crc.update(b);
md.update((byte) b);
}
}
out.write(b, off, n);
- crc.update(b, off, n);
md.update(b, off, n);
off += n;
return count;
}
- /** @return obtain the current CRC32 register. */
- int getCRC32() {
- return (int) crc.getValue();
- }
-
- /** Reinitialize the CRC32 register for a new region. */
- void resetCRC32() {
- crc.reset();
- }
-
/** @return obtain the current SHA-1 digest. */
byte[] getDigest() {
return md.digest();
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedOutputStream;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
private boolean canBuildBitmaps;
+ private boolean indexDisabled;
+
private int depth;
private Collection<? extends ObjectId> unshallowObjects;
private PackBitmapIndexBuilder writeBitmaps;
+ private CRC32 crc32;
+
/**
* Create writer for specified repository.
* <p>
this.useBitmaps = useBitmaps;
}
+ /** @return true if the index file cannot be created by this PackWriter. */
+ public boolean isIndexDisabled() {
+ return indexDisabled || !cachedPacks.isEmpty();
+ }
+
+ /**
+ * @param noIndex
+ * true to disable creation of the index file.
+ */
+ public void setIndexDisabled(boolean noIndex) {
+ this.indexDisabled = noIndex;
+ }
+
/**
* @return true to ignore objects that are uninteresting and also not found
* on local disk; false to throw a {@link MissingObjectException}
* the index data could not be written to the supplied stream.
*/
public void writeIndex(final OutputStream indexStream) throws IOException {
- if (!cachedPacks.isEmpty())
+ if (isIndexDisabled())
throw new IOException(JGitText.get().cachedPacksPreventsIndexCreation);
long writeStart = System.currentTimeMillis();
if (config.isDeltaCompress())
searchForDeltas(compressMonitor);
- final PackOutputStream out = new PackOutputStream(writeMonitor,
- packStream, this);
+ crc32 = new CRC32();
+ final PackOutputStream out = new PackOutputStream(
+ writeMonitor,
+ isIndexDisabled()
+ ? packStream
+ : new CheckedOutputStream(packStream, crc32),
+ this);
long objCnt = getObjectCount();
stats.totalObjects = objCnt;
if (otp.isWritten())
return; // Delta chain cycle caused this to write already.
- out.resetCRC32();
+ crc32.reset();
otp.setOffset(out.length());
try {
reuseSupport.copyObjectAsIs(out, otp, reuseValidate);
out.endObject();
- otp.setCRC(out.getCRC32());
+ otp.setCRC((int) crc32.getValue());
typeStats.reusedObjects++;
if (otp.isDeltaRepresentation()) {
typeStats.reusedDeltas++;
else
writeWholeObjectDeflate(out, otp);
out.endObject();
- otp.setCRC(out.getCRC32());
+ otp.setCRC((int) crc32.getValue());
}
private void writeBase(PackOutputStream out, ObjectToPack base)
final Deflater deflater = deflater();
final ObjectLoader ldr = reader.open(otp, otp.getType());
- out.resetCRC32();
+ crc32.reset();
otp.setOffset(out.length());
out.writeHeader(otp, ldr.getSize());
final ObjectToPack otp) throws IOException {
writeBase(out, otp.getDeltaBase());
- out.resetCRC32();
+ crc32.reset();
otp.setOffset(out.length());
DeltaCache.Ref ref = otp.popCachedDelta();