Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgDataFile


 
  private void collectTagsPerFile_Approach_2(HgRepository repository, final int[] tagLocalRevs, final IntMap<List<TagInfo>> tagRevIndex2TagInfo, Path targetPath) throws HgException, HgRuntimeException {
    //
    // Approach 2. No all-file map. Collect file revisions recorded at the time of tagging,
    // then for each file revision check if it is among those above, and if yes, take corresponding tags
    HgDataFile fileNode = repository.getFileNode(targetPath);
    final long start2 = System.nanoTime();
    final Map<Integer, Nodeid> fileRevisionAtTagRevision = new HashMap<Integer, Nodeid>();
    final Map<Nodeid, List<String>> fileRev2TagNames = new HashMap<Nodeid, List<String>>();
    HgManifest.Inspector collectFileRevAtCset = new HgManifest.Inspector() {
     
      private int csetRevIndex;

      public boolean next(Nodeid nid, Path fname, Flags flags) {
        fileRevisionAtTagRevision.put(csetRevIndex, nid);
        if (tagRevIndex2TagInfo.containsKey(csetRevIndex)) {
          List<String> tags = fileRev2TagNames.get(nid);
          if (tags == null) {
            fileRev2TagNames.put(nid, tags = new ArrayList<String>(3));
          }
          for (TagInfo ti : tagRevIndex2TagInfo.get(csetRevIndex)) {
            tags.add(ti.name());
          }
        }
        return true;
      }
     
      public boolean end(int manifestRevision) {
        return true;
      }
     
      public boolean begin(int mainfestRevision, Nodeid nid, int changelogRevision) {
        csetRevIndex = changelogRevision;
        return true;
      }
    };
    repository.getManifest().walkFileRevisions(targetPath, collectFileRevAtCset,tagLocalRevs);
   
    final long start2a = System.nanoTime();
    fileNode.indexWalk(0, TIP, new HgDataFile.RevisionInspector() {

      public void next(int fileRevisionIndex, Nodeid fileRevision, int changesetRevisionIndex) {
        List<String> associatedTags = new LinkedList<String>();
       
        for (int taggedRevision : tagLocalRevs) {
          // current file revision can't appear in tags that point to earlier changelog revisions (they got own file revision)
          if (taggedRevision >= changesetRevisionIndex) {
            // z points to some changeset with tag
            Nodeid wasKnownAs = fileRevisionAtTagRevision.get(taggedRevision);
            if (wasKnownAs.equals(fileRevision)) {
              // has tag associated with changeset at index z
              List<TagInfo> tagsAtRev = tagRevIndex2TagInfo.get(taggedRevision);
              assert tagsAtRev != null;
              for (TagInfo ti : tagsAtRev) {
                associatedTags.add(ti.name());
              }
            }
          }
        }
        //
        System.out.printf("%3d%7d%s\n", fileRevisionIndex, changesetRevisionIndex, associatedTags);
      }
    });
    for (int i = 0, lastRev = fileNode.getLastRevision(); i <= lastRev; i++) {
      Nodeid fileRevision = fileNode.getRevision(i);
      List<String> associatedTags2 = fileRev2TagNames.get(fileRevision);
      int changesetRevIndex = fileNode.getChangesetRevisionIndex(i);
      System.out.printf("%3d%7d%s\n", i, changesetRevIndex, associatedTags2 == null ? Collections.emptyList() : associatedTags2);
    }
    System.out.printf("Alternative total time: %d ms, of that init: %d ms\n", (System.nanoTime() - start2)/1000000, (start2a-start2)/1000000);
    System.out.printf("Free mem: %,d\n", Runtime.getRuntime().freeMemory());
  }
View Full Code Here


    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);
      List<String> revisionTags = changeSetRevisionToTags.get(changeSetRevision);
      if (revisionTags == null) {
        revisionTags = new ArrayList<String>();
        changeSetRevisionToTags.put(changeSetRevision, revisionTags);
      }
View Full Code Here

TOP

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

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.