Fix ArrayIndexOutOfBoundsException on initial commits
PatchSetInserter crashed if given a new patch set for an initial commit in a repository. The lack of parents caused getParent(0) to throw an exception. Instead require the two commits to have the same number of parents. If that number is 0, the commits are NO_CODE_CHANGE. If >0 then test only the first parent as before. Change-Id: I6cefd5f16bf866062b247143a64d3eac92710192
This commit is contained in:
committed by
David Pursehouse
parent
3affee0141
commit
eadec0d893
@@ -370,8 +370,7 @@ public class PatchSetInserter {
|
||||
public static ChangeKind getChangeKind(MergeUtil.Factory mergeUtilFactory, ProjectState project,
|
||||
Repository git, RevCommit prior, RevCommit next) {
|
||||
if (!next.getFullMessage().equals(prior.getFullMessage())) {
|
||||
if (next.getTree() == prior.getTree()
|
||||
&& prior.getParent(0).equals(next.getParent(0))) {
|
||||
if (next.getTree() == prior.getTree() && isSameParents(prior, next)) {
|
||||
return ChangeKind.NO_CODE_CHANGE;
|
||||
} else {
|
||||
return ChangeKind.REWORK;
|
||||
@@ -384,7 +383,7 @@ public class PatchSetInserter {
|
||||
}
|
||||
|
||||
if (next.getTree() == prior.getTree() &&
|
||||
prior.getParent(0).equals(next.getParent(0))) {
|
||||
isSameParents(prior, next)) {
|
||||
return ChangeKind.TRIVIAL_REBASE;
|
||||
}
|
||||
|
||||
@@ -409,6 +408,15 @@ public class PatchSetInserter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSameParents(RevCommit prior, RevCommit next) {
|
||||
if (prior.getParentCount() != next.getParentCount()) {
|
||||
return false;
|
||||
} else if (prior.getParentCount() == 0) {
|
||||
return true;
|
||||
}
|
||||
return prior.getParent(0).equals(next.getParent(0));
|
||||
}
|
||||
|
||||
public class ChangeModifiedException extends InvalidChangeOperationException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user