Skip to content

Commit 9d01fb4

Browse files
committed
refactor (#470)
1 parent 90b9c90 commit 9d01fb4

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

Diff for: git-repository/src/object/tree/diff.rs

+40-35
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::bstr::{BStr, BString, ByteVec};
22
use crate::ext::ObjectIdExt;
3-
use crate::{Id, Repository, Tree};
3+
use crate::{Repository, Tree};
44
use git_object::TreeRefIter;
55
use git_odb::FindExt;
66

@@ -37,39 +37,44 @@ pub struct Change<'a, 'repo, 'other_repo> {
3737
/// Otherwise this value is always an empty path.
3838
pub location: &'a BStr,
3939
/// The diff event itself to provide information about what would need to change.
40-
pub event: Event<'repo, 'other_repo>,
40+
pub event: change::Event<'repo, 'other_repo>,
4141
}
4242

43-
/// An event emitted when finding differences between two trees.
44-
#[derive(Debug, Clone, Copy)]
45-
pub enum Event<'repo, 'other_repo> {
46-
/// An entry was added, like the addition of a file or directory.
47-
Addition {
48-
/// The mode of the added entry.
49-
entry_mode: git_object::tree::EntryMode,
50-
/// The object id of the added entry.
51-
id: Id<'other_repo>,
52-
},
53-
/// An entry was deleted, like the deletion of a file or directory.
54-
Deletion {
55-
/// The mode of the deleted entry.
56-
entry_mode: git_object::tree::EntryMode,
57-
/// The object id of the deleted entry.
58-
id: Id<'repo>,
59-
},
60-
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
61-
/// a file into a symbolic link adjusts its mode.
62-
Modification {
63-
/// The mode of the entry before the modification.
64-
previous_entry_mode: git_object::tree::EntryMode,
65-
/// The object id of the entry before the modification.
66-
previous_id: Id<'repo>,
67-
68-
/// The mode of the entry after the modification.
69-
entry_mode: git_object::tree::EntryMode,
70-
/// The object id after the modification.
71-
id: Id<'other_repo>,
72-
},
43+
///
44+
pub mod change {
45+
use crate::Id;
46+
47+
/// An event emitted when finding differences between two trees.
48+
#[derive(Debug, Clone, Copy)]
49+
pub enum Event<'repo, 'other_repo> {
50+
/// An entry was added, like the addition of a file or directory.
51+
Addition {
52+
/// The mode of the added entry.
53+
entry_mode: git_object::tree::EntryMode,
54+
/// The object id of the added entry.
55+
id: Id<'other_repo>,
56+
},
57+
/// An entry was deleted, like the deletion of a file or directory.
58+
Deletion {
59+
/// The mode of the deleted entry.
60+
entry_mode: git_object::tree::EntryMode,
61+
/// The object id of the deleted entry.
62+
id: Id<'repo>,
63+
},
64+
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
65+
/// a file into a symbolic link adjusts its mode.
66+
Modification {
67+
/// The mode of the entry before the modification.
68+
previous_entry_mode: git_object::tree::EntryMode,
69+
/// The object id of the entry before the modification.
70+
previous_id: Id<'repo>,
71+
72+
/// The mode of the entry after the modification.
73+
entry_mode: git_object::tree::EntryMode,
74+
/// The object id after the modification.
75+
id: Id<'other_repo>,
76+
},
77+
}
7378
}
7479

7580
/// Diffing
@@ -174,11 +179,11 @@ where
174179
fn visit(&mut self, change: git_diff::tree::visit::Change) -> git_diff::tree::visit::Action {
175180
use git_diff::tree::visit::Change::*;
176181
let event = match change {
177-
Addition { entry_mode, oid } => Event::Addition {
182+
Addition { entry_mode, oid } => change::Event::Addition {
178183
entry_mode,
179184
id: oid.attach(self.other_repo),
180185
},
181-
Deletion { entry_mode, oid } => Event::Deletion {
186+
Deletion { entry_mode, oid } => change::Event::Deletion {
182187
entry_mode,
183188
id: oid.attach(self.repo),
184189
},
@@ -187,7 +192,7 @@ where
187192
previous_oid,
188193
entry_mode,
189194
oid,
190-
} => Event::Modification {
195+
} => change::Event::Modification {
191196
previous_entry_mode,
192197
entry_mode,
193198
previous_id: previous_oid.attach(self.repo),

Diff for: git-repository/tests/object/tree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod diff {
33
use git_object::bstr::ByteSlice;
44
use git_object::tree::EntryMode;
55
use git_repository as git;
6-
use git_repository::object::tree::diff::Event;
6+
use git_repository::object::tree::diff::change::Event;
77
use std::convert::Infallible;
88

99
#[test]

0 commit comments

Comments
 (0)