##// END OF EJS Templates
dirstatemap: use a common implement for reset_state...
marmoute -
r48945:55293938 default
parent child Browse files
Show More
@@ -175,6 +175,74 b' class _dirstatemapcommon(object):'
175 self._refresh_entry(f, entry)
175 self._refresh_entry(f, entry)
176 return True
176 return True
177
177
178 def reset_state(
179 self,
180 filename,
181 wc_tracked=False,
182 p1_tracked=False,
183 p2_tracked=False,
184 merged=False,
185 clean_p1=False,
186 clean_p2=False,
187 possibly_dirty=False,
188 parentfiledata=None,
189 ):
190 """Set a entry to a given state, diregarding all previous state
191
192 This is to be used by the part of the dirstate API dedicated to
193 adjusting the dirstate after a update/merge.
194
195 note: calling this might result to no entry existing at all if the
196 dirstate map does not see any point at having one for this file
197 anymore.
198 """
199 if merged and (clean_p1 or clean_p2):
200 msg = b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
201 raise error.ProgrammingError(msg)
202 # copy information are now outdated
203 # (maybe new information should be in directly passed to this function)
204 self.copymap.pop(filename, None)
205
206 if not (p1_tracked or p2_tracked or wc_tracked):
207 old_entry = self._map.get(filename)
208 self._drop_entry(filename)
209 self._dirs_decr(filename, old_entry=old_entry)
210 return
211 elif merged:
212 pass
213 elif not (p1_tracked or p2_tracked) and wc_tracked:
214 pass # file is added, nothing special to adjust
215 elif (p1_tracked or p2_tracked) and not wc_tracked:
216 pass
217 elif clean_p2 and wc_tracked:
218 pass
219 elif not p1_tracked and p2_tracked and wc_tracked:
220 clean_p2 = True
221 elif possibly_dirty:
222 pass
223 elif wc_tracked:
224 # this is a "normal" file
225 if parentfiledata is None:
226 msg = b'failed to pass parentfiledata for a normal file: %s'
227 msg %= filename
228 raise error.ProgrammingError(msg)
229 else:
230 assert False, 'unreachable'
231
232 old_entry = self._map.get(filename)
233 self._dirs_incr(filename, old_entry)
234 entry = DirstateItem(
235 wc_tracked=wc_tracked,
236 p1_tracked=p1_tracked,
237 p2_tracked=p2_tracked,
238 merged=merged,
239 clean_p1=clean_p1,
240 clean_p2=clean_p2,
241 possibly_dirty=possibly_dirty,
242 parentfiledata=parentfiledata,
243 )
244 self._insert_entry(filename, entry)
245
178
246
179 class dirstatemap(_dirstatemapcommon):
247 class dirstatemap(_dirstatemapcommon):
180 """Map encapsulating the dirstate's contents.
248 """Map encapsulating the dirstate's contents.
@@ -465,77 +533,9 b' class dirstatemap(_dirstatemapcommon):'
465 def _insert_entry(self, f, entry):
533 def _insert_entry(self, f, entry):
466 self._map[f] = entry
534 self._map[f] = entry
467
535
468 def reset_state(
469 self,
470 filename,
471 wc_tracked=False,
472 p1_tracked=False,
473 p2_tracked=False,
474 merged=False,
475 clean_p1=False,
476 clean_p2=False,
477 possibly_dirty=False,
478 parentfiledata=None,
479 ):
480 """Set a entry to a given state, diregarding all previous state
481
482 This is to be used by the part of the dirstate API dedicated to
483 adjusting the dirstate after a update/merge.
484
485 note: calling this might result to no entry existing at all if the
486 dirstate map does not see any point at having one for this file
487 anymore.
488 """
489 if merged and (clean_p1 or clean_p2):
490 msg = b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
491 raise error.ProgrammingError(msg)
492 # copy information are now outdated
493 # (maybe new information should be in directly passed to this function)
494 self.copymap.pop(filename, None)
495
496 if not (p1_tracked or p2_tracked or wc_tracked):
497 old_entry = self._map.pop(filename, None)
498 self._dirs_decr(filename, old_entry=old_entry)
499 self.copymap.pop(filename, None)
500 return
501 elif merged:
502 pass
503 elif not (p1_tracked or p2_tracked) and wc_tracked:
504 pass # file is added, nothing special to adjust
505 elif (p1_tracked or p2_tracked) and not wc_tracked:
506 pass
507 elif clean_p2 and wc_tracked:
508 pass
509 elif not p1_tracked and p2_tracked and wc_tracked:
510 clean_p2 = True
511 elif possibly_dirty:
512 pass
513 elif wc_tracked:
514 # this is a "normal" file
515 if parentfiledata is None:
516 msg = b'failed to pass parentfiledata for a normal file: %s'
517 msg %= filename
518 raise error.ProgrammingError(msg)
519 else:
520 assert False, 'unreachable'
521
522 old_entry = self._map.get(filename)
523 self._dirs_incr(filename, old_entry)
524 entry = DirstateItem(
525 wc_tracked=wc_tracked,
526 p1_tracked=p1_tracked,
527 p2_tracked=p2_tracked,
528 merged=merged,
529 clean_p1=clean_p1,
530 clean_p2=clean_p2,
531 possibly_dirty=possibly_dirty,
532 parentfiledata=parentfiledata,
533 )
534 self._map[filename] = entry
535
536 def _drop_entry(self, f):
536 def _drop_entry(self, f):
537 self._map.pop(f, None)
537 self._map.pop(f, None)
538 self._copymap.pop(f, None)
538 self.copymap.pop(f, None)
539
539
540
540
541 if rustmod is not None:
541 if rustmod is not None:
@@ -820,85 +820,6 b' if rustmod is not None:'
820 assert isinstance(value, DirstateItem)
820 assert isinstance(value, DirstateItem)
821 self._map.set_dirstate_item(key, value)
821 self._map.set_dirstate_item(key, value)
822
822
823 def reset_state(
824 self,
825 filename,
826 wc_tracked=False,
827 p1_tracked=False,
828 p2_tracked=False,
829 merged=False,
830 clean_p1=False,
831 clean_p2=False,
832 possibly_dirty=False,
833 parentfiledata=None,
834 ):
835 """Set a entry to a given state, disregarding all previous state
836
837 This is to be used by the part of the dirstate API dedicated to
838 adjusting the dirstate after a update/merge.
839
840 note: calling this might result to no entry existing at all if the
841 dirstate map does not see any point at having one for this file
842 anymore.
843 """
844 if merged and (clean_p1 or clean_p2):
845 msg = (
846 b'`merged` argument incompatible with `clean_p1`/`clean_p2`'
847 )
848 raise error.ProgrammingError(msg)
849 # copy information are now outdated
850 # (maybe new information should be in directly passed to this function)
851 self.copymap.pop(filename, None)
852
853 if not (p1_tracked or p2_tracked or wc_tracked):
854 self._map.drop_item_and_copy_source(filename)
855 elif merged:
856 # XXX might be merged and removed ?
857 entry = self.get(filename)
858 if entry is not None and entry.tracked:
859 # XXX mostly replicate dirstate.other parent. We should get
860 # the higher layer to pass us more reliable data where `merged`
861 # actually mean merged. Dropping the else clause will show
862 # failure in `test-graft.t`
863 self.addfile(filename, merged=True)
864 else:
865 self.addfile(filename, from_p2=True)
866 elif not (p1_tracked or p2_tracked) and wc_tracked:
867 self.addfile(
868 filename, added=True, possibly_dirty=possibly_dirty
869 )
870 elif (p1_tracked or p2_tracked) and not wc_tracked:
871 # XXX might be merged and removed ?
872 self[filename] = DirstateItem.from_v1_data(b'r', 0, 0, 0)
873 elif clean_p2 and wc_tracked:
874 if p1_tracked or self.get(filename) is not None:
875 # XXX the `self.get` call is catching some case in
876 # `test-merge-remove.t` where the file is tracked in p1, the
877 # p1_tracked argument is False.
878 #
879 # In addition, this seems to be a case where the file is marked
880 # as merged without actually being the result of a merge
881 # action. So thing are not ideal here.
882 self.addfile(filename, merged=True)
883 else:
884 self.addfile(filename, from_p2=True)
885 elif not p1_tracked and p2_tracked and wc_tracked:
886 self.addfile(
887 filename, from_p2=True, possibly_dirty=possibly_dirty
888 )
889 elif possibly_dirty:
890 self.addfile(filename, possibly_dirty=possibly_dirty)
891 elif wc_tracked:
892 # this is a "normal" file
893 if parentfiledata is None:
894 msg = b'failed to pass parentfiledata for a normal file: %s'
895 msg %= filename
896 raise error.ProgrammingError(msg)
897 mode, size, mtime = parentfiledata
898 self.addfile(filename, mode=mode, size=size, mtime=mtime)
899 else:
900 assert False, 'unreachable'
901
902 ### Legacy method we need to get rid of
823 ### Legacy method we need to get rid of
903
824
904 def addfile(
825 def addfile(
General Comments 0
You need to be logged in to leave comments. Login now