##// END OF EJS Templates
interfaces: convert `repository.imanifeststorage` from zope `Attribute` attrs...
interfaces: convert `repository.imanifeststorage` from zope `Attribute` attrs This is the same transformation as b455dfddfed0 did for dirstate.

File last commit:

r53033:c33734fb merge default
r53375:d01af74e default
Show More
obsolete.py
1179 lines | 37.6 KiB | text/x-python | PythonLexer
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 # obsolete.py - obsolete markers handling
#
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Logilab SA <contact@logilab.fr>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 """Obsolete marker handling
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
An obsolete marker maps an old changeset to a list of new
changesets. If the list of new changesets is empty, the old changeset
is said to be "killed". Otherwise, the old changeset is being
"replaced" by the new changesets.
Obsolete markers can be used to record and distribute changeset graph
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 transformations performed by history rewrite operations, and help
building new tools to reconcile conflicting rewrite actions. To
facilitate conflict resolution, markers include various annotations
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 besides old and news changeset identifiers, such as creation date or
author name.
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 The old obsoleted changeset is called a "predecessor" and possible
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 replacements are called "successors". Markers that used changeset X as
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 a predecessor are called "successor markers of X" because they hold
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 information about the successors of X. Markers that use changeset Y as
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 a successors are call "predecessor markers of Y" because they hold
information about the predecessors of Y.
Pierre-Yves David
obsolete: flip `obstore.successors` and `obsolete.precursors`...
r17776
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775 Examples:
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 - When changeset A is replaced by changeset A', one marker is stored:
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775
Martin Geisler
obsolete: fix one-element tuple in module docstring
r21166 (A, (A',))
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 - When changesets A and B are folded into a new changeset C, two markers are
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775 stored:
(A, (C,)) and (B, (C,))
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 - When changeset A is simply "pruned" from the graph, a marker is created:
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775
(A, ())
liscju
obsolete: fix minor module documentation issues
r29894 - When changeset A is split into B and C, a single marker is used:
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775
liscju
obsolete: fix minor module documentation issues
r29894 (A, (B, C))
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164 We use a single marker to distinguish the "split" case from the "divergence"
case. If two independent operations rewrite the same changeset A in to A' and
A'', we have an error case: divergent rewriting. We can detect it because
Pierre-Yves David
obsolete: add example of marker usage in the documentation...
r17775 two markers will be created independently:
(A, (B,)) and (A, (C,))
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Format
------
Markers are stored in an append-only file stored in
'.hg/store/obsstore'.
The file starts with a version header:
- 1 unsigned byte: version number, starting at zero.
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 The header is followed by the markers. Marker format depend of the version. See
comment associated with each format for details.
Martin Geisler
obsolete: fix language and grammar in module docstring
r21164
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 """
Gregory Szorc
obsolete: use absolute_import
r27332
Matt Harbison
typing: add `from __future__ import annotations` to most files...
r52756 from __future__ import annotations
Manuel Jacob
node: stop converting binascii.Error to TypeError in bin()...
r50143 import binascii
Gregory Szorc
obsolete: use absolute_import
r27332 import struct
obsstore: break the repo → obstore → repo loop...
r50319 import weakref
Gregory Szorc
obsolete: use absolute_import
r27332
from .i18n import _
Joerg Sonnenberger
node: import symbols explicitly...
r46729 from .node import (
bin,
hex,
)
Gregory Szorc
obsolete: use absolute_import
r27332 from . import (
Yuya Nishihara
obsolete: store user name and note in UTF-8 (issue5754) (BC)...
r38729 encoding,
Gregory Szorc
obsolete: use absolute_import
r27332 error,
obsutil: move 'successorssets' to the new modules...
r33143 obsutil,
Gregory Szorc
obsolete: use absolute_import
r27332 phases,
Yuya Nishihara
parsers: switch to policy importer...
r32372 policy,
Yuya Nishihara
obsolete: explode if metadata contains invalid UTF-8 sequence (API)...
r38730 pycompat,
Gregory Szorc
obsolete: use absolute_import
r27332 util,
)
Augie Fackler
core: migrate uses of hashlib.sha1 to hashutil.sha1...
r44517 from .utils import (
dateutil,
hashutil,
)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 parsers = policy.importmod('parsers')
Yuya Nishihara
parsers: switch to policy importer...
r32372
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 _pack = struct.pack
_unpack = struct.unpack
Pierre-Yves David
obsstore: prefetch struct.calcsize...
r23498 _calcsize = struct.calcsize
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046 propertycache = util.propertycache
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Durham Goode
obsolete: add createmarkers option...
r22951 # Options for obsolescence
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 createmarkersopt = b'createmarkers'
allowunstableopt = b'allowunstable'
Martin von Zweigbergk
rewriteutil: check for divergence...
r47784 allowdivergenceopt = b'allowdivergence'
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 exchangeopt = b'exchange'
Durham Goode
obsolete: add createmarkers option...
r22951
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
config: update evolution-related config...
r34865 def _getoptionvalue(repo, option):
"""Returns True if the given repository has the given obsolete option
enabled.
"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 configkey = b'evolution.%s' % option
newconfig = repo.ui.configbool(b'experimental', configkey)
Boris Feld
config: update evolution-related config...
r34865
# Return the value only if defined
if newconfig is not None:
return newconfig
# Fallback on generic option
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return repo.ui.configbool(b'experimental', b'evolution')
Boris Feld
config: update evolution-related config...
r34865 except (error.ConfigError, AttributeError):
# Fallback on old-fashion config
# inconsistent config: experimental.evolution
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 result = set(repo.ui.configlist(b'experimental', b'evolution'))
Boris Feld
config: update evolution-related config...
r34865
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'all' in result:
Boris Feld
config: update evolution-related config...
r34865 return True
# Temporary hack for next check
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 newconfig = repo.ui.config(b'experimental', b'evolution.createmarkers')
Boris Feld
config: update evolution-related config...
r34865 if newconfig:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 result.add(b'createmarkers')
Boris Feld
config: update evolution-related config...
r34865
return option in result
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
obsolete: refactor function for getting obsolete options...
r37149 def getoptions(repo):
"""Returns dicts showing state of obsolescence features."""
createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
av6
obsolete: disable other evolution config options if createmarkers is off...
r48579 if createmarkersvalue:
unstablevalue = _getoptionvalue(repo, allowunstableopt)
divergencevalue = _getoptionvalue(repo, allowdivergenceopt)
exchangevalue = _getoptionvalue(repo, exchangeopt)
else:
# if we cannot create obsolescence markers, we shouldn't exchange them
# or perform operations that lead to instability or divergence
unstablevalue = False
divergencevalue = False
exchangevalue = False
Gregory Szorc
obsolete: refactor function for getting obsolete options...
r37149
return {
createmarkersopt: createmarkersvalue,
allowunstableopt: unstablevalue,
Martin von Zweigbergk
rewriteutil: check for divergence...
r47784 allowdivergenceopt: divergencevalue,
Gregory Szorc
obsolete: refactor function for getting obsolete options...
r37149 exchangeopt: exchangevalue,
}
Augie Fackler
formatting: blacken the codebase...
r43346
obsolete: move the 'isenabled' function at the top of the file...
r32333 def isenabled(repo, option):
"""Returns True if the given repository has the given obsolete option
enabled.
"""
Gregory Szorc
obsolete: refactor function for getting obsolete options...
r37149 return getoptions(repo)[option]
obsolete: move the 'isenabled' function at the top of the file...
r32333
Augie Fackler
formatting: blacken the codebase...
r43346
av6
obsolete: add a note that explains creating aliases for marker flags
r37035 # Creating aliases for marker flags because evolve extension looks for
# bumpedfix in obsolete.py
av6
obsolete: move marker flags to obsutil...
r36971 bumpedfix = obsutil.bumpedfix
usingsha256 = obsutil.usingsha256
Pierre-Yves David
obsolete: add a flag that allows fixing "bumped" changeset...
r17831
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 ## Parsing and writing of version "0"
#
# The header is followed by the markers. Each marker is made of:
#
Pierre-Yves David
obsolete: use uint## in the format documention...
r22849 # - 1 uint8 : number of new changesets "N", can be zero.
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 #
Pierre-Yves David
obsolete: use uint## in the format documention...
r22849 # - 1 uint32: metadata size "M" in bytes.
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 #
# - 1 byte: a bit field. It is reserved for flags used in common
# obsolete marker operations, to avoid repeated decoding of metadata
# entries.
#
# - 20 bytes: obsoleted changeset identifier.
#
# - N*20 bytes: new changesets identifiers.
#
# - M bytes: metadata as a sequence of nul-terminated strings. Each
# string contains a key and a value, separated by a colon ':', without
# additional encoding. Keys cannot contain '\0' or ':' and values
# cannot contain '\0'.
_fm0version = 0
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _fm0fixed = b'>BIB20s'
_fm0node = b'20s'
Pierre-Yves David
obsstore: prefetch struct.calcsize...
r23498 _fm0fsize = _calcsize(_fm0fixed)
_fm0fnodesize = _calcsize(_fm0node)
Pierre-Yves David
obsolete: move _encodemarkers next to _readmarkers
r22334
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 def _fm0readmarkers(data, off, stop):
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 # Loop on markers
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 while off < stop:
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 # read fixed part
Augie Fackler
formatting: blacken the codebase...
r43346 cur = data[off : off + _fm0fsize]
Pierre-Yves David
obsolete: rename all _fm to _fm0...
r22327 off += _fm0fsize
Pierre-Yves David
obsolete: replace "nb" notation with "num" (for "number")...
r22685 numsuc, mdsize, flags, pre = _unpack(_fm0fixed, cur)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 # read replacement
sucs = ()
Pierre-Yves David
obsolete: replace "nb" notation with "num" (for "number")...
r22685 if numsuc:
Augie Fackler
formatting: blacken the codebase...
r43346 s = _fm0fnodesize * numsuc
cur = data[off : off + s]
Pierre-Yves David
obsolete: replace "nb" notation with "num" (for "number")...
r22685 sucs = _unpack(_fm0node * numsuc, cur)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 off += s
# read metadata
# (metadata will be decoded on demand)
Augie Fackler
formatting: blacken the codebase...
r43346 metadata = data[off : off + mdsize]
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 if len(metadata) != mdsize:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'parsing obsolete marker: metadata is too '
b'short, %d bytes expected, got %d'
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (mdsize, len(metadata))
)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 off += mdsize
Pierre-Yves David
obsolete: _rename decodemeta to _fm0decodemeta...
r22847 metadata = _fm0decodemeta(metadata)
Pierre-Yves David
obsmarker: add `date` as an explicit field...
r22222 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 when, offset = metadata.pop(b'date', b'0 0').split(b' ')
Gregory Szorc
obsolete: avoid slow, generic date parsing...
r22309 date = float(when), int(offset)
except ValueError:
Augie Fackler
formatting: blacken the codebase...
r43346 date = (0.0, 0)
Pierre-Yves David
obsstore: also store the 'parents' field on disk...
r22258 parents = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'p2' in metadata:
parents = (metadata.pop(b'p1', None), metadata.pop(b'p2', None))
elif b'p1' in metadata:
parents = (metadata.pop(b'p1', None),)
elif b'p0' in metadata:
Pierre-Yves David
obsstore: also store the 'parents' field on disk...
r22258 parents = ()
if parents is not None:
try:
Joerg Sonnenberger
node: import symbols explicitly...
r46729 parents = tuple(bin(p) for p in parents)
Pierre-Yves David
obsstore: also store the 'parents' field on disk...
r22258 # if parent content is not a nodeid, drop the data
for p in parents:
if len(p) != 20:
parents = None
break
Manuel Jacob
node: stop converting binascii.Error to TypeError in bin()...
r50143 except binascii.Error:
Pierre-Yves David
obsstore: also store the 'parents' field on disk...
r22258 # if content cannot be translated to nodeid drop the data.
parents = None
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 metadata = tuple(sorted(metadata.items()))
Pierre-Yves David
obsmarker: add `date` as an explicit field...
r22222
Pierre-Yves David
obsstore: also store the 'parents' field on disk...
r22258 yield (pre, sucs, flags, metadata, date, parents)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: move _fm0encodeonemarker next to _fm0readmarkers
r22330 def _fm0encodeonemarker(marker):
pre, sucs, flags, metadata, date, parents = marker
Pierre-Yves David
obsstore: add a flag for sha256 hashes...
r22850 if flags & usingsha256:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'cannot handle sha256 with old obsstore format'))
Pierre-Yves David
obsolete: store metadata as a tuple of (key, value) pairs (API)...
r22845 metadata = dict(metadata)
Pierre-Yves David
obsstore: record data as floating point in fm0 format...
r23002 time, tz = date
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 metadata[b'date'] = b'%r %i' % (time, tz)
Pierre-Yves David
obsolete: move _fm0encodeonemarker next to _fm0readmarkers
r22330 if parents is not None:
if not parents:
# mark that we explicitly recorded no parents
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 metadata[b'p0'] = b''
Gregory Szorc
obsolete: use 2 argument form of enumerate()...
r32278 for i, p in enumerate(parents, 1):
Joerg Sonnenberger
node: import symbols explicitly...
r46729 metadata[b'p%i' % i] = hex(p)
Pierre-Yves David
obsolete: _rename encodemeta to _fm0encodemeta...
r22846 metadata = _fm0encodemeta(metadata)
Pierre-Yves David
obsolete: replace "nb" notation with "num" (for "number")...
r22685 numsuc = len(sucs)
format = _fm0fixed + (_fm0node * numsuc)
data = [numsuc, len(metadata), flags, pre]
Pierre-Yves David
obsolete: move _fm0encodeonemarker next to _fm0readmarkers
r22330 data.extend(sucs)
return _pack(format, *data) + metadata
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848 def _fm0encodemeta(meta):
"""Return encoded metadata string to string mapping.
Assume no ':' in key and no '\0' in both key and value."""
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 for key, value in meta.items():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b':' in key or b'\0' in key:
raise ValueError(b"':' and '\0' are forbidden in metadata key'")
if b'\0' in value:
raise ValueError(b"':' is forbidden in metadata value'")
return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)])
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848 def _fm0decodemeta(data):
"""Return string to string dictionary from encoded version."""
d = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for l in data.split(b'\0'):
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848 if l:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 key, value = l.split(b':', 1)
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848 d[key] = value
return d
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 ## Parsing and writing of version "1"
#
# The header is followed by the markers. Each marker is made of:
#
# - uint32: total size of the marker (including this field)
#
# - float64: date in seconds since epoch
#
# - int16: timezone offset in minutes
#
# - uint16: a bit field. It is reserved for flags used in common
# obsolete marker operations, to avoid repeated decoding of metadata
# entries.
#
# - uint8: number of successors "N", can be zero.
#
# - uint8: number of parents "P", can be zero.
#
# 0: parents data stored but no parent,
# 1: one parent stored,
# 2: two parents stored,
# 3: no parent data stored
#
# - uint8: number of metadata entries M
#
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # - 20 or 32 bytes: predecessor changeset identifier.
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 #
# - N*(20 or 32) bytes: successors changesets identifiers.
#
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # - P*(20 or 32) bytes: parents of the predecessors changesets.
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 #
# - M*(uint8, uint8): size of all metadata entries (key and value)
#
# - remaining bytes: the metadata, each (key, value) pair after the other.
_fm1version = 1
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 _fm1fixed = b'>IdhHBBB'
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _fm1nodesha1 = b'20s'
_fm1nodesha256 = b'32s'
Pierre-Yves David
obsstore: cache size computation for fm1 node...
r23499 _fm1nodesha1size = _calcsize(_fm1nodesha1)
_fm1nodesha256size = _calcsize(_fm1nodesha256)
Pierre-Yves David
obsstore: prefetch struct.calcsize...
r23498 _fm1fsize = _calcsize(_fm1fixed)
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 _fm1parentnone = 3
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _fm1metapair = b'BB'
Augie Fackler
obsolete: reuse _fm1metapair for computing _fm1metapairsize...
r33633 _fm1metapairsize = _calcsize(_fm1metapair)
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 def _fm1purereadmarkers(data, off, stop):
Matt Mackall
readmarkers: promote global constants to locals for performance
r23803 # make some global constants local for performance
noneflag = _fm1parentnone
sha2flag = usingsha256
sha1size = _fm1nodesha1size
sha2size = _fm1nodesha256size
sha1fmt = _fm1nodesha1
sha2fmt = _fm1nodesha256
metasize = _fm1metapairsize
metafmt = _fm1metapair
fsize = _fm1fsize
unpack = _unpack
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 # Loop on markers
Pierre-Yves David
util: drop the 'unpacker' helper...
r25211 ufixed = struct.Struct(_fm1fixed).unpack
Augie Fackler
obsolete: use parsers.fm1readmarker if it exists for a ~38% perf win...
r24018
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 while off < stop:
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 # read fixed part
Matt Mackall
readmarkers: promote global constants to locals for performance
r23803 o1 = off + fsize
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 t, secs, tz, flags, numsuc, numpar, nummeta = ufixed(data[off:o1])
Matt Mackall
readmarkers: add some whitespace
r23792
Matt Mackall
readmarkers: promote global constants to locals for performance
r23803 if flags & sha2flag:
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 nodefmt = sha2fmt
nodesize = sha2size
else:
nodefmt = sha1fmt
nodesize = sha1size
Matt Mackall
readmarkers: add a SHA256 fixme note
r23805
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 (prec,) = unpack(nodefmt, data[o1 : o1 + nodesize])
o1 += nodesize
Matt Mackall
readmarkers: add some whitespace
r23792
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 # read 0 or more successors
if numsuc == 1:
o2 = o1 + nodesize
sucs = (data[o1:o2],)
Matt Mackall
readmarkers: read node reading into node length conditional...
r23801 else:
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 o2 = o1 + nodesize * numsuc
sucs = unpack(nodefmt * numsuc, data[o1:o2])
Matt Mackall
readmarkers: add some whitespace
r23792
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 # read parents
if numpar == noneflag:
o3 = o2
parents = None
elif numpar == 1:
o3 = o2 + nodesize
parents = (data[o2:o3],)
else:
o3 = o2 + nodesize * numpar
parents = unpack(nodefmt * numpar, data[o2:o3])
Matt Mackall
readmarkers: add some whitespace
r23792
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 # read metadata
Matt Mackall
readmarkers: promote global constants to locals for performance
r23803 off = o3 + metasize * nummeta
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 metapairsize = unpack(b'>' + (metafmt * nummeta), data[o3:off])
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 metadata = []
Manuel Jacob
py3: replace `pycompat.xrange` by `range`
r50179 for idx in range(0, len(metapairsize), 2):
Matt Mackall
readmarkers: streamline offset tracking...
r23798 o1 = off + metapairsize[idx]
o2 = o1 + metapairsize[idx + 1]
metadata.append((data[off:o1], data[o1:o2]))
off = o2
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851
Matt Mackall
readmarkers: drop a temporary...
r23800 yield (prec, sucs, flags, tuple(metadata), (secs, tz * 60), parents)
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 def _fm1encodeonemarker(marker):
pre, sucs, flags, metadata, date, parents = marker
# determine node size
_fm1node = _fm1nodesha1
if flags & usingsha256:
_fm1node = _fm1nodesha256
numsuc = len(sucs)
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 numextranodes = 1 + numsuc
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 if parents is None:
numpar = _fm1parentnone
else:
numpar = len(parents)
numextranodes += numpar
formatnodes = _fm1node * numextranodes
formatmeta = _fm1metapair * len(metadata)
format = _fm1fixed + formatnodes + formatmeta
# tz is stored in minutes so we divide by 60
Augie Fackler
formatting: blacken the codebase...
r43346 tz = date[1] // 60
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
data.extend(sucs)
if parents is not None:
data.extend(parents)
Pierre-Yves David
obsstore: prefetch struct.calcsize...
r23498 totalsize = _calcsize(format)
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 for key, value in metadata:
lk = len(key)
lv = len(value)
Simon Whitaker
obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)...
r34408 if lk > 255:
Augie Fackler
formatting: blacken the codebase...
r43346 msg = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'obsstore metadata key cannot be longer than 255 bytes'
b' (key "%s" is %u bytes)'
Augie Fackler
formatting: blacken the codebase...
r43346 ) % (key, lk)
Simon Whitaker
obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)...
r34408 raise error.ProgrammingError(msg)
if lv > 255:
Augie Fackler
formatting: blacken the codebase...
r43346 msg = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'obsstore metadata value cannot be longer than 255 bytes'
b' (value "%s" for key "%s" is %u bytes)'
Augie Fackler
formatting: blacken the codebase...
r43346 ) % (value, key, lv)
Simon Whitaker
obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)...
r34408 raise error.ProgrammingError(msg)
Pierre-Yves David
obsolete: introduce a new binary encoding for obsmarkers (version 1)...
r22851 data.append(lk)
data.append(lv)
totalsize += lk + lv
data[0] = totalsize
data = [_pack(format, *data)]
for key, value in metadata:
data.append(key)
data.append(value)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b''.join(data)
Pierre-Yves David
obsolete: gather _fm0 meta encoding with other _fm0 code
r22848
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 def _fm1readmarkers(data, off, stop):
Martin von Zweigbergk
_fm1readmarkers: generate list in C...
r24019 native = getattr(parsers, 'fm1readmarkers', None)
if not native:
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 return _fm1purereadmarkers(data, off, stop)
Martin von Zweigbergk
_fm1readmarkers: generate list in C...
r24019 return native(data, off, stop)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: support for any known obsstore format when reading or writing...
r22331 # mapping to read/write various marker formats
# <version> -> (decoder, encoder)
Augie Fackler
formatting: blacken the codebase...
r43346 formats = {
_fm0version: (_fm0readmarkers, _fm0encodeonemarker),
_fm1version: (_fm1readmarkers, _fm1encodeonemarker),
}
Pierre-Yves David
obsolete: support for any known obsstore format when reading or writing...
r22331
Jun Wu
obsstore: move marker version reading to a separate function...
r32689 def _readmarkerversion(data):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return _unpack(b'>B', data[0:1])[0]
Jun Wu
obsstore: move marker version reading to a separate function...
r32689
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsstore: disable garbage collection during initialization (issue4456)...
r23497 @util.nogc
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 def _readmarkers(data, off=None, stop=None):
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 """Read and enumerate markers from raw data"""
Jun Wu
obsstore: move marker version reading to a separate function...
r32689 diskversion = _readmarkerversion(data)
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 if not off:
off = 1 # skip 1 byte version number
if stop is None:
stop = len(data)
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 if diskversion not in formats:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b'parsing obsolete marker: unknown version %r') % diskversion
obsolete: raise richer exception on unknown version...
r32591 raise error.UnknownVersion(msg, version=diskversion)
Jun Wu
obsstore: let read marker API take a range of offsets...
r33504 return diskversion, formats[diskversion][0](data, off, stop)
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612
Augie Fackler
formatting: blacken the codebase...
r43346
Jun Wu
obsstore: move header encoding to a separate function...
r32692 def encodeheader(version=_fm0version):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return _pack(b'>B', version)
Jun Wu
obsstore: move header encoding to a separate function...
r32692
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 def encodemarkers(markers, addheader=False, version=_fm0version):
# Kept separate from flushmarkers(), it will be reused for
# markers exchange.
encodeone = formats[version][1]
if addheader:
Jun Wu
obsstore: move header encoding to a separate function...
r32692 yield encodeheader(version)
Pierre-Yves David
obsolete: gather all contents related to format version 0 in a single place...
r22612 for marker in markers:
yield encodeone(marker)
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044 @util.nogc
def _addsuccessors(successors, markers):
for mark in markers:
successors.setdefault(mark[0], set()).add(mark)
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044 @util.nogc
Boris Feld
obsolete: rename _addprecursors into _addpredecessors...
r33698 def _addpredecessors(predecessors, markers):
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044 for mark in markers:
for suc in mark[1]:
Boris Feld
obsolete: rename _addprecursors into _addpredecessors...
r33698 predecessors.setdefault(suc, set()).add(mark)
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044 @util.nogc
def _addchildren(children, markers):
for mark in markers:
parents = mark[5]
if parents is not None:
for p in parents:
children.setdefault(p, set()).add(mark)
Augie Fackler
formatting: blacken the codebase...
r43346
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 def _checkinvalidmarkers(repo, markers):
Pierre-Yves David
obsstore: make the invalid markers check wrap-able...
r23973 """search for marker with invalid data and raise error if needed
Exist as a separated function to allow the evolve extension for a more
subtle handling.
"""
Martin von Zweigbergk
obsolete: pass only new markers to _checkinvalidmarkers()...
r24045 for mark in markers:
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 if repo.nullid in mark[1]:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'bad obsolescence marker detected: '
b'invalid successors nullid'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Pierre-Yves David
obsstore: make the invalid markers check wrap-able...
r23973
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class obsstore:
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 """Store obsolete markers
Markers can be accessed with two mappings:
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 - predecessors[x] -> set(markers on predecessors edges of x)
Pierre-Yves David
obsolete: flip `obstore.successors` and `obsolete.precursors`...
r17776 - successors[x] -> set(markers on successors edges of x)
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 - children[x] -> set(markers on predecessors edges of children(x)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070 """
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fields = (b'prec', b'succs', b'flag', b'meta', b'date', b'parents')
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # prec: nodeid, predecessors changesets
Pierre-Yves David
obsstore: add a `parents` field...
r22254 # succs: tuple of nodeid, successor changesets (0-N length)
# flag: integer, flag field carrying modifier for the markers (see doc)
Yuya Nishihara
obsolete: store user name and note in UTF-8 (issue5754) (BC)...
r38729 # meta: binary blob in UTF-8, encoded metadata dictionary
Pierre-Yves David
obsstore: add a `parents` field...
r22254 # date: (float, int) tuple, date of marker creation
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # parents: (tuple of nodeid) or None, parents of predecessors
Pierre-Yves David
obsstore: add a `parents` field...
r22254 # None is used when no data has been recorded
Pierre-Yves David
obsstore: add fields attribute to track each field in a marker...
r22221
Joerg Sonnenberger
node: introduce nodeconstants class...
r47538 def __init__(self, repo, svfs, defaultformat=_fm1version, readonly=False):
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 # caches for various obsolescence related cache
self.caches = {}
Siddharth Agarwal
obsolete: replace references to 'sopener' with 'svfs'
r25669 self.svfs = svfs
obsstore: break the repo → obstore → repo loop...
r50319 self._repo = weakref.ref(repo)
Jun Wu
obsstore: move _version to a propertycache...
r32691 self._defaultformat = defaultformat
Durham Goode
obsolete: add readonly flag to obstore constructor...
r22950 self._readonly = readonly
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
obsstore: break the repo → obstore → repo loop...
r50319 @property
def repo(self):
r = self._repo()
if r is None:
msg = "using the obsstore of a deallocated repo"
raise error.ProgrammingError(msg)
return r
Pierre-Yves.David@ens-lyon.org
obsolete: add easy way to iterate over obsolete marker object
r17073 def __iter__(self):
return iter(self._all)
Pierre-Yves David
obsstore: add a __len__ method...
r20585 def __len__(self):
return len(self._all)
Pierre-Yves.David@ens-lyon.org
obsolete: exchange obsolete marker over pushkey...
r17075 def __nonzero__(self):
av6
obsolete: don't use os.stat in repo.obsstore.__nonzero__ if it's static HTTP...
r49640 from . import statichttprepo
if isinstance(self.repo, statichttprepo.statichttprepository):
# If repo is accessed via static HTTP, then we can't use os.stat()
# to just peek at the file size.
return len(self._data) > 1
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if not self._cached('_all'):
Yuya Nishihara
obsstore: fast path to check if obsstore is empty
r26310 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return self.svfs.stat(b'obsstore').st_size > 1
Manuel Jacob
py3: catch FileNotFoundError instead of checking errno == ENOENT
r50201 except FileNotFoundError:
Yuya Nishihara
obsstore: fast path to check if obsstore is empty
r26310 # just build an empty _all list if no obsstore exists, which
# avoids further stat() syscalls
Manuel Jacob
py3: catch FileNotFoundError instead of checking errno == ENOENT
r50201 pass
Pierre-Yves.David@ens-lyon.org
obsolete: exchange obsolete marker over pushkey...
r17075 return bool(self._all)
Gregory Szorc
py3: add __bool__ to every class defining __nonzero__...
r31476 __bool__ = __nonzero__
Pierre-Yves David
obsstore: make the readonly attribute accessible...
r26684 @property
def readonly(self):
"""True if marker creation is disabled
Remove me in the future when obsolete marker is always on."""
return self._readonly
Augie Fackler
formatting: blacken the codebase...
r43346 def create(
self,
transaction,
prec,
succs=(),
flag=0,
parents=None,
date=None,
metadata=None,
ui=None,
):
Pierre-Yves.David@ens-lyon.org
command: creation of obsolete marker...
r17071 """obsolete: add a new obsolete marker
* ensuring it is hashable
* check mandatory metadata
* encode metadata
Pierre-Yves David
obsstore: update create docstring to point to the coder friendly function...
r20516
If you are a human writing code creating marker you want to use the
`createmarkers` function in this module instead.
Pierre-Yves David
obsstore: `create` method return True if a marker is actually added...
r20584
return True if a new marker have been added, False if the markers
already existed (no op).
Pierre-Yves.David@ens-lyon.org
command: creation of obsolete marker...
r17071 """
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 flag = int(flag)
Pierre-Yves.David@ens-lyon.org
command: creation of obsolete marker...
r17071 if metadata is None:
metadata = {}
Pierre-Yves David
obsmarker: add `date` as an explicit field...
r22222 if date is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'date' in metadata:
Pierre-Yves David
obsmarker: add `date` as an explicit field...
r22222 # as a courtesy for out-of-tree extensions
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 date = dateutil.parsedate(metadata.pop(b'date'))
Boris Feld
devel: use default-date config field when creating obsmarkers...
r32411 elif ui is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 date = ui.configdate(b'devel', b'default-date')
Boris Feld
devel: use default-date config field when creating obsmarkers...
r32411 if date is None:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 date = dateutil.makedate()
Pierre-Yves David
obsmarker: add `date` as an explicit field...
r22222 else:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 date = dateutil.makedate()
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 if flag & usingsha256:
if len(prec) != 32:
raise ValueError(prec)
for succ in succs:
if len(succ) != 32:
raise ValueError(succ)
else:
if len(prec) != 20:
raise ValueError(prec)
for succ in succs:
if len(succ) != 20:
raise ValueError(succ)
Pierre-Yves David
obsstore.create: add a simple safeguard against cyclic markers...
r22177 if prec in succs:
Manuel Jacob
py3: use `x.hex()` instead of `pycompat.sysstr(node.hex(x))`
r50195 raise ValueError('in-marker cycle with %s' % prec.hex())
Pierre-Yves David
obsolete: store metadata as a tuple of (key, value) pairs (API)...
r22845
Gregory Szorc
global: bulk replace simple pycompat.iteritems(x) with x.items()...
r49768 metadata = tuple(sorted(metadata.items()))
Yuya Nishihara
obsolete: explode if metadata contains invalid UTF-8 sequence (API)...
r38730 for k, v in metadata:
try:
# might be better to reject non-ASCII keys
k.decode('utf-8')
v.decode('utf-8')
except UnicodeDecodeError:
raise error.ProgrammingError(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'obsstore metadata must be valid UTF-8 sequence '
b'(key = %r, value = %r)'
Augie Fackler
formatting: blacken the codebase...
r43346 % (pycompat.bytestr(k), pycompat.bytestr(v))
)
Pierre-Yves David
obsolete: store metadata as a tuple of (key, value) pairs (API)...
r22845
Joerg Sonnenberger
obsstore: refactor v1 logic to fix 32 byte hash support...
r46035 marker = (bytes(prec), tuple(succs), flag, metadata, date, parents)
Pierre-Yves David
obsstore: `create` method return True if a marker is actually added...
r20584 return bool(self.add(transaction, [marker]))
Pierre-Yves.David@ens-lyon.org
obsolete: obsstore.add now takes a list of markers....
r17220
def add(self, transaction, markers):
"""Add new markers to the store
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Pierre-Yves.David@ens-lyon.org
obsolete: obsstore.add now takes a list of markers....
r17220 Take care of filtering duplicate.
Return the number of new marker."""
Durham Goode
obsolete: add readonly flag to obstore constructor...
r22950 if self._readonly:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'creating obsolete markers is not enabled on this repo')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Jun Wu
obsstore: do not load all markers to detect duplication...
r32774 known = set()
getsuccessors = self.successors.get
Pierre-Yves David
obsolete: do not accept duplicated marker during exchange...
r20030 new = []
for m in markers:
Jun Wu
obsstore: do not load all markers to detect duplication...
r32774 if m not in getsuccessors(m[0], ()) and m not in known:
Pierre-Yves David
obsolete: do not accept duplicated marker during exchange...
r20030 known.add(m)
new.append(m)
Pierre-Yves.David@ens-lyon.org
obsolete: obsstore.add now takes a list of markers....
r17220 if new:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = self.svfs(b'obsstore', b'ab')
Pierre-Yves David
obsolete: move obsolete markers read/write logic to obsstore object...
r17124 try:
Pierre-Yves David
obsolete: write obsolete marker inside a transaction...
r17126 offset = f.tell()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 transaction.add(b'obsstore', offset)
Pierre-Yves.David@ens-lyon.org
obsolete: refactor writemarkers to only encode them...
r17219 # offset == 0: new file - add the version header
Jun Wu
obsstore: keep self._data updated with _addmarkers...
r33479 data = b''.join(encodemarkers(new, offset == 0, self._version))
f.write(data)
Pierre-Yves David
obsolete: write obsolete marker inside a transaction...
r17126 finally:
# XXX: f.close() == filecache invalidation == obsstore rebuilt.
# call 'filecacheentry.refresh()' here
Pierre-Yves David
obsolete: move obsolete markers read/write logic to obsstore object...
r17124 f.close()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 addedmarkers = transaction.changes.get(b'obsmarkers')
transaction: track new obsmarkers in the 'changes' mapping...
r33248 if addedmarkers is not None:
addedmarkers.update(new)
Jun Wu
obsstore: keep self._data updated with _addmarkers...
r33479 self._addmarkers(new, data)
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 # new marker *may* have changed several set. invalidate the cache.
self.caches.clear()
Pierre-Yves David
obsmarker: record the number of new markers in the transaction...
r22339 # records the number of new markers for the transaction hooks
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 previous = int(transaction.hookargs.get(b'new_obsmarkers', b'0'))
transaction.hookargs[b'new_obsmarkers'] = b'%d' % (previous + len(new))
Pierre-Yves.David@ens-lyon.org
obsolete: obsstore.add now takes a list of markers....
r17220 return len(new)
Pierre-Yves David
obsolete: write obsolete marker inside a transaction...
r17126
timeless@mozdev.org
spelling: transaction
r17524 def mergemarkers(self, transaction, data):
Pierre-Yves David
obsstore: have the `mergemarkers` method return the number of new markers...
r22325 """merge a binary stream of markers inside the obsstore
Returns the number of new markers added."""
Pierre-Yves David
obsolete: have _readmarkers return the format version...
r22332 version, markers = _readmarkers(data)
Pierre-Yves David
obsstore: have the `mergemarkers` method return the number of new markers...
r22325 return self.add(transaction, markers)
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046 @propertycache
Jun Wu
obsstore: separate marker parsing from obsstore reading...
r32690 def _data(self):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return self.svfs.tryread(b'obsstore')
Jun Wu
obsstore: separate marker parsing from obsstore reading...
r32690
@propertycache
Jun Wu
obsstore: move _version to a propertycache...
r32691 def _version(self):
if len(self._data) >= 1:
return _readmarkerversion(self._data)
else:
return self._defaultformat
@propertycache
Yuya Nishihara
obsstore: delay loading markers from obsstore file...
r26309 def _all(self):
Jun Wu
obsstore: separate marker parsing from obsstore reading...
r32690 data = self._data
Yuya Nishihara
obsstore: delay loading markers from obsstore file...
r26309 if not data:
return []
self._version, markers = _readmarkers(data)
markers = list(markers)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 _checkinvalidmarkers(self.repo, markers)
Yuya Nishihara
obsstore: delay loading markers from obsstore file...
r26309 return markers
@propertycache
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046 def successors(self):
successors = {}
_addsuccessors(successors, self._all)
return successors
@propertycache
Boris Feld
obsstore: rename precursors into predecessors...
r33699 def predecessors(self):
Boris Feld
obsolete: rename _addprecursors into _addpredecessors...
r33698 predecessors = {}
_addpredecessors(predecessors, self._all)
return predecessors
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046
@propertycache
def children(self):
children = {}
_addchildren(children, self._all)
return children
def _cached(self, attr):
return attr in self.__dict__
Jun Wu
obsstore: keep self._data updated with _addmarkers...
r33479 def _addmarkers(self, markers, rawdata):
Augie Fackler
formatting: blacken the codebase...
r43346 markers = list(markers) # to allow repeated iteration
Jun Wu
obsstore: keep self._data updated with _addmarkers...
r33479 self._data = self._data + rawdata
Martin von Zweigbergk
obsolete: extract helpers from _load()...
r24044 self._all.extend(markers)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if self._cached('successors'):
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046 _addsuccessors(self.successors, markers)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if self._cached('predecessors'):
Boris Feld
obsstore: rename precursors into predecessors...
r33699 _addpredecessors(self.predecessors, markers)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 if self._cached('children'):
Martin von Zweigbergk
obsolete: populate successors, precursors, children lazily...
r24046 _addchildren(self.children, markers)
Joerg Sonnenberger
node: replace nullid and friends with nodeconstants class...
r47771 _checkinvalidmarkers(self.repo, markers)
Pierre-Yves David
obsstore: make the invalid markers check wrap-able...
r23973
Joerg Sonnenberger
exchange: improve computation of relevant markers for large repos...
r52789 def relevantmarkers(self, nodes=None, revs=None):
"""return a set of all obsolescence markers relevant to a set of
nodes or revisions.
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271
Joerg Sonnenberger
exchange: improve computation of relevant markers for large repos...
r52789 "relevant" to a set of nodes or revisions mean:
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271
- marker that use this changeset as successor
- prune marker of direct children on this changeset
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 - recursive application of the two rules on predecessors of these
markers
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271
It is a set so you cannot rely on order."""
Joerg Sonnenberger
exchange: improve computation of relevant markers for large repos...
r52789 if nodes is None:
nodes = set()
if revs is None:
revs = set()
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271
Joerg Sonnenberger
exchange: improve computation of relevant markers for large repos...
r52789 tonode = self.repo.unfiltered().changelog.node
pendingnodes = set()
Boris Feld
obsstore: rename precursors into predecessors...
r33699 precursorsmarkers = self.predecessors
obsolete: fix relevant-obsmarkers computation on pruned changeset...
r32488 succsmarkers = self.successors
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271 children = self.children
Joerg Sonnenberger
exchange: improve computation of relevant markers for large repos...
r52789 for node in nodes:
if (
node in precursorsmarkers
or node in succsmarkers
or node in children
):
pendingnodes.add(node)
for rev in revs:
node = tonode(rev)
if (
node in precursorsmarkers
or node in succsmarkers
or node in children
):
pendingnodes.add(node)
seenmarkers = set()
seennodes = pendingnodes.copy()
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271 while pendingnodes:
direct = set()
for current in pendingnodes:
direct.update(precursorsmarkers.get(current, ()))
pruned = [m for m in children.get(current, ()) if not m[1]]
direct.update(pruned)
obsolete: fix relevant-obsmarkers computation on pruned changeset...
r32488 pruned = [m for m in succsmarkers.get(current, ()) if not m[1]]
direct.update(pruned)
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271 direct -= seenmarkers
Martin von Zweigbergk
cleanup: use set literals where possible...
r42224 pendingnodes = {m[0] for m in direct}
Pierre-Yves David
obsstore: add relevantmarkers method...
r22271 seenmarkers |= direct
pendingnodes -= seennodes
seennodes |= pendingnodes
return seenmarkers
Pierre-Yves.David@ens-lyon.org
obsolete: introduction of obsolete markers...
r17070
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
obsolete: move obsstore creation logic from localrepo...
r32729 def makestore(ui, repo):
"""Create an obsstore instance from a repo."""
# read default format for new obsstore.
# developer config: format.obsstore-version
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 defaultformat = ui.configint(b'format', b'obsstore-version')
Gregory Szorc
obsolete: move obsstore creation logic from localrepo...
r32729 # rely on obsstore class default when possible.
kwargs = {}
if defaultformat is not None:
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 kwargs['defaultformat'] = defaultformat
Gregory Szorc
obsolete: move obsstore creation logic from localrepo...
r32729 readonly = not isenabled(repo, createmarkersopt)
Joerg Sonnenberger
node: introduce nodeconstants class...
r47538 store = obsstore(repo, repo.svfs, readonly=readonly, **kwargs)
Gregory Szorc
obsolete: move obsstore creation logic from localrepo...
r32729 if store and readonly:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
Joerg Sonnenberger
obsolete: quote the feature name...
r52524 _(b'"obsolete" feature not enabled but %i markers found!\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % len(list(store))
)
Gregory Szorc
obsolete: move obsstore creation logic from localrepo...
r32729 return store
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: add a `commonversion` function...
r22345 def commonversion(versions):
"""Return the newest version listed in both versions and our local formats.
Returns None if no common version exists.
"""
versions.sort(reverse=True)
# search for highest version known on both side
for v in versions:
if v in formats:
return v
return None
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295 # arbitrary picked to fit into 8K limit from HTTP server
# you have to take in account:
# - the version header
# - the base85 encoding
_maxpayload = 5300
Pierre-Yves.David@ens-lyon.org
obsolete: exchange obsolete marker over pushkey...
r17075
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: extract encoding of marker for pushkey from the list key function...
r20599 def _pushkeyescape(markers):
"""encode markers into a dict suitable for pushkey exchange
Mads Kiilerich
spelling: fixes from spell checker
r21024 - binary data is base85 encoded
- split in chunks smaller than 5300 bytes"""
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295 keys = {}
parts = []
currentlen = _maxpayload * 2 # ensure we create a new part
Pierre-Yves David
obsolete: extract encoding of marker for pushkey from the list key function...
r20599 for marker in markers:
Pierre-Yves David
obsolete: rename _encodeonemarker to _fm0encodeonemarkers...
r22329 nextdata = _fm0encodeonemarker(marker)
Augie Fackler
formatting: blacken the codebase...
r43346 if len(nextdata) + currentlen > _maxpayload:
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295 currentpart = []
currentlen = 0
parts.append(currentpart)
currentpart.append(nextdata)
Pierre-Yves David
obsolete: properly increment currentlen when building pushkey payload...
r17304 currentlen += len(nextdata)
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295 for idx, part in enumerate(reversed(parts)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 data = b''.join([_pack(b'>B', _fm0version)] + part)
keys[b'dump%i' % idx] = util.b85encode(data)
Pierre-Yves David
pushkey: splits obsolete marker exchange into multiple keys...
r17295 return keys
Pierre-Yves.David@ens-lyon.org
obsolete: add easy way to iterate over obsolete marker object
r17073
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: extract encoding of marker for pushkey from the list key function...
r20599 def listmarkers(repo):
"""List markers over pushkey"""
if not repo.obsstore:
return {}
Pierre-Yves David
obsolete: sort obsmarkers during exchange...
r25118 return _pushkeyescape(sorted(repo.obsstore))
Pierre-Yves David
obsolete: extract encoding of marker for pushkey from the list key function...
r20599
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves.David@ens-lyon.org
obsolete: exchange obsolete marker over pushkey...
r17075 def pushmarker(repo, key, old, new):
"""Push markers over pushkey"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not key.startswith(b'dump'):
repo.ui.warn(_(b'unknown key: %r') % key)
Martin von Zweigbergk
pushkey: use False/True for return values from push functions...
r32822 return False
Pierre-Yves.David@ens-lyon.org
obsolete: exchange obsolete marker over pushkey...
r17075 if old:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.ui.warn(_(b'unexpected old value for %r') % key)
Martin von Zweigbergk
pushkey: use False/True for return values from push functions...
r32822 return False
Yuya Nishihara
base85: proxy through util module...
r32200 data = util.b85decode(new)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.lock(), repo.transaction(b'pushkey: obsolete markers') as tr:
Martin von Zweigbergk
obsolete: use context manager for transaction in pushmarker()...
r35592 repo.obsstore.mergemarkers(tr, data)
repo.invalidatevolatilesets()
return True
Pierre-Yves.David@ens-lyon.org
obsolete: add easy way to iterate over obsolete marker object
r17073
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: add the detection of bumped changeset....
r17828 # mapping of 'set-name' -> <function to compute this set>
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 cachefuncs = {}
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 def cachefor(name):
"""Decorator to register a function as computing the cache for a set"""
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 def decorator(func):
Pierre-Yves David
obsolete: use ProgrammingError over assert for volatile set registration...
r32884 if name in cachefuncs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b"duplicated registration for volatileset '%s' (existing: %r)"
Pierre-Yves David
obsolete: use ProgrammingError over assert for volatile set registration...
r32884 raise error.ProgrammingError(msg % (name, cachefuncs[name]))
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 cachefuncs[name] = func
return func
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 return decorator
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: rename `getobscache` into `getrevs`...
r17825 def getrevs(repo, name):
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 """Return the set of revision that belong to the <name> set
Such access may compute the set and cache it for future use"""
Pierre-Yves David
clfilter: unfilter computation of obsolescence related computation...
r18001 repo = repo.unfiltered()
Augie Fackler
tracing: add a couple of trace points on obsolete and repoview...
r43534 with util.timedcm('getrevs %s', name):
if not repo.obsstore:
return frozenset()
if name not in repo.obsstore.caches:
repo.obsstore.caches[name] = cachefuncs[name](repo)
return repo.obsstore.caches[name]
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 # To be simple we need to invalidate obsolescence cache when:
#
# - new changeset is added:
# - public phase is changed
# - obsolescence marker are added
# - strip is used a repo
def clearobscaches(repo):
"""Remove all obsolescence related cache from a repo
This remove all cache in obsstore is the obsstore already exist on the
repo.
(We could be smarter here given the exact event that trigger the cache
clearing)"""
# only clear cache is there is obsstore data in this repo
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'obsstore' in repo._filecache:
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 repo.obsstore.caches.clear()
Augie Fackler
formatting: blacken the codebase...
r43346
obsolete: provide a small function to retrieve all mutable revisions...
r33124 def _mutablerevs(repo):
"""the set of mutable revision in the repository"""
unstable: do not consider internal phases when computing unstable...
r52017 return repo._phasecache.getrevset(repo, phases.relevant_mutable_phases)
obsolete: provide a small function to retrieve all mutable revisions...
r33124
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'obsolete')
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 def _computeobsoleteset(repo):
"""the set of obsolete revisions"""
Laurent Charignon
obsolete: make _computeobsoleteset much faster...
r27784 getnode = repo.changelog.node
obsolete: provide a small function to retrieve all mutable revisions...
r33124 notpublic = _mutablerevs(repo)
Jun Wu
obsstore: minor optimization for the obsolete revset...
r32688 isobs = repo.obsstore.successors.__contains__
av6
obsolete: always return frozensets from obsolete.getrevs()...
r49574 return frozenset(r for r in notpublic if isobs(getnode(r)))
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'orphan')
Boris Feld
obsolete: rename unstable volatile set into orphan volatile set...
r33772 def _computeorphanset(repo):
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 """the set of non obsolete revisions with obsolete parents"""
obsolete: skip 'changectx' usage in unstable computation...
r33125 pfunc = repo.changelog.parentrevs
mutable = _mutablerevs(repo)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 obsolete = getrevs(repo, b'obsolete')
obsolete: skip 'changectx' usage in unstable computation...
r33125 others = mutable - obsolete
Laurent Charignon
obsolete: speed up unstable computation...
r24928 unstable = set()
obsolete: skip 'changectx' usage in unstable computation...
r33125 for r in sorted(others):
Laurent Charignon
obsolete: speed up unstable computation...
r24928 # A rev is unstable if one of its parent is obsolete or unstable
# this works since we traverse following growing rev order
obsolete: skip 'changectx' usage in unstable computation...
r33125 for p in pfunc(r):
if p in obsolete or p in unstable:
unstable.add(r)
break
av6
obsolete: always return frozensets from obsolete.getrevs()...
r49574 return frozenset(unstable)
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'suspended')
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 def _computesuspendedset(repo):
"""the set of obsolete parents with non obsolete descendants"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 suspended = repo.changelog.ancestors(getrevs(repo, b'orphan'))
av6
obsolete: always return frozensets from obsolete.getrevs()...
r49574 return frozenset(r for r in getrevs(repo, b'obsolete') if r in suspended)
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'extinct')
Pierre-Yves David
obsolete: introduce caches for all meaningful sets...
r17469 def _computeextinctset(repo):
"""the set of obsolete parents without non obsolete descendants"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return getrevs(repo, b'obsolete') - getrevs(repo, b'suspended')
Pierre-Yves David
obsolete: add a high level function to create an obsolete marker...
r17474
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'phasedivergent')
Boris Feld
obsolete: rename bumped volatile set into phasedivergent volatile set...
r33774 def _computephasedivergentset(repo):
Pierre-Yves David
obsolete: add the detection of bumped changeset....
r17828 """the set of revs trying to obsolete public revisions"""
Pierre-Yves David
obsolete: order of magnitude speedup in _computebumpedset...
r20207 bumped = set()
Mads Kiilerich
spelling: fixes from spell checker
r21024 # util function (avoid attribute lookup in the loop)
Augie Fackler
formatting: blacken the codebase...
r43346 phase = repo._phasecache.phase # would be faster to grab the full list
Pierre-Yves David
obsolete: order of magnitude speedup in _computebumpedset...
r20207 public = phases.public
cl = repo.changelog
index: use `index.get_rev` in `obsolete._computephasedivergentset`...
r43958 torev = cl.index.get_rev
Boris Feld
obsolete: drop usage of changectx in '_computephasedivergentset'...
r35134 tonode = cl.node
Boris Feld
obsolete: prefetch the repo.obsstore used in phasedivergence loop...
r40498 obsstore = repo.obsstore
unstable: use the `_mutablerevs` function when computing phase divergent...
r52015 candidates = sorted(_mutablerevs(repo) - getrevs(repo, b"obsolete"))
for rev in candidates:
Pierre-Yves David
obsolete: order of magnitude speedup in _computebumpedset...
r20207 # We only evaluate mutable, non-obsolete revision
Boris Feld
obsolete: drop usage of changectx in '_computephasedivergentset'...
r35134 node = tonode(rev)
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # (future) A cache of predecessors may worth if split is very common
Augie Fackler
formatting: blacken the codebase...
r43346 for pnode in obsutil.allpredecessors(
obsstore, [node], ignoreflags=bumpedfix
):
prev = torev(pnode) # unfiltered! but so is phasecache
Laurent Charignon
obsolete: speed up computation of bumped revset...
r24927 if (prev is not None) and (phase(repo, prev) <= public):
Boris Feld
obsolete: rename precursor into predecessor in obsolete docstrings...
r33700 # we have a public predecessor
Laurent Charignon
obsolete: speed up computation of bumped revset...
r24927 bumped.add(rev)
Augie Fackler
formatting: blacken the codebase...
r43346 break # Next draft!
av6
obsolete: always return frozensets from obsolete.getrevs()...
r49574 return frozenset(bumped)
Pierre-Yves David
obsolete: add the detection of bumped changeset....
r17828
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @cachefor(b'contentdivergent')
Boris Feld
obsolete: rename divergent volatile set into contentdivergent volatile set...
r33773 def _computecontentdivergentset(repo):
Augie Fackler
formating: upgrade to black 20.8b1...
r46554 """the set of rev that compete to be the final successors of some revision."""
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 divergent = set()
obsstore = repo.obsstore
newermap = {}
Boris Feld
obsolete: drop usage of changectx in '_computecontentdivergentset'...
r35135 tonode = repo.changelog.node
unstable: use the `_mutablerevs` function when computing content divergent...
r52016 candidates = sorted(_mutablerevs(repo) - getrevs(repo, b"obsolete"))
for rev in candidates:
Boris Feld
obsolete: drop usage of changectx in '_computecontentdivergentset'...
r35135 node = tonode(rev)
mark = obsstore.predecessors.get(node, ())
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 toprocess = set(mark)
Pierre-Yves David
obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)...
r24393 seen = set()
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 while toprocess:
prec = toprocess.pop()[0]
Pierre-Yves David
obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)...
r24393 if prec in seen:
Augie Fackler
formatting: blacken the codebase...
r43346 continue # emergency cycle hanging prevention
Pierre-Yves David
obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)...
r24393 seen.add(prec)
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 if prec not in newermap:
Boris Feld
obsolete: pass cache argument of successors set explicitly...
r33273 obsutil.successorssets(repo, prec, cache=newermap)
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 newer = [n for n in newermap[prec] if n]
evolution: stop wrongly flagging unrelated part of a split as divergent...
r53029 # Strickly speaking, the len(newer) is not needed, but it speeds
# things up.
if len(newer) > 1 and any(n for n in newer if node not in n):
Boris Feld
obsolete: drop usage of changectx in '_computecontentdivergentset'...
r35135 divergent.add(rev)
Pierre-Yves David
obsolete: detect divergent changesets...
r18070 break
Boris Feld
obsstore: rename precursors into predecessors...
r33699 toprocess.update(obsstore.predecessors.get(prec, ()))
av6
obsolete: always return frozensets from obsolete.getrevs()...
r49574 return frozenset(divergent)
Pierre-Yves David
obsolete: detect divergent changesets...
r18070
Augie Fackler
formatting: blacken the codebase...
r43346
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 def makefoldid(relation, user):
Augie Fackler
core: migrate uses of hashlib.sha1 to hashutil.sha1...
r44517 folddigest = hashutil.sha1(user)
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 for p in relation[0] + relation[1]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 folddigest.update(b'%d' % p.rev())
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 folddigest.update(p.node())
# Since fold only has to compete against fold for the same successors, it
# seems fine to use a small ID. Smaller ID save space.
Joerg Sonnenberger
node: import symbols explicitly...
r46729 return hex(folddigest.digest())[:8]
Pierre-Yves David
obsolete: detect divergent changesets...
r18070
Augie Fackler
formatting: blacken the codebase...
r43346
def createmarkers(
repo, relations, flag=0, date=None, metadata=None, operation=None
):
Pierre-Yves David
obsolete: add a high level function to create an obsolete marker...
r17474 """Add obsolete markers between changesets in a repo
Boris Feld
obsolete: allow multiple predecessors in createmarkers...
r39958 <relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
Mads Kiilerich
spelling: fixes from spell checker
r21024 tuple. `old` and `news` are changectx. metadata is an optional dictionary
Pierre-Yves David
createmarkers: allow to pass metadata for a marker only...
r20517 containing metadata for this marker only. It is merged with the global
Yuya Nishihara
obsolete: store user name and note in UTF-8 (issue5754) (BC)...
r38729 metadata specified through the `metadata` argument of this function.
Any string values in metadata must be UTF-8 bytes.
Pierre-Yves David
obsolete: add a high level function to create an obsolete marker...
r17474
Trying to obsolete a public changeset will raise an exception.
Current user and date are used except if specified otherwise in the
metadata attribute.
This function operates within a transaction of its own, but does
not take any lock on the repo.
"""
# prepare metadata
if metadata is None:
metadata = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'user' not in metadata:
luser = (
repo.ui.config(b'devel', b'user.obsmarker') or repo.ui.username()
)
metadata[b'user'] = encoding.fromlocal(luser)
Boris Feld
obsolete: clean createmarkers part about operation...
r34389
# Operation metadata handling
Augie Fackler
formatting: blacken the codebase...
r43346 useoperation = repo.ui.configbool(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'experimental', b'evolution.track-operation'
Augie Fackler
formatting: blacken the codebase...
r43346 )
obsmarker: add an experimental flag controlling "operation" recording...
r32354 if useoperation and operation:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 metadata[b'operation'] = operation
Boris Feld
obsolete: clean createmarkers part about operation...
r34389
Boris Feld
effectflag: store an empty effect flag for the moment...
r34414 # Effect flag metadata handling
Augie Fackler
formatting: blacken the codebase...
r43346 saveeffectflag = repo.ui.configbool(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'experimental', b'evolution.effect-flags'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Boris Feld
effectflag: store an empty effect flag for the moment...
r34414
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with repo.transaction(b'add-obsolescence-marker') as tr:
Durham Goode
obsolete: fix n^2 marker computation behavior...
r27984 markerargs = []
Pierre-Yves David
createmarkers: allow to pass metadata for a marker only...
r20517 for rel in relations:
Boris Feld
obsolete: allow multiple predecessors in createmarkers...
r39958 predecessors = rel[0]
if not isinstance(predecessors, tuple):
# preserve compat with old API until all caller are migrated
predecessors = (predecessors,)
Martin von Zweigbergk
cleanup: some Yoda conditions, this patch removes...
r40065 if len(predecessors) > 1 and len(rel[1]) != 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b'Fold markers can only have 1 successors, not %d'
Boris Feld
obsolete: allow multiple predecessors in createmarkers...
r39958 raise error.ProgrammingError(msg % len(rel[1]))
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 foldid = None
foldsize = len(predecessors)
if 1 < foldsize:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 foldid = makefoldid(rel, metadata[b'user'])
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 for foldidx, prec in enumerate(predecessors, 1):
Boris Feld
obsolete: preindent code in createmarkers...
r39957 sucs = rel[1]
localmetadata = metadata.copy()
Martin von Zweigbergk
cleanup: some Yoda conditions, this patch removes...
r40065 if len(rel) > 2:
Boris Feld
obsolete: preindent code in createmarkers...
r39957 localmetadata.update(rel[2])
Boris Feld
obsolete: explicitly track folds inside the markers...
r40078 if foldid is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 localmetadata[b'fold-id'] = foldid
localmetadata[b'fold-idx'] = b'%d' % foldidx
localmetadata[b'fold-size'] = b'%d' % foldsize
Pierre-Yves David
createmarkers: allow to pass metadata for a marker only...
r20517
Boris Feld
obsolete: preindent code in createmarkers...
r39957 if not prec.mutable():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"cannot obsolete public changeset: %s") % prec,
hint=b"see 'hg help phases' for details",
Augie Fackler
formatting: blacken the codebase...
r43346 )
Boris Feld
obsolete: preindent code in createmarkers...
r39957 nprec = prec.node()
nsucs = tuple(s.node() for s in sucs)
npare = None
if not nsucs:
npare = tuple(p.node() for p in prec.parents())
if nprec in nsucs:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"changeset %s cannot obsolete itself") % prec
Augie Fackler
formatting: blacken the codebase...
r43346 )
Durham Goode
obsolete: fix n^2 marker computation behavior...
r27984
Boris Feld
obsolete: preindent code in createmarkers...
r39957 # Effect flag can be different by relation
if saveeffectflag:
# The effect flag is saved in a versioned field name for
# future evolution
effectflag = obsutil.geteffectflag(prec, sucs)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 localmetadata[obsutil.EFFECTFLAGFIELD] = b"%d" % effectflag
Boris Feld
effectflag: store an empty effect flag for the moment...
r34414
Boris Feld
obsolete: preindent code in createmarkers...
r39957 # Creating the marker causes the hidden cache to become
# invalid, which causes recomputation when we ask for
# prec.parents() above. Resulting in n^2 behavior. So let's
# prepare all of the args first, then create the markers.
markerargs.append((nprec, nsucs, npare, localmetadata))
Durham Goode
obsolete: fix n^2 marker computation behavior...
r27984
for args in markerargs:
nprec, nsucs, npare, localmetadata = args
Augie Fackler
formatting: blacken the codebase...
r43346 repo.obsstore.create(
tr,
nprec,
nsucs,
flag,
parents=npare,
date=date,
metadata=localmetadata,
ui=repo.ui,
)
Pierre-Yves David
clfilter: add a cache on repo for set of revision to filter for a given set....
r18101 repo.filteredrevcache.clear()