1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Operations between two trees.
use crate::delta::TreeDelta;
use pyo3::prelude::*;
/// Represents operations between two trees.
///
/// InterTree allows comparing and performing operations between two trees,
/// such as finding differences or applying changes from one tree to another.
pub struct InterTree(Py<PyAny>);
/// Get an InterTree for operations between two trees.
///
/// # Arguments
///
/// * `source` - The source tree
/// * `target` - The target tree
///
/// # Returns
///
/// An InterTree object that can be used to perform operations between the trees
pub fn get<S: crate::tree::PyTree, T: crate::tree::PyTree>(source: &S, target: &T) -> InterTree {
Python::attach(|py| {
let source = source.to_object(py);
let target = target.to_object(py);
let intertree_cls = py
.import("breezy.tree")
.unwrap()
.getattr("InterTree")
.unwrap();
InterTree(
intertree_cls
.call_method1("get", (source, target))
.unwrap()
.unbind(),
)
})
}
impl InterTree {
/// Compare the source and target trees.
///
/// # Returns
///
/// A TreeDelta representing the differences between the source and target trees
pub fn compare(&self) -> TreeDelta {
Python::attach(|py| {
self.0
.call_method0(py, "compare")
.unwrap()
.extract(py)
.unwrap()
})
}
}