I have a start commit from which i want to find all the branches till i reach another dont find a note for the commit.
commit 1
|
commit 2
| commit5
commit3 /
| /
commit 4
|
commit 6
in this case say all the commit from commit 1-5 have notes "find branch" and commit 6 doesn't have a not with that value.
So i will start with commit 1 find all the parent (ie: commit 2) and try to check if there is an branch for this commit (ie: number of children is more than 1). if there is more than 1 childs
- the
getChildren()
method is there only for PlotCommit object, but the methodparentCommit.getParents()
return onlyRevCommit
Object. - i want to find the branch name present in the particular commit
then when there is no more notes on the commit (ie commit 6 doesnt have notes) the logic will stop there and the collection of Branch name is returned
Repository repo;//will be set as part of some other logic
private Set findBranchesForCommit(PlotCommit parentCommit, String note) throws ExecutionException, MissingObjectException, IncorrectObjectTypeException, IOException {
Set branches = new HashSet();
PlotCommit[] parents = (PlotCommit[]) parentCommit.getParents();//XXX will throw exception as this return RevCommit[]
for (int i = 0; i < parents .length; i++) {
PlotCommit commit = parents[i];
String result = extractExistingMessage(repo, "refs/notes", commit);//will return the if the note available for particular commit
if (result.trim().length() > 0 && result.equalsIgnoreCase(note)) {
System.out.println("#########"+commit.getChildCount());
//TODO need to add logic to find the branch of the particular commit
branches.add(""); //add the branches available for the commit
branches.addAll(findBranchesForCommit(commit, note));
}
}
return branches;
}
expected result
i want to find the branch names of commits that contain a particular git note. in the above example the branch name of Commit 1 and commit 5 will be returned