mercurial/obsolete.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Wed, 16 Oct 2019 17:49:30 +0200
changeset 43254 181d28ba05da
parent 43240 4353942be294
child 43506 9f70512ae2cf
permissions -rw-r--r--
copies: avoid instancing more changectx to access parent revisions We just need to know the revision numbers of the parents, creating full context is needlessly expensive. This provide a small, but noticeable performance boost. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 2.885636 comb 2.900000 user 2.870000 sys 0.030000 (median of 10) after: ! wall 2.702270 comb 2.710000 user 2.690000 sys 0.020000 (median of 10) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 4.298271 comb 4.290000 user 4.240000 sys 0.050000 (median of 10) after: ! wall 3.976610 comb 3.970000 user 3.920000 sys 0.050000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.773397 comb 0.770000 user 0.770000 sys 0.000000 (median of 11) after: ! wall 0.701634 comb 0.700000 user 0.700000 sys 0.000000 (median of 13) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013585 comb 0.010000 user 0.010000 sys 0.000000 (median of 217) after: ! wall 0.013550 comb 0.010000 user 0.010000 sys 0.000000 (median of 218) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.003202 comb 0.000000 user 0.000000 sys 0.000000 (median of 929) after: ! wall 0.002993 comb 0.010000 user 0.010000 sys 0.000000 (median of 992) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000077 comb 0.000000 user 0.000000 sys 0.000000 (median of 12060) after: ! wall 0.000072 comb 0.000000 user 0.000000 sys 0.000000 (median of 12804) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.510614 comb 0.500000 user 0.500000 sys 0.000000 (median of 18) after: ! wall 0.473681 comb 0.470000 user 0.470000 sys 0.000000 (median of 20) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.126552 comb 0.130000 user 0.130000 sys 0.000000 (median of 77) after: ! wall 0.115240 comb 0.110000 user 0.110000 sys 0.000000 (median of 85) Differential Revision: https://phab.mercurial-scm.org/D7122
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     1
# obsolete.py - obsolete markers handling
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     2
#
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     3
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     4
#                Logilab SA        <contact@logilab.fr>
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     5
#
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     8
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
     9
"""Obsolete marker handling
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    10
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    11
An obsolete marker maps an old changeset to a list of new
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    12
changesets. If the list of new changesets is empty, the old changeset
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    13
is said to be "killed". Otherwise, the old changeset is being
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    14
"replaced" by the new changesets.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    15
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    16
Obsolete markers can be used to record and distribute changeset graph
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    17
transformations performed by history rewrite operations, and help
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    18
building new tools to reconcile conflicting rewrite actions. To
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    19
facilitate conflict resolution, markers include various annotations
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    20
besides old and news changeset identifiers, such as creation date or
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    21
author name.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    22
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
    23
The old obsoleted changeset is called a "predecessor" and possible
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    24
replacements are called "successors". Markers that used changeset X as
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
    25
a predecessor are called "successor markers of X" because they hold
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    26
information about the successors of X. Markers that use changeset Y as
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
    27
a successors are call "predecessor markers of Y" because they hold
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
    28
information about the predecessors of Y.
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
    29
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    30
Examples:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    31
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    32
- When changeset A is replaced by changeset A', one marker is stored:
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    33
21166
bf2891877378 obsolete: fix one-element tuple in module docstring
Martin Geisler <martin@geisler.net>
parents: 21165
diff changeset
    34
    (A, (A',))
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    35
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    36
- When changesets A and B are folded into a new changeset C, two markers are
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    37
  stored:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    38
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    39
    (A, (C,)) and (B, (C,))
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    40
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    41
- When changeset A is simply "pruned" from the graph, a marker is created:
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    42
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    43
    (A, ())
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    44
29894
02c150850e16 obsolete: fix minor module documentation issues
liscju <piotr.listkiewicz@gmail.com>
parents: 29389
diff changeset
    45
- When changeset A is split into B and C, a single marker is used:
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    46
29894
02c150850e16 obsolete: fix minor module documentation issues
liscju <piotr.listkiewicz@gmail.com>
parents: 29389
diff changeset
    47
    (A, (B, C))
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    48
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    49
  We use a single marker to distinguish the "split" case from the "divergence"
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    50
  case. If two independent operations rewrite the same changeset A in to A' and
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    51
  A'', we have an error case: divergent rewriting. We can detect it because
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    52
  two markers will be created independently:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    53
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
    54
  (A, (B,)) and (A, (C,))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    55
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    56
Format
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    57
------
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    58
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    59
Markers are stored in an append-only file stored in
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    60
'.hg/store/obsstore'.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    61
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    62
The file starts with a version header:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    63
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    64
- 1 unsigned byte: version number, starting at zero.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    65
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
    66
The header is followed by the markers. Marker format depend of the version. See
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
    67
comment associated with each format for details.
21164
2efcef493aa2 obsolete: fix language and grammar in module docstring
Martin Geisler <martin@geisler.net>
parents: 21098
diff changeset
    68
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    69
"""
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    70
from __future__ import absolute_import
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    71
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    72
import errno
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
    73
import hashlib
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    74
import struct
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    75
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    76
from .i18n import _
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
    77
from .pycompat import getattr
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    78
from . import (
38707
6b5ca1d0aa1e obsolete: store user name and note in UTF-8 (issue5754) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38157
diff changeset
    79
    encoding,
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    80
    error,
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    81
    node,
33142
4f49810a1011 obsutil: move 'successorssets' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33130
diff changeset
    82
    obsutil,
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    83
    phases,
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32354
diff changeset
    84
    policy,
38708
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
    85
    pycompat,
27332
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    86
    util,
04f346b8768f obsolete: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26684
diff changeset
    87
)
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36423
diff changeset
    88
from .utils import dateutil
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    89
32372
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32354
diff changeset
    90
parsers = policy.importmod(r'parsers')
df448de7cf3b parsers: switch to policy importer
Yuya Nishihara <yuya@tcha.org>
parents: 32354
diff changeset
    91
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    92
_pack = struct.pack
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    93
_unpack = struct.unpack
23498
ac910b1f5658 obsstore: prefetch struct.calcsize
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23497
diff changeset
    94
_calcsize = struct.calcsize
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
    95
propertycache = util.propertycache
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    96
22951
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22950
diff changeset
    97
# Options for obsolescence
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    98
createmarkersopt = b'createmarkers'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    99
allowunstableopt = b'allowunstable'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   100
exchangeopt = b'exchange'
22951
6c86c673dde6 obsolete: add createmarkers option
Durham Goode <durham@fb.com>
parents: 22950
diff changeset
   101
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   102
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   103
def _getoptionvalue(repo, option):
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   104
    """Returns True if the given repository has the given obsolete option
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   105
    enabled.
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   106
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   107
    configkey = b'evolution.%s' % option
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   108
    newconfig = repo.ui.configbool(b'experimental', configkey)
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   109
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   110
    # Return the value only if defined
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   111
    if newconfig is not None:
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   112
        return newconfig
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   113
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   114
    # Fallback on generic option
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   115
    try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   116
        return repo.ui.configbool(b'experimental', b'evolution')
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   117
    except (error.ConfigError, AttributeError):
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   118
        # Fallback on old-fashion config
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   119
        # inconsistent config: experimental.evolution
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   120
        result = set(repo.ui.configlist(b'experimental', b'evolution'))
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   121
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   122
        if b'all' in result:
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   123
            return True
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   124
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   125
        # Temporary hack for next check
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   126
        newconfig = repo.ui.config(b'experimental', b'evolution.createmarkers')
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   127
        if newconfig:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   128
            result.add(b'createmarkers')
34864
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   129
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   130
        return option in result
fec79a3f250f config: update evolution-related config
Boris Feld <boris.feld@octobus.net>
parents: 34863
diff changeset
   131
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   132
37131
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   133
def getoptions(repo):
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   134
    """Returns dicts showing state of obsolescence features."""
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   135
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   136
    createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   137
    unstablevalue = _getoptionvalue(repo, allowunstableopt)
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   138
    exchangevalue = _getoptionvalue(repo, exchangeopt)
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   139
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   140
    # createmarkers must be enabled if other options are enabled
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   141
    if (unstablevalue or exchangevalue) and not createmarkersvalue:
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   142
        raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   143
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   144
                b"'createmarkers' obsolete option must be enabled "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   145
                b"if other obsolete options are enabled"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   146
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   147
        )
37131
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   148
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   149
    return {
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   150
        createmarkersopt: createmarkersvalue,
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   151
        allowunstableopt: unstablevalue,
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   152
        exchangeopt: exchangevalue,
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   153
    }
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   154
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   155
32333
566cfe9cbbb9 obsolete: move the 'isenabled' function at the top of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32327
diff changeset
   156
def isenabled(repo, option):
566cfe9cbbb9 obsolete: move the 'isenabled' function at the top of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32327
diff changeset
   157
    """Returns True if the given repository has the given obsolete option
566cfe9cbbb9 obsolete: move the 'isenabled' function at the top of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32327
diff changeset
   158
    enabled.
