Skip to content

Commit

Permalink
refactor (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 19, 2022
1 parent 90b9c90 commit 9d01fb4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
75 changes: 40 additions & 35 deletions git-repository/src/object/tree/diff.rs
@@ -1,6 +1,6 @@
use crate::bstr::{BStr, BString, ByteVec};
use crate::ext::ObjectIdExt;
use crate::{Id, Repository, Tree};
use crate::{Repository, Tree};
use git_object::TreeRefIter;
use git_odb::FindExt;

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

/// An event emitted when finding differences between two trees.
#[derive(Debug, Clone, Copy)]
pub enum Event<'repo, 'other_repo> {
/// An entry was added, like the addition of a file or directory.
Addition {
/// The mode of the added entry.
entry_mode: git_object::tree::EntryMode,
/// The object id of the added entry.
id: Id<'other_repo>,
},
/// An entry was deleted, like the deletion of a file or directory.
Deletion {
/// The mode of the deleted entry.
entry_mode: git_object::tree::EntryMode,
/// The object id of the deleted entry.
id: Id<'repo>,
},
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
/// a file into a symbolic link adjusts its mode.
Modification {
/// The mode of the entry before the modification.
previous_entry_mode: git_object::tree::EntryMode,
/// The object id of the entry before the modification.
previous_id: Id<'repo>,

/// The mode of the entry after the modification.
entry_mode: git_object::tree::EntryMode,
/// The object id after the modification.
id: Id<'other_repo>,
},
///
pub mod change {
use crate::Id;

/// An event emitted when finding differences between two trees.
#[derive(Debug, Clone, Copy)]
pub enum Event<'repo, 'other_repo> {
/// An entry was added, like the addition of a file or directory.
Addition {
/// The mode of the added entry.
entry_mode: git_object::tree::EntryMode,
/// The object id of the added entry.
id: Id<'other_repo>,
},
/// An entry was deleted, like the deletion of a file or directory.
Deletion {
/// The mode of the deleted entry.
entry_mode: git_object::tree::EntryMode,
/// The object id of the deleted entry.
id: Id<'repo>,
},
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
/// a file into a symbolic link adjusts its mode.
Modification {
/// The mode of the entry before the modification.
previous_entry_mode: git_object::tree::EntryMode,
/// The object id of the entry before the modification.
previous_id: Id<'repo>,

/// The mode of the entry after the modification.
entry_mode: git_object::tree::EntryMode,
/// The object id after the modification.
id: Id<'other_repo>,
},
}
}

/// Diffing
Expand Down Expand Up @@ -174,11 +179,11 @@ where
fn visit(&mut self, change: git_diff::tree::visit::Change) -> git_diff::tree::visit::Action {
use git_diff::tree::visit::Change::*;
let event = match change {
Addition { entry_mode, oid } => Event::Addition {
Addition { entry_mode, oid } => change::Event::Addition {
entry_mode,
id: oid.attach(self.other_repo),
},
Deletion { entry_mode, oid } => Event::Deletion {
Deletion { entry_mode, oid } => change::Event::Deletion {
entry_mode,
id: oid.attach(self.repo),
},
Expand All @@ -187,7 +192,7 @@ where
previous_oid,
entry_mode,
oid,
} => Event::Modification {
} => change::Event::Modification {
previous_entry_mode,
entry_mode,
previous_id: previous_oid.attach(self.repo),
Expand Down
2 changes: 1 addition & 1 deletion git-repository/tests/object/tree.rs
Expand Up @@ -3,7 +3,7 @@ mod diff {
use git_object::bstr::ByteSlice;
use git_object::tree::EntryMode;
use git_repository as git;
use git_repository::object::tree::diff::Event;
use git_repository::object::tree::diff::change::Event;
use std::convert::Infallible;

#[test]
Expand Down

0 comments on commit 9d01fb4

Please sign in to comment.