Browse Source

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>
stable-4.3
James Kolb 9 years ago
parent
commit
3096a13340
  1. 34
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
  2. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

34
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.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; 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.RevObject;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.pack.PackConfig; 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.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.transport.PackParser; import org.eclipse.jgit.transport.PackParser;
import org.junit.After; import org.junit.After;
@ -437,6 +439,38 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
assertTrue(sizePack4 > sizePack4Thin); assertTrue(sizePack4 > sizePack4Thin);
} }
@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 @Test
public void testWriteIndex() throws Exception { public void testWriteIndex() throws Exception {
config.setIndexVersion(2); config.setIndexVersion(2);

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java

@ -1551,6 +1551,8 @@ public class PackWriter implements AutoCloseable {
if (zbuf != null) { if (zbuf != null) {
out.writeHeader(otp, otp.getCachedSize()); out.writeHeader(otp, otp.getCachedSize());
out.write(zbuf); out.write(zbuf);
typeStats.cntDeltas++;
typeStats.deltaBytes += out.length() - otp.getOffset();
return; return;
} }
} }

Loading…
Cancel
Save