pub struct MutableTree { /* private fields */ }Expand description
A directory that a caller builds in memory.
A tree holds these items:
- files, each a name and a content checksum. A symlink is a file entry.
- subdirectories, each a name and a nested tree.
- the dirmeta checksum of the directory itself.
A name is a file or a subdirectory, never both. The methods that insert an
entry check that each name is not empty, is not . or .., and holds no
/. They do not check for a NUL byte. write_mtree
checks each name against the rules of a dirtree
object.
§Lazy hydration
from_commit reads only the root dirtree. It
records the dirtree and dirmeta checksums of each subdirectory. The tree
reads a subdirectory when ensure_dir or
subtree first descends into it. A walk to one
path in a large commit reads only the directories on that path.
A descent is async because it can read a dirtree. The other methods
change entries that the tree holds already, and they are synchronous.
§Dirty tracking
A subtree that matches a committed dirtree and has no change keeps the
checksum of that dirtree. write_mtree reuses
this checksum. It serializes and stages nothing for that subtree or for
the entries under it.
write_mtree writes a new dirtree for a subtree in these cases:
- The subtree has a change.
- A child of the subtree is loaded, because a descent read it.
If the new bytes are equal to a dirtree in the object store, the new dirtree has the same checksum. The store keeps one copy.
Implementations§
Source§impl MutableTree
impl MutableTree
Sourcepub fn new() -> MutableTree
pub fn new() -> MutableTree
Creates an empty tree with no dirmeta checksum.
Sourcepub async fn from_commit(repo: &Repo, rev: &str) -> Result<MutableTree>
pub async fn from_commit(repo: &Repo, rev: &str) -> Result<MutableTree>
Creates a tree from the root of a commit and reads only the root dirtree.
rev is a revision in the syntax of
Repo::resolve_rev. The root of the tree
takes the dirmeta checksum of the commit root. The tree reads each
subdirectory on the first descent, as
MutableTree states.
§Errors
Error::RefNotFoundifrevnames no ref and no commit.Error::InvalidRefspecifrevis not a checksum and not a valid refspec.Error::AmbiguousRefspecif more than one commit checksum starts with the abbreviated checksum inrev.Error::NoParentCommitif a^inrevsteps back from a commit with no parent.Error::ObjectNotFoundif the commit, a commit that a^step reads, or the root dirtree is not in the repository.Error::InvalidFormatif a ref file is not UTF-8.Error::Coreif a ref file holds no checksum, or if the commit or the root dirtree does not parse.Error::Ioif a read from the file system fails, or if an object is larger thanMAX_METADATA_SIZE.
Sourcepub fn set_metadata_checksum(&mut self, checksum: Checksum)
pub fn set_metadata_checksum(&mut self, checksum: Checksum)
Sets the dirmeta checksum of this directory.
The dirtree of a directory does not hold its own dirmeta checksum, so
this call does not count as a change of the directory. The dirtree of
the parent holds it. write_mtree writes
the new value into the parent when it writes the parent.
Sourcepub async fn ensure_dir(&mut self, name: &str) -> Result<&mut MutableTree>
pub async fn ensure_dir(&mut self, name: &str) -> Result<&mut MutableTree>
Returns the subdirectory name, and creates an empty one if it is
absent.
If the subdirectory is a committed child that is not read yet, the call reads its dirtree first. A new subdirectory has no dirmeta checksum, and it counts as a change of this directory.
§Errors
Error::MutableTreeifnameis empty, is.or.., or holds a/.Error::ReplaceFileWithDirif a file of that name exists. The payload isname.Error::ObjectNotFoundif the dirtree of the committed child is not in the repository.Error::Coreif the dirtree of the committed child does not parse.Error::Ioif the read of that dirtree fails, or if the dirtree is larger thanMAX_METADATA_SIZE.
Sourcepub async fn subtree(&mut self, name: &str) -> Result<&mut MutableTree>
pub async fn subtree(&mut self, name: &str) -> Result<&mut MutableTree>
Returns the existing subdirectory name, and creates nothing.
If the subdirectory is a committed child that is not read yet, the call reads its dirtree first.
A symlink is a file entry in this tree. A symlink to a directory gives
Error::NotADirectory too, because the call resolves one name in one
directory and reads no symlink target.
The payload of Error::NotADirectory and of Error::PathNotFound
is name alone, because a tree holds no path. The staging tree puts one
entry name in Error::ReplaceDirWithFile in the same way.
§Errors
Error::MutableTreeifnameis empty, is.or.., or holds a/.Error::NotADirectoryif a file or a symlink of that name exists.Error::PathNotFoundif no entry of that name exists.Error::ObjectNotFoundif the dirtree of the committed child is not in the repository.Error::Coreif the dirtree of the committed child does not parse.Error::Ioif the read of that dirtree fails, or if the dirtree is larger thanMAX_METADATA_SIZE.
Sourcepub fn replace_file(&mut self, name: &str, checksum: Checksum) -> Result<()>
pub fn replace_file(&mut self, name: &str, checksum: Checksum) -> Result<()>
Sets the file name to a content checksum.
If a file of that name exists, the call replaces it. The call counts as a change of this directory.
§Errors
Error::MutableTreeifnameis empty, is.or.., or holds a/.Error::ReplaceDirWithFileif a subdirectory of that name exists. The payload isname.
Sourcepub fn remove(&mut self, name: &str, allow_noent: bool) -> Result<()>
pub fn remove(&mut self, name: &str, allow_noent: bool) -> Result<()>
Removes the file or the subdirectory name.
If allow_noent is true, an absent entry is not an error. The call
does not check the form of name, so an invalid name matches no entry.
A removal counts as a change of this directory.
§Errors
Error::MutableTree if no entry of that name exists and
allow_noent is false.
Sourcepub fn metadata_checksum(&self) -> Option<Checksum>
pub fn metadata_checksum(&self) -> Option<Checksum>
Returns the dirmeta checksum of this directory, if it is set.
write_mtree cannot write a root with no
dirmeta checksum. A caller can call this method before write_mtree to
find a tree whose sources set no root dirmeta.
Trait Implementations§
Source§impl Debug for MutableTree
impl Debug for MutableTree
Source§impl Default for MutableTree
impl Default for MutableTree
Source§fn default() -> MutableTree
fn default() -> MutableTree
Auto Trait Implementations§
impl Forget for MutableTree
impl Freeze for MutableTree
impl Move for MutableTree
impl RefUnwindSafe for MutableTree
impl Send for MutableTree
impl Sync for MutableTree
impl Unpin for MutableTree
impl UnsafeUnpin for MutableTree
impl UnwindSafe for MutableTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.