Package org.tmatesoft.hg.util

Examples of org.tmatesoft.hg.util.Outcome


      System.err.println("Need a commit message");
      return;
    }
    HgCommitCommand cmd = repo.createCommitCommand();
    cmd.message(message);
    Outcome o = cmd.execute();
    if (!o.isOk()) {
      System.err.println(o.getMessage());
      return;
    }
    System.out.printf("New changeset: %s\n", cmd.getCommittedRevision().shortNotation());
  }
View Full Code Here


      int revToExtract;
      if (cset != null) {
        // TODO HgChangesetFileSneaker is handy, but bit too much here, shall extract follow rename code into separate utility
        HgChangesetFileSneaker fsneaker = new HgChangesetFileSneaker(repo);
        fsneaker.changeset(cset).followRenames(true);
        Outcome o = fsneaker.check(file);
        if (!o.isOk()) {
          if (o.getException() instanceof HgRuntimeException) {
            throw new HgLibraryFailureException(o.getMessage(), (HgRuntimeException) o.getException());
          }
          throw new HgBadArgumentException(o.getMessage(), o.getException()).setFileName(file).setRevision(cset);
        }
        if (!fsneaker.exists()) {
          throw new HgPathNotFoundException(o.getMessage(), file).setRevision(cset);
        }
        Nodeid toExtract = fsneaker.revision();
        if (fsneaker.hasAnotherName()) {
          dataFile = repo.getFileNode(fsneaker.filename());
        }
View Full Code Here

    assertTrue("[sanity]", fileB.canRead());
    RepoUtils.modifyFileAppend(fileB, " 1 \n");

    HgCommitCommand cmd = new HgCommitCommand(hgRepo);
    assertFalse(cmd.isMergeCommit());
    Outcome r = cmd.message("FIRST").execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c1 = cmd.getCommittedRevision();
   
    // check that modified files are no longer reported as such
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Modified).isEmpty());
    errorCollector.assertEquals(1, status.get(dfB.getPath()).size());
    errorCollector.assertTrue(status.get(dfB.getPath()).contains(Kind.Clean));
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    cmd = new HgCommitCommand(hgRepo);
    assertFalse(cmd.isMergeCommit());
    r = cmd.message("SECOND").execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c2 = cmd.getCommittedRevision();
    //
    errorCollector.assertEquals("SECOND", hgRepo.getCommitLastMessage());
    //
    int lastRev = hgRepo.getChangelog().getLastRevision();
View Full Code Here

    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
View Full Code Here

    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
    }
    eh.run("hg", "bookmark", activeBookmark, "--force", "--rev", initialBookmarkRevision.toString());
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cmd = new HgCommitCommand(hgRepo).message("SECOND");
    r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    //Nodeid c3 = cmd.getCommittedRevision();
    errorCollector.assertEquals(initialBookmarkRevision, hgRepo.getBookmarks().getRevision(activeBookmark));
  }
View Full Code Here

    // save the reference to HgDataFile without valid RevlogStream (entry in the dirstate
    // doesn't make it valid)
    final HgDataFile newFileNode = hgRepo.getFileNode("xx");
    assertFalse(newFileNode.exists());
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Added).isEmpty());
    errorCollector.assertTrue(status.get(newFileNode.getPath()).contains(Kind.Clean));
View Full Code Here

  }

  public Outcome updateBookmark(String name, Nodeid oldRev, Nodeid newRev) throws HgRemoteConnectionException, HgRuntimeException {
    initCapabilities();
    if (!remoteCapabilities.contains(CMD_PUSHKEY)) {
      return new Outcome(Failure, "Server doesn't support pushkey protocol");
    }
    if (pushkey("Update remote bookmark", NS_BOOKMARKS, name, oldRev.toString(), newRev.toString())) {
      return new Outcome(Success, String.format("Bookmark %s updated to %s", name, newRev.shortNotation()));
    }
    return new Outcome(Failure, String.format("Bookmark update (%s: %s -> %s) failed", name, oldRev.shortNotation(), newRev.shortNotation()));
  }
View Full Code Here

  }
 
  public Outcome updatePhase(HgPhase from, HgPhase to, Nodeid n) throws HgRemoteConnectionException, HgRuntimeException {
    initCapabilities();
    if (!remoteCapabilities.contains(CMD_PUSHKEY)) {
      return new Outcome(Failure, "Server doesn't support pushkey protocol");
    }
    if (pushkey("Update remote phases", NS_PHASES, n.toString(), String.valueOf(from.mercurialOrdinal()), String.valueOf(to.mercurialOrdinal()))) {
      return new Outcome(Success, String.format("Phase of %s updated to %s", n.shortNotation(), to.name()));
    }
    return new Outcome(Failure, String.format("Phase update (%s: %s -> %s) failed", n.shortNotation(), from.name(), to.name()));
  }
