Java Code Examples for org.eclipse.jgit.revwalk.RevWalk#next()

The following examples show how to use org.eclipse.jgit.revwalk.RevWalk#next() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetCommonAncestorCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private GitRevisionInfo getSingleBaseCommit (RevWalk walk, List<RevCommit> commits) throws IOException {
    while (commits.size() > 1) {
        walk.reset();
        for (RevCommit c : commits) {
            walk.markStart(walk.parseCommit(c));
        }
        walk.setRevFilter(RevFilter.MERGE_BASE);
        commits.clear();
        for (RevCommit commit = walk.next(); commit != null; commit = walk.next()) {
            commits.add(commit);
        }
    }
    if (commits.isEmpty()) {
        return null;
    } else {
        return getClassFactory().createRevisionInfo(commits.get(0), getRepository());
    }
}
 
Example 2
Source File: JGitOperator.java    From verigreen with Apache License 2.0 6 votes vote down vote up
boolean isRefBehind( Ref behind, Ref tracking ) throws IOException {
  RevWalk walk = new RevWalk( _git.getRepository() );
  try {
    RevCommit behindCommit = walk.parseCommit( behind.getObjectId() );
    RevCommit trackingCommit = walk.parseCommit( tracking.getObjectId() );
    walk.setRevFilter( RevFilter.MERGE_BASE );
    walk.markStart( behindCommit );
    walk.markStart( trackingCommit );
    RevCommit mergeBase = walk.next();
    walk.reset();
    walk.setRevFilter( RevFilter.ALL );
    int aheadCount = RevWalkUtils.count( walk, behindCommit, mergeBase );
    int behindCount = RevWalkUtils.count( walk, trackingCommit, mergeBase );
    
    return behindCount > aheadCount ? true:false;
  } catch (Throwable e) {
         throw new RuntimeException(String.format(
                 "Failed to check if [%s] behind [%s]",
                 behind,
                 tracking), e);
     } 
  finally {
    walk.dispose();
  }
}
 
Example 3
Source File: Git.java    From OpenSZZ-Cloud-Native with GNU General Public License v3.0 5 votes vote down vote up
/**
  * Get Commit that changed the file before the parameter commit
  * @param sha
  * @param file
  * @return
  */
 public String getPreviousCommit (String sha, String file, PrintWriter l){
  if (sha.equals("a8da84c614ba6e6e87c6c91e0c426ddfec2766a2"))
	  System.out.println();
  File  localRepo1 = new File(workingDirectory+"");
  Iterable<RevCommit> iterable;
  String finalSha = "";
  RevCommit latestCommit = null;
  String path = file;
  try {
	org.eclipse.jgit.api.Git git = org.eclipse.jgit.api.Git.open(localRepo1);
	RevWalk revWalk = new RevWalk( git.getRepository() );
    RevCommit revCommit = getCommit(sha, null);
    revWalk.markStart( revCommit );
    revWalk.sort( RevSort.COMMIT_TIME_DESC );
    revWalk.setTreeFilter( AndTreeFilter.create( PathFilter.create( path ), TreeFilter.ANY_DIFF ) );
    latestCommit = revWalk.next();
    while (!latestCommit.getName().equals(sha))
    	latestCommit = revWalk.next();
    latestCommit = revWalk.next();
    if (latestCommit == null)
    	return null;
    finalSha =  latestCommit.getName();

  } catch (Exception e) {
	 l.println("No Predecessor-Commits found for "+sha +"for file " + file);
	return null;
}
  return finalSha;
 }
 
Example 4
Source File: DifferentFiles.java    From gitflow-incremental-builder with MIT License 5 votes vote down vote up
private RevCommit getMergeBase(RevCommit baseCommit, RevCommit referenceHeadCommit) throws IOException {
    RevWalk walk = new RevWalk(git.getRepository());
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(walk.lookupCommit(baseCommit));
    walk.markStart(walk.lookupCommit(referenceHeadCommit));
    RevCommit commit = walk.next();
    walk.close();
    logger.info("Using merge base of id: " + commit.getId());
    return commit;
}
 
Example 5
Source File: AppraiseGitReviewClient.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the merge base for the two given commits.
 * Danger -- the commits need to be from the given RevWalk or this will
 * fail in a not-completely-obvious way.
 */
private RevCommit getMergeBase(RevWalk walk, RevCommit commit1, RevCommit commit2)
    throws GitClientException {
  try {
    walk.setRevFilter(RevFilter.MERGE_BASE);
    walk.markStart(commit1);
    walk.markStart(commit2);
    return walk.next();
  } catch (Exception e) {
    throw new GitClientException(
        "Failed to get merge base commit for " + commit1 + " and " + commit2, e);
  }
}
 
Example 6
Source File: Tags.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
private static int getCountBetweenCommits(Repository repo,
                                          ObjectId headObjectId,
                                          ObjectId lastTagObjectId)
        throws MissingObjectException, IncorrectObjectTypeException, IOException {
    RevWalk walk = new RevWalk(repo);
    RevCommit startingPoint = walk.parseCommit(headObjectId);
    walk.markStart(startingPoint);
    RevCommit end = walk.lookupCommit(lastTagObjectId);
    walk.sort(RevSort.TOPO);
    int commitCount = 0;
    for (RevCommit c = walk.next(); nonNullOrEnd(end, c); c = walk.next()) {
        commitCount++;
    }
    return commitCount;
}