Pass ChangeControl into CodeReviewCommit error instances

Within MergeOp these are keyed by Change.Id, but some error handling
code only receives the CodeReviewCommit and not the ID. That code is
reasonable in assuming there is a change/notes/control available, so
ensure this is the case when creating error instances.

Bug: issue 2911
Change-Id: If65398652f0e5b1a2b10a2fadc9a3b74bce7d556
This commit is contained in:
Dave Borowitz
2014-09-10 11:23:22 +02:00
committed by David Pursehouse
parent 002b9ee7b3
commit 5766bc02d8
2 changed files with 21 additions and 16 deletions

View File

@@ -27,12 +27,12 @@ import java.util.List;
/** Extended commit entity with code review specific metadata. */ /** Extended commit entity with code review specific metadata. */
public class CodeReviewCommit extends RevCommit { public class CodeReviewCommit extends RevCommit {
static CodeReviewCommit revisionGone() { static CodeReviewCommit revisionGone(ChangeControl ctl) {
return error(CommitMergeStatus.REVISION_GONE); return error(ctl, CommitMergeStatus.REVISION_GONE);
} }
static CodeReviewCommit noPatchSet() { static CodeReviewCommit noPatchSet(ChangeControl ctl) {
return error(CommitMergeStatus.NO_PATCH_SET); return error(ctl, CommitMergeStatus.NO_PATCH_SET);
} }
/** /**
@@ -42,11 +42,14 @@ public class CodeReviewCommit extends RevCommit {
* non-zero commit on which we could call {@link * non-zero commit on which we could call {@link
* #setStatusCode(CommitMergeStatus)}, enumerated in the methods above. * #setStatusCode(CommitMergeStatus)}, enumerated in the methods above.
* *
* @param ctl control for change that caused this error
* @param CommitMergeStatus status * @param CommitMergeStatus status
* @return new commit instance * @return new commit instance
*/ */
private static CodeReviewCommit error(CommitMergeStatus s) { private static CodeReviewCommit error(ChangeControl ctl,
CommitMergeStatus s) {
CodeReviewCommit r = new CodeReviewCommit(ObjectId.zeroId()); CodeReviewCommit r = new CodeReviewCommit(ObjectId.zeroId());
r.setControl(ctl);
r.statusCode = s; r.statusCode = s;
return r; return r;
} }

View File

@@ -460,9 +460,16 @@ public class MergeOp {
int commitOrder = 0; int commitOrder = 0;
for (final Change chg : submitted) { for (final Change chg : submitted) {
ChangeControl ctl;
try {
ctl = changeControlFactory.controlFor(chg,
identifiedUserFactory.create(chg.getOwner()));
} catch (NoSuchChangeException e) {
throw new MergeException("Failed to validate changes", e);
}
final Change.Id changeId = chg.getId(); final Change.Id changeId = chg.getId();
if (chg.currentPatchSetId() == null) { if (chg.currentPatchSetId() == null) {
commits.put(changeId, CodeReviewCommit.noPatchSet()); commits.put(changeId, CodeReviewCommit.noPatchSet(ctl));
toUpdate.add(chg); toUpdate.add(chg);
continue; continue;
} }
@@ -475,7 +482,7 @@ public class MergeOp {
} }
if (ps == null || ps.getRevision() == null if (ps == null || ps.getRevision() == null
|| ps.getRevision().get() == null) { || ps.getRevision().get() == null) {
commits.put(changeId, CodeReviewCommit.noPatchSet()); commits.put(changeId, CodeReviewCommit.noPatchSet(ctl));
toUpdate.add(chg); toUpdate.add(chg);
continue; continue;
} }
@@ -485,7 +492,7 @@ public class MergeOp {
try { try {
id = ObjectId.fromString(idstr); id = ObjectId.fromString(idstr);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
commits.put(changeId, CodeReviewCommit.noPatchSet()); commits.put(changeId, CodeReviewCommit.noPatchSet(ctl));
toUpdate.add(chg); toUpdate.add(chg);
continue; continue;
} }
@@ -500,7 +507,7 @@ public class MergeOp {
// want to merge the issue. We can't safely do that if the // want to merge the issue. We can't safely do that if the
// tip is not reachable. // tip is not reachable.
// //
commits.put(changeId, CodeReviewCommit.revisionGone()); commits.put(changeId, CodeReviewCommit.revisionGone(ctl));
toUpdate.add(chg); toUpdate.add(chg);
continue; continue;
} }
@@ -510,17 +517,12 @@ public class MergeOp {
commit = (CodeReviewCommit) rw.parseCommit(id); commit = (CodeReviewCommit) rw.parseCommit(id);
} catch (IOException e) { } catch (IOException e) {
log.error("Invalid commit " + id.name() + " on " + chg.getKey(), e); log.error("Invalid commit " + id.name() + " on " + chg.getKey(), e);
commits.put(changeId, CodeReviewCommit.revisionGone()); commits.put(changeId, CodeReviewCommit.revisionGone(ctl));
toUpdate.add(chg); toUpdate.add(chg);
continue; continue;
} }
try { commit.setControl(ctl);
commit.setControl(changeControlFactory.controlFor(chg,
identifiedUserFactory.create(chg.getOwner())));
} catch (NoSuchChangeException e) {
throw new MergeException("Failed to validate changes", e);
}
commit.setPatchsetId(ps.getId()); commit.setPatchsetId(ps.getId());
commit.originalOrder = commitOrder++; commit.originalOrder = commitOrder++;
commits.put(changeId, commit); commits.put(changeId, commit);