public RevCommit createRef(String refName) throws IOException {
if (Objects.equal(src, revision)) {
return revision;
}
RefUpdate ru = db.updateRef(refName);
ru.setExpectedOldObjectId(ObjectId.zeroId());
ru.setNewObjectId(src);
RefUpdate.Result result = ru.update();
switch (result) {
case NEW:
revision = rw.parseCommit(ru.getNewObjectId());
update.replicate(ru.getName());
return revision;
default:
throw new IOException("Cannot update " + ru.getName() + " in "
+ db.getDirectory() + ": " + ru.getResult());
}
}
@Override
public RevCommit commit() throws IOException {
return commitAt(revision);
}
@Override
public RevCommit commitAt(ObjectId expected) throws IOException {
if (Objects.equal(src, expected)) {
return revision;
}
RefUpdate ru = db.updateRef(getRefName());
if (expected != null) {
ru.setExpectedOldObjectId(expected);
} else {
ru.setExpectedOldObjectId(ObjectId.zeroId());
}
ru.setNewObjectId(src);
ru.disableRefLog();
inserter.flush();
switch (ru.update(rw)) {
case NEW:
case FAST_FORWARD:
revision = rw.parseCommit(ru.getNewObjectId());
update.replicate(ru.getName());
return revision;
default:
throw new IOException("Cannot update " + ru.getName() + " in "
+ db.getDirectory() + ": " + ru.getResult());
}
}
@Override
public void close() {