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>
This commit is contained in:
parent
cfa0b2fb3c
commit
3096a13340
|
@ -48,6 +48,7 @@
|
|||
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.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;
|
||||
|
@ -437,6 +439,38 @@ public void testWritePack4SizeThinVsNoThin() throws Exception {
|
|||
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
|
||||
public void testWriteIndex() throws Exception {
|
||||
config.setIndexVersion(2);
|
||||
|
|
|
@ -1551,6 +1551,8 @@ private void writeDeltaObjectDeflate(PackOutputStream out,
|
|||
if (zbuf != null) {
|
||||
out.writeHeader(otp, otp.getCachedSize());
|
||||
out.write(zbuf);
|
||||
typeStats.cntDeltas++;
|
||||
typeStats.deltaBytes += out.length() - otp.getOffset();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue