private void run(File indexFile) throws Exception {
final boolean shallDumpDiff = Boolean.TRUE.booleanValue();
final boolean thoroughCheck = Boolean.FALSE.booleanValue();
//
RevlogReader rr = new RevlogReader(indexFile);
rr.init(true);
rr.needData(true);
int startEntryIndex = 76507; // 150--87
rr.startFrom(startEntryIndex);
rr.readNext();
final long s0 = System.currentTimeMillis();
ByteBuffer baseRevision = null;
if (rr.isPatch()) {
byte[] cc = getRevisionTrueContent(indexFile.getParentFile(), rr.entryIndex, rr.linkRevision);
baseRevision = ByteBuffer.wrap(cc);
} else {
baseRevision = ByteBuffer.allocate(rr.getDataLength());
rr.getData(baseRevision);
baseRevision.flip();
}
ByteArrayDataAccess baseRevisionContent = new ByteArrayDataAccess(baseRevision.array(), baseRevision.arrayOffset(), baseRevision.remaining());
//
final long start = System.currentTimeMillis();
int n = 1419;
Patch seqPatch = new Patch(false), normalizedPatch = new Patch(true);
while (rr.hasMore() && n-- > 0) {
rr.readNext();
if (!rr.isPatch()) {
break;
}
if (rr.getDataLength() == 0) {
System.out.printf("Empty content of revision %d\n", rr.entryIndex);
continue;
}
Patch p1 = createPatch(rr);
if (n < 1) {
System.out.println("+" + p1);
System.currentTimeMillis();
}
seqPatch = seqPatch.apply(p1);
normalizedPatch = normalizedPatch.apply(p1);
// if (n <= 1) {
// System.out.println("=" + seqPatch);
// }
// if (n == 0) {
// System.out.println("A" + ppp);
// System.out.println("N" + normalizedPatch);
// normalizedPatch = ppp;
// }
//
if (!thoroughCheck) {
if (baseRevisionContent.length() + seqPatch.patchSizeDelta() != rr.actualLen) {
System.out.printf("Sequential patches:\tPatchRevision #%d (+%d, cset:%d) failed\n", rr.entryIndex, rr.entryIndex - startEntryIndex, rr.linkRevision);
}
if (baseRevisionContent.length() + normalizedPatch.patchSizeDelta() != rr.actualLen) {
System.out.printf("Normalized patches:\tPatchRevision #%d (+%d, cset:%d) failed\n", rr.entryIndex, rr.entryIndex - startEntryIndex, rr.linkRevision);
}
} else {
byte[] origin = getRevisionTrueContent(indexFile.getParentFile(), rr.entryIndex, rr.linkRevision);
try {
byte[] result1 = seqPatch.apply(baseRevisionContent, rr.actualLen);
if (!Arrays.equals(result1, origin)) {
System.out.printf("Sequential patches:\tPatchRevision #%d (+%d, cset:%d) failed\n", rr.entryIndex, rr.entryIndex - startEntryIndex, rr.linkRevision);
}
} catch (ArrayIndexOutOfBoundsException ex) {
System.err.printf("Failure at entry %d (+%d)\n", rr.entryIndex, rr.entryIndex - startEntryIndex);
ex.printStackTrace();
}
// try {
// byte[] result2 = normalizedPatch.apply(baseRevisionContent, rr.actualLen);
// if (!Arrays.equals(result2, origin)) {
// System.out.printf("Normalized patches:\tPatchRevision #%d (+%d, cset:%d) failed\n", rr.entryIndex, rr.entryIndex - startEntryIndex, rr.linkRevision);
// }
// } catch (ArrayIndexOutOfBoundsException ex) {
// System.err.printf("Failure at entry %d (+%d)\n", rr.entryIndex, rr.entryIndex - startEntryIndex);
// ex.printStackTrace();
// }
}
}
final long end1 = System.currentTimeMillis();
//
byte[] result = seqPatch.apply(baseRevisionContent, rr.actualLen);
// byte[] result = normalizedPatch.apply(baseRevisionContent, rr.actualLen);
final long end2 = System.currentTimeMillis();
byte[] origin = getRevisionTrueContent(indexFile.getParentFile(), rr.entryIndex, rr.linkRevision);
final long end3 = System.currentTimeMillis();
rr.done();
System.out.printf("Collected patches up to revision %d. Patches total: %d, sequentialPatch contains %d elements, normalized: %d\n", rr.entryIndex, rr.entryIndex - startEntryIndex + 1, seqPatch.count(), normalizedPatch.count());
if (!Arrays.equals(result, origin)) {
if (shallDumpDiff) {
diff(result, origin);
dumpLineDifference(result, origin);