History

[tree-diff] A step closer to handling additions in a directory

Sebastian Thiel committed 5 years ago

Commit a11f2101 parent f1a575c6 files · +65 −11Browse files

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

Unified · Split

3 files
  1. git-diff/src/visit/changes.rs +20 −8
  2. git-diff/src/visit/record.rs +3 −2
  3. git-diff/src/visit/recorder.rs +14 −0
git-diff/src/visit/changes.rs+20−8
@@ -52,26 +52,38 @@ impl<'a> visit::Changes<'a> { · 51 unmodified lines
52 use std::cmp::Ordering::*;52 use std::cmp::Ordering::*;
53 match lhs.filename.cmp(rhs.filename) {53 match lhs.filename.cmp(rhs.filename) {
54 Equal => {54 Equal => {
55 use tree::EntryMode::*;
55 if lhs.oid != rhs.oid || lhs.mode != rhs.mode {56 if lhs.oid != rhs.oid || lhs.mode != rhs.mode {
56 delegate.update_path_component(57 delegate.update_path_component(
57 PathComponent::new(lhs.filename, &mut path_id),58 PathComponent::new(lhs.filename, &mut path_id),
58 PathComponentUpdateMode::Replace,59 PathComponentUpdateMode::Replace,
59 );60 );
60 if delegate61 let record_result = if (lhs.mode.is_no_tree() && rhs.mode.is_tree())
61 .record(Change::Modification {62 || (rhs.mode.is_tree() && rhs.mode.is_no_tree())
63 {
64 delegate.record(Change::Deletion {
65 entry_mode: lhs.mode,
66 oid: lhs.oid.to_owned(),
67 path_id,
68 })
69 } else {
70 delegate.record(Change::Modification {
62 previous_entry_mode: lhs.mode,71 previous_entry_mode: lhs.mode,
63 previous_oid: lhs.oid.to_owned(),72 previous_oid: lhs.oid.to_owned(),
64 entry_mode: rhs.mode,73 entry_mode: rhs.mode,
65 oid: rhs.oid.to_owned(),74 oid: rhs.oid.to_owned(),
66 path_id,75 path_id,
67 })76 })
68 .cancelled()77 };
69 {78 if record_result.cancelled() {
70 break Err(Error::Cancelled);79 break Err(Error::Cancelled);
71 }80 }
72 }81 }
73 if lhs.mode == tree::EntryMode::Tree || rhs.mode == tree::EntryMode::Tree {82 match (lhs.mode, rhs.mode) {
74 todo!("handle recursion")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 => {}
75 }87 }
76 }88 }
77 Less => todo!("entry compares less - catch up"),89 Less => todo!("entry compares less - catch up"),
@@ -85,8 +97,8 @@ impl<'a> visit::Changes<'a> { · 7 unmodified lines
85 );97 );
86 if delegate98 if delegate
87 .record(Change::Deletion {99 .record(Change::Deletion {
88 previous_entry_mode: lhs.mode,100 entry_mode: lhs.mode,
89 previous_oid: lhs.oid.to_owned(),101 oid: lhs.oid.to_owned(),
90 path_id,102 path_id,
91 })103 })
92 .cancelled()104 .cancelled()
git-diff/src/visit/record.rs+3−2
@@ -3,6 +3,7 @@ use git_object::{bstr::BStr, tree}; · 2 unmodified lines
3 3
4pub type PathId = usize;4pub type PathId = usize;
5 5
6/// `path_id`s are kept for rename or copy tracking to allow referring to a path in the tree more easily.
6pub enum Change {7pub enum Change {
7 Addition {8 Addition {
8 entry_mode: tree::EntryMode,9 entry_mode: tree::EntryMode,
@@ -11,8 +12,8 @@ pub enum Change { · 2 unmodified lines
11 },12 },
12 Copy,13 Copy,
13 Deletion {14 Deletion {
14 previous_entry_mode: tree::EntryMode,15 entry_mode: tree::EntryMode,
15 previous_oid: ObjectId,16 oid: ObjectId,
16 path_id: PathId,17 path_id: PathId,
17 },18 },
18 Modification {19 Modification {
git-diff/src/visit/recorder.rs+14−0
@@ -13,6 +13,11 @@ pub enum Change { · 12 unmodified lines
13 oid: ObjectId,13 oid: ObjectId,
14 path: PathBuf,14 path: PathBuf,
15 },15 },
16 Deletion {
17 entry_mode: tree::EntryMode,
18 oid: ObjectId,
19 path: PathBuf,
20 },
16 Modification {21 Modification {
17 previous_entry_mode: tree::EntryMode,22 previous_entry_mode: tree::EntryMode,
18 previous_oid: ObjectId,23 previous_oid: ObjectId,
@@ -70,6 +75,15 @@ impl record::Record for Recorder { · 51 unmodified lines
70 fn record(&mut self, change: record::Change) -> record::Action {75 fn record(&mut self, change: record::Change) -> record::Action {
71 use record::Change::*;76 use record::Change::*;
72 self.records.push(match change {77 self.records.push(match change {
78 Deletion {
79 entry_mode,
80 oid,
81 path_id: _,
82 } => Change::Deletion {
83 entry_mode,
84 oid,
85 path: self.path_buf(),
86 },
73 Addition {87 Addition {
74 entry_mode,88 entry_mode,
75 oid,89 oid,

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