Mercurial > hg
comparison mercurial/revlog.py @ 30743:2df983125d37
revlog: add 'raw' argument to revision and _addrevision
This patch introduces a new 'raw' argument (defaults to False) to revlog's
revision() and _addrevision() methods.
When the 'raw' argument is set to True, it indicates the revision data should be
handled as raw data by the flagprocessor.
Note: Given revlog.addgroup() calls are restricted to changegroup generation, we
can always set raw to True when calling revlog._addrevision() from
revlog.addgroup().
author | Remi Chaintron <remi@fb.com> |
---|---|
date | Thu, 05 Jan 2017 17:16:07 +0000 |
parents | be5b2098a817 |
children | e12c0fa1f65b |
comparison
equal
deleted
inserted
replaced
30742:d3e2d39b97ea | 30743:2df983125d37 |
---|---|
1200 return str(self._chunk(rev2)) | 1200 return str(self._chunk(rev2)) |
1201 | 1201 |
1202 return mdiff.textdiff(self.revision(rev1), | 1202 return mdiff.textdiff(self.revision(rev1), |
1203 self.revision(rev2)) | 1203 self.revision(rev2)) |
1204 | 1204 |
1205 def revision(self, nodeorrev, _df=None): | 1205 def revision(self, nodeorrev, _df=None, raw=False): |
1206 """return an uncompressed revision of a given node or revision | 1206 """return an uncompressed revision of a given node or revision |
1207 number. | 1207 number. |
1208 | 1208 |
1209 _df is an existing file handle to read from. It is meant to only be | 1209 _df - an existing file handle to read from. (internal-only) |
1210 used internally. | 1210 raw - an optional argument specifying if the revision data is to be |
1211 treated as raw data when applying flag transforms. 'raw' should be set | |
1212 to True when generating changegroups or in debug commands. | |
1211 """ | 1213 """ |
1212 if isinstance(nodeorrev, int): | 1214 if isinstance(nodeorrev, int): |
1213 rev = nodeorrev | 1215 rev = nodeorrev |
1214 node = self.node(rev) | 1216 node = self.node(rev) |
1215 else: | 1217 else: |
1410 return False | 1412 return False |
1411 | 1413 |
1412 return True | 1414 return True |
1413 | 1415 |
1414 def _addrevision(self, node, text, transaction, link, p1, p2, flags, | 1416 def _addrevision(self, node, text, transaction, link, p1, p2, flags, |
1415 cachedelta, ifh, dfh, alwayscache=False): | 1417 cachedelta, ifh, dfh, alwayscache=False, raw=False): |
1416 """internal function to add revisions to the log | 1418 """internal function to add revisions to the log |
1417 | 1419 |
1418 see addrevision for argument descriptions. | 1420 see addrevision for argument descriptions. |
1419 invariants: | 1421 invariants: |
1420 - text is optional (can be None); if not set, cachedelta must be set. | 1422 - text is optional (can be None); if not set, cachedelta must be set. |
1421 if both are set, they must correspond to each other. | 1423 if both are set, they must correspond to each other. |
1424 - raw is optional; if set to True, it indicates the revision data is to | |
1425 be treated by _processflags() as raw. It is usually set by changegroup | |
1426 generation and debug commands. | |
1422 """ | 1427 """ |
1423 btext = [text] | 1428 btext = [text] |
1424 def buildtext(): | 1429 def buildtext(): |
1425 if btext[0] is not None: | 1430 if btext[0] is not None: |
1426 return btext[0] | 1431 return btext[0] |
1436 else: | 1441 else: |
1437 if self._inline: | 1442 if self._inline: |
1438 fh = ifh | 1443 fh = ifh |
1439 else: | 1444 else: |
1440 fh = dfh | 1445 fh = dfh |
1441 basetext = self.revision(self.node(baserev), _df=fh) | 1446 basetext = self.revision(self.node(baserev), _df=fh, raw=raw) |
1442 btext[0] = mdiff.patch(basetext, delta) | 1447 btext[0] = mdiff.patch(basetext, delta) |
1448 | |
1443 try: | 1449 try: |
1444 self.checkhash(btext[0], node, p1=p1, p2=p2) | 1450 self.checkhash(btext[0], node, p1=p1, p2=p2) |
1445 if flags & REVIDX_ISCENSORED: | 1451 if flags & REVIDX_ISCENSORED: |
1446 raise RevlogError(_('node %s is not censored') % node) | 1452 raise RevlogError(_('node %s is not censored') % node) |
1447 except CensoredNodeError: | 1453 except CensoredNodeError: |
1666 | 1672 |
1667 # We assume consumers of addrevisioncb will want to retrieve | 1673 # We assume consumers of addrevisioncb will want to retrieve |
1668 # the added revision, which will require a call to | 1674 # the added revision, which will require a call to |
1669 # revision(). revision() will fast path if there is a cache | 1675 # revision(). revision() will fast path if there is a cache |
1670 # hit. So, we tell _addrevision() to always cache in this case. | 1676 # hit. So, we tell _addrevision() to always cache in this case. |
1677 # We're only using addgroup() in the context of changegroup | |
1678 # generation so the revision data can always be handled as raw | |
1679 # by the flagprocessor. | |
1671 chain = self._addrevision(node, None, transaction, link, | 1680 chain = self._addrevision(node, None, transaction, link, |
1672 p1, p2, flags, (baserev, delta), | 1681 p1, p2, flags, (baserev, delta), |
1673 ifh, dfh, | 1682 ifh, dfh, |
1674 alwayscache=bool(addrevisioncb)) | 1683 alwayscache=bool(addrevisioncb), |
1684 raw=True) | |
1675 | 1685 |
1676 if addrevisioncb: | 1686 if addrevisioncb: |
1677 addrevisioncb(self, chain) | 1687 addrevisioncb(self, chain) |
1678 | 1688 |
1679 if not dfh and not self._inline: | 1689 if not dfh and not self._inline: |