diff options
Diffstat (limited to 'src/remake/delta.rs')
| -rw-r--r-- | src/remake/delta.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/remake/delta.rs b/src/remake/delta.rs index defdec6..caa0b79 100644 --- a/src/remake/delta.rs +++ b/src/remake/delta.rs @@ -137,7 +137,13 @@ pub(crate) fn replay_newest( .iter() .map(|path| { let at = newest(&written, path).map_or(0, |(at, _)| at); - (at, writer(&written, path)) + // Under a strict policy, whose the last write is by history, as it goes. + let user = if strict { + last_writer(&written, path) + } else { + writer(&written, path) + }; + (at, user) }) .collect(); // Only changes newer than the oldest write replayed can supersede one; the @@ -156,8 +162,7 @@ pub(crate) fn replay_newest( let mut by_time: Groups = BTreeMap::new(); // The links of the chains to signed values, each a change of its own: in the order // their changes were made, each after those it builds on, whatever the clocks say - // (one may add the key the next is signed with); and before what is written at the - // same time (it may decide who may write that). + // (one may add the key the next is signed with). let mut ordered: BTreeMap<(usize, usize), Link> = BTreeMap::new(); for place in signed { match chain(src, after, &changes, &place, dst) { @@ -220,8 +225,10 @@ pub(crate) fn replay_newest( let mut refused: HashSet<Vec<String>> = HashSet::new(); let mut links = links.into_iter().peekable(); for ((goes, user), (at, paths)) in by_time { + // Of one change, its links after its other writes: both were judged without the + // other, and a link can only take away there what the others relied on. while let Some((link_goes, ..)) = links.peek() - && *link_goes <= goes + && *link_goes < goes { let (_, when, place, envelope, signer) = links.next().expect("peeked"); write_link( @@ -665,6 +672,16 @@ fn writer(changes: &[Touched], path: &[String]) -> Option<String> { .and_then(|(_, user)| user) } +/// The user of the last of `changes` (`touched`, in their order) that wrote at `path` or +/// below it. +fn last_writer(changes: &[Touched], path: &[String]) -> Option<String> { + changes + .iter() + .rev() + .find(|(_, _, paths)| paths.iter().any(|other| other.starts_with(path))) + .and_then(|(_, user, _)| user.clone()) +} + /// `paths`, each a map that writes for more than one user changed below split into its /// entries (in `src` or `dst`), until each part is one user's: a replayed change names /// one user, and rules by path judge it by that user (`access::rules`). |