View Full Code Here

      detectParentFromDirstate(parentRevs);
      HgWorkingCopyStatusCollector sc = new HgWorkingCopyStatusCollector(repo);
      Record status = sc.status(HgRepository.WORKING_COPY);
      if (status.getModified().size() == 0 && status.getAdded().size() == 0 && status.getRemoved().size() == 0) {
        newRevision = Nodeid.NULL;
        return new Outcome(Kind.Failure, "nothing to add");
      }
      final Internals implRepo = Internals.getInstance(repo);
      CommitFacility cf = new CommitFacility(implRepo, parentRevs[0], parentRevs[1]);
      for (Path m : status.getModified()) {
        HgDataFile df = repo.getFileNode(m);
        cf.add(df, new WorkingCopyContent(df));
      }
      for (Path a : status.getAdded()) {
        HgDataFile df = repo.getFileNode(a); // TODO need smth explicit, like repo.createNewFileNode(Path) here
        // XXX might be an interesting exercise not to demand a content supplier, but instead return a "DataRequester"
        // object, that would indicate interest in data, and this code would "push" it to requester, so that any exception
        // is handled here, right away, and won't need to travel supplier and CommitFacility. (although try/catch inside
        // supplier.read (with empty throws declaration)
        cf.add(df, new FileContentSupplier(repo, a));
      }
      for (Path r : status.getRemoved()) {
        HgDataFile df = repo.getFileNode(r);
        cf.forget(df);
      }
      cf.branch(detectBranch());
      cf.user(detectUser());
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        newRevision = cf.commit(message, tr);
        tr.commit();
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgException ex) {
        tr.rollback();
        throw ex;
      }
      return new Outcome(Kind.Success, "Commit ok");
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      repoLock.release();
    }
View Full Code Here

    if (cset == null || file == null || file.isDirectory()) {
      throw new IllegalArgumentException();
    }
    HgDataFile dataFile = repo.getFileNode(file);
    if (!dataFile.exists()) {
      checkResult = new Outcome(Outcome.Kind.Success, String.format("File named %s is not known in the repository", file));
      return checkResult;
    }
    Nodeid toExtract = null;
    String phaseMsg = "Extract manifest revision failed";
    try {
      if (cachedManifest == null) {
        int csetRev = repo.getChangelog().getRevisionIndex(cset);
        cachedManifest = new ManifestRevision(null, null); // XXX how about context and cached manifest revisions
        repo.getManifest().walk(csetRev, csetRev, cachedManifest);
        // cachedManifest shall be meaningful - changelog.getRevisionIndex() above ensures we've got version that exists.
      }
      toExtract = cachedManifest.nodeid(file);
      phaseMsg = "Follow copy/rename failed";
      if (toExtract == null && followRenames) {
        int csetIndex = repo.getChangelog().getRevisionIndex(cset);
        int ccFileRevIndex = dataFile.getLastRevision(); // copy candidate
        int csetFileEnds = dataFile.getChangesetRevisionIndex(ccFileRevIndex);
        if (csetIndex > csetFileEnds) {
          return new Outcome(Outcome.Kind.Success, String.format("%s: last known changeset for the file %s is %d. Follow renames is possible towards older changesets only", phaseMsg, file, csetFileEnds));
        }
        // @see FileRenameHistory, with similar code, which doesn't trace alternative paths
        // traceback stack keeps record of all files with isCopy(fileRev) == true we've tried to follow, so that we can try earlier file
        // revisions in case followed fileRev didn't succeed
        ArrayDeque<Pair<HgDataFile, Integer>> traceback = new ArrayDeque<Pair<HgDataFile, Integer>>();
        do {
          int ccCsetIndex = dataFile.getChangesetRevisionIndex(ccFileRevIndex);
          if (ccCsetIndex <= csetIndex) {
            // present dataFile is our (distant) origin
            toExtract = dataFile.getRevision(ccFileRevIndex);
            renamed = true;
            break;
          }
          if (!dataFile.isCopy(ccFileRevIndex)) {
            // nothing left to return to when traceback.isEmpty()
            while (ccFileRevIndex == 0 && !traceback.isEmpty()) {
              Pair<HgDataFile, Integer> lastTurnPoint = traceback.pop();
              dataFile = lastTurnPoint.first();
              ccFileRevIndex = lastTurnPoint.second(); // generally ccFileRevIndex != 0 here, but doesn't hurt to check, hence while
              // fall through to shift down from the file revision we've already looked at
            }
            ccFileRevIndex--;
            continue;
          }
          if (ccFileRevIndex > 0) {
            // there's no reason to memorize turn point if it's the very first revision
            // of the file and we won't be able to try any other earlier revision
            traceback.push(new Pair<HgDataFile, Integer>(dataFile, ccFileRevIndex));
          }
          HgFileRevision origin = dataFile.getCopySource(ccFileRevIndex);
          dataFile = repo.getFileNode(origin.getPath());
          ccFileRevIndex = dataFile.getRevisionIndex(origin.getRevision());
        } while (ccFileRevIndex >= 0);
        // didn't get to csetIndex, no ancestor in file rename history found.
      }
    } catch (HgRuntimeException ex) {
      checkResult = new Outcome(Outcome.Kind.Failure, phaseMsg, ex);
      return checkResult;
    }
    if (toExtract != null) {
      Flags extractRevFlags = cachedManifest.flags(dataFile.getPath());
      fileRevision = new HgFileRevision(repo, toExtract, extractRevFlags, dataFile.getPath());
      checkResult = new Outcome(Outcome.Kind.Success, String.format("File %s, revision %s found at changeset %s", dataFile.getPath(), toExtract.shortNotation(), cset.shortNotation()));
      return checkResult;
    }
    checkResult = new Outcome(Outcome.Kind.Success, String.format("File %s nor its origins were known at revision %s", file, cset.shortNotation()));
    return checkResult;
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.util.Outcome

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.