Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.PhasesHelper


  @Test
  public void testHelperNoParentChildMap() throws Exception {
    HgRepository repo = Configuration.get().find("test-phases");
    HgPhase[] expected = readPhases(repo);
    final long start = System.nanoTime();
    PhasesHelper ph = new PhasesHelper(HgInternals.getImplementationRepo(repo), null);
    initAndCheck(ph, expected);
    final long end = System.nanoTime();
    // μ == \u03bc
    System.out.printf("Without ParentWalker (simulates log command for single file): %,d μs\n", (end - start)/1000);
  }
View Full Code Here


    HgPhase[] expected = readPhases(repo);
    final long start1 = System.nanoTime();
    HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(repo.getChangelog());
    pw.init();
    final long start2 = System.nanoTime();
    PhasesHelper ph = new PhasesHelper(HgInternals.getImplementationRepo(repo), pw);
    initAndCheck(ph, expected);
    final long end = System.nanoTime();
    System.out.printf("With ParentWalker(simulates log command for whole repo): %,d μs (pw init: %,d ns)\n", (end - start1)/1000, start2 - start1);
  }
View Full Code Here

    final RevisionSet rsDraft = new RevisionSet(draft);
    assertFalse("[sanity]", rsSecret.isEmpty());
    assertFalse("[sanity]", rsDraft.isEmpty());
    HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(repo.getChangelog());
    pw.init();
    PhasesHelper ph1 = new PhasesHelper(implRepo, null);
    PhasesHelper ph2 = new PhasesHelper(implRepo, pw);
    RevisionSet s1 = ph1.allSecret().symmetricDifference(rsSecret);
    RevisionSet s2 = ph2.allSecret().symmetricDifference(rsSecret);
    errorCollector.assertTrue("Secret,no ParentChildMap:" + s1.toString(), s1.isEmpty());
    errorCollector.assertTrue("Secret, with ParentChildMap:" + s2.toString(), s2.isEmpty());
    RevisionSet s3 = ph1.allDraft().symmetricDifference(rsDraft);
    RevisionSet s4 = ph2.allDraft().symmetricDifference(rsDraft);
    errorCollector.assertTrue("Draft,no ParentChildMap:" + s3.toString(), s3.isEmpty());
    errorCollector.assertTrue("Draft, with ParentChildMap:" + s4.toString(), s4.isEmpty());
  }
View Full Code Here

  private List<Nodeid> getOutgoingRevisions(ProgressSupport ps, CancelSupport cs) throws HgRemoteConnectionException, HgException, CancelledException {
    ps.start(10);
    final RepositoryComparator c = getComparator(new ProgressSupport.Sub(ps, 5), cs);
    List<Nodeid> local = c.getLocalOnlyRevisions();
    ps.worked(3);
    PhasesHelper phaseHelper = new PhasesHelper(Internals.getInstance(localRepo));
    if (phaseHelper.isCapableOfPhases() && phaseHelper.withSecretRoots()) {
      local = new RevisionSet(local).subtract(phaseHelper.allSecret()).asList();
    }
    ps.worked(2);
    return local;
  }
View Full Code Here

    File dstRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-pull-pub-dst");
    File f1 = new File(dstRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    final HgLookup hgLookup = new HgLookup();
    HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
    PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
    //
    // new child revision for shared public parent
    assertEquals(HgPhase.Public, phaseHelper.getPhase(4, null));
    new HgCheckoutCommand(dstRepo).changeset(4).clean(true).execute();
    RepoUtils.modifyFileAppend(f1, "// aaa");
    HgCommitCommand commitCmd = new HgCommitCommand(dstRepo).message("Commit 1");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt1 = commitCmd.getCommittedRevision();
    //
    // new child rev for parent locally draft, remotely public
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(5, null));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(7, null));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(8, null));
    new HgCheckoutCommand(dstRepo).changeset(8).clean(true).execute();
    RepoUtils.modifyFileAppend(f1, "// bbb");
    commitCmd = new HgCommitCommand(dstRepo).message("Commit 2");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt2 = commitCmd.getCommittedRevision();
    // both new revisions shall be draft
    phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo)); // refresh PhasesHelper
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt1), cmt1));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt2), cmt2));
    //

    HgServer server = new HgServer().publishing(true).start(srcRepoLoc);
    try {
      final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
      new HgPullCommand(dstRepo).source(srcRemote).execute();
    } finally {
      server.stop();
    }
    // refresh PhasesHelper
    phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
    errorCollector.assertEquals(HgPhase.Public, phaseHelper.getPhase(5, null));
    errorCollector.assertEquals(HgPhase.Public, phaseHelper.getPhase(7, null));
    errorCollector.assertEquals(HgPhase.Public, phaseHelper.getPhase(8, null));
    // phase of local-only new revisions shall not change
    errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt1), cmt1));
    errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt2), cmt2));
  }
