Package org.tmatesoft.hg.util

Examples of org.tmatesoft.hg.util.CancelSupport$Factory


   * @throws CancelledException if execution of the command was cancelled
   */
  public void execute() throws HgException, CancelledException {
    try {
      final ProgressSupport progress = getProgressSupport(null);
      final CancelSupport cancellation = getCancelSupport(null, true);
      cancellation.checkCancelled();
      progress.start(6);
      Internals internalRepo = Internals.getInstance(repo);
      if (cleanCheckout) {
        // remove tracked files from wd (perhaps, just forget 'Added'?)
        // for now, just delete each and every tracked file
        // TODO WorkingCopy container with getFile(HgDataFile/Path) to access files in WD
        HgDirstate dirstate = new HgInternals(repo).getDirstate();
        dirstate.walk(new HgDirstate.Inspector() {
         
          public boolean next(EntryKind kind, Record entry) {
            File f = new File(repo.getWorkingDir(), entry.name().toString());
            if (f.exists()) {
              f.delete();
            }
            return true;
          }
        });
      } else {
        throw new HgBadArgumentException("Sorry, only clean checkout is supported now, use #clean(true)", null);
      }
      progress.worked(1);
      cancellation.checkCancelled();
      final DirstateBuilder dirstateBuilder = new DirstateBuilder(internalRepo);
      final CheckoutWorker worker = new CheckoutWorker(internalRepo);
      HgManifest.Inspector insp = new HgManifest.Inspector() {
       
        public boolean next(Nodeid nid, Path fname, Flags flags) {
          if (worker.next(nid, fname, flags)) {
            // Mercurial seems to write "n   0  -1   unset fname" on `hg --clean co -rev <earlier rev>`
            // and the reason for 'force lookup' I suspect is a slight chance of simultaneous modification
            // of the file by user that doesn't alter its size the very second dirstate is being written
            // (or the file is being updated and the update brought in changes that didn't alter the file size -
            // with size and timestamp set, later `hg status` won't notice these changes)
           
            // However, as long as we use this class to write clean copies of the files, we can put all the fields
            // right away.
            int mtime = worker.getLastFileModificationTime();
            // Manifest flags are chars (despite octal values `hg manifest --debug` displays),
            // while dirstate keeps actual unix flags.
            int fmode = worker.getLastFileMode();
            dirstateBuilder.recordNormal(fname, fmode, mtime, worker.getLastFileSize());
            return true;
          }
          return false;
        }
       
        public boolean end(int manifestRevision) {
          return false;
        }
       
        public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
          return true;
        }
      };
      // checkout tip if no revision set
      final int coRevision = revisionToCheckout.get(HgRepository.TIP);
      dirstateBuilder.parents(repo.getChangelog().getRevision(coRevision), null);
      repo.getManifest().walk(coRevision, coRevision, insp);
      worker.checkFailed();
      progress.worked(3);
      cancellation.checkCancelled();
      File dirstateFile = internalRepo.getRepositoryFile(Dirstate);
      try {
        FileChannel dirstateFileChannel = new FileOutputStream(dirstateFile).getChannel();
        dirstateBuilder.serialize(dirstateFileChannel);
        dirstateFileChannel.close();
      } catch (IOException ex) {
        throw new HgIOException("Can't write down new directory state", ex, dirstateFile);
      }
      progress.worked(1);
      cancellation.checkCancelled();
      String branchName = repo.getChangelog().range(coRevision, coRevision).get(0).branch();
      assert branchName != null;
      File branchFile = internalRepo.getRepositoryFile(Branch);
      if (HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) {
        // clean actual branch, if any
View Full Code Here


   * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
   */
  public void workingCopy(ByteChannel sink) throws CancelledException, HgRuntimeException {
    File f = getRepo().getFile(this);
    if (f.exists()) {
      final CancelSupport cs = CancelSupport.Factory.get(sink);
      final ProgressSupport progress = ProgressSupport.Factory.get(sink);
      final long flength = f.length();
      final int bsize = (int) Math.min(flength, 32*1024);
      progress.start((int) (flength > Integer.MAX_VALUE ? flength >>> 15 /*32 kb buf size*/ : flength));
      ByteBuffer buf = ByteBuffer.allocate(bsize);
      FileInputStream fis = null;
      try {
        fis = new FileInputStream(f);
        FileChannel fc = fis.getChannel();
        while (fc.read(buf) != -1) {
          cs.checkCancelled();
          buf.flip();
          int consumed = sink.write(buf);
          progress.worked(flength > Integer.MAX_VALUE ? 1 : consumed);
          buf.compact();
        }
View Full Code Here

    final ProgressSupport progress = getProgressSupport(insp);
    progress.start(2);
    try {
      final int startRevIndex = clogRevIndexStart.get(0);
      final int endRevIndex = clogRevIndexEnd.get(TIP);
      final CancelSupport cancel = getCancelSupport(insp, true);
      int fileRevIndex1 = fileRevIndex(df, startRevIndex);
      int fileRevIndex2 = fileRevIndex(df, endRevIndex);
      BlameHelper bh = new BlameHelper(insp);
      bh.prepare(df, startRevIndex, endRevIndex);
      progress.worked(1);
      cancel.checkCancelled();
      bh.diff(fileRevIndex1, startRevIndex, fileRevIndex2, endRevIndex);
      progress.worked(1);
      cancel.checkCancelled();
    } catch (HgRuntimeException ex) {
      throw new HgLibraryFailureException(ex);
    } finally {
      progress.done();
    }
View Full Code Here

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

  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

    }
    if (firstCset < 0 || startRev > lastCset) {
      throw new HgBadArgumentException(String.format("Bad value %d for start revision for range [%1$d..%d]", startRev, lastCset), null);
    }
    final ProgressSupport progressHelper = getProgressSupport(handler);
    final CancelSupport cancelHelper = getCancelSupport(handler, true);
    final HgFileRenameHandlerMixin renameHandler = Adaptable.Factory.getAdapter(handler, HgFileRenameHandlerMixin.class, null);

    try {

      // XXX rename. dispatcher is not a proper name (most of the job done - managing history chunk interconnection)
      final HandlerDispatcher dispatcher = new HandlerDispatcher() {
 
        @Override
        protected void once(HistoryNode n) throws HgCallbackTargetException, CancelledException, HgRuntimeException {
          handler.treeElement(ei.init(n, currentFileNode));
          cancelHelper.checkCancelled();
        }
      };
 
      // renamed files in the queue are placed with respect to #iterateDirection
      // i.e. if we iterate from new to old, recent filenames come first
      FileRenameQueueBuilder frqBuilder = new FileRenameQueueBuilder();
      List<QueueElement> fileRenamesQueue = frqBuilder.buildFileRenamesQueue(firstCset, lastCset);
      // XXX perhaps, makes sense to look at selected file's revision when followAncestry is true
      // to ensure file we attempt to trace is in the WC's parent. Native hg aborts if not.
      progressHelper.start(4 * fileRenamesQueue.size());
      for (int namesIndex = 0, renamesQueueSize = fileRenamesQueue.size(); namesIndex < renamesQueueSize; namesIndex++) {
  
        final QueueElement renameInfo = fileRenamesQueue.get(namesIndex);
        dispatcher.prepare(progressHelper, renameInfo);
        cancelHelper.checkCancelled();
        if (namesIndex > 0) {
          dispatcher.connectWithLastJunctionPoint(renameInfo, fileRenamesQueue.get(namesIndex - 1));
        }
        if (namesIndex + 1 < renamesQueueSize) {
          // there's at least one more name we are going to look at
View Full Code Here

  }

  // shall not return null if create is true
  // CancelSupport from context, if any, takes precedence
  protected CancelSupport getCancelSupport(Object context, boolean create) {
    CancelSupport rv = CancelSupport.Factory.get(context, null);
    if (rv != null) {
      return rv;
    }
    if (cancelHelper != null) {
      return cancelHelper;
View Full Code Here

  public void execute() throws HgException, HgRepositoryLockException, CancelledException {
    final HgRepositoryLock wdLock = repo.getWorkingDirLock();
    wdLock.acquire();
    try {
      final ProgressSupport progress = getProgressSupport(null);
      final CancelSupport cancellation = getCancelSupport(null, true);
      cancellation.checkCancelled();
      progress.start(2 + toAdd.size() + toRemove.size());
      Internals implRepo = Internals.getInstance(repo);
      final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
      dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
      progress.worked(1);
      cancellation.checkCancelled();
      for (Path p : toAdd) {
        dirstateBuilder.recordAdded(p, Flags.RegularFile, -1);
        progress.worked(1);
        cancellation.checkCancelled();
      }
      for (Path p : toRemove) {
        dirstateBuilder.recordRemoved(p);
        progress.worked(1);
        cancellation.checkCancelled();
      }
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        dirstateBuilder.serialize(tr);
View Full Code Here

  public void execute() throws HgException, CancelledException {
    final HgRepositoryLock wdLock = repo.getWorkingDirLock();
    wdLock.acquire();
    try {
      final ProgressSupport progress = getProgressSupport(null);
      final CancelSupport cancellation = getCancelSupport(null, true);
      cancellation.checkCancelled();
      progress.start(files.size() + 2);
      final int csetRevision;
      if (changesetToCheckout.get() == HgRepository.WORKING_COPY) {
        csetRevision = repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first());
      } else {
        csetRevision = changesetToCheckout.get();
      }
      Internals implRepo = Internals.getInstance(repo);
      final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
      dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource()));
      progress.worked(1);
      cancellation.checkCancelled();
     
      final HgCheckoutCommand.CheckoutWorker worker = new HgCheckoutCommand.CheckoutWorker(implRepo);
     
      HgManifest.Inspector insp = new HgManifest.Inspector() {
       
        public boolean next(Nodeid nid, Path fname, Flags flags) {
          if (worker.next(nid, fname, flags)) {
            dirstateBuilder.recordUncertain(fname);
            return true;
          }
          return false;
        }
       
        public boolean end(int manifestRevision) {
          return false;
        }
       
        public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
          return true;
        }
      };

      for (Path file : files) {
        File f = new File(repo.getWorkingDir(), file.toString());
        if (f.isFile()) {
          if (keepOriginal) {
            File copy = new File(f.getParentFile(), f.getName() + ".orig");
            if (copy.exists()) {
              copy.delete();
            }
            f.renameTo(copy);
          } else {
            f.delete();
          }
        }
        repo.getManifest().walkFileRevisions(file, insp, csetRevision);
        worker.checkFailed();
        progress.worked(1);
        cancellation.checkCancelled();
      }
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        // TODO same code in HgAddRemoveCommand and similar in HgCommitCommand
View Full Code Here

TOP

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

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.