diff --git a/apps/origin-src/src/store/mod.rs b/apps/origin-src/src/store/mod.rs
index b375f418..511f1d8e 100644
--- a/apps/origin-src/src/store/mod.rs
+++ b/apps/origin-src/src/store/mod.rs
@@ -35,6 +35,7 @@ use std::thread;
use std::time::{Duration, SystemTime};
use origin_platform::{DurableWrite, LockMode, LockedFile, Native, Platform, WritableError};
+use origin_shared::access::PathAccess;
use origin_shared::object::{DecodeError, IdMismatch};
use origin_shared::{AttachmentId, EncodedObject, Head, ObjectId, TargetName, TypedId};
@@ -55,6 +56,9 @@ pub struct Store
{
packs: Arc,
/// Who the op log says writes.
pub(crate) actor: Actor,
+ /// What this repository may read of its remote's snapshots, if the
+ /// remote withholds some paths: see [`Store::with_withheld`].
+ pub(crate) readable: Option>,
}
impl Store
{
Self { actor, ..self }
}
+ /// The store of a repository whose remote withholds the content of the
+ /// paths `readable` doesn't read: their trees keep the entries, but the
+ /// store lacks what they point to. Tree operations then never read
+ /// them: diffs skip them, merges compare them by id, and walks leave
+ /// them out (see [`crate::tree`]).
+ #[must_use]
+ pub fn with_withheld(self, readable: PathAccess) -> Self {
+ Self {
+ readable: (!readable.reads_all()).then(|| Arc::new(readable)),
+ ..self
+ }
+ }
+
/// Who the op log says writes.
#[must_use]
pub fn actor(&self) -> &Actor {
diff --git a/apps/origin-src/src/tree.rs b/apps/origin-src/src/tree.rs
index 7912b70b..055cbf02 100644
--- a/apps/origin-src/src/tree.rs
+++ b/apps/origin-src/src/tree.rs
@@ -1,4 +1,9 @@
//! Comparing trees, merging them, and looking up what they hold.
+//!
+//! In a repository whose remote withholds some paths (see
+//! [`Store::with_withheld`]), nothing here reads what it lacks there:
+//! diffs skip withheld paths, merges compare them by id, and walks leave
+//! them out.
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
@@ -28,6 +33,12 @@ pub struct FileChange {
}
impl Store
{
+ /// What this repository may not read at or under `dir`, if anything:
+ /// tree operations check paths only while it's some.
+ fn withheld_under(&self, dir: &RepoPath) -> Option<&PathAccess> {
+ Self::unsettled(self.readable.as_deref(), dir)
+ }
+
/// Whether a tree operation may read the entry at `path` of a
/// directory whose withheld paths are `withheld`: a file it reads, or a
/// directory it reads something under.
@@ -37,14 +48,30 @@ impl Store
{
/// Lists the files that differ between two trees, sorted by path.
/// Subtrees with equal ids are skipped without being read, so the cost
- /// follows the size of the change.
+ /// follows the size of the change. Withheld paths are skipped.
///
/// # Errors
///
/// Fails if a tree that differs cannot be read.
pub fn diff(&self, old: TreeId, new: TreeId) -> Result, StoreError> {
+ self.diff_at(&RepoPath::root(), Some(old), Some(new))
+ }
+
+ /// Lists the files that differ between two versions of the directory
+ /// `dir`, like [`Store::diff`], `None` standing for one that doesn't
+ /// exist.
+ ///
+ /// # Errors
+ ///
+ /// Fails if a tree that differs cannot be read.
+ pub fn diff_at(
+ &self,
+ dir: &RepoPath,
+ old: Option,
+ new: Option,
+ ) -> Result, StoreError> {
let mut changes = Vec::new();
- self.diff_dir(&RepoPath::root(), Some(old), Some(new), &mut changes)?;
+ self.diff_dir(dir, old, new, &mut changes)?;
Ok(changes)
}
@@ -64,19 +91,23 @@ impl Store
{
read(old)?.unwrap_or_default(),
read(new)?.unwrap_or_default(),
);
+ let withheld = self.withheld_under(dir);
let mut names: Vec<&EntryName> =
old.iter().chain(new.iter()).map(|(name, _)| name).collect();
names.sort_unstable();
names.dedup();
for name in names {
+ let path = dir.join(name);
+ let readable = |entry: Option| {
+ entry.filter(|entry| Self::readable(withheld, &path, entry))
+ };
let (old, new) = (
- old.get(name.as_str()).copied(),
- new.get(name.as_str()).copied(),
+ readable(old.get(name.as_str()).copied()),
+ readable(new.get(name.as_str()).copied()),
);
if old == new {
continue;
}
- let path = dir.join(name);
// A name can hold a file on one side and a directory on the
// other: the file part is a change, the directory part is
// diffed against an empty tree.
@@ -131,7 +162,8 @@ impl Store
{
/// `ours`. A path is a file, so two sides that changed different files
/// of a directory merge cleanly. Without a base, every path either side
/// has counts as changed. Subtrees with equal ids are never read, so the
- /// cost follows the size of the changes.
+ /// cost follows the size of the changes. A withheld directory both
+ /// sides changed is a conflict, as a file is.
///
/// # Errors
///
@@ -256,15 +288,18 @@ impl Store
{
.collect();
names.sort_unstable();
names.dedup();
+ let withheld = self.withheld_under(dir);
let mut merged = Tree::default();
for name in names {
let [base, ours, theirs] =
[&base, &ours, &theirs].map(|tree| tree.get(name.as_str()).copied());
+ let readable = withheld.is_none_or(|access| access.reads_under(&dir.join(name)));
let entry = if ours == theirs || base == theirs {
ours
} else if base == ours {
theirs
- } else if base != Some(Self::UNKNOWN)
+ } else if readable
+ && base != Some(Self::UNKNOWN)
&& ours.is_none_or(|ours| ours.kind.is_tree())
&& theirs.is_none_or(|theirs| theirs.kind.is_tree())
{
@@ -346,6 +381,99 @@ impl Store
{
}
}
+impl Store
{
+ /// The working copy's files, the tree `files`, with what `kept`, the
+ /// revision it was, holds at the paths withheld from this repository:
+ /// files the user cannot read are never in the working copy, and stay
+ /// in its snapshots as they were. Returns the tree, and the trees it
+ /// made, which the store may not have yet. Only the directories on the
+ /// way to withheld paths are read.
+ ///
+ /// # Errors
+ ///
+ /// Fails if a tree on the way cannot be read.
+ pub fn keep_withheld(
+ &self,
+ files: TreeId,
+ kept: TreeId,
+ ) -> Result<(TreeId, Vec), StoreError> {
+ let mut trees = Vec::new();
+ let tree = self.keep_dir(&RepoPath::root(), Some(files), Some(kept), &mut trees)?;
+ let tree = tree.unwrap_or_else(|| {
+ let empty = Tree::default().encode();
+ let id = empty.id().into();
+ trees.push(empty);
+ id
+ });
+ Ok((tree, trees))
+ }
+
+ /// Keeps the withheld paths of `kept` in `files`, two versions of `dir`,
+ /// `None` standing for one that doesn't exist, returning the result, or
+ /// `None` if it's empty.
+ fn keep_dir(
+ &self,
+ dir: &RepoPath,
+ files: Option,
+ kept: Option,
+ trees: &mut Vec,
+ ) -> Result