Show More
@@ -561,19 +561,26 b' if rustmod is not None:' | |||
|
561 | 561 | from_p2=False, |
|
562 | 562 | possibly_dirty=False, |
|
563 | 563 | ): |
|
564 | ret = self._rustmap.addfile( | |
|
565 | f, | |
|
566 |
|
|
|
567 | size, | |
|
568 |
|
|
|
569 | added, | |
|
570 |
|
|
|
571 | from_p2, | |
|
572 | possibly_dirty, | |
|
573 | ) | |
|
564 | if added: | |
|
565 | assert not possibly_dirty | |
|
566 | assert not from_p2 | |
|
567 | item = DirstateItem.new_added() | |
|
568 | elif merged: | |
|
569 | assert not possibly_dirty | |
|
570 | assert not from_p2 | |
|
571 | item = DirstateItem.new_merged() | |
|
572 | elif from_p2: | |
|
573 | assert not possibly_dirty | |
|
574 | item = DirstateItem.new_from_p2() | |
|
575 | elif possibly_dirty: | |
|
576 | item = DirstateItem.new_possibly_dirty() | |
|
577 | else: | |
|
578 | size = size & rangemask | |
|
579 | mtime = mtime & rangemask | |
|
580 | item = DirstateItem.new_normal(mode, size, mtime) | |
|
581 | self._rustmap.addfile(f, item) | |
|
574 | 582 | if added: |
|
575 | 583 | self.copymap.pop(f, None) |
|
576 | return ret | |
|
577 | 584 | |
|
578 | 585 | def reset_state( |
|
579 | 586 | self, |
@@ -8,10 +8,8 b'' | |||
|
8 | 8 | use crate::dirstate::parsers::Timestamp; |
|
9 | 9 | use crate::{ |
|
10 | 10 | dirstate::EntryState, |
|
11 | dirstate::MTIME_UNSET, | |
|
12 | 11 | dirstate::SIZE_FROM_OTHER_PARENT, |
|
13 | 12 | dirstate::SIZE_NON_NORMAL, |
|
14 | dirstate::V1_RANGEMASK, | |
|
15 | 13 | pack_dirstate, parse_dirstate, |
|
16 | 14 | utils::hg_path::{HgPath, HgPathBuf}, |
|
17 | 15 | CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents, |
@@ -73,44 +71,7 b' impl DirstateMap {' | |||
|
73 | 71 | &mut self, |
|
74 | 72 | filename: &HgPath, |
|
75 | 73 | entry: DirstateEntry, |
|
76 | // XXX once the dust settle this should probably become an enum | |
|
77 | added: bool, | |
|
78 | merged: bool, | |
|
79 | from_p2: bool, | |
|
80 | possibly_dirty: bool, | |
|
81 | 74 | ) -> Result<(), DirstateError> { |
|
82 | let state; | |
|
83 | let size; | |
|
84 | let mtime; | |
|
85 | if added { | |
|
86 | assert!(!possibly_dirty); | |
|
87 | assert!(!from_p2); | |
|
88 | state = EntryState::Added; | |
|
89 | size = SIZE_NON_NORMAL; | |
|
90 | mtime = MTIME_UNSET; | |
|
91 | } else if merged { | |
|
92 | assert!(!possibly_dirty); | |
|
93 | assert!(!from_p2); | |
|
94 | state = EntryState::Merged; | |
|
95 | size = SIZE_FROM_OTHER_PARENT; | |
|
96 | mtime = MTIME_UNSET; | |
|
97 | } else if from_p2 { | |
|
98 | assert!(!possibly_dirty); | |
|
99 | state = EntryState::Normal; | |
|
100 | size = SIZE_FROM_OTHER_PARENT; | |
|
101 | mtime = MTIME_UNSET; | |
|
102 | } else if possibly_dirty { | |
|
103 | state = EntryState::Normal; | |
|
104 | size = SIZE_NON_NORMAL; | |
|
105 | mtime = MTIME_UNSET; | |
|
106 | } else { | |
|
107 | state = EntryState::Normal; | |
|
108 | size = entry.size() & V1_RANGEMASK; | |
|
109 | mtime = entry.mtime() & V1_RANGEMASK; | |
|
110 | } | |
|
111 | let mode = entry.mode(); | |
|
112 | let entry = DirstateEntry::from_v1_data(state, mode, size, mtime); | |
|
113 | ||
|
114 | 75 | let old_state = self.get(filename).map(|e| e.state()); |
|
115 | 76 | if old_state.is_none() || old_state == Some(EntryState::Removed) { |
|
116 | 77 | if let Some(ref mut dirs) = self.dirs { |
@@ -417,10 +378,6 b' mod tests {' | |||
|
417 | 378 | map.add_file( |
|
418 | 379 | HgPath::new(b"meh"), |
|
419 | 380 | DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337), |
|
420 | false, | |
|
421 | false, | |
|
422 | false, | |
|
423 | false, | |
|
424 | 381 | ) |
|
425 | 382 | .unwrap(); |
|
426 | 383 |
@@ -83,12 +83,7 b' impl DirstateEntry {' | |||
|
83 | 83 | mtime: 0, |
|
84 | 84 | } |
|
85 | 85 | } else { |
|
86 |
Self |
|
|
87 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, | |
|
88 | mode, | |
|
89 | size, | |
|
90 | mtime, | |
|
91 | } | |
|
86 | Self::new_normal(mode, size, mtime) | |
|
92 | 87 | } |
|
93 | 88 | } |
|
94 | 89 | EntryState::Added => Self::new_added(), |
@@ -111,7 +106,7 b' impl DirstateEntry {' | |||
|
111 | 106 | } |
|
112 | 107 | } |
|
113 | 108 | |
|
114 | fn new_from_p2() -> Self { | |
|
109 | pub fn new_from_p2() -> Self { | |
|
115 | 110 | Self { |
|
116 | 111 | // might be missing P1_TRACKED |
|
117 | 112 | flags: Flags::WDIR_TRACKED | Flags::P2_TRACKED | Flags::CLEAN_P2, |
@@ -121,7 +116,7 b' impl DirstateEntry {' | |||
|
121 | 116 | } |
|
122 | 117 | } |
|
123 | 118 | |
|
124 | fn new_possibly_dirty() -> Self { | |
|
119 | pub fn new_possibly_dirty() -> Self { | |
|
125 | 120 | Self { |
|
126 | 121 | flags: Flags::WDIR_TRACKED |
|
127 | 122 | | Flags::P1_TRACKED |
@@ -132,7 +127,7 b' impl DirstateEntry {' | |||
|
132 | 127 | } |
|
133 | 128 | } |
|
134 | 129 | |
|
135 | fn new_added() -> Self { | |
|
130 | pub fn new_added() -> Self { | |
|
136 | 131 | Self { |
|
137 | 132 | flags: Flags::WDIR_TRACKED, |
|
138 | 133 | mode: 0, |
@@ -141,7 +136,7 b' impl DirstateEntry {' | |||
|
141 | 136 | } |
|
142 | 137 | } |
|
143 | 138 | |
|
144 | fn new_merged() -> Self { | |
|
139 | pub fn new_merged() -> Self { | |
|
145 | 140 | Self { |
|
146 | 141 | flags: Flags::WDIR_TRACKED |
|
147 | 142 | | Flags::P1_TRACKED // might not be true because of rename ? |
@@ -153,6 +148,15 b' impl DirstateEntry {' | |||
|
153 | 148 | } |
|
154 | 149 | } |
|
155 | 150 | |
|
151 | pub fn new_normal(mode: i32, size: i32, mtime: i32) -> Self { | |
|
152 | Self { | |
|
153 | flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED, | |
|
154 | mode, | |
|
155 | size, | |
|
156 | mtime, | |
|
157 | } | |
|
158 | } | |
|
159 | ||
|
156 | 160 | /// Creates a new entry in "removed" state. |
|
157 | 161 | /// |
|
158 | 162 | /// `size` is expected to be zero, `SIZE_NON_NORMAL`, or |
@@ -161,14 +165,6 b' impl DirstateEntry {' | |||
|
161 | 165 | Self::from_v1_data(EntryState::Removed, 0, size, 0) |
|
162 | 166 | } |
|
163 | 167 | |
|
164 | /// TODO: refactor `DirstateMap::add_file` to not take a `DirstateEntry` | |
|
165 | /// parameter and remove this constructor | |
|
166 | pub fn new_for_add_file(mode: i32, size: i32, mtime: i32) -> Self { | |
|
167 | // XXX Arbitrary default value since the value is determined later | |
|
168 | let state = EntryState::Normal; | |
|
169 | Self::from_v1_data(state, mode, size, mtime) | |
|
170 | } | |
|
171 | ||
|
172 | 168 | pub fn tracked(&self) -> bool { |
|
173 | 169 | self.flags.contains(Flags::WDIR_TRACKED) |
|
174 | 170 | } |
@@ -11,10 +11,8 b' use crate::dirstate::parsers::pack_entry' | |||
|
11 | 11 | use crate::dirstate::parsers::packed_entry_size; |
|
12 | 12 | use crate::dirstate::parsers::parse_dirstate_entries; |
|
13 | 13 | use crate::dirstate::parsers::Timestamp; |
|
14 | use crate::dirstate::MTIME_UNSET; | |
|
15 | 14 | use crate::dirstate::SIZE_FROM_OTHER_PARENT; |
|
16 | 15 | use crate::dirstate::SIZE_NON_NORMAL; |
|
17 | use crate::dirstate::V1_RANGEMASK; | |
|
18 | 16 | use crate::matchers::Matcher; |
|
19 | 17 | use crate::utils::hg_path::{HgPath, HgPathBuf}; |
|
20 | 18 | use crate::CopyMapIter; |
@@ -771,45 +769,8 b" impl<'on_disk> super::dispatch::Dirstate" | |||
|
771 | 769 | &mut self, |
|
772 | 770 | filename: &HgPath, |
|
773 | 771 | entry: DirstateEntry, |
|
774 | added: bool, | |
|
775 | merged: bool, | |
|
776 | from_p2: bool, | |
|
777 | possibly_dirty: bool, | |
|
778 | 772 | ) -> Result<(), DirstateError> { |
|
779 | let state; | |
|
780 | let size; | |
|
781 | let mtime; | |
|
782 | if added { | |
|
783 | assert!(!possibly_dirty); | |
|
784 | assert!(!from_p2); | |
|
785 | state = EntryState::Added; | |
|
786 | size = SIZE_NON_NORMAL; | |
|
787 | mtime = MTIME_UNSET; | |
|
788 | } else if merged { | |
|
789 | assert!(!possibly_dirty); | |
|
790 | assert!(!from_p2); | |
|
791 | state = EntryState::Merged; | |
|
792 | size = SIZE_FROM_OTHER_PARENT; | |
|
793 | mtime = MTIME_UNSET; | |
|
794 | } else if from_p2 { | |
|
795 | assert!(!possibly_dirty); | |
|
796 | state = EntryState::Normal; | |
|
797 | size = SIZE_FROM_OTHER_PARENT; | |
|
798 | mtime = MTIME_UNSET; | |
|
799 | } else if possibly_dirty { | |
|
800 | state = EntryState::Normal; | |
|
801 | size = SIZE_NON_NORMAL; | |
|
802 | mtime = MTIME_UNSET; | |
|
803 | } else { | |
|
804 | state = EntryState::Normal; | |
|
805 | size = entry.size() & V1_RANGEMASK; | |
|
806 | mtime = entry.mtime() & V1_RANGEMASK; | |
|
807 | } | |
|
808 | let mode = entry.mode(); | |
|
809 | let entry = DirstateEntry::from_v1_data(state, mode, size, mtime); | |
|
810 | ||
|
811 | 773 | let old_state = self.get(filename)?.map(|e| e.state()); |
|
812 | ||
|
813 | 774 | Ok(self.add_or_remove_file(filename, old_state, entry)?) |
|
814 | 775 | } |
|
815 | 776 |
@@ -50,10 +50,6 b' pub trait DirstateMapMethods {' | |||
|
50 | 50 | &mut self, |
|
51 | 51 | filename: &HgPath, |
|
52 | 52 | entry: DirstateEntry, |
|
53 | added: bool, | |
|
54 | merged: bool, | |
|
55 | from_p2: bool, | |
|
56 | possibly_dirty: bool, | |
|
57 | 53 | ) -> Result<(), DirstateError>; |
|
58 | 54 | |
|
59 | 55 | /// Mark a file as "removed" (as in `hg rm`). |
@@ -326,12 +322,8 b' impl DirstateMapMethods for DirstateMap ' | |||
|
326 | 322 | &mut self, |
|
327 | 323 | filename: &HgPath, |
|
328 | 324 | entry: DirstateEntry, |
|
329 | added: bool, | |
|
330 | merged: bool, | |
|
331 | from_p2: bool, | |
|
332 | possibly_dirty: bool, | |
|
333 | 325 | ) -> Result<(), DirstateError> { |
|
334 |
self.add_file(filename, entry |
|
|
326 | self.add_file(filename, entry) | |
|
335 | 327 | } |
|
336 | 328 | |
|
337 | 329 | fn remove_file( |
@@ -32,19 +32,8 b' impl DirstateMapMethods for OwningDirsta' | |||
|
32 | 32 | &mut self, |
|
33 | 33 | filename: &HgPath, |
|
34 | 34 | entry: DirstateEntry, |
|
35 | added: bool, | |
|
36 | merged: bool, | |
|
37 | from_p2: bool, | |
|
38 | possibly_dirty: bool, | |
|
39 | 35 | ) -> Result<(), DirstateError> { |
|
40 | self.get_mut().add_file( | |
|
41 | filename, | |
|
42 | entry, | |
|
43 | added, | |
|
44 | merged, | |
|
45 | from_p2, | |
|
46 | possibly_dirty, | |
|
47 | ) | |
|
36 | self.get_mut().add_file(filename, entry) | |
|
48 | 37 | } |
|
49 | 38 | |
|
50 | 39 | fn remove_file( |
@@ -27,8 +27,6 b' use crate::{' | |||
|
27 | 27 | }; |
|
28 | 28 | use hg::{ |
|
29 | 29 | dirstate::parsers::Timestamp, |
|
30 | dirstate::MTIME_UNSET, | |
|
31 | dirstate::SIZE_NON_NORMAL, | |
|
32 | 30 | dirstate_tree::dirstate_map::DirstateMap as TreeDirstateMap, |
|
33 | 31 | dirstate_tree::dispatch::DirstateMapMethods, |
|
34 | 32 | dirstate_tree::on_disk::DirstateV2ParseError, |
@@ -145,50 +143,16 b' py_class!(pub class DirstateMap |py| {' | |||
|
145 | 143 | |
|
146 | 144 | def addfile( |
|
147 | 145 | &self, |
|
148 |
f: Py |
|
|
149 | mode: PyObject, | |
|
150 | size: PyObject, | |
|
151 | mtime: PyObject, | |
|
152 | added: PyObject, | |
|
153 | merged: PyObject, | |
|
154 | from_p2: PyObject, | |
|
155 | possibly_dirty: PyObject, | |
|
156 | ) -> PyResult<PyObject> { | |
|
157 | let f = f.extract::<PyBytes>(py)?; | |
|
146 | f: PyBytes, | |
|
147 | item: DirstateItem, | |
|
148 | ) -> PyResult<PyNone> { | |
|
158 | 149 | let filename = HgPath::new(f.data(py)); |
|
159 |
let |
|
|
160 | // fallback default value | |
|
161 |
|
|
|
162 | } else { | |
|
163 | mode.extract(py)? | |
|
164 | }; | |
|
165 | let size = if size.is_none(py) { | |
|
166 | // fallback default value | |
|
167 | SIZE_NON_NORMAL | |
|
168 | } else { | |
|
169 | size.extract(py)? | |
|
170 | }; | |
|
171 | let mtime = if mtime.is_none(py) { | |
|
172 | // fallback default value | |
|
173 | MTIME_UNSET | |
|
174 | } else { | |
|
175 | mtime.extract(py)? | |
|
176 | }; | |
|
177 | let entry = DirstateEntry::new_for_add_file(mode, size, mtime); | |
|
178 | let added = added.extract::<PyBool>(py)?.is_true(); | |
|
179 | let merged = merged.extract::<PyBool>(py)?.is_true(); | |
|
180 | let from_p2 = from_p2.extract::<PyBool>(py)?.is_true(); | |
|
181 | let possibly_dirty = possibly_dirty.extract::<PyBool>(py)?.is_true(); | |
|
182 | self.inner(py).borrow_mut().add_file( | |
|
183 | filename, | |
|
184 | entry, | |
|
185 | added, | |
|
186 | merged, | |
|
187 | from_p2, | |
|
188 | possibly_dirty | |
|
189 | ).and(Ok(py.None())).or_else(|e: DirstateError| { | |
|
190 | Err(PyErr::new::<exc::ValueError, _>(py, e.to_string())) | |
|
191 | }) | |
|
150 | let entry = item.get_entry(py); | |
|
151 | self.inner(py) | |
|
152 | .borrow_mut() | |
|
153 | .add_file(filename, entry) | |
|
154 | .map_err(|e |dirstate_error(py, e))?; | |
|
155 | Ok(PyNone) | |
|
192 | 156 | } |
|
193 | 157 | |
|
194 | 158 | def removefile( |
@@ -146,6 +146,36 b' py_class!(pub class DirstateItem |py| {' | |||
|
146 | 146 | DirstateItem::create_instance(py, Cell::new(entry)) |
|
147 | 147 | } |
|
148 | 148 | |
|
149 | @classmethod | |
|
150 | def new_added(_cls) -> PyResult<Self> { | |
|
151 | let entry = DirstateEntry::new_added(); | |
|
152 | DirstateItem::create_instance(py, Cell::new(entry)) | |
|
153 | } | |
|
154 | ||
|
155 | @classmethod | |
|
156 | def new_merged(_cls) -> PyResult<Self> { | |
|
157 | let entry = DirstateEntry::new_merged(); | |
|
158 | DirstateItem::create_instance(py, Cell::new(entry)) | |
|
159 | } | |
|
160 | ||
|
161 | @classmethod | |
|
162 | def new_from_p2(_cls) -> PyResult<Self> { | |
|
163 | let entry = DirstateEntry::new_from_p2(); | |
|
164 | DirstateItem::create_instance(py, Cell::new(entry)) | |
|
165 | } | |
|
166 | ||
|
167 | @classmethod | |
|
168 | def new_possibly_dirty(_cls) -> PyResult<Self> { | |
|
169 | let entry = DirstateEntry::new_possibly_dirty(); | |
|
170 | DirstateItem::create_instance(py, Cell::new(entry)) | |
|
171 | } | |
|
172 | ||
|
173 | @classmethod | |
|
174 | def new_normal(_cls, mode: i32, size: i32, mtime: i32) -> PyResult<Self> { | |
|
175 | let entry = DirstateEntry::new_normal(mode, size, mtime); | |
|
176 | DirstateItem::create_instance(py, Cell::new(entry)) | |
|
177 | } | |
|
178 | ||
|
149 | 179 | def set_clean( |
|
150 | 180 | &self, |
|
151 | 181 | mode: i32, |
General Comments 0
You need to be logged in to leave comments.
Login now