Mercurial > hg
comparison hgext/remotefilelog/repack.py @ 47012:d55b71393907
node: replace nullid and friends with nodeconstants class
The introduction of 256bit hashes require changes to nullid and other
constant magic values. Start pushing them down from repository and
revlog where sensible.
Differential Revision: https://phab.mercurial-scm.org/D9465
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Mon, 29 Mar 2021 01:52:06 +0200 |
parents | 89a2afe31e82 |
children | 6000f5b25c9b |
comparison
equal
deleted
inserted
replaced
46992:5fa019ceb499 | 47012:d55b71393907 |
---|---|
2 | 2 |
3 import os | 3 import os |
4 import time | 4 import time |
5 | 5 |
6 from mercurial.i18n import _ | 6 from mercurial.i18n import _ |
7 from mercurial.node import ( | 7 from mercurial.node import short |
8 nullid, | |
9 short, | |
10 ) | |
11 from mercurial import ( | 8 from mercurial import ( |
12 encoding, | 9 encoding, |
13 error, | 10 error, |
14 lock as lockmod, | 11 lock as lockmod, |
15 mdiff, | 12 mdiff, |
584 ) | 581 ) |
585 | 582 |
586 # Create one contiguous chain and reassign deltabases. | 583 # Create one contiguous chain and reassign deltabases. |
587 for i, node in enumerate(orphans): | 584 for i, node in enumerate(orphans): |
588 if i == 0: | 585 if i == 0: |
589 deltabases[node] = (nullid, 0) | 586 deltabases[node] = (self.repo.nullid, 0) |
590 else: | 587 else: |
591 parent = orphans[i - 1] | 588 parent = orphans[i - 1] |
592 deltabases[node] = (parent, deltabases[parent][1] + 1) | 589 deltabases[node] = (parent, deltabases[parent][1] + 1) |
593 nodes = [n for n in nodes if n not in orphans] | 590 nodes = [n for n in nodes if n not in orphans] |
594 nodes += orphans | 591 nodes += orphans |
674 # Find delta base | 671 # Find delta base |
675 # TODO: allow delta'ing against most recent descendant instead | 672 # TODO: allow delta'ing against most recent descendant instead |
676 # of immediate child | 673 # of immediate child |
677 deltatuple = deltabases.get(node, None) | 674 deltatuple = deltabases.get(node, None) |
678 if deltatuple is None: | 675 if deltatuple is None: |
679 deltabase, chainlen = nullid, 0 | 676 deltabase, chainlen = self.repo.nullid, 0 |
680 deltabases[node] = (nullid, 0) | 677 deltabases[node] = (self.repo.nullid, 0) |
681 nobase.add(node) | 678 nobase.add(node) |
682 else: | 679 else: |
683 deltabase, chainlen = deltatuple | 680 deltabase, chainlen = deltatuple |
684 referenced.add(deltabase) | 681 referenced.add(deltabase) |
685 | 682 |
690 | 687 |
691 # The presence of copyfrom means we're at a point where the | 688 # The presence of copyfrom means we're at a point where the |
692 # file was copied from elsewhere. So don't attempt to do any | 689 # file was copied from elsewhere. So don't attempt to do any |
693 # deltas with the other file. | 690 # deltas with the other file. |
694 if copyfrom: | 691 if copyfrom: |
695 p1 = nullid | 692 p1 = self.repo.nullid |
696 | 693 |
697 if chainlen < maxchainlen: | 694 if chainlen < maxchainlen: |
698 # Record this child as the delta base for its parents. | 695 # Record this child as the delta base for its parents. |
699 # This may be non optimal, since the parents may have | 696 # This may be non optimal, since the parents may have |
700 # many children, and this will only choose the last one. | 697 # many children, and this will only choose the last one. |
701 # TODO: record all children and try all deltas to find | 698 # TODO: record all children and try all deltas to find |
702 # best | 699 # best |
703 if p1 != nullid: | 700 if p1 != self.repo.nullid: |
704 deltabases[p1] = (node, chainlen + 1) | 701 deltabases[p1] = (node, chainlen + 1) |
705 if p2 != nullid: | 702 if p2 != self.repo.nullid: |
706 deltabases[p2] = (node, chainlen + 1) | 703 deltabases[p2] = (node, chainlen + 1) |
707 | 704 |
708 # experimental config: repack.chainorphansbysize | 705 # experimental config: repack.chainorphansbysize |
709 if ui.configbool(b'repack', b'chainorphansbysize'): | 706 if ui.configbool(b'repack', b'chainorphansbysize'): |
710 orphans = nobase - referenced | 707 orphans = nobase - referenced |
717 deltabase, chainlen = deltabases[node] | 714 deltabase, chainlen = deltabases[node] |
718 # Compute delta | 715 # Compute delta |
719 # TODO: Optimize the deltachain fetching. Since we're | 716 # TODO: Optimize the deltachain fetching. Since we're |
720 # iterating over the different version of the file, we may | 717 # iterating over the different version of the file, we may |
721 # be fetching the same deltachain over and over again. | 718 # be fetching the same deltachain over and over again. |
722 if deltabase != nullid: | 719 if deltabase != self.repo.nullid: |
723 deltaentry = self.data.getdelta(filename, node) | 720 deltaentry = self.data.getdelta(filename, node) |
724 delta, deltabasename, origdeltabase, meta = deltaentry | 721 delta, deltabasename, origdeltabase, meta = deltaentry |
725 size = meta.get(constants.METAKEYSIZE) | 722 size = meta.get(constants.METAKEYSIZE) |
726 if ( | 723 if ( |
727 deltabasename != filename | 724 deltabasename != filename |
789 # since the content is identical and the parents are null. | 786 # since the content is identical and the parents are null. |
790 if node in dontprocess and node not in entries: | 787 if node in dontprocess and node not in entries: |
791 # If copyfrom == filename, it means the copy history | 788 # If copyfrom == filename, it means the copy history |
792 # went to come other file, then came back to this one, so we | 789 # went to come other file, then came back to this one, so we |
793 # should continue processing it. | 790 # should continue processing it. |
794 if p1 != nullid and copyfrom != filename: | 791 if p1 != self.repo.nullid and copyfrom != filename: |
795 dontprocess.add(p1) | 792 dontprocess.add(p1) |
796 if p2 != nullid: | 793 if p2 != self.repo.nullid: |
797 dontprocess.add(p2) | 794 dontprocess.add(p2) |
798 continue | 795 continue |
799 | 796 |
800 if copyfrom: | 797 if copyfrom: |
801 dontprocess.add(p1) | 798 dontprocess.add(p1) |
812 | 809 |
813 def _toposort(self, ancestors): | 810 def _toposort(self, ancestors): |
814 def parentfunc(node): | 811 def parentfunc(node): |
815 p1, p2, linknode, copyfrom = ancestors[node] | 812 p1, p2, linknode, copyfrom = ancestors[node] |
816 parents = [] | 813 parents = [] |
817 if p1 != nullid: | 814 if p1 != self.repo.nullid: |
818 parents.append(p1) | 815 parents.append(p1) |
819 if p2 != nullid: | 816 if p2 != self.repo.nullid: |
820 parents.append(p2) | 817 parents.append(p2) |
821 return parents | 818 return parents |
822 | 819 |
823 sortednodes = shallowutil.sortnodes(ancestors.keys(), parentfunc) | 820 sortednodes = shallowutil.sortnodes(ancestors.keys(), parentfunc) |
824 return sortednodes | 821 return sortednodes |