Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 31760:ec48d57de110
revlog: make _addrevision only accept rawtext
All 3 users of _addrevision use raw:
- addrevision: passing rawtext to _addrevision
- addgroup: passing rawtext and raw=True to _addrevision
- clone: passing rawtext to _addrevision
There is no real user using _addrevision(raw=False). On the other hand,
_addrevision is low-level code dealing with raw revlog deltas and rawtexts.
It should not transform rawtext to non-raw text.
This patch removes the "raw" parameter from "_addrevision", and does some
rename and doc change to make it clear that "_addrevision" expects rawtext.
Archeology shows 2df983125d37 added "raw" flag to "_addrevision", follow-ups
e12c0fa1f65b and c1b7b2285522 seem to make the flag unnecessary.
test-revlog-raw.py no longer complains.
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 30 Mar 2017 18:38:03 -0700 |
parents | 5b93c6fdb391 |
children | 9ec03d5af48f |
comparison
equal
deleted
inserted
replaced
31759:5b93c6fdb391 | 31760:ec48d57de110 |
---|---|
1575 (self._maxchainlen and chainlen > self._maxchainlen)): | 1575 (self._maxchainlen and chainlen > self._maxchainlen)): |
1576 return False | 1576 return False |
1577 | 1577 |
1578 return True | 1578 return True |
1579 | 1579 |
1580 def _addrevision(self, node, text, transaction, link, p1, p2, flags, | 1580 def _addrevision(self, node, rawtext, transaction, link, p1, p2, flags, |
1581 cachedelta, ifh, dfh, alwayscache=False, raw=False): | 1581 cachedelta, ifh, dfh, alwayscache=False): |
1582 """internal function to add revisions to the log | 1582 """internal function to add revisions to the log |
1583 | 1583 |
1584 see addrevision for argument descriptions. | 1584 see addrevision for argument descriptions. |
1585 | |
1586 note: "addrevision" takes non-raw text, "_addrevision" takes raw text. | |
1587 | |
1585 invariants: | 1588 invariants: |
1586 - text is optional (can be None); if not set, cachedelta must be set. | 1589 - rawtext is optional (can be None); if not set, cachedelta must be set. |
1587 if both are set, they must correspond to each other. | 1590 if both are set, they must correspond to each other. |
1588 - raw is optional; if set to True, it indicates the revision data is to | 1591 """ |
1589 be treated by _processflags() as raw. It is usually set by changegroup | 1592 btext = [rawtext] |
1590 generation and debug commands. | |
1591 """ | |
1592 btext = [text] | |
1593 def buildtext(): | 1593 def buildtext(): |
1594 if btext[0] is not None: | 1594 if btext[0] is not None: |
1595 return btext[0] | 1595 return btext[0] |
1596 baserev = cachedelta[0] | 1596 baserev = cachedelta[0] |
1597 delta = cachedelta[1] | 1597 delta = cachedelta[1] |
1605 else: | 1605 else: |
1606 if self._inline: | 1606 if self._inline: |
1607 fh = ifh | 1607 fh = ifh |
1608 else: | 1608 else: |
1609 fh = dfh | 1609 fh = dfh |
1610 basetext = self.revision(baserev, _df=fh, raw=raw) | 1610 basetext = self.revision(baserev, _df=fh, raw=True) |
1611 btext[0] = mdiff.patch(basetext, delta) | 1611 btext[0] = mdiff.patch(basetext, delta) |
1612 | 1612 |
1613 try: | 1613 try: |
1614 res = self._processflags(btext[0], flags, 'read', raw=raw) | 1614 res = self._processflags(btext[0], flags, 'read', raw=True) |
1615 btext[0], validatehash = res | 1615 btext[0], validatehash = res |
1616 if validatehash: | 1616 if validatehash: |
1617 self.checkhash(btext[0], node, p1=p1, p2=p2) | 1617 self.checkhash(btext[0], node, p1=p1, p2=p2) |
1618 if flags & REVIDX_ISCENSORED: | 1618 if flags & REVIDX_ISCENSORED: |
1619 raise RevlogError(_('node %s is not censored') % node) | 1619 raise RevlogError(_('node %s is not censored') % node) |
1661 delta = None | 1661 delta = None |
1662 p1r, p2r = self.rev(p1), self.rev(p2) | 1662 p1r, p2r = self.rev(p1), self.rev(p2) |
1663 | 1663 |
1664 # full versions are inserted when the needed deltas | 1664 # full versions are inserted when the needed deltas |
1665 # become comparable to the uncompressed text | 1665 # become comparable to the uncompressed text |
1666 if text is None: | 1666 if rawtext is None: |
1667 textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]), | 1667 textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]), |
1668 cachedelta[1]) | 1668 cachedelta[1]) |
1669 else: | 1669 else: |
1670 textlen = len(text) | 1670 textlen = len(rawtext) |
1671 | 1671 |
1672 # should we try to build a delta? | 1672 # should we try to build a delta? |
1673 if prev != nullrev and self.storedeltachains: | 1673 if prev != nullrev and self.storedeltachains: |
1674 tested = set() | 1674 tested = set() |
1675 # This condition is true most of the time when processing | 1675 # This condition is true most of the time when processing |
1706 if self._isgooddelta(candidatedelta, textlen): | 1706 if self._isgooddelta(candidatedelta, textlen): |
1707 delta = candidatedelta | 1707 delta = candidatedelta |
1708 if delta is not None: | 1708 if delta is not None: |
1709 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta | 1709 dist, l, data, base, chainbase, chainlen, compresseddeltalen = delta |
1710 else: | 1710 else: |
1711 text = buildtext() | 1711 rawtext = buildtext() |
1712 data = self.compress(text) | 1712 data = self.compress(rawtext) |
1713 l = len(data[1]) + len(data[0]) | 1713 l = len(data[1]) + len(data[0]) |
1714 base = chainbase = curr | 1714 base = chainbase = curr |
1715 | 1715 |
1716 e = (offset_type(offset, flags), l, textlen, | 1716 e = (offset_type(offset, flags), l, textlen, |
1717 base, link, p1r, p2r, node) | 1717 base, link, p1r, p2r, node) |
1719 self.nodemap[node] = curr | 1719 self.nodemap[node] = curr |
1720 | 1720 |
1721 entry = self._io.packentry(e, self.node, self.version, curr) | 1721 entry = self._io.packentry(e, self.node, self.version, curr) |
1722 self._writeentry(transaction, ifh, dfh, entry, data, link, offset) | 1722 self._writeentry(transaction, ifh, dfh, entry, data, link, offset) |
1723 | 1723 |
1724 if alwayscache and text is None: | 1724 if alwayscache and rawtext is None: |
1725 text = buildtext() | 1725 rawtext = buildtext() |
1726 | 1726 |
1727 if type(text) == str: # only accept immutable objects | 1727 if type(rawtext) == str: # only accept immutable objects |
1728 self._cache = (node, curr, text) | 1728 self._cache = (node, curr, rawtext) |
1729 self._chainbasecache[curr] = chainbase | 1729 self._chainbasecache[curr] = chainbase |
1730 return node | 1730 return node |
1731 | 1731 |
1732 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset): | 1732 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset): |
1733 # Files opened in a+ mode have inconsistent behavior on various | 1733 # Files opened in a+ mode have inconsistent behavior on various |
1845 # generation so the revision data can always be handled as raw | 1845 # generation so the revision data can always be handled as raw |
1846 # by the flagprocessor. | 1846 # by the flagprocessor. |
1847 chain = self._addrevision(node, None, transaction, link, | 1847 chain = self._addrevision(node, None, transaction, link, |
1848 p1, p2, flags, (baserev, delta), | 1848 p1, p2, flags, (baserev, delta), |
1849 ifh, dfh, | 1849 ifh, dfh, |
1850 alwayscache=bool(addrevisioncb), | 1850 alwayscache=bool(addrevisioncb)) |
1851 raw=True) | |
1852 | 1851 |
1853 if addrevisioncb: | 1852 if addrevisioncb: |
1854 addrevisioncb(self, chain) | 1853 addrevisioncb(self, chain) |
1855 | 1854 |
1856 if not dfh and not self._inline: | 1855 if not dfh and not self._inline: |