##// END OF EJS Templates
dirstate: Pass the final DirstateItem to _rustmap.addfile()...
Simon Sapin -
r48865:98c04083 default
parent child Browse files
Show More
@@ -561,19 +561,26 b' if rustmod is not None:'
561 from_p2=False,
561 from_p2=False,
562 possibly_dirty=False,
562 possibly_dirty=False,
563 ):
563 ):
564 ret = self._rustmap.addfile(
564 if added:
565 f,
565 assert not possibly_dirty
566 mode,
566 assert not from_p2
567 size,
567 item = DirstateItem.new_added()
568 mtime,
568 elif merged:
569 added,
569 assert not possibly_dirty
570 merged,
570 assert not from_p2
571 from_p2,
571 item = DirstateItem.new_merged()
572 possibly_dirty,
572 elif from_p2:
573 )
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 if added:
582 if added:
575 self.copymap.pop(f, None)
583 self.copymap.pop(f, None)
576 return ret
577
584
578 def reset_state(
585 def reset_state(
579 self,
586 self,
@@ -8,10 +8,8 b''
8 use crate::dirstate::parsers::Timestamp;
8 use crate::dirstate::parsers::Timestamp;
9 use crate::{
9 use crate::{
10 dirstate::EntryState,
10 dirstate::EntryState,
11 dirstate::MTIME_UNSET,
12 dirstate::SIZE_FROM_OTHER_PARENT,
11 dirstate::SIZE_FROM_OTHER_PARENT,
13 dirstate::SIZE_NON_NORMAL,
12 dirstate::SIZE_NON_NORMAL,
14 dirstate::V1_RANGEMASK,
15 pack_dirstate, parse_dirstate,
13 pack_dirstate, parse_dirstate,
16 utils::hg_path::{HgPath, HgPathBuf},
14 utils::hg_path::{HgPath, HgPathBuf},
17 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents,
15 CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents,
@@ -73,44 +71,7 b' impl DirstateMap {'
73 &mut self,
71 &mut self,
74 filename: &HgPath,
72 filename: &HgPath,
75 entry: DirstateEntry,
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 ) -> Result<(), DirstateError> {
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 let old_state = self.get(filename).map(|e| e.state());
75 let old_state = self.get(filename).map(|e| e.state());
115 if old_state.is_none() || old_state == Some(EntryState::Removed) {
76 if old_state.is_none() || old_state == Some(EntryState::Removed) {
116 if let Some(ref mut dirs) = self.dirs {
77 if let Some(ref mut dirs) = self.dirs {
@@ -417,10 +378,6 b' mod tests {'
417 map.add_file(
378 map.add_file(
418 HgPath::new(b"meh"),
379 HgPath::new(b"meh"),
419 DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337),
380 DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337),
420 false,
421 false,
422 false,
423 false,
424 )
381 )
425 .unwrap();
382 .unwrap();
426
383
@@ -83,12 +83,7 b' impl DirstateEntry {'
83 mtime: 0,
83 mtime: 0,
84 }
84 }
85 } else {
85 } else {
86 Self {
86 Self::new_normal(mode, size, mtime)
87 flags: Flags::WDIR_TRACKED | Flags::P1_TRACKED,
88 mode,
89 size,
90 mtime,
91 }
92 }
87 }
93 }
88 }
94 EntryState::Added => Self::new_added(),
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 Self {
110 Self {
116 // might be missing P1_TRACKED
111 // might be missing P1_TRACKED
117 flags: Flags::WDIR_TRACKED | Flags::P2_TRACKED | Flags::CLEAN_P2,
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 Self {
120 Self {
126 flags: Flags::WDIR_TRACKED
121 flags: Flags::WDIR_TRACKED
127 | Flags::P1_TRACKED
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 Self {
131 Self {
137 flags: Flags::WDIR_TRACKED,
132 flags: Flags::WDIR_TRACKED,
138 mode: 0,
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 Self {
140 Self {
146 flags: Flags::WDIR_TRACKED
141 flags: Flags::WDIR_TRACKED
147 | Flags::P1_TRACKED // might not be true because of rename ?
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 /// Creates a new entry in "removed" state.
160 /// Creates a new entry in "removed" state.
157 ///
161 ///
158 /// `size` is expected to be zero, `SIZE_NON_NORMAL`, or
162 /// `size` is expected to be zero, `SIZE_NON_NORMAL`, or
@@ -161,14 +165,6 b' impl DirstateEntry {'
161 Self::from_v1_data(EntryState::Removed, 0, size, 0)
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 pub fn tracked(&self) -> bool {
168 pub fn tracked(&self) -> bool {
173 self.flags.contains(Flags::WDIR_TRACKED)
169 self.flags.contains(Flags::WDIR_TRACKED)
174 }
170 }
@@ -11,10 +11,8 b' use crate::dirstate::parsers::pack_entry'
11 use crate::dirstate::parsers::packed_entry_size;
11 use crate::dirstate::parsers::packed_entry_size;
12 use crate::dirstate::parsers::parse_dirstate_entries;
12 use crate::dirstate::parsers::parse_dirstate_entries;
13 use crate::dirstate::parsers::Timestamp;
13 use crate::dirstate::parsers::Timestamp;
14 use crate::dirstate::MTIME_UNSET;
15 use crate::dirstate::SIZE_FROM_OTHER_PARENT;
14 use crate::dirstate::SIZE_FROM_OTHER_PARENT;
16 use crate::dirstate::SIZE_NON_NORMAL;
15 use crate::dirstate::SIZE_NON_NORMAL;
17 use crate::dirstate::V1_RANGEMASK;
18 use crate::matchers::Matcher;
16 use crate::matchers::Matcher;
19 use crate::utils::hg_path::{HgPath, HgPathBuf};
17 use crate::utils::hg_path::{HgPath, HgPathBuf};
20 use crate::CopyMapIter;
18 use crate::CopyMapIter;
@@ -771,45 +769,8 b" impl<'on_disk> super::dispatch::Dirstate"
771 &mut self,
769 &mut self,
772 filename: &HgPath,
770 filename: &HgPath,
773 entry: DirstateEntry,
771 entry: DirstateEntry,
774 added: bool,
775 merged: bool,
776 from_p2: bool,
777 possibly_dirty: bool,
778 ) -> Result<(), DirstateError> {
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 let old_state = self.get(filename)?.map(|e| e.state());
773 let old_state = self.get(filename)?.map(|e| e.state());
812
813 Ok(self.add_or_remove_file(filename, old_state, entry)?)
774 Ok(self.add_or_remove_file(filename, old_state, entry)?)
814 }
775 }
815
776
@@ -50,10 +50,6 b' pub trait DirstateMapMethods {'
50 &mut self,
50 &mut self,
51 filename: &HgPath,
51 filename: &HgPath,
52 entry: DirstateEntry,
52 entry: DirstateEntry,
53 added: bool,
54 merged: bool,
55 from_p2: bool,
56 possibly_dirty: bool,
57 ) -> Result<(), DirstateError>;
53 ) -> Result<(), DirstateError>;
58
54
59 /// Mark a file as "removed" (as in `hg rm`).
55 /// Mark a file as "removed" (as in `hg rm`).
@@ -326,12 +322,8 b' impl DirstateMapMethods for DirstateMap '
326 &mut self,
322 &mut self,
327 filename: &HgPath,
323 filename: &HgPath,
328 entry: DirstateEntry,
324 entry: DirstateEntry,
329 added: bool,
330 merged: bool,
331 from_p2: bool,
332 possibly_dirty: bool,
333 ) -> Result<(), DirstateError> {
325 ) -> Result<(), DirstateError> {
334 self.add_file(filename, entry, added, merged, from_p2, possibly_dirty)
326 self.add_file(filename, entry)
335 }
327 }
336
328
337 fn remove_file(
329 fn remove_file(
@@ -32,19 +32,8 b' impl DirstateMapMethods for OwningDirsta'
32 &mut self,
32 &mut self,
33 filename: &HgPath,
33 filename: &HgPath,
34 entry: DirstateEntry,
34 entry: DirstateEntry,
35 added: bool,
36 merged: bool,
37 from_p2: bool,
38 possibly_dirty: bool,
39 ) -> Result<(), DirstateError> {
35 ) -> Result<(), DirstateError> {
40 self.get_mut().add_file(
36 self.get_mut().add_file(filename, entry)
41 filename,
42 entry,
43 added,
44 merged,
45 from_p2,
46 possibly_dirty,
47 )
48 }
37 }
49
38
50 fn remove_file(
39 fn remove_file(
@@ -27,8 +27,6 b' use crate::{'
27 };
27 };
28 use hg::{
28 use hg::{
29 dirstate::parsers::Timestamp,
29 dirstate::parsers::Timestamp,
30 dirstate::MTIME_UNSET,
31 dirstate::SIZE_NON_NORMAL,
32 dirstate_tree::dirstate_map::DirstateMap as TreeDirstateMap,
30 dirstate_tree::dirstate_map::DirstateMap as TreeDirstateMap,
33 dirstate_tree::dispatch::DirstateMapMethods,
31 dirstate_tree::dispatch::DirstateMapMethods,
34 dirstate_tree::on_disk::DirstateV2ParseError,
32 dirstate_tree::on_disk::DirstateV2ParseError,
@@ -145,50 +143,16 b' py_class!(pub class DirstateMap |py| {'
145
143
146 def addfile(
144 def addfile(
147 &self,
145 &self,
148 f: PyObject,
146 f: PyBytes,
149 mode: PyObject,
147 item: DirstateItem,
150 size: PyObject,
148 ) -> PyResult<PyNone> {
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)?;
158 let filename = HgPath::new(f.data(py));
149 let filename = HgPath::new(f.data(py));
159 let mode = if mode.is_none(py) {
150 let entry = item.get_entry(py);
160 // fallback default value
151 self.inner(py)
161 0
152 .borrow_mut()
162 } else {
153 .add_file(filename, entry)
163 mode.extract(py)?
154 .map_err(|e |dirstate_error(py, e))?;
164 };
155 Ok(PyNone)
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 })
192 }
156 }
193
157
194 def removefile(
158 def removefile(
@@ -146,6 +146,36 b' py_class!(pub class DirstateItem |py| {'
146 DirstateItem::create_instance(py, Cell::new(entry))
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 def set_clean(
179 def set_clean(
150 &self,
180 &self,
151 mode: i32,
181 mode: i32,
General Comments 0
You need to be logged in to leave comments. Login now