Examples of Outcome


Examples of org.tmatesoft.hg.util.Outcome

      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

Examples of org.tmatesoft.hg.util.Outcome

    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

Examples of org.tmatesoft.hg.util.Outcome

      }
    }
   
    public void invalid(Path fname, Exception err) {
      try {
        handler.error(fname, new Outcome(Outcome.Kind.Failure, "Failed to get file status", err));
      } catch (HgCallbackTargetException ex) {
        failure = ex;
      }
    }
View Full Code Here

Examples of org.tmatesoft.hg.util.Outcome

        RevisionSet remoteDraftsLocalPublic = phaseHelper.synchronizeWithRemote(remotePhases, outgoing);
        if (!remoteDraftsLocalPublic.isEmpty()) {
          // foreach remoteDraftsLocallyPublic.heads() do push Draft->Public
          for (Nodeid n : remoteDraftsLocalPublic.heads(parentHelper)) {
            try {
              Outcome upo = remoteRepo.updatePhase(HgPhase.Draft, HgPhase.Public, n);
              if (!upo.isOk()) {
                implRepo.getLog().dump(getClass(), Severity.Info, "Failed to update remote phase, reason: %s", upo.getMessage());
              }
            } catch (HgRemoteConnectionException ex) {
              implRepo.getLog().dump(getClass(), Severity.Error, ex, String.format("Failed to update phase of %s", n.shortNotation()));
            }
          }
View Full Code Here

Examples of org.tmatesoft.hg.util.Outcome

    HgMergeState ms = hgRepo.getMergeState();
    ms.refresh();
    errorCollector.assertTrue(ms.isMerging());
    errorCollector.assertFalse(ms.isStale());
    errorCollector.assertEquals(0, ms.getConflicts().size());
    Outcome o = commitCmd.execute();
    errorCollector.assertTrue(o.getMessage(), o.isOk());
    ms.refresh();
    errorCollector.assertFalse(ms.isMerging());
    errorCollector.assertEquals(0, ms.getConflicts().size());
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.