Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgRepository


    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-pull-pub-src");
    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


    // copy, not clone as latter updates phase information
    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-pull-nopub-src");
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-pull-nopub-dst");
    Map<String,?> props = Collections.singletonMap(Internals.CFG_PROPERTY_CREATE_PHASEROOTS, true);
    final HgLookup hgLookup = new HgLookup(new BasicSessionContext(props, null));
    HgRepository srcRepo = hgLookup.detect(srcRepoLoc);   
    // revisions 6 and 9 are secret, so
    // index of revisions 4 and 5 won't change, but that of 7 and 8 would
    Nodeid r7 = srcRepo.getChangelog().getRevision(7);
    Nodeid r8 = srcRepo.getChangelog().getRevision(8);

    HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
    HgServer server = new HgServer().publishing(false).start(srcRepoLoc);
    try {
      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

*/
public class TestMqExtension {

  @Test
  public void testMqManager() throws Exception {
    HgRepository repo = Configuration.get().find("test-mq");
    HgExtensionsManager extManager = repo.getExtensions();
    assertTrue(extManager.isEnabled(HgExt.MQ));
    MqManager mqManager = extManager.getMQ();
    mqManager.refresh();
    OutputParser.Stub output = new OutputParser.Stub();
    ExecHelper eh = new ExecHelper(output, repo.getWorkingDir());
    // `hg qseries`
    eh.run("hg", "qseries");
    LinkedList<PatchRecord> allKnownPatches = new LinkedList<PatchRecord>(mqManager.getAllKnownPatches());
    assertTrue("[sanity]", allKnownPatches.size() > 0);
    for (CharSequence l : output.lines()) {
View Full Code Here

  public void testSimple() throws Exception {
    int x = 0;
    HgLookup lookup = new HgLookup();
    for (HgRemoteRepository hgRemote : Configuration.get().allRemote()) {
      File dest = RepoUtils.initEmptyTempRepo("test-incoming-" + x++);
      HgRepository localRepo = lookup.detect(dest);
      // Idea:
      // hg in, hg4j in, compare
      // hg pull total/2
      // hg in, hg4j in, compare
      List<Nodeid> incoming = runAndCompareIncoming(localRepo, hgRemote);
View Full Code Here

  @Rule
  public ErrorCollectorExt errorCollector = new ErrorCollectorExt();

  @Test
  public void testFileRenameHistory() throws HgException {
    HgRepository repo = Configuration.get().find("log-renames");
    // history of files from their TIP perspective
    // series of (fname, fileRefStart, fileRevEnd, csetStart, csetEnd), new to old
    Object[] historyA = new Object[] {"a", 2, 2, 5, 5, "c", 0, 1, 2, 4, "b", 0, 1, 0, 1};
    Object[] historyB = new Object[] {"b", 2, 3, 3, 4, "a", 0, 1, 0, 2 };
    Object[] historyC = new Object[] {"c", 0, 1, 2, 4, "b", 0, 1, 0, 1 };
    Object[] historyD = new Object[] {"d", 1, 1, 5, 5, "b", 2, 3, 3, 4, "a", 0, 1, 0, 2};
   
    FileRenameHistory frh = new FileRenameHistory(0, 5);
    for (Object[] history : new Object[][] {historyA, historyB, historyC, historyD}) {
      String fname = history[0].toString();
      HgDataFile df = repo.getFileNode(fname);
      Assert.assertFalse(frh.isOutOfRange(df, df.getLastRevision()));
      frh.build(df, df.getLastRevision());
      int recordIndex = 0;
      errorCollector.assertEquals(history.length / 5, frh.chunks());
      for (Chunk c : frh.iterate(HgIterateDirection.NewToOld)) {
        compareChunk(fname, c, history, recordIndex++);
      }
      errorCollector.assertEquals("Shall compare full history", history.length, recordIndex * 5);
    }
    //
    HgDataFile df = repo.getFileNode("d");
    Assert.assertFalse(frh.isOutOfRange(df, 0));
    frh.build(df, 0);
    errorCollector.assertEquals(1, frh.chunks());
    Chunk c = frh.iterate(NewToOld).iterator().next();
    compareChunk("abandoned d(0)", c, new Object[] { "d", 0, 0, 4, 4 }, 0);
    //
    df = repo.getFileNode("a");
    Assert.assertFalse(frh.isOutOfRange(df, 0));
    frh.build(df, 0);
    errorCollector.assertEquals(1, frh.chunks());
    c = frh.iterate(NewToOld).iterator().next();
    compareChunk("a(0) and boundary checks", c, new Object[] { "a", 0, 0, 0, 0 }, 0);
    //
    repo = Configuration.get().find("test-annotate"); // need a long file history
    df = repo.getFileNode("file1");
    Assert.assertTrue("[sanity]", repo.getChangelog().getLastRevision() >=9);
    Assert.assertTrue("[sanity]", df.exists() && df.getLastRevision() >= 9);
    frh = new FileRenameHistory(0, 9);
    frh.build(df, 9);
    errorCollector.assertEquals(1, frh.chunks());
    c = frh.iterate(NewToOld).iterator().next();
View Full Code Here

    return lookup.detectFromWorkingDir();
  }

  // fails if repo not found
  public HgRepository find(String key) throws HgException {
    HgRepository rv = lookup.detect(new File(getRoot(), key));
    assertNotNull(rv);
    assertFalse(rv.isInvalid());
    return rv;
  }
View Full Code Here

      shared.statusHelper.change(revNumber, r);
    } catch (CancelledException ex) {
      // Record can't cancel
      throw new HgInvalidStateException("Internal error");
    }
    final HgRepository repo = getRepo();
    for (Path s : r.getModified()) {
      Nodeid nid = r.nodeidAfterChange(s);
      if (nid == null) {
        throw new HgInvalidStateException(String.format("For the file %s recorded as modified in changeset %d couldn't find revision after change", s, revNumber));
      }
View Full Code Here

    }
  }

  @Test
  public void testChangelogCancelSupport() throws Exception {
    HgRepository repository = Configuration.get().find("branches-1"); // any repo with more revisions
    class InspectorImplementsCancel extends CancelAtValue implements HgChangelog.Inspector, CancelSupport {

      public InspectorImplementsCancel(int limit) {
        super(limit);
      }
     
      public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
        nextValue(revisionNumber);
      }

      public void checkCancelled() throws CancelledException {
        cancelImpl.checkCancelled();
      }
    };
    class InspectorImplementsAdaptable extends CancelAtValue implements HgChangelog.Inspector, Adaptable {
      public InspectorImplementsAdaptable(int limit) {
        super(limit);
      }
     
      public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
        nextValue(revisionNumber);
      }

      public <T> T getAdapter(Class<T> adapterClass) {
        if (CancelSupport.class == adapterClass) {
          return adapterClass.cast(cancelImpl);
        }
        return null;
      }
    }
    //
    InspectorImplementsCancel insp1;
    repository.getChangelog().all(insp1= new InspectorImplementsCancel(2));
    Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
    repository.getChangelog().all(insp1 = new InspectorImplementsCancel(12));
    Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
    //
    InspectorImplementsAdaptable insp2;
    repository.getChangelog().all(insp2= new InspectorImplementsAdaptable(3));
    Assert.assertEquals(insp2.stopValue, insp2.lastSeen);
    repository.getChangelog().all(insp2 = new InspectorImplementsAdaptable(10));
    Assert.assertEquals(insp2.stopValue, insp2.lastSeen);
  }
View Full Code Here

    Assert.assertEquals(insp2.stopValue, insp2.lastSeen);
  }
 
  @Test
  public void testManifestCancelSupport() throws Exception {
    HgRepository repository = Configuration.get().find("branches-1"); // any repo with as many revisions as possible
    class InspectorImplementsAdaptable extends CancelAtValue implements HgManifest.Inspector, Adaptable {
      public InspectorImplementsAdaptable(int limit) {
        super(limit);
      }

      public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
        nextValue(lastSeen+1);
        return true;
      }

      public boolean end(int manifestRevision) {
        return true;
      }

      public <T> T getAdapter(Class<T> adapterClass) {
        if (CancelSupport.class == adapterClass) {
          return adapterClass.cast(cancelImpl);
        }
        return null;
      }

      public boolean next(Nodeid nid, Path fname, Flags flags) {
        return true;
      }
    }
    InspectorImplementsAdaptable insp1;
    repository.getManifest().walk(0, TIP, insp1= new InspectorImplementsAdaptable(3));
    Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
    repository.getManifest().walk(0, TIP, insp1 = new InspectorImplementsAdaptable(10));
    Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
  }
View Full Code Here

    Assert.assertEquals(insp1.stopValue, insp1.lastSeen);
  }
 
  @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 {
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.repo.HgRepository

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.