return null if commit was not merged into requested branch

This commit is contained in:
Sebastian Sdorra
2019-11-04 11:46:27 +01:00
parent d5bd83fafb
commit e4c8783c61
4 changed files with 34 additions and 12 deletions

View File

@@ -132,13 +132,16 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
{
converter = new GitChangesetConverter(gr, revWalk);
if (request != null &&
!Strings.isNullOrEmpty(request.getBranch()) &&
revWalk.isMergedInto(commit, findTipCommitForRequestBranch(request, gr, revWalk))) {
changeset = converter.createChangeset(commit, request.getBranch());
if (isBranchRequested(request)) {
String branch = request.getBranch();
if (isMergedIntoBranch(gr, revWalk, commit, branch)) {
logger.trace("returning commit {} with branch {}", commit.getId(), branch);
changeset = converter.createChangeset(commit, branch);
} else {
logger.debug("returning null, because commit {} was not merged into branch {}", commit.getId(), branch);
}
} else {
changeset = converter.createChangeset(commit);
}
}
else if (logger.isWarnEnabled())
@@ -165,8 +168,16 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
return changeset;
}
private RevCommit findTipCommitForRequestBranch(LogCommandRequest request, Repository gr, RevWalk revWalk) throws IOException {
return revWalk.parseCommit(GitUtil.getCommit(gr, revWalk, gr.findRef(request.getBranch())));
private boolean isMergedIntoBranch(Repository repository, RevWalk revWalk, RevCommit commit, String branchName) throws IOException {
return revWalk.isMergedInto(commit, findHeadCommitOfBranch(repository, revWalk, branchName));
}
private boolean isBranchRequested(LogCommandRequest request) {
return request != null && !Strings.isNullOrEmpty(request.getBranch());
}
private RevCommit findHeadCommitOfBranch(Repository repository, RevWalk revWalk, String branchName) throws IOException {
return revWalk.parseCommit(GitUtil.getCommit(repository, revWalk, repository.findRef(branchName)));
}
/**