Allow updates of commits where only the parent changes

This is necessary to support updates caused by a rebase, where the
parent commit didn't update its tree but perhaps only updated its
commit message, or the rebase is around a cherry-pick followed by
a revert.

Bug: issue 359
Change-Id: I2c53a4a5b11c2c90967b3ba0ea2452668f3f4723
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-12-22 17:27:51 -08:00
parent b3ff3d0088
commit 69bb7510d1

View File

@@ -986,19 +986,29 @@ final class Receive extends AbstractGitCommand {
return null;
}
// Don't allow the same tree if the commit message is unmodified,
// else warn that only the message changed.
// 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);
if (c.getFullMessage().equals(prior.getFullMessage())) {
final boolean messageEq =
c.getFullMessage().equals(prior.getFullMessage());
final boolean parentsEq = parentsEqual(c, prior);
if (messageEq && parentsEq) {
reject(request.cmd, "no changes made");
return null;
} else {
err.write(Constants
.encode("warning: Only commit message changed in "
+ change.getKey().abbreviate() + "\n"));
err.write(Constants.encode("warning: " //
+ change.getKey().abbreviate() + ": " //
+ " no files changed, but" //
+ (!messageEq ? " message updated" : "") //
+ (!messageEq && !parentsEq ? " and" : "") //
+ (!parentsEq ? " was rebased" : "") //
+ "\n" //
));
}
}
} catch (IOException e) {
@@ -1141,6 +1151,18 @@ final class Receive extends AbstractGitCommand {
return result != null ? result.info.getKey() : null;
}
static boolean parentsEqual(RevCommit a, RevCommit b) {
if (a.getParentCount() != b.getParentCount()) {
return false;
}
for (int i = 0; i < a.getParentCount(); i++) {
if (a.getParent(i) != b.getParent(i)) {
return false;
}
}
return true;
}
private void insertDummyApproval(final ReplaceResult result,
final Account.Id forAccount, final ApprovalCategory.Id catId,
final ReviewDb db, final Transaction txn) throws OrmException {