History

Sketch of how changes could actually be returned.

Sebastian Thiel committed 5 years ago

Commit a48db501 parent 03ee5102 files · +81 −3Browse files

Showing the changes to git-diff/src (1 of 2 files). Show all

Unified · Split

git-diff/src/lib.rs+75−2
@@ -1,11 +1,53 @@
11 // TODO: add deny(missing_docs)
22 #![forbid(unsafe_code, rust_2018_idioms)]
3+#![allow(dead_code, unused_variables)]
34
45 ///
56 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+
713 const EMPTY_TREE: immutable::Tree<'static> = immutable::Tree::empty();
814
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+
951 pub struct Changes<'a>(Option<&'a immutable::Tree<'a>>);
1052
1153 impl<'a, T> From<T> for Changes<'a>
@@ -17,11 +59,42 @@ pub mod tree { · 5 unmodified lines
1759 }
1860 }
1961
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)
2071 impl<'a> Changes<'a> {
2172 /// 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+ {
2382 let _this = *self.0.as_ref().unwrap_or(&&EMPTY_TREE);
2483 todo!("changes tree to tree")
2584 }
2685 }
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+ }
27100 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t