breezyshim/bazaar/
tree.rs

1//! Inventory trees
2use crate::error::Error;
3use crate::tree::Path;
4use pyo3::prelude::*;
5
6/// Trait for trees that have an inventory and can be modified.
7///
8/// Inventory trees are trees that track file identifiers, which is a feature
9/// specific to Bazaar trees.
10pub trait MutableInventoryTree: crate::tree::PyMutableTree {
11    /// Add files to the tree with explicit file identifiers.
12    ///
13    /// # Parameters
14    ///
15    /// * `paths` - The paths of the files to add.
16    /// * `file_ids` - The file identifiers to assign to the files.
17    ///
18    /// # Returns
19    ///
20    /// `Ok(())` on success, or an error if the files could not be added.
21    fn add(&self, paths: &[&Path], file_ids: &[crate::bazaar::FileId]) -> Result<(), Error> {
22        Python::attach(|py| {
23            self.to_object(py).call_method1(
24                py,
25                "add",
26                (
27                    paths
28                        .iter()
29                        .map(|p| p.to_string_lossy().to_string())
30                        .collect::<Vec<_>>(),
31                    file_ids.to_vec(),
32                ),
33            )
34        })
35        .map_err(|e| e.into())
36        .map(|_| ())
37    }
38}
39
40impl MutableInventoryTree for crate::workingtree::GenericWorkingTree {}