566cfe9cbbb9 obsolete: move the 'isenabled' function at the top of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32327
diff changeset
   159
    """
37131
d30810d09d6f obsolete: refactor function for getting obsolete options
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37017
diff changeset
   160
    return getoptions(repo)[option]
32333
566cfe9cbbb9 obsolete: move the 'isenabled' function at the top of the file
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32327
diff changeset
   161
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   162
37017
98c14e857e71 obsolete: add a note that explains creating aliases for marker flags
Anton Shestakov <av6@dwimlabs.net>
parents: 36953
diff changeset
   163
# Creating aliases for marker flags because evolve extension looks for
98c14e857e71 obsolete: add a note that explains creating aliases for marker flags
Anton Shestakov <av6@dwimlabs.net>
parents: 36953
diff changeset
   164
# bumpedfix in obsolete.py
36953
b9bbcf9ffac1 obsolete: move marker flags to obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 36607
diff changeset
   165
bumpedfix = obsutil.bumpedfix
b9bbcf9ffac1 obsolete: move marker flags to obsutil
Anton Shestakov <av6@dwimlabs.net>
parents: 36607
diff changeset
   166
usingsha256 = obsutil.usingsha256
17831
70b08df24fef obsolete: add a flag that allows fixing "bumped" changeset
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17828
diff changeset
   167
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   168
## Parsing and writing of version "0"
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   169
#
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   170
# The header is followed by the markers. Each marker is made of:
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   171
#
22849
fd759142c6e5 obsolete: use uint## in the format documention
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22848
diff changeset
   172
# - 1 uint8 : number of new changesets "N", can be zero.
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   173
#
22849
fd759142c6e5 obsolete: use uint## in the format documention
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22848
diff changeset
   174
# - 1 uint32: metadata size "M" in bytes.
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   175
#
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   176
# - 1 byte: a bit field. It is reserved for flags used in common
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   177
#   obsolete marker operations, to avoid repeated decoding of metadata
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   178
#   entries.
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   179
#
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   180
# - 20 bytes: obsoleted changeset identifier.
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   181
#
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   182
# - N*20 bytes: new changesets identifiers.
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   183
#
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   184
# - M bytes: metadata as a sequence of nul-terminated strings. Each
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   185
#   string contains a key and a value, separated by a colon ':', without
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   186
#   additional encoding. Keys cannot contain '\0' or ':' and values
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   187
#   cannot contain '\0'.
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   188
_fm0version = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   189
_fm0fixed = b'>BIB20s'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   190
_fm0node = b'20s'
23498
ac910b1f5658 obsstore: prefetch struct.calcsize
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23497
diff changeset
   191
_fm0fsize = _calcsize(_fm0fixed)
ac910b1f5658 obsstore: prefetch struct.calcsize
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23497
diff changeset
   192
_fm0fnodesize = _calcsize(_fm0node)
22334
f2c3cfc30e9c obsolete: move _encodemarkers next to _readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22333
diff changeset
   193
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   194
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   195
def _fm0readmarkers(data, off, stop):
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   196
    # Loop on markers
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   197
    while off < stop:
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   198
        # read fixed part
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   199
        cur = data[off : off + _fm0fsize]
22327
f737631a9f0a obsolete: rename all _fm to _fm0
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22326
diff changeset
   200
        off += _fm0fsize
22685
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   201
        numsuc, mdsize, flags, pre = _unpack(_fm0fixed, cur)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   202
        # read replacement
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   203
        sucs = ()
22685
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   204
        if numsuc:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   205
            s = _fm0fnodesize * numsuc
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   206
            cur = data[off : off + s]
22685
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   207
            sucs = _unpack(_fm0node * numsuc, cur)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   208
            off += s
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   209
        # read metadata
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   210
        # (metadata will be decoded on demand)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   211
        metadata = data[off : off + mdsize]
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   212
        if len(metadata) != mdsize:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   213
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   214
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
                    b'parsing obsolete marker: metadata is too '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
                    b'short, %d bytes expected, got %d'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   217
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   218
                % (mdsize, len(metadata))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   219
            )
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   220
        off += mdsize
22847
37460ee2003c obsolete: _rename decodemeta to _fm0decodemeta
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22846
diff changeset
   221
        metadata = _fm0decodemeta(metadata)
22222
883e8b6bd461 obsmarker: add `date` as an explicit field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22221
diff changeset
   222
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   223
            when, offset = metadata.pop(b'date', b'0 0').split(b' ')
22309
a65697c3f20e obsolete: avoid slow, generic date parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22274
diff changeset
   224
            date = float(when), int(offset)
a65697c3f20e obsolete: avoid slow, generic date parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents: 22274
diff changeset
   225
        except ValueError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   226
            date = (0.0, 0)
22258
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   227
        parents = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   228
        if b'p2' in metadata:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   229
            parents = (metadata.pop(b'p1', None), metadata.pop(b'p2', None))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   230
        elif b'p1' in metadata:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   231
            parents = (metadata.pop(b'p1', None),)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   232
        elif b'p0' in metadata:
22258
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   233
            parents = ()
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   234
        if parents is not None:
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   235
            try:
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   236
                parents = tuple(node.bin(p) for p in parents)
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   237
                # if parent content is not a nodeid, drop the data
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   238
                for p in parents:
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   239
                    if len(p) != 20:
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   240
                        parents = None
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   241
                        break
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   242
            except TypeError:
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   243
                # if content cannot be translated to nodeid drop the data.
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   244
                parents = None
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   245
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   246
        metadata = tuple(sorted(pycompat.iteritems(metadata)))
22222
883e8b6bd461 obsmarker: add `date` as an explicit field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22221
diff changeset
   247
22258
cf414981978a obsstore: also store the 'parents' field on disk
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22257
diff changeset
   248
        yield (pre, sucs, flags, metadata, date, parents)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   249
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   250
22330
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   251
def _fm0encodeonemarker(marker):
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   252
    pre, sucs, flags, metadata, date, parents = marker
22850
b078e4dc9f9a obsstore: add a flag for sha256 hashes
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22849
diff changeset
   253
    if flags & usingsha256:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   254
        raise error.Abort(_(b'cannot handle sha256 with old obsstore format'))
22845
ef880e28e56a obsolete: store metadata as a tuple of (key, value) pairs (API)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22685
diff changeset
   255
    metadata = dict(metadata)
23002
2920a96f5839 obsstore: record data as floating point in fm0 format
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22954
diff changeset
   256
    time, tz = date
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   257
    metadata[b'date'] = b'%r %i' % (time, tz)
22330
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   258
    if parents is not None:
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   259
        if not parents:
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   260
            # mark that we explicitly recorded no parents
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   261
            metadata[b'p0'] = b''
32278
7c3ef55dedbe obsolete: use 2 argument form of enumerate()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32201
diff changeset
   262
        for i, p in enumerate(parents, 1):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   263
            metadata[b'p%i' % i] = node.hex(p)
22846
b1efc4893da4 obsolete: _rename encodemeta to _fm0encodemeta
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22845
diff changeset
   264
    metadata = _fm0encodemeta(metadata)
22685
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   265
    numsuc = len(sucs)
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   266
    format = _fm0fixed + (_fm0node * numsuc)
753515d9e274 obsolete: replace "nb" notation with "num" (for "number")
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22614
diff changeset
   267
    data = [numsuc, len(metadata), flags, pre]
22330
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   268
    data.extend(sucs)
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   269
    return _pack(format, *data) + metadata
e74f8a65252d obsolete: move _fm0encodeonemarker next to _fm0readmarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22329
diff changeset
   270
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   271
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   272
def _fm0encodemeta(meta):
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   273
    """Return encoded metadata string to string mapping.
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   274
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   275
    Assume no ':' in key and no '\0' in both key and value."""
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   276
    for key, value in pycompat.iteritems(meta):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   277
        if b':' in key or b'\0' in key:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   278
            raise ValueError(b"':' and '\0' are forbidden in metadata key'")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   279
        if b'\0' in value:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   280
            raise ValueError(b"':' is forbidden in metadata value'")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   281
    return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)])
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   282
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   283
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   284
def _fm0decodemeta(data):
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   285
    """Return string to string dictionary from encoded version."""
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   286
    d = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   287
    for l in data.split(b'\0'):
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   288
        if l:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   289
            key, value = l.split(b':', 1)
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   290
            d[key] = value
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   291
    return d
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   292
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   293
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   294
## Parsing and writing of version "1"
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   295
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   296
# The header is followed by the markers. Each marker is made of:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   297
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   298
# - uint32: total size of the marker (including this field)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   299
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   300
# - float64: date in seconds since epoch
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   301
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   302
# - int16: timezone offset in minutes
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   303
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   304
# - uint16: a bit field. It is reserved for flags used in common
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   305
#   obsolete marker operations, to avoid repeated decoding of metadata
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   306
#   entries.
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   307
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   308
# - uint8: number of successors "N", can be zero.
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   309
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   310
# - uint8: number of parents "P", can be zero.
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   311
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   312
#     0: parents data stored but no parent,
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   313
#     1: one parent stored,
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   314
#     2: two parents stored,
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   315
#     3: no parent data stored
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   316
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   317
# - uint8: number of metadata entries M
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   318
#
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   319
# - 20 or 32 bytes: predecessor changeset identifier.
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   320
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   321
# - N*(20 or 32) bytes: successors changesets identifiers.
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   322
#
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   323
# - P*(20 or 32) bytes: parents of the predecessors changesets.
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   324
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   325
# - M*(uint8, uint8): size of all metadata entries (key and value)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   326
#
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   327
# - remaining bytes: the metadata, each (key, value) pair after the other.
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   328
_fm1version = 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   329
_fm1fixed = b'>IdhHBBB20s'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   330
_fm1nodesha1 = b'20s'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   331
_fm1nodesha256 = b'32s'
23499
b46876c94a93 obsstore: cache size computation for fm1 node
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23498
diff changeset
   332
_fm1nodesha1size = _calcsize(_fm1nodesha1)
b46876c94a93 obsstore: cache size computation for fm1 node
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23498
diff changeset
   333
_fm1nodesha256size = _calcsize(_fm1nodesha256)
23498
ac910b1f5658 obsstore: prefetch struct.calcsize
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23497
diff changeset
   334
_fm1fsize = _calcsize(_fm1fixed)
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   335
_fm1parentnone = 3
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   336
_fm1parentshift = 14
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   337
_fm1parentmask = _fm1parentnone << _fm1parentshift
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   338
_fm1metapair = b'BB'
33670
e5f8c7baa729 obsolete: reuse _fm1metapair for computing _fm1metapairsize
Augie Fackler <augie@google.com>
parents: 33504
diff changeset
   339
_fm1metapairsize = _calcsize(_fm1metapair)
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   340
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   341
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   342
def _fm1purereadmarkers(data, off, stop):
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   343
    # make some global constants local for performance
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   344
    noneflag = _fm1parentnone
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   345
    sha2flag = usingsha256
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   346
    sha1size = _fm1nodesha1size
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   347
    sha2size = _fm1nodesha256size
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   348
    sha1fmt = _fm1nodesha1
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   349
    sha2fmt = _fm1nodesha256
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   350
    metasize = _fm1metapairsize
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   351
    metafmt = _fm1metapair
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   352
    fsize = _fm1fsize
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   353
    unpack = _unpack
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   354
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   355
    # Loop on markers
25211
22f4ce49044d util: drop the 'unpacker' helper
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25149
diff changeset
   356
    ufixed = struct.Struct(_fm1fixed).unpack
24018
26d6a6a78c1d obsolete: use parsers.fm1readmarker if it exists for a ~38% perf win
Augie Fackler <augie@google.com>
parents: 24014
diff changeset
   357
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   358
    while off < stop:
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   359
        # read fixed part
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   360
        o1 = off + fsize
23800
83f361a21d31 readmarkers: drop a temporary
Matt Mackall <mpm@selenic.com>
parents: 23799
diff changeset
   361
        t, secs, tz, flags, numsuc, numpar, nummeta, prec = ufixed(data[off:o1])
23792
db3bc2bcb689 readmarkers: add some whitespace
Matt Mackall <mpm@selenic.com>
parents: 23791
diff changeset
   362
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   363
        if flags & sha2flag:
23805
345042e024dc readmarkers: add a SHA256 fixme note
Matt Mackall <mpm@selenic.com>
parents: 23804
diff changeset
   364
            # FIXME: prec was read as a SHA1, needs to be amended
345042e024dc readmarkers: add a SHA256 fixme note
Matt Mackall <mpm@selenic.com>
parents: 23804
diff changeset
   365
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   366
            # read 0 or more successors
23804
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   367
            if numsuc == 1:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   368
                o2 = o1 + sha2size
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   369
                sucs = (data[o1:o2],)
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   370
            else:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   371
                o2 = o1 + sha2size * numsuc
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   372
                sucs = unpack(sha2fmt * numsuc, data[o1:o2])
23792
db3bc2bcb689 readmarkers: add some whitespace
Matt Mackall <mpm@selenic.com>
parents: 23791
diff changeset
   373
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   374
            # read parents
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   375
            if numpar == noneflag:
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   376
                o3 = o2
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   377
                parents = None
23804
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   378
            elif numpar == 1:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   379
                o3 = o2 + sha2size
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   380
                parents = (data[o2:o3],)
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   381
            else:
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   382
                o3 = o2 + sha2size * numpar
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   383
                parents = unpack(sha2fmt * numpar, data[o2:o3])
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   384
        else:
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   385
            # read 0 or more successors
23804
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   386
            if numsuc == 1:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   387
                o2 = o1 + sha1size
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   388
                sucs = (data[o1:o2],)
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   389
            else:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   390
                o2 = o1 + sha1size * numsuc
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   391
                sucs = unpack(sha1fmt * numsuc, data[o1:o2])
23792
db3bc2bcb689 readmarkers: add some whitespace
Matt Mackall <mpm@selenic.com>
parents: 23791
diff changeset
   392
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   393
            # read parents
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   394
            if numpar == noneflag:
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   395
                o3 = o2
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   396
                parents = None
23804
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   397
            elif numpar == 1:
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   398
                o3 = o2 + sha1size
e880036719e3 readmarkers: fast-path single successors and parents
Matt Mackall <mpm@selenic.com>
parents: 23803
diff changeset
   399
                parents = (data[o2:o3],)
23801
20b5701cd90a readmarkers: read node reading into node length conditional
Matt Mackall <mpm@selenic.com>
parents: 23800
diff changeset
   400
            else:
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   401
                o3 = o2 + sha1size * numpar
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   402
                parents = unpack(sha1fmt * numpar, data[o2:o3])
23792
db3bc2bcb689 readmarkers: add some whitespace
Matt Mackall <mpm@selenic.com>
parents: 23791
diff changeset
   403
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   404
        # read metadata
23803
2763edaba857 readmarkers: promote global constants to locals for performance
Matt Mackall <mpm@selenic.com>
parents: 23802
diff changeset
   405
        off = o3 + metasize * nummeta
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   406
        metapairsize = unpack(b'>' + (metafmt * nummeta), data[o3:off])
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   407
        metadata = []
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38708
diff changeset
   408
        for idx in pycompat.xrange(0, len(metapairsize), 2):
23798
86d2a0c41f44 readmarkers: streamline offset tracking
Matt Mackall <mpm@selenic.com>
parents: 23797
diff changeset
   409
            o1 = off + metapairsize[idx]
86d2a0c41f44 readmarkers: streamline offset tracking
Matt Mackall <mpm@selenic.com>
parents: 23797
diff changeset
   410
            o2 = o1 + metapairsize[idx + 1]
86d2a0c41f44 readmarkers: streamline offset tracking
Matt Mackall <mpm@selenic.com>
parents: 23797
diff changeset
   411
            metadata.append((data[off:o1], data[o1:o2]))
86d2a0c41f44 readmarkers: streamline offset tracking
Matt Mackall <mpm@selenic.com>
parents: 23797
diff changeset
   412
            off = o2
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   413
23800
83f361a21d31 readmarkers: drop a temporary
Matt Mackall <mpm@selenic.com>
parents: 23799
diff changeset
   414
        yield (prec, sucs, flags, tuple(metadata), (secs, tz * 60), parents)
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   415
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   416
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   417
def _fm1encodeonemarker(marker):
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   418
    pre, sucs, flags, metadata, date, parents = marker
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   419
    # determine node size
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   420
    _fm1node = _fm1nodesha1
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   421
    if flags & usingsha256:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   422
        _fm1node = _fm1nodesha256
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   423
    numsuc = len(sucs)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   424
    numextranodes = numsuc
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   425
    if parents is None:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   426
        numpar = _fm1parentnone
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   427
    else:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   428
        numpar = len(parents)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   429
        numextranodes += numpar
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   430
    formatnodes = _fm1node * numextranodes
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   431
    formatmeta = _fm1metapair * len(metadata)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   432
    format = _fm1fixed + formatnodes + formatmeta
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   433
    # tz is stored in minutes so we divide by 60
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   434
    tz = date[1] // 60
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   435
    data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   436
    data.extend(sucs)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   437
    if parents is not None:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   438
        data.extend(parents)
23498
ac910b1f5658 obsstore: prefetch struct.calcsize
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23497
diff changeset
   439
    totalsize = _calcsize(format)
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   440
    for key, value in metadata:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   441
        lk = len(key)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   442
        lv = len(value)
34407
b6692ba7d5b0 obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)
Simon Whitaker <swhitaker@fb.com>
parents: 34388
diff changeset
   443
        if lk > 255:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   444
            msg = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   445
                b'obsstore metadata key cannot be longer than 255 bytes'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   446
                b' (key "%s" is %u bytes)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   447
            ) % (key, lk)
34407
b6692ba7d5b0 obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)
Simon Whitaker <swhitaker@fb.com>
parents: 34388
diff changeset
   448
            raise error.ProgrammingError(msg)
b6692ba7d5b0 obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)
Simon Whitaker <swhitaker@fb.com>
parents: 34388
diff changeset
   449
        if lv > 255:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   450
            msg = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   451
                b'obsstore metadata value cannot be longer than 255 bytes'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   452
                b' (value "%s" for key "%s" is %u bytes)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   453
            ) % (value, key, lv)
34407
b6692ba7d5b0 obsmarker: crash more helpfully when metadata fields are >255bytes (issue5681)
Simon Whitaker <swhitaker@fb.com>
parents: 34388
diff changeset
   454
            raise error.ProgrammingError(msg)
22851
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   455
        data.append(lk)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   456
        data.append(lv)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   457
        totalsize += lk + lv
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   458
    data[0] = totalsize
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   459
    data = [_pack(format, *data)]
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   460
    for key, value in metadata:
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   461
        data.append(key)
974389427e5f obsolete: introduce a new binary encoding for obsmarkers (version 1)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22850
diff changeset
   462
        data.append(value)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   463
    return b''.join(data)
22848
72100c1d53d4 obsolete: gather _fm0 meta encoding with other _fm0 code
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22847
diff changeset
   464
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   465
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   466
def _fm1readmarkers(data, off, stop):
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24018
diff changeset
   467
    native = getattr(parsers, 'fm1readmarkers', None)
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24018
diff changeset
   468
    if not native:
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   469
        return _fm1purereadmarkers(data, off, stop)
24019
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24018
diff changeset
   470
    return native(data, off, stop)
26fbf07482b2 _fm1readmarkers: generate list in C
Martin von Zweigbergk <martinvonz@google.com>
parents: 24018
diff changeset
   471
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   472
22331
b130b241718e obsolete: support for any known obsstore format when reading or writing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22330
diff changeset
   473
# mapping to read/write various marker formats
b130b241718e obsolete: support for any known obsstore format when reading or writing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22330
diff changeset
   474
# <version> -> (decoder, encoder)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   475
formats = {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   476
    _fm0version: (_fm0readmarkers, _fm0encodeonemarker),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   477
    _fm1version: (_fm1readmarkers, _fm1encodeonemarker),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   478
}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   479
22331
b130b241718e obsolete: support for any known obsstore format when reading or writing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22330
diff changeset
   480
32689
9933410bf763 obsstore: move marker version reading to a separate function
Jun Wu <quark@fb.com>
parents: 32688
diff changeset
   481
def _readmarkerversion(data):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   482
    return _unpack(b'>B', data[0:1])[0]
32689
9933410bf763 obsstore: move marker version reading to a separate function
Jun Wu <quark@fb.com>
parents: 32688
diff changeset
   483
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   484
23497
5817f71c2336 obsstore: disable garbage collection during initialization (issue4456)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23002
diff changeset
   485
@util.nogc
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   486
def _readmarkers(data, off=None, stop=None):
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   487
    """Read and enumerate markers from raw data"""
32689
9933410bf763 obsstore: move marker version reading to a separate function
Jun Wu <quark@fb.com>
parents: 32688
diff changeset
   488
    diskversion = _readmarkerversion(data)
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   489
    if not off:
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   490
        off = 1  # skip 1 byte version number
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   491
    if stop is None:
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   492
        stop = len(data)
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   493
    if diskversion not in formats:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   494
        msg = _(b'parsing obsolete marker: unknown version %r') % diskversion
32596
19df975eb555 obsolete: raise richer exception on unknown version
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32488
diff changeset
   495
        raise error.UnknownVersion(msg, version=diskversion)
33504
5d3ba4395288 obsstore: let read marker API take a range of offsets
Jun Wu <quark@fb.com>
parents: 33499
diff changeset
   496
    return diskversion, formats[diskversion][0](data, off, stop)
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   497
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   498
32692
9576974a3b6d obsstore: move header encoding to a separate function
Jun Wu <quark@fb.com>
parents: 32691
diff changeset
   499
def encodeheader(version=_fm0version):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   500
    return _pack(b'>B', version)
32692
9576974a3b6d obsstore: move header encoding to a separate function
Jun Wu <quark@fb.com>
parents: 32691
diff changeset
   501
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   502
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   503
def encodemarkers(markers, addheader=False, version=_fm0version):
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   504
    # Kept separate from flushmarkers(), it will be reused for
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   505
    # markers exchange.
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   506
    encodeone = formats[version][1]
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   507
    if addheader:
32692
9576974a3b6d obsstore: move header encoding to a separate function
Jun Wu <quark@fb.com>
parents: 32691
diff changeset
   508
        yield encodeheader(version)
22612
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   509
    for marker in markers:
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   510
        yield encodeone(marker)
fdfa40ee75cf obsolete: gather all contents related to format version 0 in a single place
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22507
diff changeset
   511
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   512
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   513
@util.nogc
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   514
def _addsuccessors(successors, markers):
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   515
    for mark in markers:
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   516
        successors.setdefault(mark[0], set()).add(mark)
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   517
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   518
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   519
@util.nogc
33732
32d4f815c4f4 obsolete: rename _addprecursors into _addpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33719
diff changeset
   520
def _addpredecessors(predecessors, markers):
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   521
    for mark in markers:
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   522
        for suc in mark[1]:
33732
32d4f815c4f4 obsolete: rename _addprecursors into _addpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33719
diff changeset
   523
            predecessors.setdefault(suc, set()).add(mark)
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   524
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   525
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   526
@util.nogc
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   527
def _addchildren(children, markers):
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   528
    for mark in markers:
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   529
        parents = mark[5]
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   530
        if parents is not None:
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   531
            for p in parents:
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   532
                children.setdefault(p, set()).add(mark)
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   533
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   534
24045
43061f96e40e obsolete: pass only new markers to _checkinvalidmarkers()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24044
diff changeset
   535
def _checkinvalidmarkers(markers):
23973
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   536
    """search for marker with invalid data and raise error if needed
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   537
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   538
    Exist as a separated function to allow the evolve extension for a more
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   539
    subtle handling.
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   540
    """
24045
43061f96e40e obsolete: pass only new markers to _checkinvalidmarkers()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24044
diff changeset
   541
    for mark in markers:
43061f96e40e obsolete: pass only new markers to _checkinvalidmarkers()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24044
diff changeset
   542
        if node.nullid in mark[1]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   543
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   544
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   545
                    b'bad obsolescence marker detected: '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   546
                    b'invalid successors nullid'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   547
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   548
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   549
23973
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   550
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   551
class obsstore(object):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   552
    """Store obsolete markers
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   553
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   554
    Markers can be accessed with two mappings:
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   555
    - predecessors[x] -> set(markers on predecessors edges of x)
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
   556
    - successors[x] -> set(markers on successors edges of x)
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   557
    - children[x]   -> set(markers on predecessors edges of children(x)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   558
    """
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   559
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   560
    fields = (b'prec', b'succs', b'flag', b'meta', b'date', b'parents')
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   561
    # prec:    nodeid, predecessors changesets
22254
b8a0e8176693 obsstore: add a `parents` field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22253
diff changeset
   562
    # succs:   tuple of nodeid, successor changesets (0-N length)
b8a0e8176693 obsstore: add a `parents` field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22253
diff changeset
   563
    # flag:    integer, flag field carrying modifier for the markers (see doc)
38707
6b5ca1d0aa1e obsolete: store user name and note in UTF-8 (issue5754) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38157
diff changeset
   564
    # meta:    binary blob in UTF-8, encoded metadata dictionary
22254
b8a0e8176693 obsstore: add a `parents` field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22253
diff changeset
   565
    # date:    (float, int) tuple, date of marker creation
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   566
    # parents: (tuple of nodeid) or None, parents of predecessors
22254
b8a0e8176693 obsstore: add a `parents` field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22253
diff changeset
   567
    #          None is used when no data has been recorded
22221
e75b1a3c1dbc obsstore: add fields attribute to track each field in a marker
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22219
diff changeset
   568
25669
8d94861842e5 obsolete: replace references to 'sopener' with 'svfs'
Siddharth Agarwal <sid0@fb.com>
parents: 25412
diff changeset
   569
    def __init__(self, svfs, defaultformat=_fm1version, readonly=False):
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   570
        # caches for various obsolescence related cache
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   571
        self.caches = {}
25669
8d94861842e5 obsolete: replace references to 'sopener' with 'svfs'
Siddharth Agarwal <sid0@fb.com>
parents: 25412
diff changeset
   572
        self.svfs = svfs
32691
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   573
        self._defaultformat = defaultformat
22950
bb8278b289ee obsolete: add readonly flag to obstore constructor
Durham Goode <durham@fb.com>
parents: 22949
diff changeset
   574
        self._readonly = readonly
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   575
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   576
    def __iter__(self):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   577
        return iter(self._all)
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   578
20585
f3c8db3d6d66 obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20584
diff changeset
   579
    def __len__(self):
f3c8db3d6d66 obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20584
diff changeset
   580
        return len(self._all)
f3c8db3d6d66 obsstore: add a __len__ method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20584
diff changeset
   581
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   582
    def __nonzero__(self):
35837
d8f891ec5d7d obsolete: use native string when peeking in __dict__
Augie Fackler <augie@google.com>
parents: 35574
diff changeset
   583
        if not self._cached(r'_all'):
26310
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   584
            try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   585
                return self.svfs.stat(b'obsstore').st_size > 1
26310
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   586
            except OSError as inst:
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   587
                if inst.errno != errno.ENOENT:
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   588
                    raise
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   589
                # just build an empty _all list if no obsstore exists, which
61efe9ef6ad4 obsstore: fast path to check if obsstore is empty
Yuya Nishihara <yuya@tcha.org>
parents: 26309
diff changeset
   590
                # avoids further stat() syscalls
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   591
        return bool(self._all)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   592
31476
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31018
diff changeset
   593
    __bool__ = __nonzero__
413b44003462 py3: add __bool__ to every class defining __nonzero__
Gregory Szorc <gregory.szorc@gmail.com>
parents: 31018
diff changeset
   594
26684
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   595
    @property
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   596
    def readonly(self):
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   597
        """True if marker creation is disabled
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   598
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   599
        Remove me in the future when obsolete marker is always on."""
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   600
        return self._readonly
74ff350c208c obsstore: make the readonly attribute accessible
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
   601
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   602
    def create(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   603
        self,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   604
        transaction,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   605
        prec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   606
        succs=(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   607
        flag=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   608
        parents=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   609
        date=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   610
        metadata=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   611
        ui=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   612
    ):
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   613
        """obsolete: add a new obsolete marker
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   614
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   615
        * ensuring it is hashable
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   616
        * check mandatory metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   617
        * encode metadata
20516
3af218cf2007 obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   618
3af218cf2007 obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   619
        If you are a human writing code creating marker you want to use the
3af218cf2007 obsstore: update create docstring to point to the coder friendly function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20476
diff changeset
   620
        `createmarkers` function in this module instead.
20584
224a058f7cd1 obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20549
diff changeset
   621
224a058f7cd1 obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20549
diff changeset
   622
        return True if a new marker have been added, False if the markers
224a058f7cd1 obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20549
diff changeset
   623
        already existed (no op).
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   624
        """
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   625
        if metadata is None:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   626
            metadata = {}
22222
883e8b6bd461 obsmarker: add `date` as an explicit field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22221
diff changeset
   627
        if date is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   628
            if b'date' in metadata:
22222
883e8b6bd461 obsmarker: add `date` as an explicit field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22221
diff changeset
   629
                # as a courtesy for out-of-tree extensions
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   630
                date = dateutil.parsedate(metadata.pop(b'date'))
32411
08d02c1d7e67 devel: use default-date config field when creating obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 32387
diff changeset
   631
            elif ui is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   632
                date = ui.configdate(b'devel', b'default-date')
32411
08d02c1d7e67 devel: use default-date config field when creating obsmarkers
Boris Feld <boris.feld@octobus.net>
parents: 32387
diff changeset
   633
                if date is None:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36423
diff changeset
   634
                    date = dateutil.makedate()
22222
883e8b6bd461 obsmarker: add `date` as an explicit field
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22221
diff changeset
   635
            else:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36423
diff changeset
   636
                date = dateutil.makedate()
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   637
        if len(prec) != 20:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   638
            raise ValueError(prec)
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   639
        for succ in succs:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   640
            if len(succ) != 20:
17117
217bfb10e6db obsolete: fix error message at marker creation
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17076
diff changeset
   641
                raise ValueError(succ)
22177
a56038e6a3c9 obsstore.create: add a simple safeguard against cyclic markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21166
diff changeset
   642
        if prec in succs:
40164
fee616937ef3 obsolete: convert error string to a sysstr
Augie Fackler <augie@google.com>
parents: 40081
diff changeset
   643
            raise ValueError(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   644
                r'in-marker cycle with %s' % pycompat.sysstr(node.hex(prec))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   645
            )
22845
ef880e28e56a obsolete: store metadata as a tuple of (key, value) pairs (API)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22685
diff changeset
   646
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43089
diff changeset
   647
        metadata = tuple(sorted(pycompat.iteritems(metadata)))
38708
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   648
        for k, v in metadata:
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   649
            try:
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   650
                # might be better to reject non-ASCII keys
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   651
                k.decode('utf-8')
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   652
                v.decode('utf-8')
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   653
            except UnicodeDecodeError:
ff1182d166a2 obsolete: explode if metadata contains invalid UTF-8 sequence (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
   654
                raise error.ProgrammingError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   655
                    b'obsstore metadata must be valid UTF-8 sequence '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   656
                    b'(key = %r, value = %r)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   657
                    % (pycompat.bytestr(k), pycompat.bytestr(v))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   658
                )
22845
ef880e28e56a obsolete: store metadata as a tuple of (key, value) pairs (API)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22685
diff changeset
   659
33719
388901a15bfa obsolete: use bytes() instead of str() so the node is bytes on py3
Augie Fackler <augie@google.com>
parents: 33670
diff changeset
   660
        marker = (bytes(prec), tuple(succs), int(flag), metadata, date, parents)
20584
224a058f7cd1 obsstore: `create` method return True if a marker is actually added
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20549
diff changeset
   661
        return bool(self.add(transaction, [marker]))
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   662
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   663
    def add(self, transaction, markers):
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   664
        """Add new markers to the store
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   665
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   666
        Take care of filtering duplicate.
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   667
        Return the number of new marker."""
22950
bb8278b289ee obsolete: add readonly flag to obstore constructor
Durham Goode <durham@fb.com>
parents: 22949
diff changeset
   668
        if self._readonly:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   669
            raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   670
                _(b'creating obsolete markers is not enabled on this repo')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   671
            )
32774
5ffb138d7b1a obsstore: do not load all markers to detect duplication
Jun Wu <quark@fb.com>
parents: 32729
diff changeset
   672
        known = set()
5ffb138d7b1a obsstore: do not load all markers to detect duplication
Jun Wu <quark@fb.com>
parents: 32729
diff changeset
   673
        getsuccessors = self.successors.get
20030
5931489b65e0 obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20028
diff changeset
   674
        new = []
5931489b65e0 obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20028
diff changeset
   675
        for m in markers:
32774
5ffb138d7b1a obsstore: do not load all markers to detect duplication
Jun Wu <quark@fb.com>
parents: 32729
diff changeset
   676
            if m not in getsuccessors(m[0], ()) and m not in known:
20030
5931489b65e0 obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20028
diff changeset
   677
                known.add(m)
5931489b65e0 obsolete: do not accept duplicated marker during exchange
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20028
diff changeset
   678
                new.append(m)
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   679
        if new:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   680
            f = self.svfs(b'obsstore', b'ab')
17124
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   681
            try:
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   682
                offset = f.tell()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   683
                transaction.add(b'obsstore', offset)
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   684
                # offset == 0: new file - add the version header
33479
8b48dad66be4 obsstore: keep self._data updated with _addmarkers
Jun Wu <quark@fb.com>
parents: 33273
diff changeset
   685
                data = b''.join(encodemarkers(new, offset == 0, self._version))
8b48dad66be4 obsstore: keep self._data updated with _addmarkers
Jun Wu <quark@fb.com>
parents: 33273
diff changeset
   686
                f.write(data)
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   687
            finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   688
                # XXX: f.close() == filecache invalidation == obsstore rebuilt.
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   689
                # call 'filecacheentry.refresh()'  here
17124
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   690
                f.close()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   691
            addedmarkers = transaction.changes.get(b'obsmarkers')
33251
a5cb2e4460de transaction: track new obsmarkers in the 'changes' mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33244
diff changeset
   692
            if addedmarkers is not None:
a5cb2e4460de transaction: track new obsmarkers in the 'changes' mapping
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33244
diff changeset
   693
                addedmarkers.update(new)
33479
8b48dad66be4 obsstore: keep self._data updated with _addmarkers
Jun Wu <quark@fb.com>
parents: 33273
diff changeset
   694
            self._addmarkers(new, data)
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   695
            # new marker *may* have changed several set. invalidate the cache.
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   696
            self.caches.clear()
22339
9680da73cfe0 obsmarker: record the number of new markers in the transaction
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22335
diff changeset
   697
        # records the number of new markers for the transaction hooks
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   698
        previous = int(transaction.hookargs.get(b'new_obsmarkers', b'0'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   699
        transaction.hookargs[b'new_obsmarkers'] = b'%d' % (previous + len(new))
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   700
        return len(new)
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   701
17524
a736e1e15e46 spelling: transaction
timeless@mozdev.org
parents: 17516
diff changeset
   702
    def mergemarkers(self, transaction, data):
22325
3363f2d36015 obsstore: have the `mergemarkers` method return the number of new markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22309
diff changeset
   703
        """merge a binary stream of markers inside the obsstore
3363f2d36015 obsstore: have the `mergemarkers` method return the number of new markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22309
diff changeset
   704
3363f2d36015 obsstore: have the `mergemarkers` method return the number of new markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22309
diff changeset
   705
        Returns the number of new markers added."""
22332
13e22358e9d2 obsolete: have _readmarkers return the format version
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22331
diff changeset
   706
        version, markers = _readmarkers(data)
22325
3363f2d36015 obsstore: have the `mergemarkers` method return the number of new markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22309
diff changeset
   707
        return self.add(transaction, markers)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   708
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   709
    @propertycache
32690
3fad59faba8a obsstore: separate marker parsing from obsstore reading
Jun Wu <quark@fb.com>
parents: 32689
diff changeset
   710
    def _data(self):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   711
        return self.svfs.tryread(b'obsstore')
32690
3fad59faba8a obsstore: separate marker parsing from obsstore reading
Jun Wu <quark@fb.com>
parents: 32689
diff changeset
   712
3fad59faba8a obsstore: separate marker parsing from obsstore reading
Jun Wu <quark@fb.com>
parents: 32689
diff changeset
   713
    @propertycache
32691
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   714
    def _version(self):
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   715
        if len(self._data) >= 1:
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   716
            return _readmarkerversion(self._data)
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   717
        else:
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   718
            return self._defaultformat
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   719
5d8dd6c90af9 obsstore: move _version to a propertycache
Jun Wu <quark@fb.com>
parents: 32690
diff changeset
   720
    @propertycache
26309
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   721
    def _all(self):
32690
3fad59faba8a obsstore: separate marker parsing from obsstore reading
Jun Wu <quark@fb.com>
parents: 32689
diff changeset
   722
        data = self._data
26309
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   723
        if not data:
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   724
            return []
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   725
        self._version, markers = _readmarkers(data)
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   726
        markers = list(markers)
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   727
        _checkinvalidmarkers(markers)
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   728
        return markers
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   729
44918682093f obsstore: delay loading markers from obsstore file
Yuya Nishihara <yuya@tcha.org>
parents: 26308
diff changeset
   730
    @propertycache
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   731
    def successors(self):
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   732
        successors = {}
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   733
        _addsuccessors(successors, self._all)
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   734
        return successors
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   735
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   736
    @propertycache
33733
d5acd967f95a obsstore: rename precursors into predecessors
Boris Feld <boris.feld@octobus.net>
parents: 33732
diff changeset
   737
    def predecessors(self):
33732
32d4f815c4f4 obsolete: rename _addprecursors into _addpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33719
diff changeset
   738
        predecessors = {}
32d4f815c4f4 obsolete: rename _addprecursors into _addpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33719
diff changeset
   739
        _addpredecessors(predecessors, self._all)
32d4f815c4f4 obsolete: rename _addprecursors into _addpredecessors
Boris Feld <boris.feld@octobus.net>
parents: 33719
diff changeset
   740
        return predecessors
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   741
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   742
    @propertycache
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   743
    def children(self):
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   744
        children = {}
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   745
        _addchildren(children, self._all)
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   746
        return children
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   747
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   748
    def _cached(self, attr):
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   749
        return attr in self.__dict__
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   750
33479
8b48dad66be4 obsstore: keep self._data updated with _addmarkers
Jun Wu <quark@fb.com>
parents: 33273
diff changeset
   751
    def _addmarkers(self, markers, rawdata):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   752
        markers = list(markers)  # to allow repeated iteration
33479
8b48dad66be4 obsstore: keep self._data updated with _addmarkers
Jun Wu <quark@fb.com>
parents: 33273
diff changeset
   753
        self._data = self._data + rawdata
24044
e0e6dd806b23 obsolete: extract helpers from _load()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24019
diff changeset
   754
        self._all.extend(markers)
35837
d8f891ec5d7d obsolete: use native string when peeking in __dict__
Augie Fackler <augie@google.com>
parents: 35574
diff changeset
   755
        if self._cached(r'successors'):
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   756
            _addsuccessors(self.successors, markers)
35837
d8f891ec5d7d obsolete: use native string when peeking in __dict__
Augie Fackler <augie@google.com>
parents: 35574
diff changeset
   757
        if self._cached(r'predecessors'):
33733
d5acd967f95a obsstore: rename precursors into predecessors
Boris Feld <boris.feld@octobus.net>
parents: 33732
diff changeset
   758
            _addpredecessors(self.predecessors, markers)
35837
d8f891ec5d7d obsolete: use native string when peeking in __dict__
Augie Fackler <augie@google.com>
parents: 35574
diff changeset
   759
        if self._cached(r'children'):
24046
6e1d9f9932a9 obsolete: populate successors, precursors, children lazily
Martin von Zweigbergk <martinvonz@google.com>
parents: 24045
diff changeset
   760
            _addchildren(self.children, markers)
24045
43061f96e40e obsolete: pass only new markers to _checkinvalidmarkers()
Martin von Zweigbergk <martinvonz@google.com>
parents: 24044
diff changeset
   761
        _checkinvalidmarkers(markers)
23973
18d431147cc1 obsstore: make the invalid markers check wrap-able
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 23805
diff changeset
   762
22271
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   763
    def relevantmarkers(self, nodes):
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   764
        """return a set of all obsolescence markers relevant to a set of nodes.
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   765
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   766
        "relevant" to a set of nodes mean:
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   767
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   768
        - marker that use this changeset as successor
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   769
        - prune marker of direct children on this changeset
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   770
        - recursive application of the two rules on predecessors of these
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   771
          markers
22271
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   772
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   773
        It is a set so you cannot rely on order."""
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   774
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   775
        pendingnodes = set(nodes)
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   776
        seenmarkers = set()
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   777
        seennodes = set(pendingnodes)
33733
d5acd967f95a obsstore: rename precursors into predecessors
Boris Feld <boris.feld@octobus.net>
parents: 33732
diff changeset
   778
        precursorsmarkers = self.predecessors
32488
176d1a0ce385 obsolete: fix relevant-obsmarkers computation on pruned changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32411
diff changeset
   779
        succsmarkers = self.successors
22271
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   780
        children = self.children
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   781
        while pendingnodes:
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   782
            direct = set()
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   783
            for current in pendingnodes:
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   784
                direct.update(precursorsmarkers.get(current, ()))
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   785
                pruned = [m for m in children.get(current, ()) if not m[1]]
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   786
                direct.update(pruned)
32488
176d1a0ce385 obsolete: fix relevant-obsmarkers computation on pruned changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32411
diff changeset
   787
                pruned = [m for m in succsmarkers.get(current, ()) if not m[1]]
176d1a0ce385 obsolete: fix relevant-obsmarkers computation on pruned changeset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32411
diff changeset
   788
                direct.update(pruned)
22271
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   789
            direct -= seenmarkers
42057
566daffc607d cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents: 40462
diff changeset
   790
            pendingnodes = {m[0] for m in direct}
22271
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   791
            seenmarkers |= direct
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   792
            pendingnodes -= seennodes
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   793
            seennodes |= pendingnodes
8c69262df82d obsstore: add relevantmarkers method
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22270
diff changeset
   794
        return seenmarkers
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   795
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   796
32729
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   797
def makestore(ui, repo):
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   798
    """Create an obsstore instance from a repo."""
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   799
    # read default format for new obsstore.
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   800
    # developer config: format.obsstore-version
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   801
    defaultformat = ui.configint(b'format', b'obsstore-version')
32729
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   802
    # rely on obsstore class default when possible.
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   803
    kwargs = {}
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   804
    if defaultformat is not None:
35365
7354fda50e8b py3: handle keyword arguments correctly in obsolete.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35137
diff changeset
   805
        kwargs[r'defaultformat'] = defaultformat
32729
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   806
    readonly = not isenabled(repo, createmarkersopt)
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   807
    store = obsstore(repo.svfs, readonly=readonly, **kwargs)
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   808
    if store and readonly:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   809
        ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   810
            _(b'obsolete feature not enabled but %i markers found!\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   811
            % len(list(store))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   812
        )
32729
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   813
    return store
c8177792fef6 obsolete: move obsstore creation logic from localrepo
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32692
diff changeset
   814
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   815
22345
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   816
def commonversion(versions):
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   817
    """Return the newest version listed in both versions and our local formats.
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   818
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   819
    Returns None if no common version exists.
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   820
    """
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   821
    versions.sort(reverse=True)
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   822
    # search for highest version known on both side
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   823
    for v in versions:
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   824
        if v in formats:
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   825
            return v
cf7014c5f087 obsolete: add a `commonversion` function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22339
diff changeset
   826
    return None
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   827
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   828
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   829
# arbitrary picked to fit into 8K limit from HTTP server
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   830
# you have to take in account:
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   831
# - the version header
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   832
# - the base85 encoding
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   833
_maxpayload = 5300
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   834
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   835
20599
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   836
def _pushkeyescape(markers):
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   837
    """encode markers into a dict suitable for pushkey exchange
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   838
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20599
diff changeset
   839
    - binary data is base85 encoded
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20599
diff changeset
   840
    - split in chunks smaller than 5300 bytes"""
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   841
    keys = {}
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   842
    parts = []
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   843
    currentlen = _maxpayload * 2  # ensure we create a new part
20599
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   844
    for marker in markers:
22329
ed37aa74d208 obsolete: rename _encodeonemarker to _fm0encodeonemarkers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22328
diff changeset
   845
        nextdata = _fm0encodeonemarker(marker)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   846
        if len(nextdata) + currentlen > _maxpayload:
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   847
            currentpart = []
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   848
            currentlen = 0
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   849
            parts.append(currentpart)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   850
        currentpart.append(nextdata)
17304
0368fc55d572 obsolete: properly increment currentlen when building pushkey payload
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17298
diff changeset
   851
        currentlen += len(nextdata)
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   852
    for idx, part in enumerate(reversed(parts)):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   853
        data = b''.join([_pack(b'>B', _fm0version)] + part)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   854
        keys[b'dump%i' % idx] = util.b85encode(data)
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
   855
    return keys
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   856
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   857
20599
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   858
def listmarkers(repo):
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   859
    """List markers over pushkey"""
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   860
    if not repo.obsstore:
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   861
        return {}
25118
e632a2429982 obsolete: sort obsmarkers during exchange
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24928
diff changeset
   862
    return _pushkeyescape(sorted(repo.obsstore))
20599
dad29624b056 obsolete: extract encoding of marker for pushkey from the list key function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20585
diff changeset
   863
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   864
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   865
def pushmarker(repo, key, old, new):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   866
    """Push markers over pushkey"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   867
    if not key.startswith(b'dump'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   868
        repo.ui.warn(_(b'unknown key: %r') % key)
32822
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32774
diff changeset
   869
        return False
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   870
    if old:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   871
        repo.ui.warn(_(b'unexpected old value for %r') % key)
32822
e65ff29dbeb0 pushkey: use False/True for return values from push functions
Martin von Zweigbergk <martinvonz@google.com>
parents: 32774
diff changeset
   872
        return False
32201
4462a981e8df base85: proxy through util module
Yuya Nishihara <yuya@tcha.org>
parents: 31476
diff changeset
   873
    data = util.b85decode(new)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   874
    with repo.lock(), repo.transaction(b'pushkey: obsolete markers') as tr:
35574
09285733ad71 obsolete: use context manager for transaction in pushmarker()
Martin von Zweigbergk <martinvonz@google.com>
parents: 35573
diff changeset
   875
        repo.obsstore.mergemarkers(tr, data)
09285733ad71 obsolete: use context manager for transaction in pushmarker()
Martin von Zweigbergk <martinvonz@google.com>
parents: 35573
diff changeset
   876
        repo.invalidatevolatilesets()
09285733ad71 obsolete: use context manager for transaction in pushmarker()
Martin von Zweigbergk <martinvonz@google.com>
parents: 35573
diff changeset
   877
        return True
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   878
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   879
17828
9495be4126ef obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17827
diff changeset
   880
# mapping of 'set-name' -> <function to compute this set>
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   881
cachefuncs = {}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   882
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   883
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   884
def cachefor(name):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   885
    """Decorator to register a function as computing the cache for a set"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   886
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   887
    def decorator(func):
32884
9d472b219fb0 obsolete: use ProgrammingError over assert for volatile set registration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32822
diff changeset
   888
        if name in cachefuncs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   889
            msg = b"duplicated registration for volatileset '%s' (existing: %r)"
32884
9d472b219fb0 obsolete: use ProgrammingError over assert for volatile set registration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32822
diff changeset
   890
            raise error.ProgrammingError(msg % (name, cachefuncs[name]))
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   891
        cachefuncs[name] = func
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   892
        return func
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   893
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   894
    return decorator
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   895
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   896
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17776
diff changeset
   897
def getrevs(repo, name):
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   898
    """Return the set of revision that belong to the <name> set
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   899
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   900
    Such access may compute the set and cache it for future use"""
18001
e02feadd15ea clfilter: unfilter computation of obsolescence related computation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17831
diff changeset
   901
    repo = repo.unfiltered()
43240
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   902
    with util.timedcm('getrevs %s', name):
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   903
        if not repo.obsstore:
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   904
            return frozenset()
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   905
        if name not in repo.obsstore.caches:
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   906
            repo.obsstore.caches[name] = cachefuncs[name](repo)
4353942be294 tracing: add a couple of trace points on obsolete and repoview
Augie Fackler <augie@google.com>
parents: 43117
diff changeset
   907
        return repo.obsstore.caches[name]
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   908
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   909
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   910
# To be simple we need to invalidate obsolescence cache when:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   911
#
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   912
# - new changeset is added:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   913
# - public phase is changed
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   914
# - obsolescence marker are added
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   915
# - strip is used a repo
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   916
def clearobscaches(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   917
    """Remove all obsolescence related cache from a repo
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   918
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   919
    This remove all cache in obsstore is the obsstore already exist on the
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   920
    repo.
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   921
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   922
    (We could be smarter here given the exact event that trigger the cache
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   923
    clearing)"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   924
    # only clear cache is there is obsstore data in this repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   925
    if b'obsstore' in repo._filecache:
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   926
        repo.obsstore.caches.clear()
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   927
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   928
33129
765c6ab07a88 obsolete: provide a small function to retrieve all mutable revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32884
diff changeset
   929
def _mutablerevs(repo):
765c6ab07a88 obsolete: provide a small function to retrieve all mutable revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32884
diff changeset
   930
    """the set of mutable revision in the repository"""
38157
02f992ac26e9 phases: define an official tuple of mutable phases
Boris Feld <boris.feld@octobus.net>
parents: 37131
diff changeset
   931
    return repo._phasecache.getrevset(repo, phases.mutablephases)
33129
765c6ab07a88 obsolete: provide a small function to retrieve all mutable revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32884
diff changeset
   932
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   933
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   934
@cachefor(b'obsolete')
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   935
def _computeobsoleteset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   936
    """the set of obsolete revisions"""
27784
432242f41d9f obsolete: make _computeobsoleteset much faster
Laurent Charignon <lc2817@columbia.edu>
parents: 27332
diff changeset
   937
    getnode = repo.changelog.node
33129
765c6ab07a88 obsolete: provide a small function to retrieve all mutable revisions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32884
diff changeset
   938
    notpublic = _mutablerevs(repo)
32688
2c1400d43fd2 obsstore: minor optimization for the obsolete revset
Jun Wu <quark@fb.com>
parents: 32627
diff changeset
   939
    isobs = repo.obsstore.successors.__contains__
2c1400d43fd2 obsstore: minor optimization for the obsolete revset
Jun Wu <quark@fb.com>
parents: 32627
diff changeset
   940
    obs = set(r for r in notpublic if isobs(getnode(r)))
18271
67872e939945 performance: speedup computation of obsolete revisions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18101
diff changeset
   941
    return obs
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   942
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   943
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   944
@cachefor(b'orphan')
33777
d4b7496f7d0b obsolete: rename unstable volatile set into orphan volatile set
Boris Feld <boris.feld@octobus.net>
parents: 33772
diff changeset
   945
def _computeorphanset(repo):
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   946
    """the set of non obsolete revisions with obsolete parents"""
33130
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   947
    pfunc = repo.changelog.parentrevs
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   948
    mutable = _mutablerevs(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   949
    obsolete = getrevs(repo, b'obsolete')
33130
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   950
    others = mutable - obsolete
24928
876a2ebfbf4f obsolete: speed up unstable computation
Laurent Charignon <lcharignon@fb.com>
parents: 24927
diff changeset
   951
    unstable = set()
33130
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   952
    for r in sorted(others):
24928
876a2ebfbf4f obsolete: speed up unstable computation
Laurent Charignon <lcharignon@fb.com>
parents: 24927
diff changeset
   953
        # A rev is unstable if one of its parent is obsolete or unstable
876a2ebfbf4f obsolete: speed up unstable computation
Laurent Charignon <lcharignon@fb.com>
parents: 24927
diff changeset
   954
        # this works since we traverse following growing rev order
33130
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   955
        for p in pfunc(r):
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   956
            if p in obsolete or p in unstable:
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   957
                unstable.add(r)
31ab1912678a obsolete: skip 'changectx' usage in unstable computation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33129
diff changeset
   958
                break
24928
876a2ebfbf4f obsolete: speed up unstable computation
Laurent Charignon <lcharignon@fb.com>
parents: 24927
diff changeset
   959
    return unstable
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   960
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   961
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   962
@cachefor(b'suspended')
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   963
def _computesuspendedset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   964
    """the set of obsolete parents with non obsolete descendants"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   965
    suspended = repo.changelog.ancestors(getrevs(repo, b'orphan'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   966
    return set(r for r in getrevs(repo, b'obsolete') if r in suspended)
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   967
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   968
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   969
@cachefor(b'extinct')
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   970
def _computeextinctset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
   971
    """the set of obsolete parents without non obsolete descendants"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   972
    return getrevs(repo, b'obsolete') - getrevs(repo, b'suspended')
17474
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
   973
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   974
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   975
@cachefor(b'phasedivergent')
33779
9fa874fb34e1 obsolete: rename bumped volatile set into phasedivergent volatile set
Boris Feld <boris.feld@octobus.net>
parents: 33778
diff changeset
   976
def _computephasedivergentset(repo):
17828
9495be4126ef obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17827
diff changeset
   977
    """the set of revs trying to obsolete public revisions"""
20207
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   978
    bumped = set()
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20599
diff changeset
   979
    # util function (avoid attribute lookup in the loop)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   980
    phase = repo._phasecache.phase  # would be faster to grab the full list
20207
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   981
    public = phases.public
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   982
    cl = repo.changelog
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   983
    torev = cl.nodemap.get
35136
82680919d75e obsolete: drop usage of changectx in '_computephasedivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 34902
diff changeset
   984
    tonode = cl.node
40462
6e2a24550b7e obsolete: prefetch the repo.obsstore used in phasedivergence loop
Boris Feld <boris.feld@octobus.net>
parents: 40255
diff changeset
   985
    obsstore = repo.obsstore
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   986
    for rev in repo.revs(b'(not public()) and (not obsolete())'):
20207
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   987
        # We only evaluate mutable, non-obsolete revision
35136
82680919d75e obsolete: drop usage of changectx in '_computephasedivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 34902
diff changeset
   988
        node = tonode(rev)
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   989
        # (future) A cache of predecessors may worth if split is very common
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   990
        for pnode in obsutil.allpredecessors(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   991
            obsstore, [node], ignoreflags=bumpedfix
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   992
        ):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   993
            prev = torev(pnode)  # unfiltered! but so is phasecache
24927
cd0068232ec0 obsolete: speed up computation of bumped revset
Laurent Charignon <lcharignon@fb.com>
parents: 24393
diff changeset
   994
            if (prev is not None) and (phase(repo, prev) <= public):
33734
0c3112f17610 obsolete: rename precursor into predecessor in obsolete docstrings
Boris Feld <boris.feld@octobus.net>
parents: 33733
diff changeset
   995
                # we have a public predecessor
24927
cd0068232ec0 obsolete: speed up computation of bumped revset
Laurent Charignon <lcharignon@fb.com>
parents: 24393
diff changeset
   996
                bumped.add(rev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
   997
                break  # Next draft!
20207
cd62532c62a1 obsolete: order of magnitude speedup in _computebumpedset
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20206
diff changeset
   998
    return bumped
17828
9495be4126ef obsolete: add the detection of bumped changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17827
diff changeset
   999
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1000
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1001
@cachefor(b'contentdivergent')
33778
f3f06c260e9e obsolete: rename divergent volatile set into contentdivergent volatile set
Boris Feld <boris.feld@octobus.net>
parents: 33777
diff changeset
  1002
def _computecontentdivergentset(repo):
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1003
    """the set of rev that compete to be the final successors of some revision.
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1004
    """
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1005
    divergent = set()
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1006
    obsstore = repo.obsstore
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1007
    newermap = {}
35137
5cd6682b5a90 obsolete: drop usage of changectx in '_computecontentdivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 35136
diff changeset
  1008
    tonode = repo.changelog.node
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1009
    for rev in repo.revs(b'(not public()) - obsolete()'):
35137
5cd6682b5a90 obsolete: drop usage of changectx in '_computecontentdivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 35136
diff changeset
  1010
        node = tonode(rev)
5cd6682b5a90 obsolete: drop usage of changectx in '_computecontentdivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 35136
diff changeset
  1011
        mark = obsstore.predecessors.get(node, ())
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1012
        toprocess = set(mark)
24393
77eace2a63cb obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24335
diff changeset
  1013
        seen = set()
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1014
        while toprocess:
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1015
            prec = toprocess.pop()[0]
24393
77eace2a63cb obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24335
diff changeset
  1016
            if prec in seen:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1017
                continue  # emergency cycle hanging prevention
24393
77eace2a63cb obsolete: avoid infinite loop from obs-cycle in divergence (issue4126)
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 24335
diff changeset
  1018
            seen.add(prec)
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1019
            if prec not in newermap:
33273
5724aaa99dd6 obsolete: pass cache argument of successors set explicitly
Boris Feld <boris.feld@octobus.net>
parents: 33251
diff changeset
  1020
                obsutil.successorssets(repo, prec, cache=newermap)
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1021
            newer = [n for n in newermap[prec] if n]
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1022
            if len(newer) > 1:
35137
5cd6682b5a90 obsolete: drop usage of changectx in '_computecontentdivergentset'
Boris Feld <boris.feld@octobus.net>
parents: 35136
diff changeset
  1023
                divergent.add(rev)
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1024
                break
33733
d5acd967f95a obsstore: rename precursors into predecessors
Boris Feld <boris.feld@octobus.net>
parents: 33732
diff changeset
  1025
            toprocess.update(obsstore.predecessors.get(prec, ()))
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1026
    return divergent
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1027
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1028
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1029
def makefoldid(relation, user):
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1030
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1031
    folddigest = hashlib.sha1(user)
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1032
    for p in relation[0] + relation[1]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1033
        folddigest.update(b'%d' % p.rev())
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1034
        folddigest.update(p.node())
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1035
    # Since fold only has to compete against fold for the same successors, it
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1036
    # seems fine to use a small ID. Smaller ID save space.
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1037
    return node.hex(folddigest.digest())[:8]
18070
af632936d3d9 obsolete: detect divergent changesets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 18069
diff changeset
  1038
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1039
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1040
def createmarkers(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1041
    repo, relations, flag=0, date=None, metadata=None, operation=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1042
):
17474
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1043
    """Add obsolete markers between changesets in a repo
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1044
39922
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1045
    <relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20599
diff changeset
  1046
    tuple. `old` and `news` are changectx. metadata is an optional dictionary
20517
2158e8f3cbd2 createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20516
diff changeset
  1047
    containing metadata for this marker only. It is merged with the global
38707
6b5ca1d0aa1e obsolete: store user name and note in UTF-8 (issue5754) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38157
diff changeset
  1048
    metadata specified through the `metadata` argument of this function.
6b5ca1d0aa1e obsolete: store user name and note in UTF-8 (issue5754) (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 38157
diff changeset
  1049
    Any string values in metadata must be UTF-8 bytes.
17474
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1050
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1051
    Trying to obsolete a public changeset will raise an exception.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1052
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1053
    Current user and date are used except if specified otherwise in the
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1054
    metadata attribute.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1055
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1056
    This function operates within a transaction of its own, but does
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1057
    not take any lock on the repo.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1058
    """
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1059
    # prepare metadata
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1060
    if metadata is None:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
  1061
        metadata = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1062
    if b'user' not in metadata:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1063
        luser = (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1064
            repo.ui.config(b'devel', b'user.obsmarker') or repo.ui.username()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1065
        )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1066
        metadata[b'user'] = encoding.fromlocal(luser)
34388
ddcef6d0b0ef obsolete: clean createmarkers part about operation
Boris Feld <boris.feld@octobus.net>
parents: 34379
diff changeset
  1067
ddcef6d0b0ef obsolete: clean createmarkers part about operation
Boris Feld <boris.feld@octobus.net>
parents: 34379
diff changeset
  1068
    # Operation metadata handling
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1069
    useoperation = repo.ui.configbool(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1070
        b'experimental', b'evolution.track-operation'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1071
    )
32354
f432897a9f49 obsmarker: add an experimental flag controlling "operation" recording
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32333
diff changeset
  1072
    if useoperation and operation:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1073
        metadata[b'operation'] = operation
34388
ddcef6d0b0ef obsolete: clean createmarkers part about operation
Boris Feld <boris.feld@octobus.net>
parents: 34379
diff changeset
  1074
34413
014d467f9d08 effectflag: store an empty effect flag for the moment
Boris Feld <boris.feld@octobus.net>
parents: 34407
diff changeset
  1075
    # Effect flag metadata handling
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1076
    saveeffectflag = repo.ui.configbool(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1077
        b'experimental', b'evolution.effect-flags'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1078
    )
34413
014d467f9d08 effectflag: store an empty effect flag for the moment
Boris Feld <boris.feld@octobus.net>
parents: 34407
diff changeset
  1079
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1080
    with repo.transaction(b'add-obsolescence-marker') as tr:
27984
e60e13a86529 obsolete: fix n^2 marker computation behavior
Durham Goode <durham@fb.com>
parents: 27784
diff changeset
  1081
        markerargs = []
20517
2158e8f3cbd2 createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20516
diff changeset
  1082
        for rel in relations:
39922
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1083
            predecessors = rel[0]
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1084
            if not isinstance(predecessors, tuple):
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1085
                # preserve compat with old API until all caller are migrated
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1086
                predecessors = (predecessors,)
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39922
diff changeset
  1087
            if len(predecessors) > 1 and len(rel[1]) != 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1088
                msg = b'Fold markers can only have 1 successors, not %d'
39922
6335c0de80fa obsolete: allow multiple predecessors in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39921
diff changeset
  1089
                raise error.ProgrammingError(msg % len(rel[1]))
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1090
            foldid = None
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1091
            foldsize = len(predecessors)
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1092
            if 1 < foldsize:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1093
                foldid = makefoldid(rel, metadata[b'user'])
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1094
            for foldidx, prec in enumerate(predecessors, 1):
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1095
                sucs = rel[1]
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1096
                localmetadata = metadata.copy()
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39922
diff changeset
  1097
                if len(rel) > 2:
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1098
                    localmetadata.update(rel[2])
40042
208303a8172c obsolete: explicitly track folds inside the markers
Boris Feld <boris.feld@octobus.net>
parents: 40029
diff changeset
  1099
                if foldid is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1100
                    localmetadata[b'fold-id'] = foldid
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1101
                    localmetadata[b'fold-idx'] = b'%d' % foldidx
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1102
                    localmetadata[b'fold-size'] = b'%d' % foldsize
20517
2158e8f3cbd2 createmarkers: allow to pass metadata for a marker only
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20516
diff changeset
  1103
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1104
                if not prec.mutable():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1105
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1106
                        _(b"cannot obsolete public changeset: %s") % prec,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1107
                        hint=b"see 'hg help phases' for details",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1108
                    )
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1109
                nprec = prec.node()
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1110
                nsucs = tuple(s.node() for s in sucs)
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1111
                npare = None
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1112
                if not nsucs:
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1113
                    npare = tuple(p.node() for p in prec.parents())
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1114
                if nprec in nsucs:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1115
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1116
                        _(b"changeset %s cannot obsolete itself") % prec
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1117
                    )
27984
e60e13a86529 obsolete: fix n^2 marker computation behavior
Durham Goode <durham@fb.com>
parents: 27784
diff changeset
  1118
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1119
                # Effect flag can be different by relation
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1120
                if saveeffectflag:
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1121
                    # The effect flag is saved in a versioned field name for
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1122
                    # future evolution
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1123
                    effectflag = obsutil.geteffectflag(prec, sucs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1124
                    localmetadata[obsutil.EFFECTFLAGFIELD] = b"%d" % effectflag
34413
014d467f9d08 effectflag: store an empty effect flag for the moment
Boris Feld <boris.feld@octobus.net>
parents: 34407
diff changeset
  1125
39921
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1126
                # Creating the marker causes the hidden cache to become
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1127
                # invalid, which causes recomputation when we ask for
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1128
                # prec.parents() above.  Resulting in n^2 behavior.  So let's
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1129
                # prepare all of the args first, then create the markers.
99f0f052b6bf obsolete: preindent code in createmarkers
Boris Feld <boris.feld@octobus.net>
parents: 39920
diff changeset
  1130
                markerargs.append((nprec, nsucs, npare, localmetadata))
27984
e60e13a86529 obsolete: fix n^2 marker computation behavior
Durham Goode <durham@fb.com>
parents: 27784
diff changeset
  1131
e60e13a86529 obsolete: fix n^2 marker computation behavior
Durham Goode <durham@fb.com>
parents: 27784
diff changeset
  1132
        for args in markerargs:
e60e13a86529 obsolete: fix n^2 marker computation behavior
Durham Goode <durham@fb.com>
parents: 27784
diff changeset
  1133
            nprec, nsucs, npare, localmetadata = args
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1134
            repo.obsstore.create(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1135
                tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1136
                nprec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1137
                nsucs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1138
                flag,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1139
                parents=npare,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1140
                date=date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1141
                metadata=localmetadata,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1142
                ui=repo.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42217
diff changeset
  1143
            )
18101
a464deecc9dd clfilter: add a cache on repo for set of revision to filter for a given set.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 18070
diff changeset
  1144
            repo.filteredrevcache.clear()