packfileCorruptionDetected=Packfile corruption detected: {0}
packfileIsTruncated=Packfile is truncated.
packingCancelledDuringObjectsWriting=Packing cancelled during objects writing
+packWriterStatistics=Total {0,number,#0} (delta {1,number,#0}), reused {2,number,#0} (delta {3,number,#0})
pathIsNotInWorkingDir=Path is not in working dir
peeledLineBeforeRef=Peeled line before ref.
peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
private final PackConfig config;
+ private final Statistics stats;
+
private List<ObjectToPack> sortedByName;
private byte packcsum[];
deltaBaseAsOffset = config.isDeltaBaseAsOffset();
reuseDeltas = config.isReuseDeltas();
+ stats = new Statistics();
}
/**
packStream, this);
int objCnt = getObjectsNumber();
+ stats.totalObjects = objCnt;
writeMonitor.beginTask(JGitText.get().writingObjects, objCnt);
out.writeFileHeader(PACK_VERSION_GENERATED, objCnt);
out.flush();
writeMonitor.endTask();
}
+ /**
+ * @return description of what this PackWriter did in order to create the
+ * final pack stream. The object is only available to callers after
+ * {@link #writePack(ProgressMonitor, ProgressMonitor, OutputStream)}
+ */
+ public Statistics getStatistics() {
+ return stats;
+ }
+
/** Release all resources used by this writer. */
public void release() {
reader.release();
reuseSupport.copyObjectAsIs(out, otp);
out.endObject();
otp.setCRC(out.getCRC32());
+ stats.reusedObjects++;
+ if (otp.isDeltaRepresentation())
+ stats.reusedDeltas++;
return;
} catch (StoredObjectRepresentationNotAvailableException gone) {
if (otp.getOffset() == out.length()) {
DeflaterOutputStream dst = new DeflaterOutputStream(out, deflater);
delta.writeTo(dst, null);
dst.finish();
+ stats.totalDeltas++;
}
private TemporaryBuffer.Heap delta(final ObjectToPack otp)
otp.select(next);
}
+
+ /** Summary of how PackWriter created the pack. */
+ public static class Statistics {
+ long totalObjects;
+
+ long totalDeltas;
+
+ long reusedObjects;
+
+ long reusedDeltas;
+
+ /** @return formatted message string for display to clients. */
+ public String getMessage() {
+ return MessageFormat.format(JGitText.get().packWriterStatistics, //
+ totalObjects, totalDeltas, //
+ reusedObjects, reusedDeltas);
+ }
+ }
}
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.PackProtocolException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
OutputStream packOut = rawOut;
+ SideBandOutputStream msgOut = null;
if (sideband) {
int bufsz = SideBandOutputStream.SMALL_BUF;
packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA,
bufsz, rawOut);
- if (!options.contains(OPTION_NO_PROGRESS))
- pm = new SideBandProgressMonitor(new SideBandOutputStream(
- SideBandOutputStream.CH_PROGRESS, bufsz, rawOut));
+ if (!options.contains(OPTION_NO_PROGRESS)) {
+ msgOut = new SideBandOutputStream(
+ SideBandOutputStream.CH_PROGRESS, bufsz, rawOut);
+ pm = new SideBandProgressMonitor(msgOut);
+ }
}
PackConfig cfg = packConfig;
pw.addObject(t);
}
}
+
pw.writePack(pm, NullProgressMonitor.INSTANCE, packOut);
+ packOut.flush();
+
+ if (msgOut != null) {
+ String msg = pw.getStatistics().getMessage() + '\n';
+ msgOut.write(Constants.encode(msg));
+ msgOut.flush();
+ }
+
} finally {
pw.release();
}
- packOut.flush();
if (sideband)
pckOut.end();