示例#1
0
  // find commits that are (only?) in each remote
  private void getCommitsInR(RevWalk walk, boolean only)
      throws MissingObjectException, IncorrectObjectTypeException, IOException {

    Iterator<BranchRef> brIt;
    LinkedHashMap<String, ArrayList<Commit>> commits;
    ArrayList<RevCommit> comm;
    ArrayList<RevCommit> included = new ArrayList<RevCommit>();
    ArrayList<RevCommit> excluded = new ArrayList<RevCommit>();
    Entry<String, ArrayList<BranchRef>> er;
    String r;
    Commit c;
    ArrayList<Commit> newcos;
    Iterator<Entry<String, ArrayList<BranchRef>>> erit;
    Iterator<String> sit = branches.keySet().iterator();
    commits = new LinkedHashMap<String, ArrayList<Commit>>(branches.size() / 2, 1);
    if (only) excluded.ensureCapacity(allBranches.size() - 1);
    //  int j = 0;
    while (sit.hasNext()) {
        /**/
      // System.err.println("###### Iteration " + (++j));
      r = sit.next();
      erit = branches.entrySet().iterator();
      while (erit.hasNext()) {
        er = erit.next();
        brIt = er.getValue().iterator();
        if (er.getKey().equals(r)) {
          while (brIt.hasNext()) {
            GitWorks.addUnique(included, walk.parseCommit(brIt.next().id));
          }
        } else if (only) {
          while (brIt.hasNext()) {
            GitWorks.addUnique(excluded, walk.parseCommit(brIt.next().id));
          }
        }
      }
      comm = findCommits(walk, included, excluded, false, 0);
      if (comm != null) {
        newcos = new ArrayList<Commit>(comm.size());
        for (int i = 0; i < comm.size(); i++) {
          c = GitWorks.getElement(allCommits, comm.get(i));
          newcos.add(c);
        }
        commits.put(r, newcos);
      }
      included.clear();
      excluded.clear();
      walk.reset();
    }
    included.trimToSize();
    included.ensureCapacity(50);
    excluded.trimToSize();
    excluded.ensureCapacity(50);

    if (only) comOnlyInF = commits.isEmpty() ? null : commits;
    else comInF = commits.isEmpty() ? null : commits;
  }
示例#2
0
  // printout all commit messages in a given range -> use and reset an existing RevWalk
  private void printCommits(String outFile, RevWalk walk)
      throws IOException, NoHeadException, GitAPIException {

    PrintWriter pout = new PrintWriter(new FileWriter(outFile), true);
    RevCommit c = walk.next();
    while (c != null && !c.has(RevFlag.UNINTERESTING)) {
      pout.println(printCommit(c));
      c = walk.next();
    }
    walk.reset();
    pout.close();
  }
示例#3
0
  @NotNull
  public SortedSet<RevCommit> calculate(@NotNull String branchName, @Nullable RevFilter revFilter)
      throws IOException {
    Ref head = myRepository.getRef(branchName);

    if (head == null) {
      throw new IllegalArgumentException("Branch does not exist: [branchName: " + branchName + "]");
    }

    myRevWalk.markStart(myRevWalk.parseCommit(head.getObjectId()));
    myRevWalk.setRevFilter(revFilter);

    SortedSet<RevCommit> roots = new TreeSet<>(REV_COMMIT_COMPARATOR);

    for (RevCommit commit : myRevWalk) {
      roots.add(commit);
    }

    myRevWalk.reset();
    myRevWalk.dispose();

    return roots;
  }
