Package org.tmatesoft.hg.core

Examples of org.tmatesoft.hg.core.Nodeid


    String activeBookmark = "bm1";
    eh.run("hg", "bookmarks", activeBookmark);

    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    Nodeid activeBookmarkRevision = hgRepo.getBookmarks().getRevision(activeBookmark);
    assertEquals("[sanity]", activeBookmarkRevision, hgRepo.getWorkingCopyParents().first());
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", dfD.exists());
    assertTrue("[sanity]", fileD.canRead());

    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c = cmd.getCommittedRevision();
   
    errorCollector.assertEquals(activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    errorCollector.assertEquals(c, hgRepo.getBookmarks().getRevision(activeBookmark));
    // reload repo, and repeat the check
    hgRepo = new HgLookup().detect(repoLoc);
View Full Code Here


    assertNull("[sanity]", hgRepo.getBookmarks().getActiveBookmarkName());
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    String activeBookmark = "bm1";
    eh.run("hg", "bookmarks", activeBookmark);
    assertEquals("Bookmarks has to reload", activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    Nodeid initialBookmarkRevision = hgRepo.getBookmarks().getRevision(activeBookmark); // c1
    assertEquals("[sanity]", initialBookmarkRevision, hgRepo.getWorkingCopyParents().first());

    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c2 = cmd.getCommittedRevision();
    errorCollector.assertEquals(c2, hgRepo.getBookmarks().getRevision(activeBookmark));
    //
    if (!Internals.runningOnWindows()) {
      // need change to happen not the same moment as the last commit (and read of bookmark file)
      Thread.sleep(1000); // XXX remove once better file change detection in place
View Full Code Here

    // HgCommitCommand can't do branch yet
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    cf.add(hgRepo.getFileNode("a"), new FileContentSupplier(hgRepo, new File(repoLoc, "a")));
    cf.branch(branch);
    Transaction tr = newTransaction(hgRepo);
    Nodeid commit = cf.commit("FIRST",  tr);
    tr.commit();
    errorCollector.assertEquals("commit with branch shall update WC", branch, hgRepo.getWorkingCopyBranchName());
   
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    eh.run("hg", "tag", tag);
View Full Code Here

    cf.add(hgRepo.getFileNode("xx"), new FileContentSupplier(hgRepo, newFile));
    cf.add(dfB, new FileContentSupplier(hgRepo, modifiedFile));
    cf.forget(dfD);
    cf.branch("another-branch");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit to fail",  tr);
    tr.rollback();
    //
    errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());
    errorCollector.assertEquals(lastManifestRev, hgRepo.getManifest().getLastRevision());
    errorCollector.assertEquals(DEFAULT_BRANCH_NAME, DirstateReader.readBranch(Internals.getInstance(hgRepo)));
View Full Code Here

            int sep = line.indexOf(':');
            if (sep == -1) {
              log.dump(MqManager.class, Warn, "Bad line in %s:%s", fileStatus.getPath(), line);
              return true;
            }
            Nodeid nid = Nodeid.fromAscii(line.substring(0, sep));
            String name = new String(line.substring(sep+1));
            result.add(new PatchRecord(nid, name, patchLocation.path(name)));
            return true;
          }
        }, applied = new LinkedList<PatchRecord>());
View Full Code Here

        String line = it.next();
        int x = line.indexOf(':');
        if (x == -1) {
          throw new HgInvalidStateException(line);
        }
        Nodeid oldRev = Nodeid.fromAscii(line.substring(0, x));
        Nodeid newRev;
        if (line.regionMatches(x+1, nullmerge, 0, nullmerge.length())) {
          newRev = null;
        } else {
          newRev = Nodeid.fromAscii(line.substring(x+1));
        }