View Full Code Here

      final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
      new HgPullCommand(dstRepo).source(srcRemote).execute();
    } finally {
      server.stop();
    }
    PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
    errorCollector.assertEquals(HgPhase.Public, phaseHelper.getPhase(4, null));
    errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(5, null));
    errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(r7), r7));
    errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(r8), r8));
    final RevisionSet dstSecret = phaseHelper.allSecret();
    errorCollector.assertTrue(dstSecret.toString(), dstSecret.isEmpty());
  }
View Full Code Here

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

      // XXX would be handy to obtain ProgressSupport (perhaps, from statusHelper?)
      // and pass it to #init(), so that  there could be indication of file being read and cache being built
      synchronized (shared) {
        // ensure field is initialized only once
        if (shared.phaseHelper == null) {
          shared.phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(getRepo()), shared.parentHelper);
        }
      }
    }
    return shared.phaseHelper.getPhase(this);
  }
View Full Code Here

    HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      final RevisionSet allDraft = phaseHelper.allDraft();
      assertFalse("[sanity]", allDraft.isEmpty());
      final int publicCsetToBranchAt = 4;
      assertEquals("[sanity]", HgPhase.Public, phaseHelper.getPhase(publicCsetToBranchAt, null));
      // in addition to existing draft csets, add one more draft, branching at some other public revision
      new HgCheckoutCommand(srcRepo).changeset(publicCsetToBranchAt).clean(true).execute();
      RepoUtils.modifyFileAppend(f1, "// aaa");
      final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit aaa");
      assertTrue(commitCmd.execute().isOk());
      Nodeid newCommit = commitCmd.getCommittedRevision();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog srcClog = srcRepo.getChangelog();
      final HgChangelog dstClog = dstRepo.getChangelog();
      // refresh PhasesHelper
      phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      // check if phase didn't change
      errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(srcClog.getRevisionIndex(newCommit), newCommit));
      for (Nodeid n : allDraft) {
        // check drafts from src were actually pushed to dst
        errorCollector.assertTrue(dstClog.isKnown(n));
        // check drafts didn't change their phase
        errorCollector.assertEquals(HgPhase.Draft, phaseHelper.getPhase(srcClog.getRevisionIndex(n), n));
      }
    } finally {
      server.stop();
    }
  }
View Full Code Here

    final HgLookup hgLookup = new HgLookup();
    final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
    final ExecHelper dstRun = new ExecHelper(new OutputParser.Stub(), dstRepoLoc);
    final int publicCsetToBranchAt = 4;
    final int r5 = 5, r6 = 6, r8 = 8;
    PhasesHelper srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
    assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r5, null));
    assertEquals("[sanity]", HgPhase.Secret, srcPhase.getPhase(r6, null));
    assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r8, null));
    // change phases in repository of remote server:
    dstRun.exec("hg", "phase", "--public", String.valueOf(r5));
    assertEquals(0, dstRun.getExitValue());
    dstRun.exec("hg", "phase", "--draft", String.valueOf(r6));
    assertEquals(0, dstRun.getExitValue());
    dstRun.exec("hg", "phase", "--secret", "--force", String.valueOf(r8));
    assertEquals(0, dstRun.getExitValue());
    HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
    try {
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      // commit new draft head
      new HgCheckoutCommand(srcRepo).changeset(publicCsetToBranchAt).clean(true).execute();
      RepoUtils.modifyFileAppend(f1, "// aaa");
      final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit aaa");
      assertTrue(commitCmd.execute().isOk());
      final Nodeid newCommit = commitCmd.getCommittedRevision();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      // refresh phase information
      srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      // r5 and r6 are changed to match server phases (more exposed)
      errorCollector.assertEquals(HgPhase.Public, srcPhase.getPhase(r5, null));
      errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r6, null));
      // r8 is secret on server, locally can't make it less exposed though
      errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r8, null));
      //
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog dstClog = dstRepo.getChangelog();
      assertTrue(dstClog.isKnown(newCommit));
      PhasesHelper dstPhase = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
      errorCollector.assertEquals(HgPhase.Draft, dstPhase.getPhase(dstClog.getRevisionIndex(newCommit), newCommit));
      // the one that was secret is draft now
      errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r8, null));
    } finally {
      server.stop();
    }
View Full Code Here

TOP

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

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.