org.eclipse.jgit.revwalk.RevSort Java Examples

The following examples show how to use org.eclipse.jgit.revwalk.RevSort. 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: GitConnector.java    From compiler with Apache License 2.0 6 votes vote down vote up
public void countChangedFiles(List<String> commits, Map<String, Integer> counts) {
	RevWalk temprevwalk = new RevWalk(repository);
	try {
		revwalk.reset();
		Set<RevCommit> heads = getHeads();
		revwalk.markStart(heads);
		revwalk.sort(RevSort.TOPO, true);
		revwalk.sort(RevSort.COMMIT_TIME_DESC, true);
		revwalk.sort(RevSort.REVERSE, true);
		for (final RevCommit rc: revwalk) {
			final GitCommit gc = new GitCommit(this, repository, temprevwalk, projectName);
			System.out.println(rc.getName());
			commits.add(rc.getName());
			int count = gc.countChangedFiles(rc);
			counts.put(rc.getName(), count);
		}
	} catch (final IOException e) {
		if (debug)
			System.err.println("Git Error getting parsing HEAD commit for " + path + ". " + e.getMessage());
	} finally {
		temprevwalk.dispose();
		temprevwalk.close();
	}
}
 
Example #2
Source File: GitConnector.java    From compiler with Apache License 2.0 6 votes vote down vote up
public List<String> logCommitIds() {
	List<String> commits = new ArrayList<String>();
	RevWalk temprevwalk = new RevWalk(repository);
	try {
		revwalk.reset();
		Set<RevCommit> heads = getHeads();
		revwalk.markStart(heads);
		revwalk.sort(RevSort.TOPO, true);
		revwalk.sort(RevSort.COMMIT_TIME_DESC, true);
		revwalk.sort(RevSort.REVERSE, true);
		for (final RevCommit rc : revwalk)
			commits.add(rc.getName());
	} catch (final IOException e) {
		e.printStackTrace();
	} finally {
		temprevwalk.dispose();
		temprevwalk.close();
	}
	return commits;
}
 
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: DistanceCalculator.java    From jgitver with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<Integer> distanceTo(ObjectId target) {
    Objects.requireNonNull(target);
    try (RevWalk walk = new RevWalk(this.repository)) {
        RevCommit startCommit = walk.parseCommit(startId);
        walk.setRetainBody(false);
        walk.markStart(startCommit);
        walk.sort(RevSort.TOPO);

        System.out.printf("from %s :: %s\n", startId.name(), target.name());

        Iterator<? extends RevCommit> commitIterator = walk.iterator();
        int distance = 0;
        while (commitIterator.hasNext()) {
            RevCommit commit = commitIterator.next();

            System.out.printf("%d - %s\n", distance, commit.getId().name());
            if (commit.getId().getName().equals(target.getName())) {
                // we found it
                return Optional.of(distance);
            }

            distance++;

            if (distance > maxDepth) {
                return Optional.empty();
            }
        }
    } catch (Exception ignore) {
        ignore.printStackTrace();
    }

    return Optional.empty();
}
 
Example #5
Source File: AppraiseGitReviewClient.java    From git-appraise-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the review commit, which is the first commit on the review branch
 * after the merge base.
 */
public RevCommit getReviewCommit(String reviewBranch, String targetBranch)
    throws GitClientException {
  try (RevWalk walk = new RevWalk(repo)) {
    walk.markStart(walk.parseCommit(repo.resolve(reviewBranch)));
    walk.markUninteresting(walk.parseCommit(repo.resolve(targetBranch)));
    walk.sort(RevSort.REVERSE);
    return walk.next();
  } catch (Exception e) {
    throw new GitClientException(
        "Failed to get review commit for " + reviewBranch + " and " + targetBranch, e);
  }
}
 
Example #6
Source File: AbstractGitPersistenceResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private List<String> listTags(Git git) throws IOException, GitAPIException {
    List<String> tags = new ArrayList<>();
    for (Ref tag : git.tagList().call()) {
        RevWalk revWalk = new RevWalk(git.getRepository());
        revWalk.sort(RevSort.COMMIT_TIME_DESC, true);
        try {
            RevTag annotatedTag = revWalk.parseTag(tag.getObjectId());
            tags.add(annotatedTag.getTagName() + " : " + annotatedTag.getFullMessage());
        } catch (IncorrectObjectTypeException ex) {
            tags.add(tag.getName().substring("refs/tags/".length()));
        }
    }
    return tags;
}
 
Example #7
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;
}