comparison mercurial/manifest.py @ 39317:eb9b8679c852

manifest: change terminology for storage in context classes Storage may not be backed by revlogs. So it is wrong to refer to storage as "revlog" or use abbreviations like "rl." This commit replaces revlog terminology in manifest context classes and starts referring to things as "store" or "storage." Differential Revision: https://phab.mercurial-scm.org/D4389
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 27 Aug 2018 08:52:33 -0700
parents 53363a8eff57
children 57301ba47e66
comparison
equal deleted inserted replaced
39316:53363a8eff57 39317:eb9b8679c852
1580 class memmanifestctx(object): 1580 class memmanifestctx(object):
1581 def __init__(self, manifestlog): 1581 def __init__(self, manifestlog):
1582 self._manifestlog = manifestlog 1582 self._manifestlog = manifestlog
1583 self._manifestdict = manifestdict() 1583 self._manifestdict = manifestdict()
1584 1584
1585 def _revlog(self): 1585 def _storage(self):
1586 return self._manifestlog._revlog 1586 return self._manifestlog._revlog
1587 1587
1588 def new(self): 1588 def new(self):
1589 return memmanifestctx(self._manifestlog) 1589 return memmanifestctx(self._manifestlog)
1590 1590
1595 1595
1596 def read(self): 1596 def read(self):
1597 return self._manifestdict 1597 return self._manifestdict
1598 1598
1599 def write(self, transaction, link, p1, p2, added, removed): 1599 def write(self, transaction, link, p1, p2, added, removed):
1600 return self._revlog().add(self._manifestdict, transaction, link, p1, p2, 1600 return self._storage().add(self._manifestdict, transaction, link,
1601 added, removed) 1601 p1, p2, added, removed)
1602 1602
1603 @interfaceutil.implementer(repository.imanifestrevisionstored) 1603 @interfaceutil.implementer(repository.imanifestrevisionstored)
1604 class manifestctx(object): 1604 class manifestctx(object):
1605 """A class representing a single revision of a manifest, including its 1605 """A class representing a single revision of a manifest, including its
1606 contents, its parent revs, and its linkrev. 1606 contents, its parent revs, and its linkrev.
1612 self._node = node 1612 self._node = node
1613 1613
1614 # TODO: We eventually want p1, p2, and linkrev exposed on this class, 1614 # TODO: We eventually want p1, p2, and linkrev exposed on this class,
1615 # but let's add it later when something needs it and we can load it 1615 # but let's add it later when something needs it and we can load it
1616 # lazily. 1616 # lazily.
1617 #self.p1, self.p2 = revlog.parents(node) 1617 #self.p1, self.p2 = store.parents(node)
1618 #rev = revlog.rev(node) 1618 #rev = store.rev(node)
1619 #self.linkrev = revlog.linkrev(rev) 1619 #self.linkrev = store.linkrev(rev)
1620 1620
1621 def _revlog(self): 1621 def _storage(self):
1622 return self._manifestlog._revlog 1622 return self._manifestlog._revlog
1623 1623
1624 def node(self): 1624 def node(self):
1625 return self._node 1625 return self._node
1626 1626
1632 memmf._manifestdict = self.read().copy() 1632 memmf._manifestdict = self.read().copy()
1633 return memmf 1633 return memmf
1634 1634
1635 @propertycache 1635 @propertycache
1636 def parents(self): 1636 def parents(self):
1637 return self._revlog().parents(self._node) 1637 return self._storage().parents(self._node)
1638 1638
1639 def read(self): 1639 def read(self):
1640 if self._data is None: 1640 if self._data is None:
1641 if self._node == nullid: 1641 if self._node == nullid:
1642 self._data = manifestdict() 1642 self._data = manifestdict()
1643 else: 1643 else:
1644 rl = self._revlog() 1644 store = self._storage()
1645 if self._node in rl._fulltextcache: 1645 # TODO accessing non-public API.
1646 text = pycompat.bytestr(rl._fulltextcache[self._node]) 1646 if self._node in store._fulltextcache:
1647 text = pycompat.bytestr(store._fulltextcache[self._node])
1647 else: 1648 else:
1648 text = rl.revision(self._node) 1649 text = store.revision(self._node)
1649 arraytext = bytearray(text) 1650 arraytext = bytearray(text)
1650 rl._fulltextcache[self._node] = arraytext 1651 store._fulltextcache[self._node] = arraytext
1651 self._data = manifestdict(text) 1652 self._data = manifestdict(text)
1652 return self._data 1653 return self._data
1653 1654
1654 def readfast(self, shallow=False): 1655 def readfast(self, shallow=False):
1655 '''Calls either readdelta or read, based on which would be less work. 1656 '''Calls either readdelta or read, based on which would be less work.
1656 readdelta is called if the delta is against the p1, and therefore can be 1657 readdelta is called if the delta is against the p1, and therefore can be
1657 read quickly. 1658 read quickly.
1658 1659
1659 If `shallow` is True, nothing changes since this is a flat manifest. 1660 If `shallow` is True, nothing changes since this is a flat manifest.
1660 ''' 1661 '''
1661 rl = self._revlog() 1662 store = self._storage()
1662 r = rl.rev(self._node) 1663 r = store.rev(self._node)
1663 deltaparent = rl.deltaparent(r) 1664 deltaparent = store.deltaparent(r)
1664 if deltaparent != nullrev and deltaparent in rl.parentrevs(r): 1665 if deltaparent != nullrev and deltaparent in store.parentrevs(r):
1665 return self.readdelta() 1666 return self.readdelta()
1666 return self.read() 1667 return self.read()
1667 1668
1668 def readdelta(self, shallow=False): 1669 def readdelta(self, shallow=False):
1669 '''Returns a manifest containing just the entries that are present 1670 '''Returns a manifest containing just the entries that are present
1670 in this manifest, but not in its p1 manifest. This is efficient to read 1671 in this manifest, but not in its p1 manifest. This is efficient to read
1671 if the revlog delta is already p1. 1672 if the revlog delta is already p1.
1672 1673
1673 Changing the value of `shallow` has no effect on flat manifests. 1674 Changing the value of `shallow` has no effect on flat manifests.
1674 ''' 1675 '''
1675 revlog = self._revlog() 1676 store = self._storage()
1676 r = revlog.rev(self._node) 1677 r = store.rev(self._node)
1677 d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) 1678 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1678 return manifestdict(d) 1679 return manifestdict(d)
1679 1680
1680 def find(self, key): 1681 def find(self, key):
1681 return self.read().find(key) 1682 return self.read().find(key)
1682 1683
1685 def __init__(self, manifestlog, dir=''): 1686 def __init__(self, manifestlog, dir=''):
1686 self._manifestlog = manifestlog 1687 self._manifestlog = manifestlog
1687 self._dir = dir 1688 self._dir = dir
1688 self._treemanifest = treemanifest() 1689 self._treemanifest = treemanifest()
1689 1690
1690 def _revlog(self): 1691 def _storage(self):
1691 return self._manifestlog._revlog 1692 return self._manifestlog._revlog
1692 1693
1693 def new(self, dir=''): 1694 def new(self, dir=''):
1694 return memtreemanifestctx(self._manifestlog, dir=dir) 1695 return memtreemanifestctx(self._manifestlog, dir=dir)
1695 1696
1702 return self._treemanifest 1703 return self._treemanifest
1703 1704
1704 def write(self, transaction, link, p1, p2, added, removed): 1705 def write(self, transaction, link, p1, p2, added, removed):
1705 def readtree(dir, node): 1706 def readtree(dir, node):
1706 return self._manifestlog.get(dir, node).read() 1707 return self._manifestlog.get(dir, node).read()
1707 return self._revlog().add(self._treemanifest, transaction, link, p1, p2, 1708 return self._storage().add(self._treemanifest, transaction, link,
1708 added, removed, readtree=readtree) 1709 p1, p2, added, removed, readtree=readtree)
1709 1710
1710 @interfaceutil.implementer(repository.imanifestrevisionstored) 1711 @interfaceutil.implementer(repository.imanifestrevisionstored)
1711 class treemanifestctx(object): 1712 class treemanifestctx(object):
1712 def __init__(self, manifestlog, dir, node): 1713 def __init__(self, manifestlog, dir, node):
1713 self._manifestlog = manifestlog 1714 self._manifestlog = manifestlog
1717 self._node = node 1718 self._node = node
1718 1719
1719 # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that 1720 # TODO: Load p1/p2/linkrev lazily. They need to be lazily loaded so that
1720 # we can instantiate treemanifestctx objects for directories we don't 1721 # we can instantiate treemanifestctx objects for directories we don't
1721 # have on disk. 1722 # have on disk.
1722 #self.p1, self.p2 = revlog.parents(node) 1723 #self.p1, self.p2 = store.parents(node)
1723 #rev = revlog.rev(node) 1724 #rev = store.rev(node)
1724 #self.linkrev = revlog.linkrev(rev) 1725 #self.linkrev = store.linkrev(rev)
1725 1726
1726 def _revlog(self): 1727 def _storage(self):
1727 narrowmatch = self._manifestlog._narrowmatch 1728 narrowmatch = self._manifestlog._narrowmatch
1728 if not narrowmatch.always(): 1729 if not narrowmatch.always():
1729 if not narrowmatch.visitdir(self._dir[:-1] or '.'): 1730 if not narrowmatch.visitdir(self._dir[:-1] or '.'):
1730 return excludedmanifestrevlog(self._dir) 1731 return excludedmanifestrevlog(self._dir)
1731 return self._manifestlog.getstorage(self._dir) 1732 return self._manifestlog.getstorage(self._dir)
1732 1733
1733 def read(self): 1734 def read(self):
1734 if self._data is None: 1735 if self._data is None:
1735 rl = self._revlog() 1736 store = self._storage()
1736 if self._node == nullid: 1737 if self._node == nullid:
1737 self._data = treemanifest() 1738 self._data = treemanifest()
1738 elif rl._treeondisk: 1739 # TODO accessing non-public API
1740 elif store._treeondisk:
1739 m = treemanifest(dir=self._dir) 1741 m = treemanifest(dir=self._dir)
1740 def gettext(): 1742 def gettext():
1741 return rl.revision(self._node) 1743 return store.revision(self._node)
1742 def readsubtree(dir, subm): 1744 def readsubtree(dir, subm):
1743 # Set verify to False since we need to be able to create 1745 # Set verify to False since we need to be able to create
1744 # subtrees for trees that don't exist on disk. 1746 # subtrees for trees that don't exist on disk.
1745 return self._manifestlog.get(dir, subm, verify=False).read() 1747 return self._manifestlog.get(dir, subm, verify=False).read()
1746 m.read(gettext, readsubtree) 1748 m.read(gettext, readsubtree)
1747 m.setnode(self._node) 1749 m.setnode(self._node)
1748 self._data = m 1750 self._data = m
1749 else: 1751 else:
1750 if self._node in rl.fulltextcache: 1752 if self._node in store.fulltextcache:
1751 text = pycompat.bytestr(rl.fulltextcache[self._node]) 1753 text = pycompat.bytestr(store.fulltextcache[self._node])
1752 else: 1754 else:
1753 text = rl.revision(self._node) 1755 text = store.revision(self._node)
1754 arraytext = bytearray(text) 1756 arraytext = bytearray(text)
1755 rl.fulltextcache[self._node] = arraytext 1757 store.fulltextcache[self._node] = arraytext
1756 self._data = treemanifest(dir=self._dir, text=text) 1758 self._data = treemanifest(dir=self._dir, text=text)
1757 1759
1758 return self._data 1760 return self._data
1759 1761
1760 def node(self): 1762 def node(self):
1768 memmf._treemanifest = self.read().copy() 1770 memmf._treemanifest = self.read().copy()
1769 return memmf 1771 return memmf
1770 1772
1771 @propertycache 1773 @propertycache
1772 def parents(self): 1774 def parents(self):
1773 return self._revlog().parents(self._node) 1775 return self._storage().parents(self._node)
1774 1776
1775 def readdelta(self, shallow=False): 1777 def readdelta(self, shallow=False):
1776 '''Returns a manifest containing just the entries that are present 1778 '''Returns a manifest containing just the entries that are present
1777 in this manifest, but not in its p1 manifest. This is efficient to read 1779 in this manifest, but not in its p1 manifest. This is efficient to read
1778 if the revlog delta is already p1. 1780 if the revlog delta is already p1.
1781 without recursively reading subdirectory manifests. Instead, any 1783 without recursively reading subdirectory manifests. Instead, any
1782 subdirectory entry will be reported as it appears in the manifest, i.e. 1784 subdirectory entry will be reported as it appears in the manifest, i.e.
1783 the subdirectory will be reported among files and distinguished only by 1785 the subdirectory will be reported among files and distinguished only by
1784 its 't' flag. 1786 its 't' flag.
1785 ''' 1787 '''
1786 revlog = self._revlog() 1788 store = self._storage()
1787 if shallow: 1789 if shallow:
1788 r = revlog.rev(self._node) 1790 r = store.rev(self._node)
1789 d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) 1791 d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r))
1790 return manifestdict(d) 1792 return manifestdict(d)
1791 else: 1793 else:
1792 # Need to perform a slow delta 1794 # Need to perform a slow delta
1793 r0 = revlog.deltaparent(revlog.rev(self._node)) 1795 r0 = store.deltaparent(store.rev(self._node))
1794 m0 = self._manifestlog.get(self._dir, revlog.node(r0)).read() 1796 m0 = self._manifestlog.get(self._dir, store.node(r0)).read()
1795 m1 = self.read() 1797 m1 = self.read()
1796 md = treemanifest(dir=self._dir) 1798 md = treemanifest(dir=self._dir)
1797 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): 1799 for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
1798 if n1: 1800 if n1:
1799 md[f] = n1 1801 md[f] = n1
1807 read quickly. 1809 read quickly.
1808 1810
1809 If `shallow` is True, it only returns the entries from this manifest, 1811 If `shallow` is True, it only returns the entries from this manifest,
1810 and not any submanifests. 1812 and not any submanifests.
1811 ''' 1813 '''
1812 rl = self._revlog() 1814 store = self._storage()
1813 r = rl.rev(self._node) 1815 r = store.rev(self._node)
1814 deltaparent = rl.deltaparent(r) 1816 deltaparent = store.deltaparent(r)
1815 if (deltaparent != nullrev and 1817 if (deltaparent != nullrev and
1816 deltaparent in rl.parentrevs(r)): 1818 deltaparent in store.parentrevs(r)):
1817 return self.readdelta(shallow=shallow) 1819 return self.readdelta(shallow=shallow)
1818 1820
1819 if shallow: 1821 if shallow:
1820 return manifestdict(rl.revision(self._node)) 1822 return manifestdict(store.revision(self._node))
1821 else: 1823 else:
1822 return self.read() 1824 return self.read()
1823 1825
1824 def find(self, key): 1826 def find(self, key):
1825 return self.read().find(key) 1827 return self.read().find(key)