commit method
Future<String>
commit(
- String locator,
- TomChangeset changeset, {
- String? expectedHead,
- String? message,
- TomCommitProgressSink? onProgress,
override
Applies changeset atomically, refusing the write if the container has
moved away from expectedHead.
Pass a null expectedHead to create a container that does not exist yet;
a backend MUST fail with TomCasConflictException if one does.
Returns the new head.
onProgress, when given, receives TomCommitProgress as the
changeset's objects go up — before each and after the last. It is
optional on both sides: a caller need not ask, and a backend whose
save is effectively instantaneous need not report. Silence from a backend
is therefore not a failure to implement it; it is the honest answer for a
local filesystem write.
Implementation
@override
Future<String> commit(
String locator,
TomChangeset changeset, {
String? expectedHead,
String? message,
TomCommitProgressSink? onProgress,
}) async {
tomGuardChangeset(locator, changeset, this);
final loc = TomGitLocator.parse(locator);
final path = loc.path;
if (path.isEmpty) {
throw TomStorageException(
locator,
'A git locator with no path names the repository, not a document',
);
}
final result = await _commitLoop(
locator,
loc,
expectedHead: expectedHead,
changeset: changeset,
message: message ?? '${commitMessagePrefix}save ${path.split('/').last}',
writes: {
for (final w in changeset.writes.entries)
w.key == TomChangeset.containerPath ? path : '$path/${w.key}':
w.value,
},
deletes: {for (final d in changeset.deletes) '$path/$d'},
);
return result ?? TomStorage.emptyHead;
}