if (head.equals(base)) {
// Nothing was written to this branch: return base state
head = null; // Mark as merged
return base;
} else {
MicroKernel kernel = store.getKernel();
String newRevision;
JsopDiff diff = new JsopDiff(kernel);
if (headRevision == null) {
// no branch created yet, commit directly
head.compareAgainstBaseState(base, diff);
newRevision = kernel.commit("", diff.toString(), baseRevision, null);
} else {
// commit into branch and merge
head.compareAgainstBaseState(store.getRootState(headRevision), diff);
String jsop = diff.toString();
if (!jsop.isEmpty()) {
headRevision = kernel.commit("", jsop, headRevision, null);
}
newRevision = kernel.merge(headRevision, null);
headRevision = null;
}
head = null; // Mark as merged
return store.getRootState(newRevision);
}