1713 Available as a function so that subclasses can replace the hash |
1713 Available as a function so that subclasses can replace the hash |
1714 as needed. |
1714 as needed. |
1715 """ |
1715 """ |
1716 return storageutil.hashrevisionsha1(text, p1, p2) |
1716 return storageutil.hashrevisionsha1(text, p1, p2) |
1717 |
1717 |
1718 def _processflags(self, text, flags, operation, raw=False): |
|
1719 """Inspect revision data flags and applies transforms defined by |
|
1720 registered flag processors. |
|
1721 |
|
1722 ``text`` - the revision data to process |
|
1723 ``flags`` - the revision flags |
|
1724 ``operation`` - the operation being performed (read or write) |
|
1725 ``raw`` - an optional argument describing if the raw transform should be |
|
1726 applied. |
|
1727 |
|
1728 This method processes the flags in the order (or reverse order if |
|
1729 ``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the |
|
1730 flag processors registered for present flags. The order of flags defined |
|
1731 in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. |
|
1732 |
|
1733 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
|
1734 processed text and ``validatehash`` is a bool indicating whether the |
|
1735 returned text should be checked for hash integrity. |
|
1736 |
|
1737 Note: If the ``raw`` argument is set, it has precedence over the |
|
1738 operation and will only update the value of ``validatehash``. |
|
1739 """ |
|
1740 # fast path: no flag processors will run |
|
1741 if flags == 0: |
|
1742 return text, True |
|
1743 if not operation in ('read', 'write'): |
|
1744 raise error.ProgrammingError(_("invalid '%s' operation") % |
|
1745 operation) |
|
1746 # Check all flags are known. |
|
1747 if flags & ~flagutil.REVIDX_KNOWN_FLAGS: |
|
1748 raise error.RevlogError(_("incompatible revision flag '%#x'") % |
|
1749 (flags & ~flagutil.REVIDX_KNOWN_FLAGS)) |
|
1750 validatehash = True |
|
1751 # Depending on the operation (read or write), the order might be |
|
1752 # reversed due to non-commutative transforms. |
|
1753 orderedflags = REVIDX_FLAGS_ORDER |
|
1754 if operation == 'write': |
|
1755 orderedflags = reversed(orderedflags) |
|
1756 |
|
1757 for flag in orderedflags: |
|
1758 # If a flagprocessor has been registered for a known flag, apply the |
|
1759 # related operation transform and update result tuple. |
|
1760 if flag & flags: |
|
1761 vhash = True |
|
1762 |
|
1763 if flag not in self._flagprocessors: |
|
1764 message = _("missing processor for flag '%#x'") % (flag) |
|
1765 raise error.RevlogError(message) |
|
1766 |
|
1767 processor = self._flagprocessors[flag] |
|
1768 if processor is not None: |
|
1769 readtransform, writetransform, rawtransform = processor |
|
1770 |
|
1771 if raw: |
|
1772 vhash = rawtransform(self, text) |
|
1773 elif operation == 'read': |
|
1774 text, vhash = readtransform(self, text) |
|
1775 else: # write operation |
|
1776 text, vhash = writetransform(self, text) |
|
1777 validatehash = validatehash and vhash |
|
1778 |
|
1779 return text, validatehash |
|
1780 |
|
1781 def checkhash(self, text, node, p1=None, p2=None, rev=None): |
1718 def checkhash(self, text, node, p1=None, p2=None, rev=None): |
1782 """Check node hash integrity. |
1719 """Check node hash integrity. |
1783 |
1720 |
1784 Available as a function so that subclasses can extend hash mismatch |
1721 Available as a function so that subclasses can extend hash mismatch |
1785 behaviors as needed. |
1722 behaviors as needed. |