mercurial/revlog.py
changeset 42730 92ac6b1697a7
parent 42729 05c80f9ef100
child 42731 5109217a9ab6
equal deleted inserted replaced
42729:05c80f9ef100 42730:92ac6b1697a7
    51     REVIDX_DEFAULT_FLAGS,
    51     REVIDX_DEFAULT_FLAGS,
    52     REVIDX_ELLIPSIS,
    52     REVIDX_ELLIPSIS,
    53     REVIDX_EXTSTORED,
    53     REVIDX_EXTSTORED,
    54     REVIDX_FLAGS_ORDER,
    54     REVIDX_FLAGS_ORDER,
    55     REVIDX_ISCENSORED,
    55     REVIDX_ISCENSORED,
    56     REVIDX_KNOWN_FLAGS,
       
    57     REVIDX_RAWTEXT_CHANGING_FLAGS,
    56     REVIDX_RAWTEXT_CHANGING_FLAGS,
    58 )
    57 )
    59 from .thirdparty import (
    58 from .thirdparty import (
    60     attr,
    59     attr,
    61 )
    60 )
    95 REVIDX_ISCENSORED
    94 REVIDX_ISCENSORED
    96 REVIDX_ELLIPSIS
    95 REVIDX_ELLIPSIS
    97 REVIDX_EXTSTORED
    96 REVIDX_EXTSTORED
    98 REVIDX_DEFAULT_FLAGS
    97 REVIDX_DEFAULT_FLAGS
    99 REVIDX_FLAGS_ORDER
    98 REVIDX_FLAGS_ORDER
   100 REVIDX_KNOWN_FLAGS
       
   101 REVIDX_RAWTEXT_CHANGING_FLAGS
    99 REVIDX_RAWTEXT_CHANGING_FLAGS
   102 
   100 
   103 parsers = policy.importmod(r'parsers')
   101 parsers = policy.importmod(r'parsers')
   104 rustancestor = policy.importrust(r'ancestor')
   102 rustancestor = policy.importrust(r'ancestor')
   105 rustdagop = policy.importrust(r'dagop')
   103 rustdagop = policy.importrust(r'dagop')
   153       contents can be used for hash integrity checks.
   151       contents can be used for hash integrity checks.
   154     """
   152     """
   155     _insertflagprocessor(flag, processor, flagutil.flagprocessors)
   153     _insertflagprocessor(flag, processor, flagutil.flagprocessors)
   156 
   154 
   157 def _insertflagprocessor(flag, processor, flagprocessors):
   155 def _insertflagprocessor(flag, processor, flagprocessors):
   158     if not flag & REVIDX_KNOWN_FLAGS:
   156     if not flag & flagutil.REVIDX_KNOWN_FLAGS:
   159         msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
   157         msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
   160         raise error.ProgrammingError(msg)
   158         raise error.ProgrammingError(msg)
   161     if flag not in REVIDX_FLAGS_ORDER:
   159     if flag not in REVIDX_FLAGS_ORDER:
   162         msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % (flag)
   160         msg = _("flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % (flag)
   163         raise error.ProgrammingError(msg)
   161         raise error.ProgrammingError(msg)
   171 
   169 
   172 def gettype(q):
   170 def gettype(q):
   173     return int(q & 0xFFFF)
   171     return int(q & 0xFFFF)
   174 
   172 
   175 def offset_type(offset, type):
   173 def offset_type(offset, type):
   176     if (type & ~REVIDX_KNOWN_FLAGS) != 0:
   174     if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0:
   177         raise ValueError('unknown revlog index flags')
   175         raise ValueError('unknown revlog index flags')
   178     return int(int(offset) << 16 | type)
   176     return int(int(offset) << 16 | type)
   179 
   177 
   180 @attr.s(slots=True, frozen=True)
   178 @attr.s(slots=True, frozen=True)
   181 class _revisioninfo(object):
   179 class _revisioninfo(object):
   683     def size(self, rev):
   681     def size(self, rev):
   684         """length of non-raw text (processed by a "read" flag processor)"""
   682         """length of non-raw text (processed by a "read" flag processor)"""
   685         # fast path: if no "read" flag processor could change the content,
   683         # fast path: if no "read" flag processor could change the content,
   686         # size is rawsize. note: ELLIPSIS is known to not change the content.
   684         # size is rawsize. note: ELLIPSIS is known to not change the content.
   687         flags = self.flags(rev)
   685         flags = self.flags(rev)
   688         if flags & (REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
   686         if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
   689             return self.rawsize(rev)
   687             return self.rawsize(rev)
   690 
   688 
   691         return len(self.revision(rev, raw=False))
   689         return len(self.revision(rev, raw=False))
   692 
   690 
   693     def chainbase(self, rev):
   691     def chainbase(self, rev):
  1760             return text, True
  1758             return text, True
  1761         if not operation in ('read', 'write'):
  1759         if not operation in ('read', 'write'):
  1762             raise error.ProgrammingError(_("invalid '%s' operation") %
  1760             raise error.ProgrammingError(_("invalid '%s' operation") %
  1763                                          operation)
  1761                                          operation)
  1764         # Check all flags are known.
  1762         # Check all flags are known.
  1765         if flags & ~REVIDX_KNOWN_FLAGS:
  1763         if flags & ~flagutil.REVIDX_KNOWN_FLAGS:
  1766             raise error.RevlogError(_("incompatible revision flag '%#x'") %
  1764             raise error.RevlogError(_("incompatible revision flag '%#x'") %
  1767                                     (flags & ~REVIDX_KNOWN_FLAGS))
  1765                                     (flags & ~flagutil.REVIDX_KNOWN_FLAGS))
  1768         validatehash = True
  1766         validatehash = True
  1769         # Depending on the operation (read or write), the order might be
  1767         # Depending on the operation (read or write), the order might be
  1770         # reversed due to non-commutative transforms.
  1768         # reversed due to non-commutative transforms.
  1771         orderedflags = REVIDX_FLAGS_ORDER
  1769         orderedflags = REVIDX_FLAGS_ORDER
  1772         if operation == 'write':
  1770         if operation == 'write':