Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.Internals$ImplAccess


  }
 
  @Test
  public void testAllSecretAndDraft() throws Exception {
    HgRepository repo = Configuration.get().find("test-phases");
    Internals implRepo = HgInternals.getImplementationRepo(repo);
    HgPhase[] expected = readPhases(repo);
    ArrayList<Nodeid> secret = new ArrayList<Nodeid>();
    ArrayList<Nodeid> draft = new ArrayList<Nodeid>();
    ArrayList<Nodeid> pub = new ArrayList<Nodeid>();
    for (int i = 0; i < expected.length; i++) {
View Full Code Here


    if (workingDir == null) {
      throw new IllegalArgumentException(repositoryRoot.toString());
    }
    repoLocation = repositoryPath;
    sessionContext = ctx;
    impl = new Internals(this, repositoryRoot, new Internals.ImplAccess() {
     
      public RevlogStream getStream(HgDataFile df) {
        return df.content;
      }
      public RevlogStream getManifestStream() {
View Full Code Here

            // flags modified, no need to do expensive content check
            inspector.modified(fname);
          } else {
            HgDataFile df = repo.getFileNode(fname);
            if (!df.exists()) {
              Internals implRepo = repo.getImplHelper();
              String msg = String.format("File %s known as normal in dirstate (%d, %d), doesn't exist at %s", fname, r.modificationTime(), r.size(), implRepo.getStoragePath(df));
              throw new HgInvalidFileException(msg, null).setFileName(fname);
            }
            Nodeid rev = getDirstateParentManifest().nodeid(fname);
            // rev might be null here if fname comes to dirstate as a result of a merge operation
            // where one of the parents (first parent) had no fname file, but second parent had.
View Full Code Here

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

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

    wdLock.acquire();
    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;
      m1 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, firstCset);
      m2 = new ManifestRevision(cacheRevs, cacheFiles).init(repo, secondCset);
      ma = new ManifestRevision(cacheRevs, cacheFiles).init(repo, ancestorCset);
      Transaction transaction = implRepo.getTransactionFactory().create(repo);
      ResolverImpl resolver = new ResolverImpl(implRepo, dirstateBuilder, mergeStateBuilder);
      try {
        for (Path f : m1.files()) {
          Nodeid fileRevBase, fileRevA, fileRevB;
          if (m2.contains(f)) {
View Full Code Here

    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
        if (branchFile.isFile()) {
          branchFile.delete();
        }
View Full Code Here

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

      // find out missing
      // TODO refactor same code in HgOutgoingCommand #getComparator and #getParentHelper
      final HgChangelog clog = repo.getChangelog();
      final HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(clog);
      parentHelper.init();
      final Internals implRepo = HgInternals.getImplementationRepo(repo);
      final PhasesHelper phaseHelper = new PhasesHelper(implRepo, parentHelper);
      final RepositoryComparator comparator = new RepositoryComparator(parentHelper, remoteRepo);
      comparator.compare(new ProgressSupport.Sub(progress, 50), getCancelSupport(null, true));
      List<Nodeid> l = comparator.getLocalOnlyRevisions();
      if (phaseHelper.isCapableOfPhases() && phaseHelper.withSecretRoots()) {
        RevisionSet secret = phaseHelper.allSecret();
        outgoing = new RevisionSet(l).subtract(secret);
      } else {
        outgoing = new RevisionSet(l);
      }
      HgBundle b = null;
      if (!outgoing.isEmpty()) {
        //
        // prepare bundle
        BundleGenerator bg = new BundleGenerator(implRepo);
        File bundleFile = bg.create(outgoing.asList());
        progress.worked(20);
        b = new HgLookup(repo.getSessionContext()).loadBundle(bundleFile);
        //
        // send changes
        remoteRepo.unbundle(b, comparator.getRemoteHeads());
      } // update phase information nevertheless
      progress.worked(20);
      //
      // update phase information
      if (phaseHelper.isCapableOfPhases()) {
        HgRemoteRepository.Phases remotePhases = remoteRepo.getPhases();
        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()));
            }
          }
        }
      }
      progress.worked(5);
View Full Code Here

      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
        dirstateBuilder.serialize(tr);
        tr.commit();
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.Internals$ImplAccess

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.