Mercurial > hg
comparison mercurial/dirstate.py @ 33981:5cb0a8fe096e
dirstate: perform transactions with _copymap using single call, where possible
This replaces patterns such as this:
```
if f in self._copymap:
del self._copymap[f]
```
with this:
```
self._copymap.pop(f, None)
```
Although eliminating the extra lookup/call may be a negligible performance win
in the standard dirstate, alternative implementations, such as
[sqldirstate](https://bitbucket.org/facebook/hg-experimental/src/default/sqldirstate/)
may see a bigger win where each of these calls results in an RPC,
so the savings is greater.
Test Plan:
`make tests`
Differential Revision: https://phab.mercurial-scm.org/D493
author | Michael Bolin <mbolin@fb.com> |
---|---|
date | Wed, 23 Aug 2017 18:24:57 +0000 |
parents | 02a745c20121 |
children | d5b2beca16c0 |
comparison
equal
deleted
inserted
replaced
33980:8abbae93045a | 33981:5cb0a8fe096e |
---|---|
404 if s is None: | 404 if s is None: |
405 continue | 405 continue |
406 | 406 |
407 # Discard 'm' markers when moving away from a merge state | 407 # Discard 'm' markers when moving away from a merge state |
408 if s[0] == 'm': | 408 if s[0] == 'm': |
409 if f in self._copymap: | 409 source = self._copymap.get(f) |
410 copies[f] = self._copymap[f] | 410 if source: |
411 copies[f] = source | |
411 self.normallookup(f) | 412 self.normallookup(f) |
412 # Also fix up otherparent markers | 413 # Also fix up otherparent markers |
413 elif s[0] == 'n' and s[2] == -2: | 414 elif s[0] == 'n' and s[2] == -2: |
414 if f in self._copymap: | 415 source = self._copymap.get(f) |
415 copies[f] = self._copymap[f] | 416 if source: |
417 copies[f] = source | |
416 self.add(f) | 418 self.add(f) |
417 return copies | 419 return copies |
418 | 420 |
419 def setbranch(self, branch): | 421 def setbranch(self, branch): |
420 self._branch = encoding.fromlocal(branch) | 422 self._branch = encoding.fromlocal(branch) |
516 self._dirty = True | 518 self._dirty = True |
517 if source is not None: | 519 if source is not None: |
518 self._copymap[dest] = source | 520 self._copymap[dest] = source |
519 self._updatedfiles.add(source) | 521 self._updatedfiles.add(source) |
520 self._updatedfiles.add(dest) | 522 self._updatedfiles.add(dest) |
521 elif dest in self._copymap: | 523 elif self._copymap.pop(dest, None): |
522 del self._copymap[dest] | |
523 self._updatedfiles.add(dest) | 524 self._updatedfiles.add(dest) |
524 | 525 |
525 def copied(self, file): | 526 def copied(self, file): |
526 return self._copymap.get(file, None) | 527 return self._copymap.get(file, None) |
527 | 528 |
566 '''Mark a file normal and clean.''' | 567 '''Mark a file normal and clean.''' |
567 s = os.lstat(self._join(f)) | 568 s = os.lstat(self._join(f)) |
568 mtime = s.st_mtime | 569 mtime = s.st_mtime |
569 self._addpath(f, 'n', s.st_mode, | 570 self._addpath(f, 'n', s.st_mode, |
570 s.st_size & _rangemask, mtime & _rangemask) | 571 s.st_size & _rangemask, mtime & _rangemask) |
571 if f in self._copymap: | 572 self._copymap.pop(f, None) |
572 del self._copymap[f] | |
573 if f in self._nonnormalset: | 573 if f in self._nonnormalset: |
574 self._nonnormalset.remove(f) | 574 self._nonnormalset.remove(f) |
575 if mtime > self._lastnormaltime: | 575 if mtime > self._lastnormaltime: |
576 # Remember the most recent modification timeslot for status(), | 576 # Remember the most recent modification timeslot for status(), |
577 # to make sure we won't miss future size-preserving file content | 577 # to make sure we won't miss future size-preserving file content |
595 self.copy(source, f) | 595 self.copy(source, f) |
596 return | 596 return |
597 if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2: | 597 if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2: |
598 return | 598 return |
599 self._addpath(f, 'n', 0, -1, -1) | 599 self._addpath(f, 'n', 0, -1, -1) |
600 if f in self._copymap: | 600 self._copymap.pop(f, None) |
601 del self._copymap[f] | |
602 if f in self._nonnormalset: | 601 if f in self._nonnormalset: |
603 self._nonnormalset.remove(f) | 602 self._nonnormalset.remove(f) |
604 | 603 |
605 def otherparent(self, f): | 604 def otherparent(self, f): |
606 '''Mark as coming from the other parent, always dirty.''' | 605 '''Mark as coming from the other parent, always dirty.''' |
611 # merge-like | 610 # merge-like |
612 self._addpath(f, 'm', 0, -2, -1) | 611 self._addpath(f, 'm', 0, -2, -1) |
613 else: | 612 else: |
614 # add-like | 613 # add-like |
615 self._addpath(f, 'n', 0, -2, -1) | 614 self._addpath(f, 'n', 0, -2, -1) |
616 | 615 self._copymap.pop(f, None) |
617 if f in self._copymap: | |
618 del self._copymap[f] | |
619 | 616 |
620 def add(self, f): | 617 def add(self, f): |
621 '''Mark a file added.''' | 618 '''Mark a file added.''' |
622 self._addpath(f, 'a', 0, -1, -1) | 619 self._addpath(f, 'a', 0, -1, -1) |
623 if f in self._copymap: | 620 self._copymap.pop(f, None) |
624 del self._copymap[f] | |
625 | 621 |
626 def remove(self, f): | 622 def remove(self, f): |
627 '''Mark a file removed.''' | 623 '''Mark a file removed.''' |
628 self._dirty = True | 624 self._dirty = True |
629 self._droppath(f) | 625 self._droppath(f) |
636 elif entry[0] == 'n' and entry[2] == -2: # other parent | 632 elif entry[0] == 'n' and entry[2] == -2: # other parent |
637 size = -2 | 633 size = -2 |
638 self._otherparentset.add(f) | 634 self._otherparentset.add(f) |
639 self._map[f] = dirstatetuple('r', 0, size, 0) | 635 self._map[f] = dirstatetuple('r', 0, size, 0) |
640 self._nonnormalset.add(f) | 636 self._nonnormalset.add(f) |
641 if size == 0 and f in self._copymap: | 637 if size == 0: |
642 del self._copymap[f] | 638 self._copymap.pop(f, None) |
643 | 639 |
644 def merge(self, f): | 640 def merge(self, f): |
645 '''Mark a file merged.''' | 641 '''Mark a file merged.''' |
646 if self._pl[1] == nullid: | 642 if self._pl[1] == nullid: |
647 return self.normallookup(f) | 643 return self.normallookup(f) |
653 self._dirty = True | 649 self._dirty = True |
654 self._droppath(f) | 650 self._droppath(f) |
655 del self._map[f] | 651 del self._map[f] |
656 if f in self._nonnormalset: | 652 if f in self._nonnormalset: |
657 self._nonnormalset.remove(f) | 653 self._nonnormalset.remove(f) |
658 if f in self._copymap: | 654 self._copymap.pop(f, None) |
659 del self._copymap[f] | |
660 | 655 |
661 def _discoverpath(self, path, normed, ignoremissing, exists, storemap): | 656 def _discoverpath(self, path, normed, ignoremissing, exists, storemap): |
662 if exists is None: | 657 if exists is None: |
663 exists = os.path.lexists(os.path.join(self._root, path)) | 658 exists = os.path.lexists(os.path.join(self._root, path)) |
664 if not exists: | 659 if not exists: |