Package org.tmatesoft.hg.util

Examples of org.tmatesoft.hg.util.CancelSupport


      System.err.printf("Can't find repository in: %s\n", hgRepo.getLocation());
      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"));
View Full Code Here


      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

        // no command-specific cancel helper, no need for extra proxy
        // sink itself still may supply CS
        sinkWrap = sink;
      } else {
        // try CS from sink, if any. at least there is CS from command
        CancelSupport cancelHelper = getCancelSupport(sink, true);
        cancelHelper.checkCancelled();
        sinkWrap = new ByteChannelProxy(sink, cancelHelper);
      }
      dataFile.contentWithFilters(revToExtract, sinkWrap);
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
View Full Code Here

        throw new HgInvalidControlFileException("Failed reading manifest", ex, null).setRevisionIndex(revisionNumber);
      }
    }

    public void start(int count, Callback callback, Object token) {
      CancelSupport cs = CancelSupport.Factory.get(inspector, null);
      iterateControl = new IterateControlMediator(cs, callback);
      progressHelper.start(count);
    }
View Full Code Here

    }
    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 {
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);
View Full Code Here

      } else {
        rev1 = baseRevision;
      }
      ((HgStatusCollector.Record) inspector).init(rev1, rev2, sc);
    }
    final CancelSupport cs = CancelSupport.Factory.get(inspector);
    final HgIgnore hgIgnore = repo.getIgnore();
    repoWalker.reset();
    TreeSet<Path> processed = new TreeSet<Path>(); // names of files we handled as they known to Dirstate (not FileIterator)
    final HgDirstate ds = getDirstateImpl();
    TreeSet<Path> knownEntries = ds.all(); // here just to get dirstate initialized
    while (repoWalker.hasNext()) {
      cs.checkCancelled();
      repoWalker.next();
      final Path fname = getPathPool().mangle(repoWalker.name());
      FileInfo f = repoWalker.file();
      Path knownInDirstate;
      if (!f.exists()) {
        // file coming from iterator doesn't exist.
        if ((knownInDirstate = ds.known(fname)) != null) {
          // found in dirstate
          processed.add(knownInDirstate);
          if (ds.checkRemoved(knownInDirstate) == null) {
            inspector.missing(knownInDirstate);
          } else {
            inspector.removed(knownInDirstate);
          }
          // do not report it as removed later
          if (collect != null) {
            baseRevFiles.remove(knownInDirstate);
          }
        } else {
          // chances are it was known in baseRevision. We may rely
          // that later iteration over baseRevFiles leftovers would yield correct Removed,
          // but it doesn't hurt to be explicit (provided we know fname *is* inScope of the FileIterator
          if (collect != null && baseRevFiles.remove(fname)) {
            inspector.removed(fname);
          } else {
            // not sure I shall report such files (i.e. arbitrary name coming from FileIterator)
            // as unknown. Command-line HG aborts "system can't find the file specified"
            // in similar case (against wc), or just gives nothing if --change <rev> is specified.
            // however, as it's unlikely to get unexisting files from FileIterator, and
            // its better to see erroneous file status rather than not to see any (which is too easy
            // to overlook), I think unknown() is reasonable approach here
            inspector.unknown(fname);
          }
        }
        continue;
      }
      if ((knownInDirstate = ds.known(fname)) != null) {
        // tracked file.
        // modified, added, removed, clean
        processed.add(knownInDirstate);
        if (collect != null) { // need to check against base revision, not FS file
          checkLocalStatusAgainstBaseRevision(baseRevFiles, collect, baseRevision, knownInDirstate, f, inspector);
        } else {
          checkLocalStatusAgainstFile(knownInDirstate, f, inspector);
        }
      } else {
        if (hgIgnore.isIgnored(fname)) { // hgignore shall be consulted only for non-tracked files
          inspector.ignored(fname);
        } else {
          inspector.unknown(fname);
        }
        // the file is not tracked. Even if it's known at baseRevision, we don't need to remove it
        // from baseRevFiles, it might need to be reported as removed as well (cmdline client does
        // yield two statuses for the same file)
      }
    }
    if (collect != null) {
      // perhaps, this code shall go after processing leftovers of knownEntries, below
      // as it's sort of last resort - what to do with otherwise unprocessed base revision files
      for (Path fromBase : baseRevFiles) {
        if (repoWalker.inScope(fromBase)) {
          inspector.removed(fromBase);
          processed.add(fromBase);
          cs.checkCancelled();
        }
      }
    }
    knownEntries.removeAll(processed);
    for (Path m : knownEntries) {
      if (!repoWalker.inScope(m)) {
        // do not report as missing/removed those FileIterator doesn't care about.
        continue;
      }
      cs.checkCancelled();
      // missing known file from a working dir 
      if (ds.checkRemoved(m) == null) {
        // not removed from the repository = 'deleted' 
        inspector.missing(m);
      } else {
View Full Code Here

      }
    }
    r1 = get(rev1);
    r2 = get(rev2);

    final CancelSupport cs = CancelSupport.Factory.get(inspector);

    Collection<Path> allBaseFiles = r1.files();
    TreeSet<Path> r1Files = new TreeSet<Path>(allBaseFiles);
    for (Path r2fname : r2.files()) {
      if (!scope.accept(r2fname)) {
        continue;
      }
      if (r1Files.remove(r2fname)) {
        Nodeid nidR1 = r1.nodeid(r2fname);
        Nodeid nidR2 = r2.nodeid(r2fname);
        HgManifest.Flags flagsR1 = r1.flags(r2fname);
        HgManifest.Flags flagsR2 = r2.flags(r2fname);
        if (nidR1.equals(nidR2) && flagsR2 == flagsR1) {
          inspector.clean(r2fname);
        } else {
          inspector.modified(r2fname);
        }
        cs.checkCancelled();
      } else {
        try {
          Path copyTarget = r2fname;
          Path copyOrigin = detectCopies ? getOriginIfCopy(repo, copyTarget, r2.nodeid(copyTarget), allBaseFiles, rev1) : null;
          if (copyOrigin != null) {
            inspector.copied(getPathPool().mangle(copyOrigin) /*pipe through pool, just in case*/, copyTarget);
          } else {
            inspector.added(copyTarget);
          }
        } catch (HgInvalidFileException ex) {
          // record exception to a mediator and continue,
          // for a single file not to be irresolvable obstacle for a status operation
          inspector.invalid(r2fname, ex);
        }
        cs.checkCancelled();
      }
    }
    for (Path r1fname : r1Files) {
      if (scope.accept(r1fname)) {
        inspector.removed(r1fname);
        cs.checkCancelled();
      }
    }
  }
View Full Code Here

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

  @Test
  public void testCatCommandCancelSupport() throws Exception {
    HgRepository repository = Configuration.get().find("branches-1"); // any repo
    final HgCatCommand cmd = new HgCatCommand(repository);
    cmd.file(Path.create("file1"));
    cmd.set(new CancelSupport() {
      int i = 0;
      public void checkCancelled() throws CancelledException {
        if (i++ == 2) {
          throw new CancelledException();
        }
View Full Code Here

TOP

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

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.