Package org.tmatesoft.hg.util

Examples of org.tmatesoft.hg.util.ProgressSupport


      return;
    }
    //
    // in fact, neither cancel nor progress of any use, need them just to check comamnd API
    final CancelSupport noCancel = CancelSupport.Factory.get(null);
    final ProgressSupport noProgress = ProgressSupport.Factory.get(null);
    //
    final Dump dump = new Dump(hgRepo);
    dump.complete(cmdLineOpts.getBoolean("--debug"));
    dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
    final boolean reverseOrder = !cmdLineOpts.getBoolean("--hg4j-order-direct");
View Full Code Here


   *
   * @return branch manager instance, never <code>null</code>
   * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
   */
  public HgBranches getBranches() throws HgRuntimeException {
    final ProgressSupport ps = ProgressSupport.Factory.get(null);
    if (branches == null) {
      branches = new HgBranches(impl);
      branches.collect(ps);
    } else {
      branches.reloadIfChanged(ps);
View Full Code Here

      assert delegate != null;
      inspector = delegate;
      csetBuilder = new ChangesetParser(sessionContext, new RawCsetFactory(true));
      inspectorLifecycle = Adaptable.Factory.getAdapter(delegate, Lifecycle.class, null);
      if (inspectorLifecycle == null) {
        ProgressSupport ph = Adaptable.Factory.getAdapter(delegate, ProgressSupport.class, null);
        CancelSupport cs = Adaptable.Factory.getAdapter(delegate, CancelSupport.class, null);
        if (cs != null || ph != null) {
          lifecycleStub = new LifecycleBridge(ph, cs);
        } else {
          lifecycleStub = null;
View Full Code Here

      throw new IllegalArgumentException();
    }
    if (file == null) {
      throw new HgBadArgumentException("Command needs file argument", null);
    }
    final ProgressSupport progress = getProgressSupport(inspector);
    final CancelSupport cancellation = getCancelSupport(inspector, true);
    cancellation.checkCancelled();
    progress.start(200);
    try {
      HgDataFile df = repo.getFileNode(file);
      if (!df.exists()) {
        return;
      }
      final int changesetStart = followRename ? 0 : df.getChangesetRevisionIndex(0);
      final int annotateRevIndex = annotateRevision.get(TIP);
      HgDiffCommand cmd = new HgDiffCommand(repo).file(df);
      cmd.range(changesetStart, annotateRevIndex);
      cmd.set(cancellation);
      cmd.set(new ProgressSupport.Sub(progress, 100));
      //
//      ReverseAnnotateInspector ai = new ReverseAnnotateInspector();
      ForwardAnnotateInspector ai = new ForwardAnnotateInspector();
      cmd.order(ai.iterateDirection());
      //
      cmd.executeAnnotate(ai);
      cancellation.checkCancelled();
      final int lastCsetWithFileChange;
      Nodeid fileRev = repo.getManifest().getFileRevision(annotateRevIndex, df.getPath());
      if (fileRev != null) {
        lastCsetWithFileChange = df.getChangesetRevisionIndex(df.getRevisionIndex(fileRev));
      } else {
        lastCsetWithFileChange = annotateRevIndex;
      }
      ai.report(lastCsetWithFileChange, inspector, new ProgressSupport.Sub(progress, 100), cancellation);
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    }
    progress.done();
  }
View Full Code Here

   * @throws HgRemoteConnectionException when failed to communicate with remote repository
   * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
   * @throws CancelledException if execution of the command was cancelled
   */
  public List<Nodeid> executeLite() throws HgRemoteConnectionException, HgException, CancelledException {
    final ProgressSupport ps = getProgressSupport(null);
    try {
      return getOutgoingRevisions(ps, getCancelSupport(null, true));
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      ps.done();
    }
  }
View Full Code Here

   */
  public void executeFull(final HgChangesetHandler handler) throws HgCallbackTargetException, HgException, CancelledException {
    if (handler == null) {
      throw new IllegalArgumentException("Delegate can't be null");
    }
    final ProgressSupport ps = getProgressSupport(handler);
    final CancelSupport cs = getCancelSupport(handler, true);
    try {
      ps.start(200);
      ChangesetTransformer inspector = new ChangesetTransformer(localRepo, handler, getParentHelper(), new ProgressSupport.Sub(ps, 100), cs);
      inspector.limitBranches(branches);
      List<Nodeid> out = getOutgoingRevisions(new ProgressSupport.Sub(ps, 100), cs);
      int[] outRevIndex = new int[out.size()];
      int i = 0;
      for (Nodeid o : out) {
        outRevIndex[i++] = localRepo.getChangelog().getRevisionIndex(o);
      }
      localRepo.getChangelog().range(inspector, outRevIndex);
      inspector.checkFailure();
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      ps.done();
    }
  }
View Full Code Here

   * @throws CancelledException if execution of the command was cancelled
   * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
   */
  public void executeAnnotate(HgBlameInspector insp) throws HgCallbackTargetException, CancelledException, HgException {
    checkFile();
    ProgressSupport progress = null;
    try {
      if (!df.exists()) {
        return;
      }
      final CancelSupport cancel = getCancelSupport(insp, true);
      BlameHelper bh = new BlameHelper(insp);
      final int startRevIndex = clogRevIndexStart.get(0);
      final int endRevIndex = clogRevIndexEnd.get(TIP);
      FileHistory fileHistory = bh.prepare(df, startRevIndex, endRevIndex);
      //
      cancel.checkCancelled();
      int totalWork = 0;
      for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateDirection)) {
        totalWork += fhc.revisionCount();
      }
      progress = getProgressSupport(insp);
      progress.start(totalWork + 1);
      progress.worked(1); // BlameHelper.prepare
      //
      int[] fileClogParentRevs = new int[2];
      int[] fileParentRevs = new int[2];
      for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateDirection)) {
        for (int fri : fhc.fileRevisions(iterateDirection)) {
          int clogRevIndex = fhc.changeset(fri);
          // the way we built fileHistory ensures we won't walk past [changelogRevIndexStart..changelogRevIndexEnd]
          assert clogRevIndex >= startRevIndex;
          assert clogRevIndex <= endRevIndex;
          fhc.fillFileParents(fri, fileParentRevs);
          fhc.fillCsetParents(fri, fileClogParentRevs);
          bh.annotateChange(fri, clogRevIndex, fileParentRevs, fileClogParentRevs);
          progress.worked(1);
          cancel.checkCancelled();
        }
      }
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      if (progress != null) {
        progress.done();
      }
    }
  }
