Showing the changes to git-diff/src (1 of 2 files). Show all
Unified · Split
| @@ -1,11 +1,53 @@ | ||
| 1 | 1 | // TODO: add deny(missing_docs) |
| 2 | 2 | #![forbid(unsafe_code, rust_2018_idioms)] |
| 3 | +#![allow(dead_code, unused_variables)] | |
| 3 | 4 | |
| 4 | 5 | /// |
| 5 | 6 | pub mod tree { |
| 6 | − use git_object::immutable; | |
| 7 | + use git_hash::{oid, ObjectId}; | |
| 8 | + use git_object::{ | |
| 9 | + bstr::{BStr, BString}, | |
| 10 | + immutable, tree, | |
| 11 | + }; | |
| 12 | + | |
| 7 | 13 | const EMPTY_TREE: immutable::Tree<'static> = immutable::Tree::empty(); |
| 8 | 14 | |
| 15 | + type PathNodeId = usize; | |
| 16 | + | |
| 17 | + /// A tree of paths to make storage and allocation of paths more efficient. | |
| 18 | + pub struct PathNode { | |
| 19 | + name: BString, | |
| 20 | + /// The offset into our structure, and the id of this PathTree node | |
| 21 | + id: PathNodeId, | |
| 22 | + /// The biggest offset seen in all of our children. This is the total amounf of paths stored for | |
| 23 | + /// the root node. | |
| 24 | + max_id: usize, | |
| 25 | + children: Vec<PathNode>, | |
| 26 | + } | |
| 27 | + | |
| 28 | + impl PathNode { | |
| 29 | + /// Find the path with the given `id` and place all of its elements in `out_elements`. | |
| 30 | + /// Returns the amount of elements the path contains, like `&["a", "b", "c"]` would be `Some(3)`. | |
| 31 | + /// | |
| 32 | + /// The output vector will be cleared beforehand. | |
| 33 | + pub fn elements(id: PathNodeId, out_elements: &mut Vec<&BStr>) -> Option<usize> { | |
| 34 | + todo!("fetch elements") | |
| 35 | + } | |
| 36 | + } | |
| 37 | + | |
| 38 | + pub enum Change { | |
| 39 | + Addition { | |
| 40 | + mode: tree::Mode, | |
| 41 | + oid: ObjectId, | |
| 42 | + path: PathNodeId, | |
| 43 | + }, | |
| 44 | + Copy, | |
| 45 | + Deletion, | |
| 46 | + Modification, | |
| 47 | + Renaming, | |
| 48 | + Type, | |
| 49 | + } | |
| 50 | + | |
| 9 | 51 | pub struct Changes<'a>(Option<&'a immutable::Tree<'a>>); |
| 10 | 52 | |
| 11 | 53 | impl<'a, T> From<T> for Changes<'a> |
| @@ -17,11 +59,42 @@ pub mod tree { · 5 unmodified lines | ||
| 17 | 59 | } |
| 18 | 60 | } |
| 19 | 61 | |
| 62 | + // Possible things to detect (from git diff --help) | |
| 63 | + // o A: addition of a file | |
| 64 | + // o C: copy of a file into a new one | |
| 65 | + // o D: deletion of a file | |
| 66 | + // o M: modification of the contents or mode of a file | |
| 67 | + // o R: renaming of a file | |
| 68 | + // o T: change in the type of the file | |
| 69 | + // o U: file is unmerged (you must complete the merge before it can be committed) | |
| 70 | + // o X: "unknown" change type (most probably a bug, please report it) | |
| 20 | 71 | impl<'a> Changes<'a> { |
| 21 | 72 | /// Returns the changes that need to be applied to `self` to get `other`. |
| 22 | − pub fn to_obtain(&self, _other: &git_object::immutable::Tree<'_>) { | |
| 73 | + pub fn to_obtain<LocateFn>( | |
| 74 | + &self, | |
| 75 | + _other: &git_object::immutable::Tree<'_>, | |
| 76 | + buf: (&mut Vec<u8>, &mut Vec<u8>), | |
| 77 | + locate: LocateFn, | |
| 78 | + ) -> (PathNode, Vec<Change>) | |
| 79 | + where | |
| 80 | + LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Tree<'b>>, | |
| 81 | + { | |
| 23 | 82 | let _this = *self.0.as_ref().unwrap_or(&&EMPTY_TREE); |
| 24 | 83 | todo!("changes tree to tree") |
| 25 | 84 | } |
| 26 | 85 | } |
| 86 | + | |
| 87 | + #[cfg(test)] | |
| 88 | + mod tests { | |
| 89 | + use super::*; | |
| 90 | + | |
| 91 | + #[test] | |
| 92 | + fn size_of_change() { | |
| 93 | + assert_eq!( | |
| 94 | + std::mem::size_of::<Change>(), | |
| 95 | + 32, | |
| 96 | + "this type shouldn't grow without us knowing" | |
| 97 | + ) | |
| 98 | + } | |
| 99 | + } | |
| 27 | 100 | } |