Package org.tmatesoft.hg.core

Examples of org.tmatesoft.hg.core.HgLogCommand


    final Dump dump = new Dump(hgRepo);
    dump.complete(cmdLineOpts.getBoolean("--debug"));
    dump.verbose(cmdLineOpts.getBoolean("-v", "--verbose"));
    final boolean reverseOrder = !cmdLineOpts.getBoolean("--hg4j-order-direct");
    dump.reversed(reverseOrder);
    HgLogCommand cmd = new HgLogCommand(hgRepo);
    for (String u : cmdLineOpts.getList("-u", "--user")) {
      cmd.user(u);
    }
    for (String b : cmdLineOpts.getList("-b", "--branches")) {
      cmd.branch(b);
    }
    int limit = cmdLineOpts.getSingleInt(-1, "-l", "--limit");
    if (limit != -1) {
      cmd.limit(limit);
    }
    cmd.set(noCancel).set(noProgress);
    List<String> files = cmdLineOpts.getList("");
    final long start = System.currentTimeMillis();
    if (files.isEmpty()) {
      if (limit == -1) {
        // no revisions and no limit
        cmd.execute(dump);
      } else {
        // in fact, external (to dump inspector) --limit processing yelds incorrect results when other args
        // e.g. -u or -b are used (i.e. with -u shall give <limit> csets with user, not check last <limit> csets for user
        int[] r = new int[] { 0, hgRepo.getChangelog().getRevisionCount() };
        if (fixRange(r, reverseOrder, limit) == 0) {
          System.out.println("No changes");
          return;
        }
        cmd.range(r[0], r[1]).execute(dump);
      }
      dump.done();
    } else {
      for (String fname : files) {
        HgDataFile f1 = hgRepo.getFileNode(fname);
        System.out.println("History of the file: " + f1.getPath());
        if (limit == -1) {
          cmd.file(f1.getPath(), true).execute(dump);
        } else {
          int[] r = new int[] { 0, f1.getRevisionCount() };
          if (fixRange(r, reverseOrder, limit) == 0) {
            System.out.println("No changes");
            continue;
          }
          cmd.range(r[0], r[1]).file(f1.getPath(), true).execute(dump);
        }
        dump.done();
      }
    }
//    cmd = null;
View Full Code Here


    System.out.println(hgRepo.getCommitLastMessage());
  }

  private void buildFileLog() throws Exception {
    final long start = System.nanoTime();
    HgLogCommand cmd = new HgLogCommand(hgRepo);
    cmd.file("a2.txt", true, false);
    final int[] count = new int[] { 0 };
    class MyHandler implements HgChangesetTreeHandler, Adaptable {
      public void treeElement(HgChangesetTreeHandler.TreeElement entry) throws HgRuntimeException {
        StringBuilder sb = new StringBuilder();
        HashSet<Nodeid> test = new HashSet<Nodeid>(entry.childRevisions());
        for (HgChangeset cc : entry.children()) {
          sb.append(cc.getRevisionIndex());
          sb.append(':');
          sb.append(cc.getNodeid().shortNotation());
          sb.append(", ");
        }
        final Pair<Nodeid, Nodeid> parents = entry.parentRevisions();
        final boolean isJoin = !parents.first().isNull() && !parents.second().isNull();
        final boolean isFork = entry.children().size() > 1;
        final HgChangeset cset = entry.changeset();
        System.out.printf("%d:%s - %s (%s)\n", cset.getRevisionIndex(), cset.getNodeid().shortNotation(), cset.getComment(), cset.getPhase());
        System.out.printf("\tKnown as %s (file rev:%s)\n", entry.file().getPath(), entry.fileRevision().shortNotation());
        if (!isJoin && !isFork && !entry.children().isEmpty()) {
          HgChangeset p1 = entry.parents().first();
          HgChangeset p2 = entry.parents().second();
          System.out.printf("\tp1:%d, p2:%d\n", p1 == null ? -1 : p1.getRevisionIndex(), p2 == null ? -1 : p2.getRevisionIndex());
          System.out.printf("\t=> %s\n", sb);
        }
        if (isJoin) {
          HgChangeset p1 = entry.parents().first();
          HgChangeset p2 = entry.parents().second();
          System.out.printf("\tjoin <= (%d:%s, %d:%s)", p1.getRevisionIndex(), p1.getNodeid().shortNotation(), p2.getRevisionIndex(), p2.getNodeid().shortNotation());
          if (isFork) {
            System.out.print(", ");
          }
        }
        if (isFork) {
          if (!isJoin) {
            System.out.print('\t');
          }
          System.out.printf("fork => [%s]", sb);
        }
        if (isJoin || isFork) {
          System.out.println();
        }
        count[0]++;
      }

      public <T> T getAdapter(Class<T> adapterClass) {
        if (adapterClass == HgFileRenameHandlerMixin.class) {
          // in fact, new instance is not very nice, however
          // getAdapter callers are supposed to understand the risk of new instance
          // and cache returned value
          // besides, stateless implementation of RenameDumpHandler
          // doesn't really care about few instances
          return adapterClass.cast(new Log.RenameDumpHandler());
        }
        return null;
      }
    };
    cmd.execute(new MyHandler());
    System.out.println(count[0]);
    final long end = System.nanoTime();
    System.out.printf("buildFileLog: %,d ms\n", (end-start)/1000);
  }