View Full Code Here

   * @throws CancelledException if execution of the command was cancelled
   * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
   */
  public void executeParentsAnnotate(HgBlameInspector insp) throws HgCallbackTargetException, CancelledException, HgException {
    checkFile();
    final ProgressSupport progress = getProgressSupport(insp);
    progress.start(2);
    try {
      final CancelSupport cancel = getCancelSupport(insp, true);
      int changelogRevisionIndex = clogRevIndexEnd.get(TIP);
      // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f
      int fileRevIndex = fileRevIndex(df, changelogRevisionIndex);
      int[] fileRevParents = new int[2];
      df.parents(fileRevIndex, fileRevParents, null, null);
      if (changelogRevisionIndex == TIP) {
        changelogRevisionIndex = df.getChangesetRevisionIndex(fileRevIndex);
      }
      int[] fileClogParentRevs = new int[2];
      fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[0]);
      fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[1]);
      BlameHelper bh = new BlameHelper(insp);
      int clogIndexStart = fileClogParentRevs[0] == NO_REVISION ? (fileClogParentRevs[1] == NO_REVISION ? 0 : fileClogParentRevs[1]) : fileClogParentRevs[0];
      bh.prepare(df, clogIndexStart, changelogRevisionIndex);
      progress.worked(1);
      cancel.checkCancelled();
      bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs);
      progress.worked(1);
      cancel.checkCancelled();
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      progress.done();
    }
  }
View Full Code Here

    return this;
  }

  // FIXME get repository lock
  public void execute() throws HgRemoteConnectionException, HgIOException, HgLibraryFailureException, CancelledException {
    final ProgressSupport progress = getProgressSupport(null);
    try {
      progress.start(100);
      // TODO refactor same code in HgIncomingCommand #getComparator and #getParentHelper
      final HgChangelog clog = repo.getChangelog();
      final HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(clog);
      parentHelper.init();
      final RepositoryComparator comparator = new RepositoryComparator(parentHelper, remote);
      // get incoming revisions
      comparator.compare(new ProgressSupport.Sub(progress, 50), getCancelSupport(null, true));
      final List<Nodeid> common = comparator.getCommon();
      // get bundle with changes from remote
      HgBundle incoming = remote.getChanges(common);
      //
      // add revisions to changelog, manifest, files
      final Internals implRepo = HgInternals.getImplementationRepo(repo);
      final AddRevInspector insp;
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        incoming.inspectAll(insp = new AddRevInspector(implRepo, tr));
        insp.done();
        tr.commit();
      } catch (HgRuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgIOException ex) {
        tr.rollback();
        throw ex;
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      }
      progress.worked(45);
      added = insp.addedChangesets();
     
      if (!added.isEmpty()) {
        parentHelper.init(); // refresh the map, we use it for phases below
      }
      // get remote phases, update local phases to match that of remote
      // do not update any remote phase (it's pull, after all)
      final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper);
      if (phaseHelper.isCapableOfPhases()) {
        RevisionSet rsCommon = new RevisionSet(common);
        HgRemoteRepository.Phases remotePhases = remote.getPhases();
        phaseHelper.synchronizeWithRemote(remotePhases, rsCommon.union(added));
      }
      progress.worked(5);
      incoming.unlink(); // keep the file only in case of failure
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      progress.done();
    }
  }
View Full Code Here

        throw new HgBadArgumentException(String.format("%s shall be empty", destination), null);
      }
    } else {
      destination.mkdirs();
    }
    ProgressSupport progress = getProgressSupport(null);
    CancelSupport cancel = getCancelSupport(null, true);
    cancel.checkCancelled();
    // if cloning remote repo, which can stream and no revision is specified -
    // can use 'stream_out' wireproto
    //
    try {
      // pull all changes from the very beginning
      // XXX consult getContext() if by any chance has a bundle ready, if not, then read and register
      HgBundle completeChanges = srcRepo.getChanges(Collections.singletonList(NULL));
      cancel.checkCancelled();
      WriteDownMate mate = new WriteDownMate(srcRepo.getSessionContext(), destination, progress, cancel);
      try {
        // instantiate new repo in the destdir
        mate.initEmptyRepository();
        // pull changes
        completeChanges.inspectAll(mate);
        mate.checkFailure();
        mate.complete();
      } finally {
        completeChanges.unlink();
        progress.done();
      }
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    }
    return new HgLookup().detect(destination);
View Full Code Here

TOP

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

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.