Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgRepository


    assertEquals("9cb6ad32b9074021356c38050e2aab6addba4393", b5.getHeads().get(0).toString());
  }

  @Test
  public void testBranchInfoClosedHeads() throws Exception{
    HgRepository repo = Configuration.get().find("branches-1");
    HgBranches branches = repo.getBranches();
    // branch1 - two closed heads
    BranchInfo b1 = branches.getBranch("branch1");
    assertTrue(b1.isClosed(b1.getHeads().get(0)));
    assertTrue(b1.isClosed(b1.getHeads().get(1)));
    try {
View Full Code Here


 

  // revision == 2406  -   5 ms per run (baseRevision == 2406)
  // revision == 2405  -  69 ms per run (baseRevision == 1403)
  public void measurePatchAffectsArbitraryRevisionRead() throws Exception {
    final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
    final DoNothingManifestInspector insp = new DoNothingManifestInspector();
    final int revision = 2405;
    // warm-up.
    repository.getManifest().walk(revision, revision, insp);
    final int runs = 10;
    final long start = System.nanoTime();
    for (int i = 0; i < runs; i++) {
      repository.getManifest().walk(revision, revision, insp);
    }
    final long end = System.nanoTime();
    System.out.printf("%d ms per run\n", (end - start)/ (runs*1000000));
  }
 
View Full Code Here

   * Approach 1: total 309, init: 6, iteration: 302
   * Approach 2: total 213, init: 63, iteration: 150
   * Approach 3: total 140
    */
  private void buildFile2ChangelogRevisionMap(String... fileNames) throws Exception {
    final HgRepository repository = new HgLookup().detect(new File("/home/artem/hg/cpython"));
    final HgChangelog clog = repository.getChangelog();
    // warm-up
    HgRevisionMap<HgChangelog> clogMap = new HgRevisionMap<HgChangelog>(clog).init();

    for (String fname : fileNames) {
      HgDataFile fileNode = repository.getFileNode(fname);
      // warm-up
      HgRevisionMap<HgDataFile> fileMap = new HgRevisionMap<HgDataFile>(fileNode).init();
      //
      final int latestRevision = fileNode.getLastRevision();
      //
View Full Code Here

   * each 1000'th revision, total 71 revision: 1 230 vs 270
   * each 2000'th revision, total 36 revision: 620 vs 270
   * each 3000'th revision, total 24 revision: 410 vs 275
   */
  public void revisionMap() throws Exception {
    final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
    final HgChangelog clog = repository.getChangelog();
    ArrayList<Nodeid> revisions = new ArrayList<Nodeid>();
    final int step = 5000;
    for (int i = 0, top = clog.getLastRevision(); i < top; i += step) {
      revisions.add(clog.getRevision(i));
    }
View Full Code Here

    }
    System.out.printf("RevisionMap time: %d ms, of that init() %,d ns\n", (System.nanoTime() - s2) / 1000000, s3 - s2);
  }

  public void changelogWalk() throws Exception {
    final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
    final long start = System.currentTimeMillis();
    repository.getChangelog().all(new HgChangelog.Inspector() {
      public int xx = 0;
     
      public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
        if (xx+revisionNumber < 0) {
          System.out.println(xx);
View Full Code Here

  }

  public void manifestWalk() throws Exception {
    System.out.println(System.getProperty("java.version"));
    final long start = System.currentTimeMillis();
    final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
    repository.getManifest().walk(0, 10000, new DoNothingManifestInspector());
    // cpython: 1,1 sec for 0..1000, 43 sec for 0..10000, 115 sec for 0..20000 (Pool with HashMap)
    // 2,4 sec for 1000..2000
    // cpython -r 1000: 484 files, -r 2000: 1015 files. Iteration 1000..2000; fnamePool.size:1019 nodeidPool.size:2989
    // nodeidPool for two subsequent revisions only: 840. 37 sec for 0..10000. 99 sec for 0..20k
    // 0..10000 fnamePool: hits:15989152, misses:3020
View Full Code Here

    return tagLocalRevs;
  }

  public void collectTagsPerFile() throws HgException, CancelledException, HgRuntimeException {
    final long start = System.currentTimeMillis();
    final HgRepository repository = new HgLookup().detect(new File("/home/artem/hg/cpython"));
    final HgTags tags = repository.getTags();
    //
    // build cache
    //
    final TagInfo[] allTags = new TagInfo[tags.getAllTags().size()];
    tags.getAllTags().values().toArray(allTags);
    // effective translation of changeset revisions to their local indexes
    final HgRevisionMap<HgChangelog> clogrmap = new HgRevisionMap<HgChangelog>(repository.getChangelog()).init();
    // map to look up tag by changeset local number
    final IntMap<List<TagInfo>> tagLocalRev2TagInfo = new IntMap<List<TagInfo>>(allTags.length);
    System.out.printf("Collecting manifests for %d tags\n", allTags.length);
    final int[] tagLocalRevs = collectLocalTagRevisions(clogrmap, allTags, tagLocalRev2TagInfo);
    System.out.printf("Prepared %d tag revisions to analyze: %d ms\n", tagLocalRevs.length, System.currentTimeMillis() - start);
View Full Code Here

  }
   
  // Approach 1. Build map with all files, their revisions and corresponding tags
  //
  private void collectTagsPerFile_Approach_1(final HgRevisionMap<HgChangelog> clogrmap, final int[] tagLocalRevs, final TagInfo[] allTags, Path targetPath) throws HgException, IllegalArgumentException, HgRuntimeException {
    HgRepository repository = clogrmap.getRepo();
    final long start = System.currentTimeMillis();
    // file2rev2tag value is array of revisions, always of allTags.length. Revision index in the array
    // is index of corresponding TagInfo in allTags;
    final Map<Path, Nodeid[]> file2rev2tag = new HashMap<Path, Nodeid[]>();
    repository.getManifest().walk(new HgManifest.Inspector() {
      private int[] tagIndexAtRev = new int[4]; // it's unlikely there would be a lot of tags associated with a given cset

      public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
        // may do better here using tagLocalRev2TagInfo, but need to change a lot, too lazy now
        Nodeid cset = clogrmap.revision(changelogRevision);
        Arrays.fill(tagIndexAtRev, -1);
        for (int i = 0, x = 0; i < allTags.length; i++) {
          if (cset.equals(allTags[i].revision())) {
            tagIndexAtRev[x++] = i;
            if (x == tagIndexAtRev.length) {
              // expand twice as much
              int[] expanded = new int[x << 1];
              System.arraycopy(tagIndexAtRev, 0, expanded, 0, x);
              expanded[x] = -1; // just in case there'd be no more tags associated with this cset
              tagIndexAtRev = expanded;
            }
          }
        }
        if (tagIndexAtRev[0] == -1) {
          System.out.println("Can't happen, provided we iterate over revisions with tags only");
        }
        return true;
      }

      public boolean next(Nodeid nid, Path fname, HgManifest.Flags flags) {
        Nodeid[] m = file2rev2tag.get(fname);
        if (m == null) {
          file2rev2tag.put(fname, m = new Nodeid[allTags.length]);
        }
        for (int tagIndex : tagIndexAtRev) {
          if (tagIndex == -1) {
            break;
          }
          if (m[tagIndex] != null) {
            System.out.printf("There's another revision (%s) associated with tag %s already while we try to associate %s\n", m[tagIndex].shortNotation(), allTags[tagIndex].name(), nid.shortNotation());
          }
          m[tagIndex] = nid;
        }
        return true;
      }
     
      public boolean end(int manifestRevision) {
        return true;
      }
     
    }, tagLocalRevs);
    System.out.printf("Cache built: %d ms\n", System.currentTimeMillis() - start);
    //
    // look up specific file. This part is fast.
    HgDataFile fileNode = repository.getFileNode(targetPath);
    final Nodeid[] allTagsOfTheFile = file2rev2tag.get(targetPath);
    // TODO if fileNode.isCopy, repeat for each getCopySourceName()
    for (int fileRevIndex = 0; fileRevIndex < fileNode.getRevisionCount(); fileRevIndex++) {
      Nodeid fileRev = fileNode.getRevision(fileRevIndex);
      int changesetRevIndex = fileNode.getChangesetRevisionIndex(fileRevIndex);
View Full Code Here

      return true;
    }
  }
 
  public static void main2(String[] args) throws HgCallbackTargetException, HgException, CancelledException, HgRuntimeException {
    final HgRepository repository = new HgLookup().detect(new File("/temp/hg/cpython"));
    final Path targetPath = Path.create("README");
    final HgTags tags = repository.getTags();
    final Map<String, HgTags.TagInfo> tagToInfo = tags.getAllTags();
    final HgManifest manifest = repository.getManifest();
    final Map<Nodeid, List<String>> changeSetRevisionToTags = new HashMap<Nodeid, List<String>>();
    final HgDataFile fileNode = repository.getFileNode(targetPath);
    for (String tagName : tagToInfo.keySet()) {
      final HgTags.TagInfo info = tagToInfo.get(tagName);
      final Nodeid nodeId = info.revision();
      // TODO: This is not correct as we can't be sure that file at the corresponding revision is actually our target file (which may have been renamed, etc.)
      final Nodeid fileRevision = manifest.getFileRevision(repository.getChangelog().getRevisionIndex(nodeId), targetPath);
      if (fileRevision == null) {
        continue;
      }

      final Nodeid changeSetRevision = fileNode.getChangesetRevision(fileRevision);
View Full Code Here

  @Rule
  public ErrorCollectorExt errorCollector = new ErrorCollectorExt();

  @Test
  public void testCreateBundle() throws Exception {
    final HgRepository hgRepo = Configuration.get().own();
    BundleGenerator bg = new BundleGenerator(HgInternals.getImplementationRepo(hgRepo));
    ArrayList<Nodeid> l = new ArrayList<Nodeid>();
    l.add(Nodeid.fromAscii("9ef1fab9f5e3d51d70941121dc27410e28069c2d")); // 640
    l.add(Nodeid.fromAscii("2f33f102a8fa59274a27ebbe1c2903cecac6c5d5")); // 639
    l.add(Nodeid.fromAscii("d074971287478f69ab0a64176ce2284d8c1e91c3")); // 638
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.