History

refactor

Sebastian Thiel committed 5 years ago

Commit c0318cf1 parent aaba9dc7 files · +51 −51Browse files

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

Unified · Split

5 files
  1. git-diff/src/lib.rs +1 −1
  2. git-diff/src/tree/changes.rs +21 −21
  3. git-diff/src/tree/mod.rs +3 −3
  4. git-diff/src/tree/recorder.rs +8 −8
  5. git-diff/src/tree/visit.rs +4 −4
git-diff/src/lib.rs+1−1
@@ -3,4 +3,4 @@ · 2 unmodified lines
33 #[deny(missing_docs)]
44
55 ///
6−pub mod visit;
6+pub mod tree;
git-diff/src/tree/changes.rsrenamed from git-diff/src/visit/changes.rs+21−21
@@ -1,9 +1,9 @@
11 use crate::{
2− visit,
3− visit::{changes::Error::Cancelled, record::Change, TreeInfo, TreeInfoPair},
2+ tree,
3+ tree::{changes::Error::Cancelled, visit::Change, TreeInfo, TreeInfoPair},
44 };
55 use git_hash::{oid, ObjectId};
6−use git_object::{immutable, tree};
6+use git_object::immutable;
77 use quick_error::quick_error;
88 use std::{borrow::BorrowMut, collections::VecDeque};
99
@@ -24,8 +24,8 @@ quick_error! { · 14 unmodified lines
2424 }
2525 }
2626
27−impl<'a> visit::Changes<'a> {
28− /// Returns the changes that need to be applied to `self` to get `other`.
27+impl<'a> tree::Changes<'a> {
28+ /// that need to be applied to `self` to get `other`.
2929 /// TODO: Talk about choices in error handling and why Option<T> is enough, as opposed to the usual Result<Option<T>>
3030 /// Talk about progress (done via delegate if needed)
3131 ///
@@ -51,8 +51,8 @@ impl<'a> visit::Changes<'a> { · 19 unmodified lines
5151 ) -> Result<(), Error>
5252 where
5353 LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>,
54− R: visit::Record,
55− StateMut: BorrowMut<visit::State<R::PathId>>,
54+ R: tree::Visit,
55+ StateMut: BorrowMut<tree::State<R::PathId>>,
5656 {
5757 let state = state.borrow_mut();
5858 state.clear();
@@ -111,14 +111,14 @@ impl<'a> visit::Changes<'a> { · 52 unmodified lines
111111 }
112112 }
113113
114−fn delete_entry_schedule_recursion<R: visit::Record>(
114+fn delete_entry_schedule_recursion<R: tree::Visit>(
115115 entry: immutable::tree::Entry<'_>,
116116 queue: &mut VecDeque<TreeInfoPair<R::PathId>>,
117117 delegate: &mut R,
118118 ) -> Result<(), Error> {
119119 delegate.push_path_component(entry.filename);
120120 if delegate
121− .record(Change::Deletion {
121+ .visit(Change::Deletion {
122122 entry_mode: entry.mode,
123123 oid: entry.oid.to_owned(),
124124 })
@@ -140,14 +140,14 @@ fn delete_entry_schedule_recursion<R: visit::Record>( · 15 unmodified lines
140140 Ok(())
141141 }
142142
143−fn add_entry_schedule_recursion<R: visit::Record>(
143+fn add_entry_schedule_recursion<R: tree::Visit>(
144144 entry: immutable::tree::Entry<'_>,
145145 queue: &mut VecDeque<TreeInfoPair<R::PathId>>,
146146 delegate: &mut R,
147147 ) -> Result<(), Error> {
148148 delegate.push_path_component(entry.filename);
149149 if delegate
150− .record(Change::Addition {
150+ .visit(Change::Addition {
151151 entry_mode: entry.mode,
152152 oid: entry.oid.to_owned(),
153153 })
@@ -168,7 +168,7 @@ fn add_entry_schedule_recursion<R: visit::Record>( · 14 unmodified lines
168168 }
169169 Ok(())
170170 }
171−fn catchup_rhs_with_lhs<R: visit::Record>(
171+fn catchup_rhs_with_lhs<R: tree::Visit>(
172172 rhs_entries: &mut IteratorType<immutable::TreeIter<'_>>,
173173 lhs: immutable::tree::Entry<'_>,
174174 rhs: immutable::tree::Entry<'_>,
@@ -208,7 +208,7 @@ fn catchup_rhs_with_lhs<R: visit::Record>( · 33 unmodified lines
208208 Ok(())
209209 }
210210
211−fn catchup_lhs_with_rhs<R: visit::Record>(
211+fn catchup_lhs_with_rhs<R: tree::Visit>(
212212 lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>,
213213 lhs: immutable::tree::Entry<'_>,
214214 rhs: immutable::tree::Entry<'_>,
@@ -248,19 +248,19 @@ fn catchup_lhs_with_rhs<R: visit::Record>( · 33 unmodified lines
248248 Ok(())
249249 }
250250
251−fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>(
251+fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>(
252252 lhs: immutable::tree::Entry<'_>,
253253 rhs: immutable::tree::Entry<'_>,
254254 queue: &mut VecDeque<TreeInfoPair<R::PathId>>,
255255 delegate: &mut R,
256256 ) -> Result<(), Error> {
257− use tree::EntryMode::*;
257+ use git_object::tree::EntryMode::*;
258258 match (lhs.mode, rhs.mode) {
259259 (Tree, Tree) => {
260260 let path_id = delegate.push_tracked_path_component(lhs.filename);
261261 if lhs.oid != rhs.oid
262262 && delegate
263− .record(Change::Modification {
263+ .visit(Change::Modification {
264264 previous_entry_mode: lhs.mode,
265265 previous_oid: lhs.oid.to_owned(),
266266 entry_mode: rhs.mode,
@@ -284,7 +284,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 17 unmodified lines
284284 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {
285285 let path_id = delegate.push_tracked_path_component(lhs.filename);
286286 if delegate
287− .record(Change::Deletion {
287+ .visit(Change::Deletion {
288288 entry_mode: lhs.mode,
289289 oid: lhs.oid.to_owned(),
290290 })
@@ -293,7 +293,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 2 unmodified lines
293293 return Err(Cancelled);
294294 };
295295 if delegate
296− .record(Change::Addition {
296+ .visit(Change::Addition {
297297 entry_mode: rhs.mode,
298298 oid: rhs.oid.to_owned(),
299299 })
@@ -312,7 +312,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 12 unmodified lines
312312 (Tree, rhs_mode) if rhs_mode.is_no_tree() => {
313313 let path_id = delegate.push_tracked_path_component(lhs.filename);
314314 if delegate
315− .record(Change::Deletion {
315+ .visit(Change::Deletion {
316316 entry_mode: lhs.mode,
317317 oid: lhs.oid.to_owned(),
318318 })
@@ -321,7 +321,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 2 unmodified lines
321321 return Err(Error::Cancelled);
322322 }
323323 if delegate
324− .record(Change::Addition {
324+ .visit(Change::Addition {
325325 entry_mode: rhs.mode,
326326 oid: rhs.oid.to_owned(),
327327 })
@@ -342,7 +342,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 14 unmodified lines
342342 debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree());
343343 if lhs.oid != rhs.oid
344344 && delegate
345− .record(Change::Modification {
345+ .visit(Change::Modification {
346346 previous_entry_mode: lhs.mode,
347347 previous_oid: lhs.oid.to_owned(),
348348 entry_mode: rhs.mode,
git-diff/src/tree/mod.rsrenamed from git-diff/src/visit/mod.rs+3−3
@@ -41,9 +41,9 @@ where · 40 unmodified lines
4141 mod changes;
4242
4343 ///
44−pub mod record;
45−pub use record::Record;
44+pub mod visit;
45+pub use visit::Visit;
4646
47−/// Houses a [`record::Record`] to keep track of all seen changes. Useful for debugging primarily.
47+/// Houses a [`visit::Visit`] to keep track of all seen changes. Useful for debugging primarily.
4848 pub mod recorder;
4949 pub use recorder::Recorder;
git-diff/src/tree/recorder.rsrenamed from git-diff/src/visit/recorder.rs+8−8
@@ -1,4 +1,4 @@
1−use crate::visit::record;
1+use crate::tree::visit;
22 use git_hash::ObjectId;
33 use git_object::{
44 bstr::{BStr, BString, ByteSlice, ByteVec},
@@ -6,8 +6,8 @@ use git_object::{ · 1 unmodified line
66 };
77 use std::{collections::BTreeMap, ops::Deref, path::PathBuf};
88
9−/// A Change as observed by a call to [`record::Record::record`], enhanced with the path affected by the change.
10−/// Its similar to [record::Change] but adds a path.
9+/// A Change as observed by a call to [`visit::Visit::visit`], enhanced with the path affected by the change.
10+/// Its similar to [visit::Change] but adds a path.
1111 #[derive(Clone, Debug, PartialEq, Eq)]
1212 #[allow(missing_docs)]
1313 pub enum Change {
@@ -32,7 +32,7 @@ pub enum Change { · 18 unmodified lines
3232 },
3333 }
3434
35−/// A [record::Record] implementation to record every observed change and keep track of the changed paths.
35+/// A [visit::Visit] implementation to record every observed change and keep track of the changed paths.
3636 #[derive(Clone, Debug, Default)]
3737 pub struct Recorder {
3838 path_count: usize,
@@ -67,7 +67,7 @@ impl Recorder { · 28 unmodified lines
6767 }
6868 }
6969
70−impl record::Record for Recorder {
70+impl visit::Visit for Recorder {
7171 type PathId = usize;
7272
7373 fn set_current_path(&mut self, path: Self::PathId) {
@@ -90,8 +90,8 @@ impl record::Record for Recorder { · 16 unmodified lines
9090 self.pop_element();
9191 }
9292
93− fn record(&mut self, change: record::Change) -> record::Action {
94− use record::Change::*;
93+ fn visit(&mut self, change: visit::Change) -> visit::Action {
94+ use visit::Change::*;
9595 self.records.push(match change {
9696 Deletion { entry_mode, oid } => Change::Deletion {
9797 entry_mode,
@@ -116,6 +116,6 @@ impl record::Record for Recorder { · 18 unmodified lines
116116 path: self.path_buf(),
117117 },
118118 });
119− record::Action::Continue
119+ visit::Action::Continue
120120 }
121121 }
git-diff/src/tree/visit.rsrenamed from git-diff/src/visit/record.rs+4−4
@@ -32,12 +32,12 @@ pub enum Change { · 31 unmodified lines
3232 },
3333 }
3434
35−/// What to do after a [Change] was [recorded][Record::record()].
35+/// What to do after a [Change] was [recorded][Visit::visit()].
3636 #[derive(Clone, Copy, PartialOrd, PartialEq, Ord, Eq, Hash)]
3737 pub enum Action {
3838 /// Continue the traversal of changes.
3939 Continue,
40− /// Stop the traversal of changes, making this te last call to [record(…)][Record::record()].
40+ /// Stop the traversal of changes, making this te last call to [record(…)][Visit::visit()].
4141 Cancel,
4242 }
4343
@@ -50,7 +50,7 @@ impl Action { · 6 unmodified lines
5050
5151 /// A trait to allow responding to a traversal designed to figure out the [changes][Change]
5252 /// to turn tree A into tree B.
53−pub trait Record {
53+pub trait Visit {
5454 /// A type capable of uniquely identifying paths in a tree.
5555 type PathId: Clone + Default;
5656
@@ -65,7 +65,7 @@ pub trait Record { · 8 unmodified lines
6565 /// Record a `change` and return an instruction whether to continue or not.
6666 ///
6767 /// The implementation may use the current path to lean where in the tree the change is located.
68− fn record(&mut self, change: Change) -> Action;
68+ fn visit(&mut self, change: Change) -> Action;
6969 }
7070
7171 #[cfg(test)]