Insert Change-Id for revert commits

The 'Revert Change' action on a merged change allows to create a new
change that reverts the merged change. The commit message of the revert
commit currently does not contain a Change-Id.

It is convenient if a Change-Id is automatically created and inserted
into the commit message of the revert commit since it makes rebasing of
the revert commit easier.

Change-Id: Ide66b8f6e704e82a7450eba5bc3dd0b892520caa
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-07-13 10:38:36 +02:00
parent 2b41c9c739
commit c0ff557078

View File

@@ -62,6 +62,7 @@ import org.eclipse.jgit.revwalk.FooterLine;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.Base64;
import org.eclipse.jgit.util.ChangeIdUtil;
import org.eclipse.jgit.util.NB;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -463,7 +464,11 @@ public class ChangeUtil {
revertCommit.setTreeId(parentToCommitToRevert.getTree());
revertCommit.setAuthor(authorIdent);
revertCommit.setCommitter(myIdent);
revertCommit.setMessage(message);
final ObjectId computedChangeId =
ChangeIdUtil.computeChangeId(parentToCommitToRevert.getTree(),
commitToRevert, authorIdent, myIdent, message);
revertCommit.setMessage(ChangeIdUtil.insertId(message, computedChangeId, true));
final ObjectInserter oi = git.newObjectInserter();;
ObjectId id;
@@ -474,7 +479,7 @@ public class ChangeUtil {
oi.release();
}
Change.Key changeKey = new Change.Key("I" + id.name());
Change.Key changeKey = new Change.Key("I" + computedChangeId.name());
final Change change =
new Change(changeKey, new Change.Id(db.nextChangeId()),
user.getAccountId(), db.changes().get(changeId).getDest());