History

refactor

Sebastian Thiel committed 5 years ago

Commit fdc8c791 parent 29b527a3 files · +15 −21Browse files

Showing the changes to git-diff (3 of 3 files). Show all

Unified · Split

3 files
  1. git-diff/src/visit/changes.rs +11 −10
  2. git-diff/src/visit/mod.rs +3 −10
  3. git-diff/tests/visit/mod.rs +1 −1
git-diff/src/visit/changes.rs+11−10
@@ -1,6 +1,10 @@
1use crate::visit;1use crate::{
2use crate::visit::changes::Error::Cancelled;2 visit,
3use crate::visit::record::{Action, Change, PathComponent, PathComponentUpdateMode};3 visit::{
4 changes::Error::Cancelled,
5 record::{Action, Change, PathComponent, PathComponentUpdateMode},
6 },
7};
4use git_hash::{oid, ObjectId};8use git_hash::{oid, ObjectId};
5use git_object::{immutable, tree};9use git_object::{immutable, tree};
6use quick_error::quick_error;10use quick_error::quick_error;
@@ -22,10 +26,7 @@ quick_error! { · 15 unmodified lines
22 }26 }
23}27}
24 28
25impl<'a, Iter> visit::Changes<'a, Iter>29impl<'a> visit::Changes<'a> {
26where
27 Iter: Iterator<Item = super::TreeEntryResult<'a>>,
28{
29 /// Returns the changes that need to be applied to `self` to get `other`.30 /// Returns the changes that need to be applied to `self` to get `other`.
30 ///31 ///
31 /// # Notes32 /// # Notes
@@ -36,8 +37,8 @@ where · 4 unmodified lines
36 /// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/git-object/src/mutable/tree.rs#L52-L5537 /// [git_cmp_rs]: https://github.com/Byron/gitoxide/blob/a4d5f99c8dc99bf814790928a3bf9649cd99486b/git-object/src/mutable/tree.rs#L52-L55
37 ///38 ///
38 pub fn needed_to_obtain<LocateFn>(39 pub fn needed_to_obtain<LocateFn>(
39 self,40 mut self,
40 other: Iter,41 other: immutable::TreeIter<'a>,
41 _state: &mut visit::State,42 _state: &mut visit::State,
42 _locate: LocateFn,43 _locate: LocateFn,
43 delegate: &mut impl visit::Record,44 delegate: &mut impl visit::Record,
@@ -45,7 +46,7 @@ where · 1 unmodified line
45 where46 where
46 LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Object<'b>>,47 LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Object<'b>>,
47 {48 {
48 let mut lhs_entries = self.0;49 let mut lhs_entries = self.0.take().unwrap_or_default();
49 let mut rhs_entries = other;50 let mut rhs_entries = other;
50 51
51 let mut path_id = 0;52 let mut path_id = 0;
git-diff/src/visit/mod.rs+3−10
@@ -6,17 +6,10 @@ pub struct State { · 5 unmodified lines
6 buf2: Vec<u8>,6 buf2: Vec<u8>,
7}7}
8 8
9pub(crate) type TreeEntryResult<'a> = Result<immutable::tree::Entry<'a>, immutable::object::decode::Error>;9pub struct Changes<'a>(Option<immutable::TreeIter<'a>>);
10 10
11pub struct Changes<'a, Iter>(Iter)11impl<'a> From<Option<immutable::TreeIter<'a>>> for Changes<'a> {
12where12 fn from(v: Option<immutable::TreeIter<'a>>) -> Self {
13 Iter: Iterator<Item = TreeEntryResult<'a>>;
14
15impl<'a, Iter> From<Iter> for Changes<'a, Iter>
16where
17 Iter: Iterator<Item = TreeEntryResult<'a>>,
18{
19 fn from(v: Iter) -> Self {
20 Changes(v)13 Changes(v)
21 }14 }
22}15}
git-diff/tests/visit/mod.rs+1−1
@@ -47,7 +47,7 @@ mod changes { · 46 unmodified lines
47 };47 };
48 48
49 let mut recorder = git_diff::visit::Recorder::default();49 let mut recorder = git_diff::visit::Recorder::default();
50 git_diff::visit::Changes::from(previous_tree.unwrap_or_default()).needed_to_obtain(50 git_diff::visit::Changes::from(previous_tree).needed_to_obtain(
51 main_tree,51 main_tree,
52 &mut git_diff::visit::State::default(),52 &mut git_diff::visit::State::default(),
53 |_oid, _buf| todo!("Actual lookup in db"),53 |_oid, _buf| todo!("Actual lookup in db"),