Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ce9832

Browse files
committed
refactor
1 parent a11f210 commit 9ce9832

1 file changed

Lines changed: 57 additions & 26 deletions

File tree

git-diff/src/visit/changes.rs

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::visit;
2-
use crate::visit::record::{Change, PathComponent, PathComponentUpdateMode};
2+
use crate::visit::changes::Error::Cancelled;
3+
use crate::visit::record::{Action, Change, PathComponent, PathComponentUpdateMode};
34
use git_hash::{oid, ObjectId};
45
use git_object::{immutable, tree};
56
use quick_error::quick_error;
@@ -53,37 +54,61 @@ impl<'a> visit::Changes<'a> {
5354
match lhs.filename.cmp(rhs.filename) {
5455
Equal => {
5556
use tree::EntryMode::*;
56-
if lhs.oid != rhs.oid || lhs.mode != rhs.mode {
57-
delegate.update_path_component(
58-
PathComponent::new(lhs.filename, &mut path_id),
59-
PathComponentUpdateMode::Replace,
60-
);
61-
let record_result = if (lhs.mode.is_no_tree() && rhs.mode.is_tree())
62-
|| (rhs.mode.is_tree() && rhs.mode.is_no_tree())
63-
{
57+
delegate.update_path_component(
58+
PathComponent::new(lhs.filename, &mut path_id),
59+
PathComponentUpdateMode::Replace,
60+
);
61+
let record_result = match (lhs.mode, rhs.mode) {
62+
(Tree, Tree) => {
63+
if lhs.oid != rhs.oid {
64+
if delegate
65+
.record(Change::Modification {
66+
previous_entry_mode: lhs.mode,
67+
previous_oid: lhs.oid.to_owned(),
68+
entry_mode: rhs.mode,
69+
oid: rhs.oid.to_owned(),
70+
path_id,
71+
})
72+
.cancelled()
73+
{
74+
break Err(Cancelled);
75+
}
76+
}
77+
todo!("schedule tree|tree iteration schedule the trees with stack")
78+
}
79+
(lhs_mode, Tree) if lhs_mode.is_no_tree() => {
6480
delegate.record(Change::Deletion {
6581
entry_mode: lhs.mode,
6682
oid: lhs.oid.to_owned(),
6783
path_id,
68-
})
69-
} else {
70-
delegate.record(Change::Modification {
71-
previous_entry_mode: lhs.mode,
72-
previous_oid: lhs.oid.to_owned(),
73-
entry_mode: rhs.mode,
74-
oid: rhs.oid.to_owned(),
84+
});
85+
todo!("delete non-tree ✓|tree - add rhs recursively")
86+
}
87+
(Tree, rhs_mode) if rhs_mode.is_no_tree() => {
88+
delegate.record(Change::Deletion {
89+
entry_mode: lhs.mode,
90+
oid: lhs.oid.to_owned(),
7591
path_id,
76-
})
77-
};
78-
if record_result.cancelled() {
79-
break Err(Error::Cancelled);
92+
});
93+
todo!("delete lhs recursively|add non-tree")
8094
}
81-
}
82-
match (lhs.mode, rhs.mode) {
83-
(Tree, Tree) => todo!("recurse tree|tree"),
84-
(lhs, Tree) if !lhs.is_tree() => todo!("recurse non-tree|tree"),
85-
(Tree, rhs) if !rhs.is_tree() => todo!("recurse tree|non-tree"),
86-
_both_are_not_trees => {}
95+
(lhs_non_tree, rhs_non_tree) => {
96+
debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree());
97+
if lhs.oid != rhs.oid {
98+
delegate.record(Change::Modification {
99+
previous_entry_mode: lhs.mode,
100+
previous_oid: lhs.oid.to_owned(),
101+
entry_mode: rhs.mode,
102+
oid: rhs.oid.to_owned(),
103+
path_id,
104+
})
105+
} else {
106+
Action::Continue
107+
}
108+
}
109+
};
110+
if record_result.cancelled() {
111+
break Err(Error::Cancelled);
87112
}
88113
}
89114
Less => todo!("entry compares less - catch up"),
@@ -105,6 +130,9 @@ impl<'a> visit::Changes<'a> {
105130
{
106131
break Err(Error::Cancelled);
107132
}
133+
if lhs.mode.is_tree() {
134+
todo!("delete tree recursively")
135+
}
108136
}
109137
(None, Some(rhs)) => {
110138
delegate.update_path_component(
@@ -121,6 +149,9 @@ impl<'a> visit::Changes<'a> {
121149
{
122150
break Err(Error::Cancelled);
123151
}
152+
if rhs.mode.is_tree() {
153+
todo!("add tree recursively")
154+
}
124155
}
125156
}
126157
}

0 commit comments

Comments
 (0)