Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgRepository


    }
  }

  @Test
  public void testRevlogInspectors() throws Exception { // TODO move to better place
    HgRepository repository = Configuration.get().find("branches-1"); // any repo
    repository.getChangelog().indexWalk(0, TIP, new HgChangelog.RevisionInspector() {

      public void next(int localRevision, Nodeid revision, int linkedRevision) {
        Assert.assertEquals(localRevision, linkedRevision);
      }
    });
    final HgDataFile fileNode = repository.getFileNode("file1");
    fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() {
      int i = 0;

      public void next(int localRevision, Nodeid revision, int linkedRevision) throws HgRuntimeException {
        assertEquals(i++, localRevision);
View Full Code Here


   * Revlog.indexWalk implementation defect, aka:
   * Issue 31: Revlog#walk doesn't handle ParentInspector correctly with start revision other than 0, fails with AIOOBE
   */
  @Test
  public void testRevisionDescendants() throws Exception {
    HgRepository hgRepo = Configuration.get().find("branches-1");
    int[] roots = new int[] {0, 1, 2, 3, 4, 5};
    // 0: all revisions are descendants, 17 total.
    // 1: 2, 4, 7, 8, 9
    // 2: 7, 8, 9
    // 3: 5,6, 10-16
    // 4: no children
    // 5: 6, 10-16
    // array values represent bit mask, '1' for revision that shall re reported as descendant
    // least significant bit is revision 0, and so on, so that 1<<revision points to bit in the bitmask
    int[] descendantBitset = new int[] { 0x01FFFF, 0x0396, 0x0384, 0x01FC68, 0x010, 0x01FC60 };
    RevisionDescendants[] result = new RevisionDescendants[roots.length];
    for (int i = 0; i < roots.length; i++) {
      result[i] = new RevisionDescendants(hgRepo, roots[i]);
      result[i].build();
    }
    /*
    for (int i = 0; i < roots.length; i++) {
      System.out.printf("For root %d descendats are:", roots[i]);
      for (int j = roots[i], x = hgRepo.getChangelog().getLastRevision(); j <= x; j++) {
        if (result[i].isDescendant(j)) {
          System.out.printf("%3d ", j);
        }
      }
      System.out.printf(", isEmpty:%b\n", !result[i].hasDescendants());
    }
    */
    for (int i = 0; i < roots.length; i++) {
//      System.out.printf("%s & %s = 0x%x\n", toBinaryString(descendantBitset[i]), toBinaryString(~(1<<roots[i])), descendantBitset[i] & ~(1<<roots[i]));
      if ((descendantBitset[i] & ~(1<<roots[i])) != 0) {
        assertTrue(result[i].hasDescendants());
      } else {
        assertFalse(result[i].hasDescendants());
      }
      for (int j = roots[i], x = hgRepo.getChangelog().getLastRevision(); j <= x; j++) {
        int bit = 1<<j;
        boolean shallBeDescendant = (descendantBitset[i] & bit) != 0;
        String m = String.format("Check rev %d from root %d. Bit %s in %s, shallBeDescendant:%b", j, roots[i], toBinaryString(bit), toBinaryString(descendantBitset[i]), shallBeDescendant);
        if (result[i].isDescendant(j)) {
          assertTrue(m, shallBeDescendant);
View Full Code Here

  @Rule
  public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
 
  @Test
  public void testMediator() throws Exception {
    HgRepository repo = Configuration.get().find("merge-1");
    Assert.assertEquals("[sanity]", repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first()), 1);

    HgMergeCommand cmd = new HgMergeCommand(repo);

    MergeNotificationCollector c;
    // (fastForward(file1, file2, file3) changes, newInB(file5), same(file4))
View Full Code Here

 
  @Test
  public void testResolver() throws Exception {
    File repoLoc1 = RepoUtils.copyRepoToTempLocation("merge-1", "test-merge-no-conflicts");
    File repoLoc2 = RepoUtils.copyRepoToTempLocation("merge-1", "test-merge-with-conflicts");
    HgRepository repo = new HgLookup().detect(repoLoc1);
    Assert.assertEquals("[sanity]", repo.getChangelog().getRevisionIndex(repo.getWorkingCopyParents().first()), 1);

    HgMergeCommand cmd = new HgMergeCommand(repo);
    cmd.changeset(2).execute(new HgMergeCommand.MediatorBase() {
     
      public void resolve(HgFileRevision base, HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
        errorCollector.fail("There's no conflict in changesets 1 and 2 merge");
      }
    });
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc1);
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(repo).all().execute(status);
    final List<Path> clean = status.get(Kind.Clean);
    final List<Path> modified = status.get(Kind.Modified);
    Collections.sort(clean);
    Collections.sort(modified);
    errorCollector.assertEquals(new Path[] {create("file1"), create("file3"), create("file4")}, clean.toArray());
    errorCollector.assertEquals(new Path[] {create("file2"), create("file5")}, modified.toArray());
    repo = new HgLookup().detect(repoLoc2);
    cmd = new HgMergeCommand(repo);
    cmd.changeset(3).execute(new HgMergeCommand.MediatorBase());
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc2);
    new HgStatusCommand(repo).all().execute(status = new TestStatus.StatusCollector());
    errorCollector.assertEquals(1, status.get(Kind.Modified).size());
    errorCollector.assertEquals(create("file1"), status.get(Kind.Modified).get(0));
    final HgMergeState ms = repo.getMergeState();
    ms.refresh();
    errorCollector.assertTrue(ms.isMerging());
    errorCollector.assertFalse(ms.isStale());
    errorCollector.assertFalse(ms.getStateParent().isNull());
    errorCollector.assertEquals(1, ms.getConflicts().size());
View Full Code Here

  private LineSequence getBaseRevisionLines(int clogRevIndex, int[] fileParentClogRevs) {
    assert fileParentClogRevs[0] >= 0;
    assert fileParentClogRevs[1] >= 0;
    HgDataFile targetFile = linesCache.getFile(clogRevIndex);
    final HgRepository repo = targetFile.getRepo();
    if (clogMap == null) {
      // FIXME replace HgParentChildMap with revlog.indexWalk(AncestorIterator))
      clogMap = new HgParentChildMap<HgChangelog>(repo.getChangelog());
      clogMap.init();
    }
    final HgRevisionMap<HgChangelog> m = clogMap.getRevisionMap();
    Nodeid ancestor = clogMap.ancestor(m.revision(fileParentClogRevs[0]), m.revision(fileParentClogRevs[1]));
    final int ancestorRevIndex = m.revisionIndex(ancestor);
    Nodeid fr = repo.getManifest().getFileRevision(ancestorRevIndex, targetFile.getPath());
    if (fr == null) {
      return LineSequence.newlines(new byte[0]);
    }
    return linesCache.lines(ancestorRevIndex, targetFile.getRevisionIndex(fr));
  }
View Full Code Here

  @Test
  public void testRefreshOnChange() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-refresh-hgignore", false);
    File hgignoreFile = new File(repoLoc, HgRepositoryFiles.HgIgnore.getPath());
    RepoUtils.createFile(hgignoreFile, "bin/");
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    final Path p1 = Path.create("bin/a/b/c");
    final Path p2 = Path.create("src/a/b/c");
    HgIgnore ignore = hgRepo.getIgnore();
    errorCollector.assertTrue(ignore.isIgnored(p1));
    errorCollector.assertFalse(ignore.isIgnored(p2));
    Thread.sleep(1000); // Linux granularity for modification time is 1 second
    // file of the same length
    RepoUtils.createFile(hgignoreFile, "src/");
    ignore = hgRepo.getIgnore();
    errorCollector.assertFalse(ignore.isIgnored(p1));
    errorCollector.assertTrue(ignore.isIgnored(p2));
   
  }
View Full Code Here

    File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-push2empty-src", false);
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push2empty-dst");
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      HgPushCommand cmd = new HgPushCommand(srcRepo);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      cmd.destination(dstRemote);
      cmd.execute();
      final HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      checkRepositoriesAreSame(srcRepo, dstRepo);
      final List<Nodeid> outgoing = new HgOutgoingCommand(srcRepo).against(dstRemote).executeLite();
      errorCollector.assertTrue(outgoing.toString(), outgoing.isEmpty());
    } finally {
      server.stop();
View Full Code Here

    File f1 = new File(srcRepoLoc, "file1");
    assertTrue("[sanity]", f1.canWrite());
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      RepoUtils.modifyFileAppend(f1, "change1");
      new HgCommitCommand(srcRepo).message("Commit 1").execute();
      new HgCheckoutCommand(srcRepo).changeset(7).clean(true).execute();
      assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName());
      RepoUtils.modifyFileAppend(f1, "change2");
      new HgCommitCommand(srcRepo).message("Commit 2").execute();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      checkRepositoriesAreSame(srcRepo, hgLookup.detect(dstRepoLoc));
View Full Code Here

    File f1 = new File(srcRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    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) {
View Full Code Here

    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-phase-update-1-src");
    File dstRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-phase-update-1-dst");
    File f1 = new File(srcRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    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));
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.