diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/document/store.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/document/store.rs b/src/document/store.rs index d314a4c..061df35 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -282,25 +282,9 @@ fn read_path_inner( path: &[String], mut log: Option<&mut ConflictLog>, ) -> Result<Option<JsonValue>, StoreError> { - let mut current = Resolved::Maps(vec![automerge::ROOT]); - - for (index, segment) in path.iter().enumerate() { - if let Some(log) = log.as_deref_mut() { - // The last segment is the requested value itself, not an ancestor. - log.in_ancestors = index + 1 < path.len(); - } - match step(doc, ¤t, segment, log.as_deref_mut())? { - Some(next) => current = next, - None => return Ok(None), - } - if let Some(log) = log.as_deref_mut() { - log.path.push(segment.clone()); - } - } - - if let Some(log) = log.as_deref_mut() { - log.in_ancestors = false; - } + let Some(current) = resolve_logged(doc, path, log.as_deref_mut())? else { + return Ok(None); + }; Ok(Some(resolved_to_json(doc, ¤t, log)?)) } @@ -357,12 +341,32 @@ pub(crate) fn read_shallow( /// The resolved value at `path` (the empty path is the root map), through maps and /// lists (`step`). fn resolve_through(doc: &AutoCommit, path: &[String]) -> Result<Option<Resolved>, StoreError> { + resolve_logged(doc, path, None) +} + +/// `resolve_through`, noting the conflicts on the way in `log` (as ancestors, but the +/// last segment's: the requested value's), its path left at `path`. +fn resolve_logged( + doc: &AutoCommit, + path: &[String], + mut log: Option<&mut ConflictLog>, +) -> Result<Option<Resolved>, StoreError> { let mut current = Resolved::Maps(vec![automerge::ROOT]); - for segment in path { - match step(doc, ¤t, segment, None)? { + for (index, segment) in path.iter().enumerate() { + if let Some(log) = log.as_deref_mut() { + // The last segment is the requested value itself, not an ancestor. + log.in_ancestors = index + 1 < path.len(); + } + match step(doc, ¤t, segment, log.as_deref_mut())? { Some(next) => current = next, None => return Ok(None), } + if let Some(log) = log.as_deref_mut() { + log.path.push(segment.clone()); + } + } + if let Some(log) = log { + log.in_ancestors = false; } Ok(Some(current)) } |
