History

[git-diff] refactor

Sebastian Thiel committed 5 years ago

Commit 9373cd61 parent 087e8533 files · +19 −68Browse files

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

Unified · Split

2 files
  1. git-diff/src/tree/changes.rs +15 −56
  2. git-diff/src/tree/mod.rs +1 −7
git-diff/src/tree/changes.rs+15−56
@@ -1,6 +1,6 @@
11 use crate::{
22 tree,
3− tree::{visit::Change, TreeInfo, TreeInfoPair},
3+ tree::{visit::Change, TreeInfoPair},
44 };
55 use git_hash::{oid, ObjectId};
66 use git_object::immutable;
@@ -77,24 +77,16 @@ impl<'a> tree::Changes<'a> { · 70 unmodified lines
7777 match state.trees.pop_front() {
7878 Some((None, Some(rhs))) => {
7979 delegate.pop_front_tracked_path_and_set_current();
80− rhs_entries = peekable(
81− locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound { oid: rhs.tree_id })?,
82− );
80+ rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
8381 }
8482 Some((Some(lhs), Some(rhs))) => {
8583 delegate.pop_front_tracked_path_and_set_current();
86− lhs_entries = peekable(
87− locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound { oid: lhs.tree_id })?,
88− );
89− rhs_entries = peekable(
90− locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound { oid: rhs.tree_id })?,
91− );
84+ lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
85+ rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?);
9286 }
9387 Some((Some(lhs), None)) => {
9488 delegate.pop_front_tracked_path_and_set_current();
95− lhs_entries = peekable(
96− locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound { oid: lhs.tree_id })?,
97− );
89+ lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?);
9890 }
9991 Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"),
10092 None => return Ok(()),
@@ -140,14 +132,8 @@ fn delete_entry_schedule_recursion<R: tree::Visit>( · 39 unmodified lines
140132 }
141133 if entry.mode.is_tree() {
142134 delegate.pop_path_component();
143− let path_id = delegate.push_back_tracked_path_component(entry.filename);
144− queue.push_back((
145− Some(TreeInfo {
146− tree_id: entry.oid.to_owned(),
147− parent_path_id: Some(path_id),
148− }),
149− None,
150− ));
135+ delegate.push_back_tracked_path_component(entry.filename);
136+ queue.push_back((Some(entry.oid.to_owned()), None));
151137 }
152138 Ok(())
153139 }
@@ -169,14 +155,8 @@ fn add_entry_schedule_recursion<R: tree::Visit>( · 15 unmodified lines
169155 }
170156 if entry.mode.is_tree() {
171157 delegate.pop_path_component();
172− let path_id = delegate.push_back_tracked_path_component(entry.filename);
173− queue.push_back((
174− None,
175− Some(TreeInfo {
176− tree_id: entry.oid.to_owned(),
177− parent_path_id: Some(path_id),
178− }),
179− ))
158+ delegate.push_back_tracked_path_component(entry.filename);
159+ queue.push_back((None, Some(entry.oid.to_owned())))
180160 }
181161 Ok(())
182162 }
@@ -269,7 +249,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 86 unmodified lines
269249 use git_object::tree::EntryMode::*;
270250 match (lhs.mode, rhs.mode) {
271251 (Tree, Tree) => {
272− let path_id = delegate.push_back_tracked_path_component(lhs.filename);
252+ delegate.push_back_tracked_path_component(lhs.filename);
273253 if lhs.oid != rhs.oid
274254 && delegate
275255 .visit(Change::Modification {
@@ -282,19 +262,10 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 6 unmodified lines
282262 {
283263 return Err(Error::Cancelled);
284264 }
285− queue.push_back((
286− Some(TreeInfo {
287− tree_id: lhs.oid.to_owned(),
288− parent_path_id: Some(path_id),
289− }),
290− Some(TreeInfo {
291− tree_id: rhs.oid.to_owned(),
292− parent_path_id: None,
293− }),
294− ));
265+ queue.push_back((Some(lhs.oid.to_owned()), Some(rhs.oid.to_owned())));
295266 }
296267 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {
297− let path_id = delegate.push_back_tracked_path_component(lhs.filename);
268+ delegate.push_back_tracked_path_component(lhs.filename);
298269 if delegate
299270 .visit(Change::Deletion {
300271 entry_mode: lhs.mode,
@@ -313,16 +284,10 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 12 unmodified lines
313284 {
314285 return Err(Error::Cancelled);
315286 };
316− queue.push_back((
317− None,
318− Some(TreeInfo {
319− tree_id: rhs.oid.to_owned(),
320− parent_path_id: Some(path_id),
321− }),
322− ));
287+ queue.push_back((None, Some(rhs.oid.to_owned())));
323288 }
324289 (Tree, rhs_mode) if rhs_mode.is_no_tree() => {
325− let path_id = delegate.push_back_tracked_path_component(lhs.filename);
290+ delegate.push_back_tracked_path_component(lhs.filename);
326291 if delegate
327292 .visit(Change::Deletion {
328293 entry_mode: lhs.mode,
@@ -341,13 +306,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 12 unmodified lines
341306 {
342307 return Err(Error::Cancelled);
343308 };
344− queue.push_back((
345− Some(TreeInfo {
346− tree_id: lhs.oid.to_owned(),
347− parent_path_id: Some(path_id),
348− }),
349− None,
350− ));
309+ queue.push_back((Some(lhs.oid.to_owned()), None));
351310 }
352311 (lhs_non_tree, rhs_non_tree) => {
353312 delegate.push_path_component(lhs.filename);
git-diff/src/tree/mod.rs+1−7
@@ -10,13 +10,7 @@ pub struct State { · 9 unmodified lines
1010 trees: VecDeque<TreeInfoPair>,
1111 }
1212
13−type TreeInfoPair = (Option<TreeInfo>, Option<TreeInfo>);
14−
15−#[derive(Clone)]
16−pub(crate) struct TreeInfo {
17− pub tree_id: ObjectId,
18− pub parent_path_id: Option<()>,
19−}
13+type TreeInfoPair = (Option<ObjectId>, Option<ObjectId>);
2014
2115 impl State {
2216 fn clear(&mut self) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t