Package org.tmatesoft.hg.core

Examples of org.tmatesoft.hg.core.Nodeid


  }
 
  public Pair<Integer,Nodeid> addPatchRevision(GroupElement ge, RevisionToIndexMap clogRevs, RevisionToIndexMap revlogRevs) throws HgIOException, HgRuntimeException {
    populateLastEntryIndex();
    //
    final Nodeid nodeRev = ge.node();
    final Nodeid csetRev = ge.cset();
    int linkRev;
    if (nodeRev.equals(csetRev)) {
      linkRev = lastEntryIndex+1;
    } else {
      linkRev = clogRevs.revisionIndex(csetRev);
    }
    assert linkRev >= 0;
    final Nodeid p1Rev = ge.firstParent();
    int p1 = p1Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p1Rev);
    final Nodeid p2Rev = ge.secondParent();
    int p2 = p2Rev.isNull() ? NO_REVISION : revlogRevs.revisionIndex(p2Rev);
    Patch p = null;
    try {
      p = HgInternals.patchFromData(ge);
    } catch (IOException ex) {
      throw new HgIOException("Failed to read patch information", ex, null);
    }
    //
    final Nodeid patchBase = ge.patchBase();
    int patchBaseRev = patchBase.isNull() ? NO_REVISION : revlogRevs.revisionIndex(patchBase);
    int baseRev = lastEntryIndex == NO_REVISION ? 0 : revlogStream.baseRevision(patchBaseRev);
    int revLen;
    DataSource ds;
    byte[] complete = null;
    if (patchBaseRev == lastEntryIndex && lastEntryIndex != NO_REVISION) {
View Full Code Here


  public Pair<Integer,Nodeid> addRevision(DataSource content, int linkRevision, int p1, int p2) throws HgIOException, HgRuntimeException {
    populateLastEntryIndex();
    populateLastEntryContent();
    //
    byte[] contentByteArray = toByteArray(content);
    Nodeid p1Rev = revision(p1);
    Nodeid p2Rev = revision(p2);
    Nodeid newRev = Nodeid.fromBinary(dh.sha1(p1Rev, p2Rev, contentByteArray).asBinary(), 0);
    if (newRev.equals(p1Rev)) { // shall never happen, same content but different parents give new SHA. Doesn't hurt to check, though
      assert p2Rev.isNull();
      return new Pair<Integer, Nodeid>(p1, p1Rev);
    }
    //
    Patch patch = GeneratePatchInspector.delta(lastFullContent.second(), contentByteArray);
View Full Code Here

  private Nodeid revision(int revisionIndex) throws HgInvalidControlFileException, HgInvalidRevisionException {
    if (revisionIndex == NO_REVISION) {
      return Nodeid.NULL;
    }
    Nodeid n = revisionCache.get(revisionIndex);
    if (n == null) {
      n = Nodeid.fromBinary(revlogStream.nodeid(revisionIndex), 0);
      revisionCache.put(revisionIndex, n);
    }
    return n;
View Full Code Here

  @Test
  public void testCatAtCsetRevision() throws Exception {
    HgCatCommand cmd = new HgCatCommand(repo);
    final Path file = Path.create("src/org/tmatesoft/hg/internal/RevlogStream.java");
    cmd.file(file);
    final Nodeid cset = Nodeid.fromAscii("08db726a0fb7914ac9d27ba26dc8bbf6385a0554");
    cmd.changeset(cset);
    final ByteArrayChannel sink = new ByteArrayChannel();
    cmd.execute(sink);
    final int result1 = sink.toArray().length;
    HgChangesetFileSneaker i = new HgChangesetFileSneaker(repo);
View Full Code Here

    parentHelper.init();
    errorCollector.assertEquals(Arrays.asList(allRevs), parentHelper.all());
    for (Nodeid n : allRevs) {
      errorCollector.assertTrue(parentHelper.knownNode(n));
      // parents
      final Nodeid p1 = parentHelper.safeFirstParent(n);
      final Nodeid p2 = parentHelper.safeSecondParent(n);
      errorCollector.assertFalse(p1 == null);
      errorCollector.assertFalse(p2 == null);
      errorCollector.assertEquals(p1.isNull() ? null : p1, parentHelper.firstParent(n));
      errorCollector.assertEquals(p2.isNull() ? null : p2, parentHelper.secondParent(n));
      HashSet<Nodeid> parents = new HashSet<Nodeid>();
      boolean modified = parentHelper.appendParentsOf(n, parents);
      errorCollector.assertEquals(p1.isNull() && p2.isNull(), !modified);
      HashSet<Nodeid> cp = new HashSet<Nodeid>();
      cp.add(parentHelper.firstParent(n));
      cp.add(parentHelper.secondParent(n));
      cp.remove(null);
      errorCollector.assertEquals(cp, parents);
      modified = parentHelper.appendParentsOf(n, parents);
      errorCollector.assertFalse(modified);
      //
      // isChild, hasChildren, childrenOf, directChildren
      if (!p1.isNull()) {
        errorCollector.assertTrue(parentHelper.isChild(p1, n));
        errorCollector.assertTrue(parentHelper.hasChildren(p1));
        errorCollector.assertTrue(parentHelper.childrenOf(Collections.singleton(p1)).contains(n));
        errorCollector.assertTrue(parentHelper.directChildren(p1).contains(n));
      }
      if (!p2.isNull()) {
        errorCollector.assertTrue(parentHelper.isChild(p2, n));
        errorCollector.assertTrue(parentHelper.hasChildren(p2));
        errorCollector.assertTrue(parentHelper.childrenOf(Collections.singleton(p2)).contains(n));
        errorCollector.assertTrue(parentHelper.directChildren(p2).contains(n));
      }
View Full Code Here

      progressHelper = ProgressSupport.Factory.get(delegate);
    }
   
    public void next(int revisionNumber, int actualLen, int baseRevision, int linkRevision, int parent1Revision, int parent2Revision, byte[] nodeid, DataAccess da) throws HgRuntimeException {
      try {
        if (!inspector.begin(revisionNumber, new Nodeid(nodeid, true), linkRevision)) {
          iterateControl.stop();
          return;
        }
        if (!da.isEmpty()) {
          // although unlikely, manifest entry may be empty, when all files have been deleted from the repository
          Path fname = null;
          Flags flags = null;
          Nodeid nid = null;
          int i;
          byte[] data = da.byteArray();
          for (i = 0; i < actualLen; i++) {
            int x = i;
            for( ; data[i] != '\n' && i < actualLen; i++) {
              if (fname == null && data[i] == 0) {
                PathProxy px = fnamePool.unify(new PathProxy(data, x, i - x));
                // if (cached = fnamePool.unify(px))== px then cacheMiss, else cacheHit
                // cpython 0..10k: hits: 15 989 152, misses: 3020
                fname = px.freeze();
                x = i+1;
              }
            }
            if (i < actualLen) {
              assert data[i] == '\n';
              int nodeidLen = i - x < 40 ? i-x : 40; // if > 40, there are flags
              DigestHelper.ascii2bin(data, x, nodeidLen, nodeidLookupBuffer); // ignore return value as it's unlikely to have NULL in manifest
              nid = new Nodeid(nodeidLookupBuffer, false); // this Nodeid is for pool lookup only, mock object
              Nodeid cached = nodeidPool.unify(nid);
              if (cached == nid) {
                // buffer now belongs to the cached nodeid
                nodeidLookupBuffer = new byte[20];
              } else {
                nid = cached; // use existing version, discard the lookup object
View Full Code Here

            missingCsetToManifest.put(revisionIndex, cset.manifest());
          }
        }, undefinedClogRevs);
        assert missingCsetToManifest.size() == undefinedChangelogRevision.size();
        for (int u : undefinedClogRevs) {
          Nodeid manifest = missingCsetToManifest.get(u);
          if (manifest == null || manifest.isNull()) {
            HgManifest.this.getRepo().getSessionContext().getLog().dump(getClass(), Severity.Warn, "Changeset %d has no associated manifest entry", u);
            // keep BAD_REVISION in the changelog2manifest map.
            continue;
          }
          if (manifestNodeids != null) {
            int manifestRevIndex = manifestNodeids.findIndex(manifest);
            // mimic HgManifest#getRevisionIndex() to keep behavior the same
            if (manifestRevIndex == BAD_REVISION) {
              throw new HgInvalidRevisionException(String.format("Can't find index of revision %s", manifest.shortNotation()), manifest, null);
            }
            changelog2manifest[u] = manifestRevIndex;
          } else {
            changelog2manifest[u] = HgManifest.this.getRevisionIndex(manifest);
          }
View Full Code Here

        while (!data.isEmpty() && (b = data.readByte()) != '\n') {
          if (b != 0) {
            byteVector.add(b);
          } else {
            if (byteVector.equalsTo(filenameAsBytes)) {
              Nodeid fileRev = null;
              Flags flags = null;
              if (csetIndex2FileRev != null || delegate != null) {
                byte[] nid = new byte[40]
                data.readBytes(nid, 0, 40);
                fileRev = Nodeid.fromAscii(nid, 0, 40);
View Full Code Here

    }
    return mr;
  }

  private void initDirstateParentManifest() throws HgRuntimeException {
    Nodeid dirstateParent = getDirstateImpl().parents().first();
    if (dirstateParent.isNull()) {
      dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(NO_REVISION) : HgStatusCollector.createEmptyManifestRevision();
    } else {
      int changeloRevIndex = repo.getChangelog().getRevisionIndex(dirstateParent);
      dirstateParentManifest = getManifest(changeloRevIndex);
    }
View Full Code Here

    // see #checkLocalStatusAgainstFile() below for the origin of changed file check
    HgDataFile df = repo.getFileNode(fname);
    if (!df.exists()) {
      throw new HgInvalidFileException("File not found", null).setFileName(fname);
    }
    Nodeid rev = getDirstateParentManifest().nodeid(fname);
    return rev == null || !areTheSame(fileInfo, df, rev);
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.core.Nodeid

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.