Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.Patch


    }
    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);
      } else {
        System.out.println("FAILURE!");
      }
    } else {
      System.out.println("OK!");
      System.out.printf("Iterate: %d ms, read base:%d, apply collected: %d ms, total=%d ms; Conventional: %d ms\n", (end1-start), (start-s0), (end2-end1), (end2-s0), (end3-end2));
    }
    Patch normalized = seqPatch.normalize();
    System.out.printf("N%s\n%d => %d patch elements\n", normalized, seqPatch.count(), normalized.count());
//    System.out.println(rs);
  }
View Full Code Here


    } else {
      patchData.clear();
    }
    rr.getData(patchData);
    patchData.flip();
    Patch patch1 = new Patch();
    patch1.read(new ByteArrayDataAccess(patchData.array(), patchData.arrayOffset(), patchData.remaining()));
    return patch1;
  }
View Full Code Here

    }
   
    /*package-local*/ Patch patch() throws IOException {
      if (patches == null) {
        dataAccess.reset();
        patches = new Patch();
        patches.read(dataAccess);
      }
      return patches;
    }
View Full Code Here

            String m = String.format("Revision %s import failed: delta base %s is not the last node we've handled (and know content for) %s", ge.node(), deltaBase, prevRevision);
            throw new HgInvalidStateException(m);
          }
        }
        //
        Patch patch = HgInternals.patchFromData(ge);
        byte[] content = patch.apply(prevRevContent, -1);
        Nodeid p1 = ge.firstParent();
        Nodeid p2 = ge.secondParent();
        byte[] calculated = dh.sha1(p1, p2, content).asBinary();
        final Nodeid node = ge.node();
        if (!node.equalsTo(calculated)) {
          String m = String.format("Checksum failed: expected %s, calculated %s. File %s", node, calculated, filename);
          throw new HgRevisionIntegrityException(m, null, new File(hgDir, filename));
        }
        revlogHeader.nodeid(node);
        //
        if (collectChangelogIndexes) {
          changelogIndexes.put(node, revisionSequence.size());
          revlogHeader.linkRevision(revisionSequence.size());
        } else {
          Integer csRev = changelogIndexes.get(ge.cset());
          if (csRev == null) {
            throw new HgInvalidStateException(String.format("Changelog doesn't contain revision %s of %s", ge.cset().shortNotation(), filename));
          }
          revlogHeader.linkRevision(csRev.intValue());
        }
        //
        revlogHeader.parents(knownRevision(p1), knownRevision(p2));
        //
        int patchSerializedLength = patch.serializedLength();
        // no reason to keep patch if it's close (here, >75%) in size to the complete contents,
        // save patching effort in this case
        writeComplete = writeComplete || preferCompleteOverPatch(patchSerializedLength, content.length);

        if (writeComplete) {
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.Patch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.