Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [egit-dev] EGit PDE - help with EGit/JGit

This is my attempt to find all tags that can contain a given commit:

public static Set<Ref> getTagsContainingCommit(Repository repo,
		RevCommit latestCommit) throws Exception {
	final Set<Ref> tags = new HashSet<Ref>();
	final RevWalk walk = new RevWalk(repo);
	walk.sort(RevSort.TOPO, true);
	walk.sort(RevSort.COMMIT_TIME_DESC, true);
	for (final Ref ref : repo.getTags().values()) {
		final RevObject obj = walk.parseAny(ref.getObjectId());
		final RevCommit tagCommit;
		if (obj instanceof RevCommit) {
			tagCommit = (RevCommit) obj;
		} else {
			tagCommit = walk.parseCommit(((RevTag) obj).getObject());
		}
		if (walk.isMergedInto(latestCommit, tagCommit)) {
			tags.add(ref);
		}
	}
	return tags;
}


Two things I noticed:

1) even if they're the same commit, walk.isMergedInto(latestCommit,
tagCommit) returns false.  OK, I can add a
tagCommit.equals(latestCommit).

2) walk.isMergedInto(latestCommit, tagCommit) returns false for all of
my cases, My repo has no branches ATM, instead it's a straight parent
child walk between b42ad39c90fc57b679154ca33dfb306004dc08a3 and the
last commit on master, d660f0a07c8ff16c9b46b3d69bc1c271b2cf4aba, which
has 2 tags and is definitely being parsed into tagCommit.

PW


-- 
Paul Webster
Hi floor.  Make me a sammich! - GIR


Back to the top