##// END OF EJS Templates
dirstate: use a `added` parameter to _addpath...
marmoute -
r48314:fe4641cf default
parent child Browse files
Show More
@@ -443,15 +443,16 b' class dirstate(object):'
443 443 def _addpath(
444 444 self,
445 445 f,
446 state,
447 mode,
446 state=None,
447 mode=0,
448 448 size=None,
449 449 mtime=None,
450 added=False,
450 451 from_p2=False,
451 452 possibly_dirty=False,
452 453 ):
453 454 entry = self._map.get(f)
454 if state == b'a' or entry is not None and entry.removed:
455 if added or entry is not None and entry.removed:
455 456 scmutil.checkfilename(f)
456 457 if self._map.hastrackeddir(f):
457 458 msg = _(b'directory %r already in dirstate')
@@ -474,6 +475,7 b' class dirstate(object):'
474 475 mode=mode,
475 476 size=size,
476 477 mtime=mtime,
478 added=added,
477 479 from_p2=from_p2,
478 480 possibly_dirty=possibly_dirty,
479 481 )
@@ -544,7 +546,7 b' class dirstate(object):'
544 546
545 547 def add(self, f):
546 548 '''Mark a file added.'''
547 self._addpath(f, b'a', 0)
549 self._addpath(f, added=True)
548 550 self._map.copymap.pop(f, None)
549 551
550 552 def remove(self, f):
@@ -147,17 +147,19 b' class dirstatemap(object):'
147 147 def addfile(
148 148 self,
149 149 f,
150 state,
151 mode,
150 state=None,
151 mode=0,
152 152 size=None,
153 153 mtime=None,
154 added=False,
154 155 from_p2=False,
155 156 possibly_dirty=False,
156 157 ):
157 158 """Add a tracked file to the dirstate."""
158 if state == b'a':
159 if added:
159 160 assert not possibly_dirty
160 161 assert not from_p2
162 state = b'a'
161 163 size = NONNORMAL
162 164 mtime = AMBIGUOUS_TIME
163 165 elif from_p2:
@@ -168,10 +170,12 b' class dirstatemap(object):'
168 170 size = NONNORMAL
169 171 mtime = AMBIGUOUS_TIME
170 172 else:
173 assert state != b'a'
171 174 assert size != FROM_P2
172 175 assert size != NONNORMAL
173 176 size = size & rangemask
174 177 mtime = mtime & rangemask
178 assert state is not None
175 179 assert size is not None
176 180 assert mtime is not None
177 181 old_entry = self.get(f)
@@ -461,10 +465,11 b' if rustmod is not None:'
461 465 def addfile(
462 466 self,
463 467 f,
464 state,
465 mode,
468 state=None,
469 mode=0,
466 470 size=None,
467 471 mtime=None,
472 added=False,
468 473 from_p2=False,
469 474 possibly_dirty=False,
470 475 ):
@@ -474,6 +479,7 b' if rustmod is not None:'
474 479 mode,
475 480 size,
476 481 mtime,
482 added,
477 483 from_p2,
478 484 possibly_dirty,
479 485 )
@@ -70,13 +70,15 b' impl DirstateMap {'
70 70 filename: &HgPath,
71 71 entry: DirstateEntry,
72 72 // XXX once the dust settle this should probably become an enum
73 added: bool,
73 74 from_p2: bool,
74 75 possibly_dirty: bool,
75 76 ) -> Result<(), DirstateError> {
76 77 let mut entry = entry;
77 if entry.state == EntryState::Added {
78 if added {
78 79 assert!(!possibly_dirty);
79 80 assert!(!from_p2);
81 entry.state = EntryState::Added;
80 82 entry.size = SIZE_NON_NORMAL;
81 83 entry.mtime = MTIME_UNSET;
82 84 } else if from_p2 {
@@ -407,6 +409,7 b' mod tests {'
407 409 },
408 410 false,
409 411 false,
412 false,
410 413 )
411 414 .unwrap();
412 415
@@ -722,13 +722,15 b" impl<'on_disk> super::dispatch::Dirstate"
722 722 &mut self,
723 723 filename: &HgPath,
724 724 entry: DirstateEntry,
725 added: bool,
725 726 from_p2: bool,
726 727 possibly_dirty: bool,
727 728 ) -> Result<(), DirstateError> {
728 729 let mut entry = entry;
729 if entry.state == EntryState::Added {
730 if added {
730 731 assert!(!possibly_dirty);
731 732 assert!(!from_p2);
733 entry.state = EntryState::Added;
732 734 entry.size = SIZE_NON_NORMAL;
733 735 entry.mtime = MTIME_UNSET;
734 736 } else if from_p2 {
@@ -48,6 +48,7 b' pub trait DirstateMapMethods {'
48 48 &mut self,
49 49 filename: &HgPath,
50 50 entry: DirstateEntry,
51 added: bool,
51 52 from_p2: bool,
52 53 possibly_dirty: bool,
53 54 ) -> Result<(), DirstateError>;
@@ -287,10 +288,11 b' impl DirstateMapMethods for DirstateMap '
287 288 &mut self,
288 289 filename: &HgPath,
289 290 entry: DirstateEntry,
291 added: bool,
290 292 from_p2: bool,
291 293 possibly_dirty: bool,
292 294 ) -> Result<(), DirstateError> {
293 self.add_file(filename, entry, from_p2, possibly_dirty)
295 self.add_file(filename, entry, added, from_p2, possibly_dirty)
294 296 }
295 297
296 298 fn remove_file(
@@ -112,17 +112,28 b' py_class!(pub class DirstateMap |py| {'
112 112 mode: PyObject,
113 113 size: PyObject,
114 114 mtime: PyObject,
115 added: PyObject,
115 116 from_p2: PyObject,
116 117 possibly_dirty: PyObject,
117 118 ) -> PyResult<PyObject> {
118 119 let f = f.extract::<PyBytes>(py)?;
119 120 let filename = HgPath::new(f.data(py));
120 let state = state.extract::<PyBytes>(py)?.data(py)[0]
121 let state = if state.is_none(py) {
122 // Arbitrary default value
123 EntryState::Normal
124 } else {
125 state.extract::<PyBytes>(py)?.data(py)[0]
121 126 .try_into()
122 127 .map_err(|e: HgError| {
123 128 PyErr::new::<exc::ValueError, _>(py, e.to_string())
124 })?;
125 let mode = mode.extract(py)?;
129 })?
130 };
131 let mode = if mode.is_none(py) {
132 // fallback default value
133 0
134 } else {
135 mode.extract(py)?
136 };
126 137 let size = if size.is_none(py) {
127 138 // fallback default value
128 139 SIZE_NON_NORMAL
@@ -141,11 +152,13 b' py_class!(pub class DirstateMap |py| {'
141 152 size: size,
142 153 mtime: mtime,
143 154 };
155 let added = added.extract::<PyBool>(py)?.is_true();
144 156 let from_p2 = from_p2.extract::<PyBool>(py)?.is_true();
145 157 let possibly_dirty = possibly_dirty.extract::<PyBool>(py)?.is_true();
146 158 self.inner(py).borrow_mut().add_file(
147 159 filename,
148 160 entry,
161 added,
149 162 from_p2,
150 163 possibly_dirty
151 164 ).and(Ok(py.None())).or_else(|e: DirstateError| {
@@ -25,11 +25,17 b' impl DirstateMapMethods for OwningDirsta'
25 25 &mut self,
26 26 filename: &HgPath,
27 27 entry: DirstateEntry,
28 added: bool,
28 29 from_p2: bool,
29 30 possibly_dirty: bool,
30 31 ) -> Result<(), DirstateError> {
31 self.get_mut()
32 .add_file(filename, entry, from_p2, possibly_dirty)
32 self.get_mut().add_file(
33 filename,
34 entry,
35 added,
36 from_p2,
37 possibly_dirty,
38 )
33 39 }
34 40
35 41 fn remove_file(
General Comments 0
You need to be logged in to leave comments. Login now