baseRev = headRevision;
baseRevId = baseRev.toString();
} else {
baseRev = Revision.fromString(stripBranchRevMarker(baseRevId));
}
JsopReader t = new JsopTokenizer(json);
Revision rev = newRevision();
Commit commit = new Commit(this, baseRev, rev);
while (true) {
int r = t.read();
if (r == JsopReader.END) {
break;
}
String path = PathUtils.concat(rootPath, t.readString());
switch (r) {
case '+':
t.read(':');
t.read('{');
parseAddNode(commit, t, path);
break;
case '-':
commit.removeNode(path);
markAsDeleted(path, commit, true);
commit.removeNodeDiff(path);
break;
case '^':
t.read(':');
String value;
if (t.matches(JsopReader.NULL)) {
value = null;
} else {
value = t.readRawValue().trim();
}
String p = PathUtils.getParentPath(path);
String propertyName = PathUtils.getName(path);
commit.updateProperty(p, propertyName, value);
commit.updatePropertyDiff(p, propertyName, value);
break;
case '>': {
// TODO support moving nodes that were modified within this commit
t.read(':');
String sourcePath = path;
String targetPath = t.readString();
if (!PathUtils.isAbsolute(targetPath)) {
targetPath = PathUtils.concat(rootPath, targetPath);
}
if (!nodeExists(sourcePath, baseRevId)) {
throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
} else if (nodeExists(targetPath, baseRevId)) {
throw new MicroKernelException("Node already exists: " + targetPath + " in revision " + baseRevId);
}
commit.moveNode(sourcePath, targetPath);
moveNode(sourcePath, targetPath, baseRev, commit);
break;
}
case '*': {
// TODO support copying nodes that were modified within this commit
t.read(':');
String sourcePath = path;
String targetPath = t.readString();
if (!PathUtils.isAbsolute(targetPath)) {
targetPath = PathUtils.concat(rootPath, targetPath);
}
if (!nodeExists(sourcePath, baseRevId)) {
throw new MicroKernelException("Node not found: " + sourcePath + " in revision " + baseRevId);
} else if (nodeExists(targetPath, baseRevId)) {
throw new MicroKernelException("Node already exists: " + targetPath + " in revision " + baseRevId);
}
commit.copyNode(sourcePath, targetPath);
copyNode(sourcePath, targetPath, baseRev, commit);
break;
}
default:
throw new MicroKernelException("token: " + (char) t.getTokenType());
}
}
if (baseRevId.startsWith("b")) {
// remember branch commit
Branch b = branches.getBranch(baseRev);