View Full Code Here

 
  private void testParents() throws Exception {
    // hg parents cmd
    final Pair<Nodeid, Nodeid> wcParents = hgRepo.getWorkingCopyParents();
    ChangesetDumpHandler dump = new ChangesetDumpHandler(hgRepo);
    HgLogCommand cmd = new HgLogCommand(hgRepo);
    if (wcParents.hasFirst()) {
      cmd.changeset(wcParents.first()).execute(dump);
    }
    if (wcParents.hasSecond()) {
      cmd.changeset(wcParents.second()).execute(dump);
    }
    System.out.println("Branch:" + hgRepo.getWorkingCopyBranchName());
  }
View Full Code Here

    cf.add(df, new ByteArrayDataSource("hello\nworld".getBytes()));
    Transaction tr = newTransaction(hgRepo);
    Nodeid secondRev = cf.commit("SECOND", tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(2, commits.size());
    HgChangeset c1 = commits.get(0);
    HgChangeset c2 = commits.get(1);
    errorCollector.assertEquals("FIRST", c1.getComment());
    errorCollector.assertEquals("SECOND", c2.getComment());
View Full Code Here

    String fname = "file1";
    RepoUtils.createFile(new File(repoLoc, fname), null);
    new ExecHelper(new OutputParser.Stub(), repoLoc).run("hg", "add", fname);
    //
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", 0, new HgLogCommand(hgRepo).execute().size());
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), NO_REVISION);
    HgDataFile df = hgRepo.getFileNode(fname);
    final byte[] initialContent = "hello\nworld".getBytes();
    cf.add(df, new ByteArrayDataSource(initialContent));
    String comment = "commit 1";
    Transaction tr = newTransaction(hgRepo);
    Nodeid c1Rev = cf.commit(comment,  tr);
    tr.commit();
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
    errorCollector.assertEquals(1, c1.getAffectedFiles().size());
    errorCollector.assertEquals(df.getPath(), c1.getAffectedFiles().get(0));
    errorCollector.assertEquals(0, c1.getRevisionIndex());
View Full Code Here

    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    HgChangeset parentCset = new HgLogCommand(hgRepo).range(parentCsetRevIndex, parentCsetRevIndex).execute().get(0);
    assertEquals("[sanity]", DEFAULT_BRANCH_NAME, parentCset.getBranch());
    assertEquals("[sanity]", DEFAULT_BRANCH_NAME, hgRepo.getWorkingCopyBranchName());
    //
    RepoUtils.modifyFileAppend(fileD, "A CHANGE\n");
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, fileD);
    cf.add(dfD, contentProvider);
    cf.branch("branch1");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev1 = cf.commit("FIRST",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
    errorCollector.assertEquals(c1.getNodeid(), commitRev1);
    errorCollector.assertEquals("branch1", c1.getBranch());
    errorCollector.assertEquals("FIRST", c1.getComment());
View Full Code Here

    cf.forget(hgRepo.getFileNode("d"));
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit with add/remove cmd",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).changeset(commitRev).execute();
    HgChangeset cmt = commits.get(0);
    errorCollector.assertEquals(1, cmt.getAddedFiles().size());
    errorCollector.assertEquals("xx", cmt.getAddedFiles().get(0).getPath().toString());
    errorCollector.assertEquals(1, cmt.getRemovedFiles().size());
    errorCollector.assertEquals("d", cmt.getRemovedFiles().get(0).toString());
View Full Code Here

    cf.add(dfD, contentProvider = new FileContentSupplier(hgRepo, fileD));
    cf.branch(DEFAULT_BRANCH_NAME);
    Nodeid commitRev3 = cf.commit("THIRD",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(3, commits.size());
    HgChangeset c1 = commits.get(0);
    HgChangeset c2 = commits.get(1);
    HgChangeset c3 = commits.get(2);
    errorCollector.assertEquals(c1.getNodeid(), commitRev1);
View Full Code Here

    Nodeid c2 = cmd.getCommittedRevision();
    //
    errorCollector.assertEquals("SECOND", hgRepo.getCommitLastMessage());
    //
    int lastRev = hgRepo.getChangelog().getLastRevision();
    List<HgChangeset> csets = new HgLogCommand(hgRepo).range(lastRev-1, lastRev).execute();
    errorCollector.assertEquals(csets.get(0).getNodeid(), c1);
    errorCollector.assertEquals(csets.get(1).getNodeid(), c2);
    errorCollector.assertEquals(csets.get(0).getComment(), "FIRST");
    errorCollector.assertEquals(csets.get(1).getComment(), "SECOND");
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc);
View Full Code Here

      repo = Configuration.get().own();
      eh.cwd(repo.getWorkingDir());
    }
    changelogParser.reset();
    eh.run("hg", "log", "--debug");
    List<HgChangeset> r = new HgLogCommand(repo).execute();
    report("hg log - COMPLETE REPO HISTORY", r, true);
   
    r = new HgLogCommand(repo).order(NewToOld).execute();
    report("hg log - COMPLETE REPO HISTORY, FROM NEW TO OLD", r, false);
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.core.HgLogCommand

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.