comparison mercurial/dirstate.py @ 47512:769037a279ec

dirstate-entry: add a `state` property (and use it) This replace the [0] access. Ultimately is we should probably get ride of this in its current form. However this is a good transitional solution to move away for tuple indexing for now. Differential Revision: https://phab.mercurial-scm.org/D10954
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 04 Jul 2021 03:29:20 +0200
parents eaae39894312
children 10e740292dff
comparison
equal deleted inserted replaced
47511:eaae39894312 47512:769037a279ec
309 n normal 309 n normal
310 m needs merging 310 m needs merging
311 r marked for removal 311 r marked for removal
312 a marked for addition 312 a marked for addition
313 ? not tracked 313 ? not tracked
314 """ 314
315 return self._map.get(key, (b"?",))[0] 315 XXX The "state" is a bit obscure to be in the "public" API. we should
316 consider migrating all user of this to going through the dirstate entry
317 instead.
318 """
319 entry = self._map.get(key)
320 if entry is not None:
321 return entry.state
322 return b'?'
316 323
317 def __contains__(self, key): 324 def __contains__(self, key):
318 return key in self._map 325 return key in self._map
319 326
320 def __iter__(self): 327 def __iter__(self):
378 s = self._map.get(f) 385 s = self._map.get(f)
379 if s is None: 386 if s is None:
380 continue 387 continue
381 388
382 # Discard 'm' markers when moving away from a merge state 389 # Discard 'm' markers when moving away from a merge state
383 if s[0] == b'm': 390 if s.state == b'm':
384 source = self._map.copymap.get(f) 391 source = self._map.copymap.get(f)
385 if source: 392 if source:
386 copies[f] = source 393 copies[f] = source
387 self.normallookup(f) 394 self.normallookup(f)
388 # Also fix up otherparent markers 395 # Also fix up otherparent markers
389 elif s[0] == b'n' and s[2] == FROM_P2: 396 elif s.state == b'n' and s[2] == FROM_P2:
390 source = self._map.copymap.get(f) 397 source = self._map.copymap.get(f)
391 if source: 398 if source:
392 copies[f] = source 399 copies[f] = source
393 self.add(f) 400 self.add(f)
394 return copies 401 return copies
463 # shadows 470 # shadows
464 for d in pathutil.finddirs(f): 471 for d in pathutil.finddirs(f):
465 if self._map.hastrackeddir(d): 472 if self._map.hastrackeddir(d):
466 break 473 break
467 entry = self._map.get(d) 474 entry = self._map.get(d)
468 if entry is not None and entry[0] != b'r': 475 if entry is not None and entry.state != b'r':
469 msg = _(b'file %r in dirstate clashes with %r') 476 msg = _(b'file %r in dirstate clashes with %r')
470 msg %= (pycompat.bytestr(d), pycompat.bytestr(f)) 477 msg %= (pycompat.bytestr(d), pycompat.bytestr(f))
471 raise error.Abort(msg) 478 raise error.Abort(msg)
472 if state == b'a': 479 if state == b'a':
473 assert not possibly_dirty 480 assert not possibly_dirty
522 # if there is a merge going on and the file was either 529 # if there is a merge going on and the file was either
523 # in state 'm' (-1) or coming from other parent (-2) before 530 # in state 'm' (-1) or coming from other parent (-2) before
524 # being removed, restore that state. 531 # being removed, restore that state.
525 entry = self._map.get(f) 532 entry = self._map.get(f)
526 if entry is not None: 533 if entry is not None:
527 if entry[0] == b'r' and entry[2] in (NONNORMAL, FROM_P2): 534 if entry.state == b'r' and entry[2] in (NONNORMAL, FROM_P2):
528 source = self._map.copymap.get(f) 535 source = self._map.copymap.get(f)
529 if entry[2] == NONNORMAL: 536 if entry[2] == NONNORMAL:
530 self.merge(f) 537 self.merge(f)
531 elif entry[2] == FROM_P2: 538 elif entry[2] == FROM_P2:
532 self.otherparent(f) 539 self.otherparent(f)
533 if source: 540 if source:
534 self.copy(source, f) 541 self.copy(source, f)
535 return 542 return
536 if entry[0] == b'm' or entry[0] == b'n' and entry[2] == FROM_P2: 543 if (
544 entry.state == b'm'
545 or entry.state == b'n'
546 and entry[2] == FROM_P2
547 ):
537 return 548 return
538 self._addpath(f, b'n', 0, possibly_dirty=True) 549 self._addpath(f, b'n', 0, possibly_dirty=True)
539 self._map.copymap.pop(f, None) 550 self._map.copymap.pop(f, None)
540 551
541 def otherparent(self, f): 552 def otherparent(self, f):
759 # timestamp of each entries in dirstate, because of 'now > mtime' 770 # timestamp of each entries in dirstate, because of 'now > mtime'
760 delaywrite = self._ui.configint(b'debug', b'dirstate.delaywrite') 771 delaywrite = self._ui.configint(b'debug', b'dirstate.delaywrite')
761 if delaywrite > 0: 772 if delaywrite > 0:
762 # do we have any files to delay for? 773 # do we have any files to delay for?
763 for f, e in pycompat.iteritems(self._map): 774 for f, e in pycompat.iteritems(self._map):
764 if e[0] == b'n' and e[3] == now: 775 if e.state == b'n' and e[3] == now:
765 import time # to avoid useless import 776 import time # to avoid useless import
766 777
767 # rather than sleep n seconds, sleep until the next 778 # rather than sleep n seconds, sleep until the next
768 # multiple of n seconds 779 # multiple of n seconds
769 clock = time.time() 780 clock = time.time()
1313 # opcode has fast paths when the value to be unpacked is a tuple or 1324 # opcode has fast paths when the value to be unpacked is a tuple or
1314 # a list, but falls back to creating a full-fledged iterator in 1325 # a list, but falls back to creating a full-fledged iterator in
1315 # general. That is much slower than simply accessing and storing the 1326 # general. That is much slower than simply accessing and storing the
1316 # tuple members one by one. 1327 # tuple members one by one.
1317 t = dget(fn) 1328 t = dget(fn)
1318 state = t[0] 1329 state = t.state
1319 mode = t[1] 1330 mode = t[1]
1320 size = t[2] 1331 size = t[2]
1321 time = t[3] 1332 time = t[3]
1322 1333
1323 if not st and state in b"nma": 1334 if not st and state in b"nma":