View Full Code Here

    if (!branchheadsCache.canWrite()) {
      return;
    }
    final HgRepository repo = internalRepo.getRepo();
    final int lastRev = repo.getChangelog().getLastRevision();
    final Nodeid lastNid = repo.getChangelog().getRevision(lastRev);
    BufferedWriter bw = new BufferedWriter(new FileWriter(branchheadsCache));
    bw.write(lastNid.toString());
    bw.write((int) ' ');
    bw.write(Integer.toString(lastRev));
    bw.write("\n");
    for (BranchInfo bi : branches.values()) {
      for (Nodeid nid : bi.getHeads()) {
View Full Code Here

  public Nodeid commit(String message, Transaction transaction) throws HgIOException, HgRepositoryLockException, HgRuntimeException {
    final HgChangelog clog = repo.getRepo().getChangelog();
    final int clogRevisionIndex = clog.getRevisionCount();
    ManifestRevision c1Manifest = new ManifestRevision(null, null);
    ManifestRevision c2Manifest = new ManifestRevision(null, null);
    final Nodeid p1Cset = p1Commit == NO_REVISION ? null : clog.getRevision(p1Commit);
    final Nodeid p2Cset = p2Commit == NO_REVISION ? null : clog.getRevision(p2Commit);
    if (p1Commit != NO_REVISION) {
      repo.getRepo().getManifest().walk(p1Commit, p1Commit, c1Manifest);
    }
    if (p2Commit != NO_REVISION) {
      repo.getRepo().getManifest().walk(p2Commit, p2Commit, c2Manifest);
    }
//    Pair<Integer, Integer> manifestParents = getManifestParents();
    Pair<Integer, Integer> manifestParents = new Pair<Integer, Integer>(c1Manifest.revisionIndex(), c2Manifest.revisionIndex());
    TreeMap<Path, Nodeid> newManifestRevision = new TreeMap<Path, Nodeid>();
    HashMap<Path, Pair<Integer, Integer>> fileParents = new HashMap<Path, Pair<Integer,Integer>>();
    for (Path f : c1Manifest.files()) {
      HgDataFile df = repo.getRepo().getFileNode(f);
      Nodeid fileKnownRev1 = c1Manifest.nodeid(f), fileKnownRev2;
      final int fileRevIndex1 = df.getRevisionIndex(fileKnownRev1);
      final int fileRevIndex2;
      if ((fileKnownRev2 = c2Manifest.nodeid(f)) != null) {
        // merged files
        fileRevIndex2 = df.getRevisionIndex(fileKnownRev2);
      } else {
        fileRevIndex2 = NO_REVISION;
      }
       
      fileParents.put(f, new Pair<Integer, Integer>(fileRevIndex1, fileRevIndex2));
      newManifestRevision.put(f, fileKnownRev1);
    }
    //
    // Forget removed
    for (Path p : removals) {
      newManifestRevision.remove(p);
    }
    //
    saveCommitMessage(message);
    //
    // Register new/changed
    FNCacheFile.Mediator fncache = new FNCacheFile.Mediator(repo, transaction);
    ArrayList<Path> touchInDirstate = new ArrayList<Path>();
    for (Pair<HgDataFile, DataSource> e : files.values()) {
      HgDataFile df = e.first();
      DataSource bds = e.second();
      Pair<Integer, Integer> fp = fileParents.get(df.getPath());
      if (fp == null) {
        // NEW FILE, either just added or resurrected from p2
        Nodeid fileRevInP2;
        if ((fileRevInP2 = c2Manifest.nodeid(df.getPath())) != null) {
          fp = new Pair<Integer, Integer>(df.getRevisionIndex(fileRevInP2), NO_REVISION);
        } else {
          // brand new
          fp = new Pair<Integer, Integer>(NO_REVISION, NO_REVISION);
        }
      }
      // TODO if fp.first() != NO_REVISION and fp.second() != NO_REVISION check if one
      // revision is ancestor of another and use the latest as p1, then
      Nodeid fileRev = null;
      final boolean isNewFile = !df.exists();
      if (fp.first() != NO_REVISION && fp.second() == NO_REVISION && !isNewFile) {
        // compare file contents to see if anything has changed, and reuse old revision, if unchanged.
        // XXX ineffective, need better access to revision conten
        ByteArraySerializer bas = new ByteArraySerializer();
        bds.serialize(bas);
        final byte[] newContent = bas.toByteArray();
        // unless there's a way to reset DataSource, replace it with the content just read
        bds = new DataSerializer.ByteArrayDataSource(newContent);
        if (new ComparatorChannel(newContent).same(df, fp.first())) {
          fileRev = df.getRevision(fp.first());
        }
      }
      if (fileRev == null) {
        RevlogStream contentStream = repo.getImplAccess().getStream(df);
        RevlogStreamWriter fileWriter = new RevlogStreamWriter(repo, contentStream, transaction);
        fileRev = fileWriter.addRevision(bds, clogRevisionIndex, fp.first(), fp.second()).second();
        if (isNewFile) {
          // registerNew shall go after fileWriter.addRevision as it needs to know if data is inlined or not
          fncache.registerNew(df.getPath(), contentStream);
        }
      }
      newManifestRevision.put(df.getPath(), fileRev);
      touchInDirstate.add(df.getPath());
    }
    //
    final EncodingHelper encHelper = repo.buildFileNameEncodingHelper();
    //
    // Manifest
    final ManifestEntryBuilder manifestBuilder = new ManifestEntryBuilder(encHelper);
    for (Map.Entry<Path, Nodeid> me : newManifestRevision.entrySet()) {
      manifestBuilder.add(me.getKey().toString(), me.getValue());
    }
    RevlogStreamWriter manifestWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getManifestStream(), transaction);
    Nodeid manifestRev = manifestWriter.addRevision(manifestBuilder, clogRevisionIndex, manifestParents.first(), manifestParents.second()).second();
    //
    // Changelog
    final ChangelogEntryBuilder changelogBuilder = new ChangelogEntryBuilder(encHelper);
    changelogBuilder.setModified(files.keySet());
    changelogBuilder.branch(branch == null ? DEFAULT_BRANCH_NAME : branch);
    changelogBuilder.user(String.valueOf(user));
    changelogBuilder.manifest(manifestRev).comment(message);
    RevlogStreamWriter changelogWriter = new RevlogStreamWriter(repo, repo.getImplAccess().getChangelogStream(), transaction);
    Nodeid changesetRev = changelogWriter.addRevision(changelogBuilder, clogRevisionIndex, p1Commit, p2Commit).second();
    // TODO move dirstate and bookmark update update to an external facility
    fncache.complete();
    String oldBranchValue = DirstateReader.readBranch(repo);
    String newBranchValue = branch == null ? DEFAULT_BRANCH_NAME : branch;
    if (!oldBranchValue.equals(newBranchValue)) {
View Full Code Here

        try {
          if (prevRevContent == null) {
            if (ge.firstParent().isNull() && ge.secondParent().isNull()) {
              prevRevContent = new ByteArrayDataAccess(new byte[0]);
            } else {
              final Nodeid base = ge.firstParent();
              if (!changelog.isKnown(base) /*only first parent, that's Bundle contract*/) {
                throw new IllegalStateException(String.format("Revision %s needs a parent %s, which is missing in the supplied repo %s", ge.node().shortNotation(), base.shortNotation(), hgRepo.toString()));
              }
              ByteArrayChannel bac = new ByteArrayChannel();
              changelog.rawContent(base, bac); // TODO post-1.0 get DataAccess directly, to avoid
              // extra byte[] (inside ByteArrayChannel) duplication just for the sake of subsequent ByteArrayDataChannel wrap.
              prevRevContent = new ByteArrayDataAccess(bac.toArray());
View Full Code Here

  }

  private static void readGroup(DataAccess da, Inspector inspector) throws IOException, HgRuntimeException {
    int len = da.readInt();
    boolean good2go = true;
    Nodeid prevNodeid = null;
    while (len > 4 && !da.isEmpty() && good2go) {
      byte[] nb = new byte[80];
      da.readBytes(nb, 0, 80);
      int dataLength = len - 84 /* length field + 4 nodeids */;
      byte[] data = new byte[dataLength];
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.