Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.DirstateBuilder


    try {
      Pool<Nodeid> cacheRevs = new Pool<Nodeid>();
      Pool<Path> cacheFiles = new Pool<Path>();

      Internals implRepo = Internals.getInstance(repo);
      final DirstateBuilder dirstateBuilder = new DirstateBuilder(implRepo);
      dirstateBuilder.fillFrom(new DirstateReader(implRepo, new Path.SimpleSource(repo.getSessionContext().getPathFactory(), cacheFiles)));
      final HgChangelog clog = repo.getChangelog();
      final Nodeid headCset1 = clog.getRevision(firstCset);
      dirstateBuilder.parents(headCset1, clog.getRevision(secondCset));
      //
      MergeStateBuilder mergeStateBuilder = new MergeStateBuilder(implRepo);
      mergeStateBuilder.prepare(headCset1);

      ManifestRevision m1, m2, ma;
View Full Code Here


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

      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);
        tr.commit();
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgException ex) {
View Full Code Here

        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
        dirstateBuilder.serialize(tr);
        tr.commit();
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgException ex) {
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.DirstateBuilder

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.