# HG changeset patch # User Boris Feld # Date 1534378093 -7200 # Node ID 729082bb9938f73d834a6a3ab1ec249fb8922133 # Parent 94a4980695f801b62b0af4fa576230a6170d1c0e revlog: split constants into a new `revlogutils.constants` module We want to split some logic out of the main revlog file (the delta computing logic). However, this logic needs access to multiple constants related to the revlog. So we move all revlog related constants into a new module that could be imported from multiple places. We don't copy the file (preserving blame history) because there are only a few moving lines. Also, copying the file would result in annoying merge conflicts with ongoing work from others contributors. diff -r 94a4980695f8 -r 729082bb9938 contrib/import-checker.py --- a/contrib/import-checker.py Thu Jul 12 12:11:20 2018 -0700 +++ b/contrib/import-checker.py Thu Aug 16 02:08:13 2018 +0200 @@ -28,6 +28,8 @@ 'mercurial.hgweb.request', 'mercurial.i18n', 'mercurial.node', + # for revlog to re-export constant to extensions + 'mercurial.revlogutils.constants', # for cffi modules to re-export pure functions 'mercurial.pure.base85', 'mercurial.pure.bdiff', diff -r 94a4980695f8 -r 729082bb9938 mercurial/revlog.py --- a/mercurial/revlog.py Thu Jul 12 12:11:20 2018 -0700 +++ b/mercurial/revlog.py Thu Aug 16 02:08:13 2018 +0200 @@ -36,6 +36,26 @@ wdirrev, ) from .i18n import _ +from .revlogutils.constants import ( + FLAG_GENERALDELTA, + FLAG_INLINE_DATA, + LIMIT_DELTA2TEXT, + REVIDX_DEFAULT_FLAGS, + REVIDX_ELLIPSIS, + REVIDX_EXTSTORED, + REVIDX_FLAGS_ORDER, + REVIDX_ISCENSORED, + REVIDX_KNOWN_FLAGS, + REVIDX_RAWTEXT_CHANGING_FLAGS, + REVLOGV0, + REVLOGV1, + REVLOGV1_FLAGS, + REVLOGV2, + REVLOGV2_FLAGS, + REVLOG_DEFAULT_FLAGS, + REVLOG_DEFAULT_FORMAT, + REVLOG_DEFAULT_VERSION, +) from .thirdparty import ( attr, ) @@ -54,40 +74,31 @@ stringutil, ) +# blanked usage of all the name to prevent pyflakes constraints +# We need these name available in the module for extensions. +REVLOGV0 +REVLOGV1 +REVLOGV2 +FLAG_INLINE_DATA +FLAG_GENERALDELTA +REVLOG_DEFAULT_FLAGS +REVLOG_DEFAULT_FORMAT +REVLOG_DEFAULT_VERSION +REVLOGV1_FLAGS +REVLOGV2_FLAGS +REVIDX_ISCENSORED +REVIDX_ELLIPSIS +REVIDX_EXTSTORED +REVIDX_DEFAULT_FLAGS +REVIDX_FLAGS_ORDER +REVIDX_KNOWN_FLAGS +REVIDX_RAWTEXT_CHANGING_FLAGS + parsers = policy.importmod(r'parsers') # Aliased for performance. _zlibdecompress = zlib.decompress -# revlog header flags -REVLOGV0 = 0 -REVLOGV1 = 1 -# Dummy value until file format is finalized. -# Reminder: change the bounds check in revlog.__init__ when this is changed. -REVLOGV2 = 0xDEAD -FLAG_INLINE_DATA = (1 << 16) -FLAG_GENERALDELTA = (1 << 17) -REVLOG_DEFAULT_FLAGS = FLAG_INLINE_DATA -REVLOG_DEFAULT_FORMAT = REVLOGV1 -REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS -REVLOGV1_FLAGS = FLAG_INLINE_DATA | FLAG_GENERALDELTA -REVLOGV2_FLAGS = REVLOGV1_FLAGS - -# revlog index flags -REVIDX_ISCENSORED = (1 << 15) # revision has censor metadata, must be verified -REVIDX_ELLIPSIS = (1 << 14) # revision hash does not match data (narrowhg) -REVIDX_EXTSTORED = (1 << 13) # revision data is stored externally -REVIDX_DEFAULT_FLAGS = 0 -# stable order in which flags need to be processed and their processors applied -REVIDX_FLAGS_ORDER = [ - REVIDX_ISCENSORED, - REVIDX_ELLIPSIS, - REVIDX_EXTSTORED, -] -REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER) -# bitmark for flags that could cause rawdata content change -REVIDX_RAWTEXT_CHANGING_FLAGS = REVIDX_ISCENSORED | REVIDX_EXTSTORED - # max size of revlog with inline data _maxinline = 131072 _chunksize = 1048576 @@ -854,9 +865,6 @@ return (0, 0, 0, -1, -1, -1, -1, nullid) return list.__getitem__(self, i) -# maximum / ratio -LIMIT_DELTA2TEXT = 2 - class revlogoldio(object): def __init__(self): self.size = indexformatv0.size diff -r 94a4980695f8 -r 729082bb9938 mercurial/revlogutils/__init__.py diff -r 94a4980695f8 -r 729082bb9938 mercurial/revlogutils/constants.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/revlogutils/constants.py Thu Aug 16 02:08:13 2018 +0200 @@ -0,0 +1,46 @@ +# revlogdeltas.py - constant used for revlog logic +# +# Copyright 2005-2007 Matt Mackall +# Copyright 2018 Octobus +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. +"""Helper class to compute deltas stored inside revlogs""" + +from __future__ import absolute_import + +from .. import ( + util, +) + +# revlog header flags +REVLOGV0 = 0 +REVLOGV1 = 1 +# Dummy value until file format is finalized. +# Reminder: change the bounds check in revlog.__init__ when this is changed. +REVLOGV2 = 0xDEAD +FLAG_INLINE_DATA = (1 << 16) +FLAG_GENERALDELTA = (1 << 17) +REVLOG_DEFAULT_FLAGS = FLAG_INLINE_DATA +REVLOG_DEFAULT_FORMAT = REVLOGV1 +REVLOG_DEFAULT_VERSION = REVLOG_DEFAULT_FORMAT | REVLOG_DEFAULT_FLAGS +REVLOGV1_FLAGS = FLAG_INLINE_DATA | FLAG_GENERALDELTA +REVLOGV2_FLAGS = REVLOGV1_FLAGS + +# revlog index flags +REVIDX_ISCENSORED = (1 << 15) # revision has censor metadata, must be verified +REVIDX_ELLIPSIS = (1 << 14) # revision hash does not match data (narrowhg) +REVIDX_EXTSTORED = (1 << 13) # revision data is stored externally +REVIDX_DEFAULT_FLAGS = 0 +# stable order in which flags need to be processed and their processors applied +REVIDX_FLAGS_ORDER = [ + REVIDX_ISCENSORED, + REVIDX_ELLIPSIS, + REVIDX_EXTSTORED, +] +REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER) +# bitmark for flags that could cause rawdata content change +REVIDX_RAWTEXT_CHANGING_FLAGS = REVIDX_ISCENSORED | REVIDX_EXTSTORED + +# maximum / ratio +LIMIT_DELTA2TEXT = 2 diff -r 94a4980695f8 -r 729082bb9938 setup.py --- a/setup.py Thu Jul 12 12:11:20 2018 -0700 +++ b/setup.py Thu Aug 16 02:08:13 2018 +0200 @@ -817,6 +817,7 @@ 'mercurial.thirdparty.zope', 'mercurial.thirdparty.zope.interface', 'mercurial.utils', + 'mercurial.revlogutils', 'hgext', 'hgext.convert', 'hgext.fsmonitor', 'hgext.fastannotate', 'hgext.fsmonitor.pywatchman',