aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Kolb <jkolb@google.com>2015-12-15 17:14:45 -0500
committerJames Kolb <jkolb@google.com>2015-12-16 14:06:16 -0500
commit3096a133409ebda900415e9988be49c3426cbcdb (patch)
treea34c499e50dd7ec0c29ea77ae32e844bb6ef3b9d
parentcfa0b2fb3c695bf6698148e5d5626acb17106aed (diff)
downloadjgit-3096a133409ebda900415e9988be49c3426cbcdb.tar.gz
jgit-3096a133409ebda900415e9988be49c3426cbcdb.zip
Included cached deltas in delta packStatistics.
Previously, non-reuse deltas were only included in packStatistics if they were not cached by the deltaWindow. Change-Id: I7684d8214875f0a7569b34614f8a3ba341dbde9c Signed-off-by: James Kolb <jkolb@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java34
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java2
2 files changed, 36 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index bc880a13ef..80efe199fb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -48,6 +48,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -79,6 +80,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.PackConfig;
+import org.eclipse.jgit.storage.pack.PackStatistics;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.transport.PackParser;
import org.junit.After;
@@ -438,6 +440,38 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testDeltaStatistics() throws Exception {
+ config.setDeltaCompress(true);
+ FileRepository repo = createBareRepository();
+ TestRepository<FileRepository> testRepo = new TestRepository<FileRepository>(repo);
+ ArrayList<RevObject> blobs = new ArrayList<>();
+ blobs.add(testRepo.blob(genDeltableData(1000)));
+ blobs.add(testRepo.blob(genDeltableData(1005)));
+
+ try (PackWriter pw = new PackWriter(repo)) {
+ NullProgressMonitor m = NullProgressMonitor.INSTANCE;
+ pw.preparePack(blobs.iterator());
+ pw.writePack(m, m, os);
+ PackStatistics stats = pw.getStatistics();
+ assertEquals(1, stats.getTotalDeltas());
+ assertTrue("Delta bytes not set.",
+ stats.byObjectType(OBJ_BLOB).getDeltaBytes() > 0);
+ }
+ }
+
+ // Generate consistent junk data for building files that delta well
+ private String genDeltableData(int length) {
+ assertTrue("Generated data must have a length > 0", length > 0);
+ char[] data = {'a', 'b', 'c', '\n'};
+ StringBuilder builder = new StringBuilder(length);
+ for (int i = 0; i < length; i++) {
+ builder.append(data[i % 4]);
+ }
+ return builder.toString();
+ }
+
+
+ @Test
public void testWriteIndex() throws Exception {
config.setIndexVersion(2);
writeVerifyPack4(false);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index 19b6b080da..f3f77c4498 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
@@ -1551,6 +1551,8 @@ public class PackWriter implements AutoCloseable {
if (zbuf != null) {
out.writeHeader(otp, otp.getCachedSize());
out.write(zbuf);
+ typeStats.cntDeltas++;
+ typeStats.deltaBytes += out.length() - otp.getOffset();
return;
}
}