示例#4
0
文件: Merger.java 项目: abayer/jgit
  /**
   * Create an iterator to walk the merge base of two commits.
   *
   * @param aIdx index of the first commit in {@link #sourceObjects}.
   * @param bIdx index of the second commit in {@link #sourceObjects}.
   * @return the new iterator
   * @throws IncorrectObjectTypeException one of the input objects is not a commit.
   * @throws IOException objects are missing or multiple merge bases were found.
   */
  protected AbstractTreeIterator mergeBase(final int aIdx, final int bIdx) throws IOException {
    if (sourceCommits[aIdx] == null)
      throw new IncorrectObjectTypeException(sourceObjects[aIdx], Constants.TYPE_COMMIT);
    if (sourceCommits[bIdx] == null)
      throw new IncorrectObjectTypeException(sourceObjects[bIdx], Constants.TYPE_COMMIT);

    walk.reset();
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(sourceCommits[aIdx]);
    walk.markStart(sourceCommits[bIdx]);
    final RevCommit base = walk.next();
    if (base == null) return new EmptyTreeIterator();
    final RevCommit base2 = walk.next();
    if (base2 != null) {
      throw new IOException(
          MessageFormat.format(
              JGitText.get().multipleMergeBasesFor,
              sourceCommits[aIdx].name(),
              sourceCommits[bIdx].name(),
              base.name(),
              base2.name()));
    }
    return openTree(base.getTree());
  }
示例#5
0
  // fast but resource-demanding
  // find commits that are (uniquely?) in a branch
  // used to build the allCommits and allAuthors arrays as well
  private void getCommitsInB(RevWalk walk, boolean only)
      throws MissingObjectException, IncorrectObjectTypeException, IOException {

    int c;
    BranchRef b;
    Iterator<BranchRef> brIt;
    LinkedHashMap<Commit, ArrayList<Commit>> commits;
    Commit newco, co;
    Person newpe;
    ArrayList<Commit> newcos;
    ArrayList<RevCommit> comm;

    ArrayList<RevCommit> included = new ArrayList<RevCommit>();
    ArrayList<RevCommit> excluded = new ArrayList<RevCommit>();

    ArrayList<BranchRef> temp = new ArrayList<BranchRef>();
    if (only) {
      temp.ensureCapacity(allBranches.size() - 1);
      excluded.ensureCapacity(allBranches.size() - 1);
    } else if (allCommits.size() > 0) {
      System.err.println(
          "GitMIner ( "
              + name
              + " -- "
              + id
              + " ) ERROR : the allCommits array has already been built!");
      return;
    }
    commits =
        only
            ? new LinkedHashMap<Commit, ArrayList<Commit>>()
            : new LinkedHashMap<Commit, ArrayList<Commit>>(allBranches.size(), 1);
    for (int i = 0; i < allBranches.size(); i++) {
      b = allBranches.get(i); /**/ // System.err.println("###### Iteration " + (i+1));
      if (commits.containsKey(b.id)) {
        commits.get(b.id).get(0).addHead(b);
        continue;
      }
      if (only) {
        temp.clear();
        if (i > 0) temp.addAll(allBranches.subList(0, i));
        temp.addAll(allBranches.subList(i + 1, allBranches.size()));
        brIt = temp.iterator();
        while (brIt.hasNext()) {
          GitWorks.addUnique(excluded, walk.parseCommit(brIt.next().id));
        }
      }
      GitWorks.addUnique(included, walk.parseCommit(b.id));
      comm = findCommits(walk, included, excluded, !only, 0);
      if (comm != null) { // if only == false this is always true
        newcos = new ArrayList<Commit>(comm.size());
        for (int j = 0; j < comm.size(); j++) {
          if (!only) {
            newco = new Commit(comm.get(j)); // this RevCommit has a buffer -> populate allCommits
            c = GitWorks.addUnique(allCommits, newco);
            co = allCommits.get(c);
            co.addBranch(b);
            if (j == 0) {
              co.addHead(b);
            }
            newpe = new Person(co.getAuthoringInfo());
            GitWorks.addUnique(allAuthors, newpe);
          } else { // this RevCommit has no buffer
            co = GitWorks.getElement(allCommits, comm.get(j));
          }
          newcos.add(co);
        }
        commits.put(newcos.get(0), newcos);
      }
      included.clear();
      excluded.clear();
      walk.reset();
    }
    included.trimToSize();
    included.ensureCapacity(50);
    excluded.trimToSize();
    excluded.ensureCapacity(50);

    if (only) comOnlyInB = commits.isEmpty() ? null : commits;
    else comInB = commits;
  }