repo.lock();
HgInputStream stream = launchStream(changeset.getNode());
try {
if (stream.match("grafting revision ".getBytes())) {
int rev = stream.revisionUpTo('\n');
GraftContext ctx = new GraftContext(this, rev);
if (!stream.isEof()) {
ctx.processStream(stream, true);
}
stream.consumeAll();
boolean flagOrKeepDeleteConflicts = !ctx.getFlagConflicts().isEmpty()
|| !ctx.getKeepDeleteConflicts().isEmpty();
if (getReturnCode() == -1 && this.hasConflicts || flagOrKeepDeleteConflicts) {
if (flagOrKeepDeleteConflicts && ctx.getMergeConflicts().isEmpty()) {
// graft has actually made a new changeset,
// but
// there is actually flag conflict or
// keep/delete
// conflict. So rollback the changeset.
Changeset rollbackChangeset = repo.tip();
if (!changeset.getNode().equals(rollbackChangeset.getExtra().getString("source"))) {
throw new IllegalStateException("Current tip is not grafted from expected changeset");
}
RollbackCommand.on(repo).execute();
ctx.setRollbackChangeset(rollbackChangeset);
}
return ctx;
} else {
return null;
}