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