List of usage examples for org.eclipse.jgit.revwalk RevWalk isMergedInto
public boolean isMergedInto(RevCommit base, RevCommit tip) throws MissingObjectException, IncorrectObjectTypeException, IOException
From source file:com.gitblit.utils.JGitUtils.java
License:Apache License
/** * Returns true if the commit identified by commitId is an ancestor or the * the commit identified by tipId.//from ww w . j a va2 s . co m * * @param repository * @param commitId * @param tipId * @return true if there is the commit is an ancestor of the tip */ public static boolean isMergedInto(Repository repository, ObjectId commitId, ObjectId tipCommitId) { // traverse the revlog looking for a commit chain between the endpoints RevWalk rw = new RevWalk(repository); try { // must re-lookup RevCommits to workaround undocumented RevWalk bug RevCommit tip = rw.lookupCommit(tipCommitId); RevCommit commit = rw.lookupCommit(commitId); return rw.isMergedInto(commit, tip); } catch (Exception e) { LOGGER.error("Failed to determine isMergedInto", e); } finally { rw.dispose(); } return false; }
From source file:com.google.gerrit.httpd.rpc.changedetail.IncludedInDetailFactory.java
License:Apache License
private List<String> includedIn(final Repository repo, final RevWalk rw, final RevCommit rev, final String namespace) throws IOException, MissingObjectException, IncorrectObjectTypeException { final List<String> result = new ArrayList<String>(); for (final Ref ref : repo.getRefDatabase().getRefs(namespace).values()) { final RevCommit tip; try {//from w ww .ja v a 2s . co m tip = rw.parseCommit(ref.getObjectId()); } catch (IncorrectObjectTypeException notCommit) { // Its OK for a tag reference to point to a blob or a tree, this // is common in the Linux kernel or git.git repository. // continue; } catch (MissingObjectException notHere) { // Log the problem with this branch, but keep processing. // log.warn("Reference " + ref.getName() + " in " + repo.getDirectory() + " points to dangling object " + ref.getObjectId()); continue; } if (rw.isMergedInto(rev, tip)) { result.add(ref.getName().substring(namespace.length())); } } return result; }
From source file:com.google.gerrit.server.change.DeleteChangeOp.java
License:Apache License
private boolean isPatchSetMerged(ChangeContext ctx, PatchSet patchSet) throws IOException { Optional<ObjectId> destId = ctx.getRepoView().getRef(ctx.getChange().getDest().get()); if (!destId.isPresent()) { return false; }//from ww w . ja v a 2s . c om RevWalk revWalk = ctx.getRevWalk(); ObjectId objectId = ObjectId.fromString(patchSet.getRevision().get()); return revWalk.isMergedInto(revWalk.parseCommit(objectId), revWalk.parseCommit(destId.get())); }
From source file:com.google.gerrit.server.change.Rebase.java
License:Apache License
private boolean isMergedInto(RevWalk rw, PatchSet base, PatchSet tip) throws IOException { ObjectId baseId = ObjectId.fromString(base.getRevision().get()); ObjectId tipId = ObjectId.fromString(tip.getRevision().get()); return rw.isMergedInto(rw.parseCommit(baseId), rw.parseCommit(tipId)); }
From source file:com.google.gerrit.server.git.MergeUtil.java
License:Apache License
public CodeReviewCommit getFirstFastForward(final CodeReviewCommit mergeTip, final RevWalk rw, final List<CodeReviewCommit> toMerge) throws MergeException { for (final Iterator<CodeReviewCommit> i = toMerge.iterator(); i.hasNext();) { try {//from w w w . j a v a2s . c o m final CodeReviewCommit n = i.next(); if (mergeTip == null || rw.isMergedInto(mergeTip, n)) { i.remove(); return n; } } catch (IOException e) { throw new MergeException("Cannot fast-forward test during merge", e); } } return mergeTip; }
From source file:com.google.gerrit.server.git.ReceiveCommits.java
License:Apache License
private boolean isMergedInto(final RevCommit commit, final Ref ref) throws IOException { final RevWalk rw = rp.getRevWalk(); return rw.isMergedInto(commit, rw.parseCommit(ref.getObjectId())); }
From source file:com.google.gerrit.server.git.ReplaceOp.java
License:Apache License
private static boolean isMergedInto(RevWalk rw, RevCommit commit, Ref ref) throws IOException { return rw.isMergedInto(commit, rw.parseCommit(ref.getObjectId())); }
From source file:com.google.gerrit.server.git.TagSet.java
License:Apache License
void prepare(TagMatcher m) { @SuppressWarnings("resource") RevWalk rw = null;/*from w w w . j a v a 2 s. c o m*/ try { for (Ref currentRef : m.include) { if (currentRef.isSymbolic()) { continue; } if (currentRef.getObjectId() == null) { continue; } CachedRef savedRef = refs.get(currentRef.getName()); if (savedRef == null) { // If the reference isn't known to the set, return null // and force the caller to rebuild the set in a new copy. m.newRefs.add(currentRef); continue; } // The reference has not been moved. It can be used as-is. ObjectId savedObjectId = savedRef.get(); if (currentRef.getObjectId().equals(savedObjectId)) { m.mask.set(savedRef.flag); continue; } // Check on-the-fly to see if the branch still reaches the tag. // This is very likely for a branch that fast-forwarded. try { if (rw == null) { rw = new RevWalk(m.db); rw.setRetainBody(false); } RevCommit savedCommit = rw.parseCommit(savedObjectId); RevCommit currentCommit = rw.parseCommit(currentRef.getObjectId()); if (rw.isMergedInto(savedCommit, currentCommit)) { // Fast-forward. Safely update the reference in-place. savedRef.compareAndSet(savedObjectId, currentRef.getObjectId()); m.mask.set(savedRef.flag); continue; } // The branch rewound. Walk the list of commits removed from // the reference. If any matches to a tag, this has to be removed. boolean err = false; rw.reset(); rw.markStart(savedCommit); rw.markUninteresting(currentCommit); rw.sort(RevSort.TOPO, true); RevCommit c; while ((c = rw.next()) != null) { Tag tag = tags.get(c); if (tag != null && tag.refFlags.get(savedRef.flag)) { m.lostRefs.add(new TagMatcher.LostRef(tag, savedRef.flag)); err = true; } } if (!err) { // All of the tags are still reachable. Update in-place. savedRef.compareAndSet(savedObjectId, currentRef.getObjectId()); m.mask.set(savedRef.flag); } } catch (IOException err) { // Defer a cache update until later. No conclusion can be made // based on an exception reading from the repository storage. log.warn("Error checking tags of " + projectName, err); } } } finally { if (rw != null) { rw.close(); } } }
From source file:com.googlesource.gerrit.plugins.manifest.Git.java
License:Apache License
public static boolean mergedInto(GitRepositoryManager repos, String project, ObjectId haystack, ObjectId needle) throws IOException { Repository repo = repos.openRepository(Project.NameKey.parse(project)); RevWalk walk = new RevWalk(repo); try {/*w w w. j a v a 2 s . co m*/ return walk.isMergedInto(walk.parseCommit(needle), walk.parseCommit(haystack)); } finally { repo.close(); } }
From source file:com.verigreen.jgit.JGitOperator.java
License:Apache License
@Override public boolean isBranchContainsCommit(String branchName, String commitId) { boolean ans = false; RevWalk walk = new RevWalk(_repo); RevCommit commit;//from w w w. j a v a 2s . c o m Ref ref; try { commit = walk.parseCommit(_repo.resolve(commitId + "^0")); ref = _repo.getRef(branchName); if (walk.isMergedInto(commit, walk.parseCommit(ref.getObjectId()))) { ans = true; } walk.dispose(); } catch (Throwable e) { throw new RuntimeException( String.format("Failed to check if commit [%s] is part of branch[%s]", commitId, branchName), e); } return ans; }