Java Code Examples for org.eclipse.jgit.revwalk.RevCommit#getId()
The following examples show how to use
org.eclipse.jgit.revwalk.RevCommit#getId() .
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: CommitUtil.java From SZZUnleashed with MIT License | 6 votes |
/** * Parse the lines a commit recently made changes to compared to its parent. * * @param revc the current revision. * @return a commit object containing all differences. */ public Commit getCommitDiffingLines(RevCommit revc, RevCommit... revother) throws IOException, GitAPIException { if (revc.getId() == revc.zeroId()) return null; RevCommit parent = null; if (revother.length > 0) parent = revother[0]; else if (revc.getParents().length > 0) parent = revc.getParent(0); else parent = revc; if (parent.getId() == ObjectId.zeroId()) return null; List<DiffEntry> diffEntries = diffRevisions(parent, revc); Commit commit = new Commit(revc); for (DiffEntry entry : diffEntries) { DiffLines changedLines = diffFile(entry); commit.diffWithParent.put(entry.getNewPath(), changedLines); commit.changeTypes.put(entry.getNewPath(), entry.getChangeType()); } return commit; }
Example 2
Source File: GitVersionCalculatorImpl.java From jgitver with Apache License 2.0 | 6 votes |
private Commit deepestReachableCommit(ObjectId headId, int maxDepth) throws IOException { try (RevWalk revWalk = new RevWalk(repository)) { RevCommit headCommit = repository.parseCommit(headId); revWalk.markStart(headCommit); int depth = 0; RevCommit lastCommit = headCommit; Iterator<RevCommit> iterator = revWalk.iterator(); while (iterator.hasNext() && depth <= maxDepth) { lastCommit = iterator.next(); depth++; } int retainedDepth = depth - 1; // we do not count head return new Commit(lastCommit.getId(), retainedDepth, Collections.emptyList(), Collections.emptyList()); } }
Example 3
Source File: GitVersionCalculatorImpl.java From jgitver with Apache License 2.0 | 6 votes |
/** * Filters the given list of tags based on their reachability starting from the given commit. * It returns a new non null List. */ private List<Ref> filterReachableTags(ObjectId headId, List<Ref> allVersionTags) throws IOException { List<Ref> filtered = new ArrayList<>(); try (RevWalk walk = new RevWalk(repository)) { walk.markStart(walk.parseCommit(headId)); for (RevCommit revCommit : walk) { ObjectId commitId = revCommit.getId(); Predicate<Ref> tagCorresponds = r -> commitId.getName().equals(refToObjectIdFunction.apply(r).getName()); allVersionTags.stream().filter(tagCorresponds).forEach(filtered::add); } } return filtered; }
Example 4
Source File: JGitAPIImpl.java From git-client-plugin with MIT License | 6 votes |
/** {@inheritDoc} */ @Deprecated @Override public ObjectId mergeBase(ObjectId id1, ObjectId id2) throws InterruptedException { try (Repository repo = getRepository(); ObjectReader or = repo.newObjectReader(); RevWalk walk = new RevWalk(or)) { walk.setRetainBody(false); // we don't need the body for this computation walk.setRevFilter(RevFilter.MERGE_BASE); walk.markStart(walk.parseCommit(id1)); walk.markStart(walk.parseCommit(id2)); RevCommit base = walk.next(); if (base==null) return null; // no common base return base.getId(); } catch (IOException e) { throw new GitException(e); } }
Example 5
Source File: Tags.java From gradle-gitsemver with Apache License 2.0 | 5 votes |
private static TagAndVersion findLatestTopoTag(Repository repo, Map<ObjectId, Set<String>> allTags, String prefix) throws MissingObjectException, IncorrectObjectTypeException, IOException { try { RevWalk walk = new RevWalk(repo); walk.markStart(walk.parseCommit(GitRepos.getHeadObjectId(repo))); for (RevCommit commit : walk) { ObjectId commitId = commit.getId(); // Find the very first tag in history if (allTags.containsKey(commitId)) { List<TagAndVersion> foundTags = new LinkedList<TagAndVersion>(); // If there are more than one tag for this commit, choose the lexographically superior one for (String tagName : allTags.get(commitId)) { String tagVersion = GitRepos.stripVFromVersionString(tagName); if (prefix == null) { foundTags.add(new TagAndVersion(tagName, SemanticVersions.parse(tagVersion))); } else { foundTags.add(new TagAndVersion(tagName, SemanticVersions.parse(prefix, tagVersion))); } } Collections.sort(foundTags); return foundTags.get(foundTags.size() - 1); } } // No tags found - return null return null; } catch (NullPointerException e) { return new TagAndVersion("0.0.0", new DefaultSemanticVersion( "0.0.0", 0, 0, 0, null, null)); } }
Example 6
Source File: Tags.java From gradle-gitsemver with Apache License 2.0 | 5 votes |
private static List<TagAndVersion> findAllTagsOnWalk(RevWalk walk, Map<ObjectId, Set<String>> tags, String prefix) { List<TagAndVersion> foundTags = new LinkedList<TagAndVersion>(); for (RevCommit commit : walk) { ObjectId commitId = commit.getId(); if (tags.containsKey(commitId)) { addTagsToListForCommitId(foundTags, tags, commitId, prefix); } } return foundTags; }