comparison mercurial/dirstate.py @ 47483:4ac418b4a6af

dirstate: introduce a symbolic constant for the NONNORMAL marker This is going to be clearer and easier to track than -1. Ultimately I would like to get ride of this special value everywhere but in the lower level, however we need to clarify the API first. This changeset is part of such clarification. Differential Revision: https://phab.mercurial-scm.org/D10927
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 01 Jul 2021 19:15:22 +0200
parents cb29484eaade
children 3f13dfa1fa78
comparison
equal deleted inserted replaced
47482:cb29484eaade 47483:4ac418b4a6af
48 dirstatetuple = parsers.dirstatetuple 48 dirstatetuple = parsers.dirstatetuple
49 49
50 50
51 # a special value used internally for `size` if the file come from the other parent 51 # a special value used internally for `size` if the file come from the other parent
52 FROM_P2 = -2 52 FROM_P2 = -2
53
54 # a special value used internally for `size` if the file is modified/merged/added
55 NONNORMAL = -1
53 56
54 57
55 class repocache(filecache): 58 class repocache(filecache):
56 """filecache for files in .hg/""" 59 """filecache for files in .hg/"""
57 60
486 # if there is a merge going on and the file was either 489 # if there is a merge going on and the file was either
487 # in state 'm' (-1) or coming from other parent (-2) before 490 # in state 'm' (-1) or coming from other parent (-2) before
488 # being removed, restore that state. 491 # being removed, restore that state.
489 entry = self._map.get(f) 492 entry = self._map.get(f)
490 if entry is not None: 493 if entry is not None:
491 if entry[0] == b'r' and entry[2] in (-1, FROM_P2): 494 if entry[0] == b'r' and entry[2] in (NONNORMAL, FROM_P2):
492 source = self._map.copymap.get(f) 495 source = self._map.copymap.get(f)
493 if entry[2] == -1: 496 if entry[2] == NONNORMAL:
494 self.merge(f) 497 self.merge(f)
495 elif entry[2] == FROM_P2: 498 elif entry[2] == FROM_P2:
496 self.otherparent(f) 499 self.otherparent(f)
497 if source: 500 if source:
498 self.copy(source, f) 501 self.copy(source, f)
499 return 502 return
500 if entry[0] == b'm' or entry[0] == b'n' and entry[2] == FROM_P2: 503 if entry[0] == b'm' or entry[0] == b'n' and entry[2] == FROM_P2:
501 return 504 return
502 self._addpath(f, b'n', 0, -1, -1) 505 self._addpath(f, b'n', 0, NONNORMAL, -1)
503 self._map.copymap.pop(f, None) 506 self._map.copymap.pop(f, None)
504 507
505 def otherparent(self, f): 508 def otherparent(self, f):
506 '''Mark as coming from the other parent, always dirty.''' 509 '''Mark as coming from the other parent, always dirty.'''
507 if self._pl[1] == self._nodeconstants.nullid: 510 if self._pl[1] == self._nodeconstants.nullid:
515 self._addpath(f, b'n', 0, FROM_P2, -1) 518 self._addpath(f, b'n', 0, FROM_P2, -1)
516 self._map.copymap.pop(f, None) 519 self._map.copymap.pop(f, None)
517 520
518 def add(self, f): 521 def add(self, f):
519 '''Mark a file added.''' 522 '''Mark a file added.'''
520 self._addpath(f, b'a', 0, -1, -1) 523 self._addpath(f, b'a', 0, NONNORMAL, -1)
521 self._map.copymap.pop(f, None) 524 self._map.copymap.pop(f, None)
522 525
523 def remove(self, f): 526 def remove(self, f):
524 '''Mark a file removed.''' 527 '''Mark a file removed.'''
525 self._dirty = True 528 self._dirty = True
528 if self._pl[1] != self._nodeconstants.nullid: 531 if self._pl[1] != self._nodeconstants.nullid:
529 entry = self._map.get(f) 532 entry = self._map.get(f)
530 if entry is not None: 533 if entry is not None:
531 # backup the previous state 534 # backup the previous state
532 if entry[0] == b'm': # merge 535 if entry[0] == b'm': # merge
533 size = -1 536 size = NONNORMAL
534 elif entry[0] == b'n' and entry[2] == FROM_P2: # other parent 537 elif entry[0] == b'n' and entry[2] == FROM_P2: # other parent
535 size = FROM_P2 538 size = FROM_P2
536 self._map.otherparentset.add(f) 539 self._map.otherparentset.add(f)
537 self._updatedfiles.add(f) 540 self._updatedfiles.add(f)
538 self._map.removefile(f, oldstate, size) 541 self._map.removefile(f, oldstate, size)