}
}
private PatchSet.Id doReplace(final ReplaceRequest request, boolean ignoreNoChanges)
throws IOException, OrmException {
final RevCommit c = request.newCommit;
rp.getRevWalk().parseBody(c);
warnMalformedMessage(c);
final Account.Id me = currentUser.getAccountId();
final Set<Account.Id> reviewers = new HashSet<Account.Id>(reviewerId);
final Set<Account.Id> cc = new HashSet<Account.Id>(ccId);
final List<FooterLine> footerLines = c.getFooterLines();
for (final FooterLine footerLine : footerLines) {
try {
if (isReviewer(footerLine)) {
reviewers.add(toAccountId(footerLine.getValue().trim()));
} else if (footerLine.matches(FooterKey.CC)) {
cc.add(toAccountId(footerLine.getValue().trim()));
}
} catch (NoSuchAccountException e) {
continue;
}
}
reviewers.remove(me);
cc.remove(me);
cc.removeAll(reviewers);
final ReplaceResult result = new ReplaceResult();
final Set<Account.Id> oldReviewers = new HashSet<Account.Id>();
final Set<Account.Id> oldCC = new HashSet<Account.Id>();
Change change = db.changes().get(request.ontoChange);
if (change == null) {
reject(request.cmd, "change " + request.ontoChange + " not found");
return null;
}
if (change.getStatus().isClosed()) {
reject(request.cmd, "change " + request.ontoChange + " closed");
return null;
}
final ChangeControl changeCtl = projectControl.controlFor(change);
if (!changeCtl.canAddPatchSet()) {
reject(request.cmd, "cannot replace " + request.ontoChange);
return null;
}
if (!validCommit(changeCtl.getRefControl(), request.cmd, c)) {
return null;
}
final PatchSet.Id priorPatchSet = change.currentPatchSetId();
for (final PatchSet ps : db.patchSets().byChange(request.ontoChange)) {
if (ps.getRevision() == null) {
log.warn("Patch set " + ps.getId() + " has no revision");
reject(request.cmd, "change state corrupt");
return null;
}
final String revIdStr = ps.getRevision().get();
final ObjectId commitId;
try {
commitId = ObjectId.fromString(revIdStr);
} catch (IllegalArgumentException e) {
log.warn("Invalid revision in " + ps.getId() + ": " + revIdStr);
reject(request.cmd, "change state corrupt");
return null;
}
try {
final RevCommit prior = rp.getRevWalk().parseCommit(commitId);
// Don't allow a change to directly depend upon itself. This is a
// very common error due to users making a new commit rather than
// amending when trying to address review comments.
//
if (rp.getRevWalk().isMergedInto(prior, c)) {
reject(request.cmd, "squash commits first");
return null;
}
// Don't allow the same commit to appear twice on the same change
//
if (c == prior) {
reject(request.cmd, "commit already exists");
return null;
}
// Don't allow the same tree if the commit message is unmodified
// or no parents were updated (rebase), else warn that only part
// of the commit was modified.
//
if (priorPatchSet.equals(ps.getId()) && c.getTree() == prior.getTree()) {
rp.getRevWalk().parseBody(prior);
final boolean messageEq =
eq(c.getFullMessage(), prior.getFullMessage());
final boolean parentsEq = parentsEqual(c, prior);
final boolean authorEq = authorEqual(c, prior);
if (messageEq && parentsEq && authorEq && !ignoreNoChanges) {
reject(request.cmd, "no changes made");