mercurial/obsolete.py
author Matt Harbison <matt_harbison@yahoo.com>
Sun, 15 Jul 2012 12:43:10 -0400
changeset 17198 ecde35a1af9e
parent 17195 48c232873a54
child 17200 19f5dec2d61f
permissions -rw-r--r--
outgoing: accept revset argument for --rev There may be a more generic way that would add revset support to more commands by adding revset support to addbranchrevs(), but given the proximity of the next code freeze, a minimal change seems like the better choice.
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
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
     9
"""Obsolete markers handling
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
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    17
transformations performed by history rewriting operations, and help
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    18
building new tools to reconciliate conflicting rewriting actions. To
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    19
facilitate conflicts resolution, markers include various annotations
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
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    23
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    24
Format
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    25
------
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    26
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    27
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
    28
'.hg/store/obsstore'.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    29
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    30
The file starts with a version header:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    31
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    32
- 1 unsigned byte: version number, starting at zero.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    33
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    34
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    35
The header is followed by the markers. Each marker is made of:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    36
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    37
- 1 unsigned byte: number of new changesets "R", could be zero.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    38
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    39
- 1 unsigned 32-bits integer: metadata size "M" in bytes.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    40
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    41
- 1 byte: a bit field. It is reserved for flags used in obsolete
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    42
  markers common operations, to avoid repeated decoding of metadata
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    43
  entries.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    44
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    45
- 20 bytes: obsoleted changeset identifier.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    46
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    47
- N*20 bytes: new changesets identifiers.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    48
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    49
- M bytes: metadata as a sequence of nul-terminated strings. Each
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    50
  string contains a key and a value, separated by a color ':', without
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    51
  additional encoding. Keys cannot contain '\0' or ':' and values
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    52
  cannot contain '\0'.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    53
"""
17195
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
    54
import os, struct
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
    55
from mercurial import util, base85
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    56
from i18n import _
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
_pack = struct.pack
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    59
_unpack = struct.unpack
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    60
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
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    63
# data used for parsing and writing
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    64
_fmversion = 0
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    65
_fmfixed   = '>BIB20s'
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    66
_fmnode = '20s'
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    67
_fmfsize = struct.calcsize(_fmfixed)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    68
_fnodesize = struct.calcsize(_fmnode)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    69
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    70
def _readmarkers(data):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    71
    """Read and enumerate markers from raw data"""
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    72
    off = 0
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    73
    diskversion = _unpack('>B', data[off:off + 1])[0]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    74
    off += 1
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    75
    if diskversion != _fmversion:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    76
        raise util.Abort(_('parsing obsolete marker: unknown version %r')
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    77
                         % diskversion)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    78
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    79
    # Loop on markers
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    80
    l = len(data)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    81
    while off + _fmfsize <= l:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    82
        # read fixed part
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    83
        cur = data[off:off + _fmfsize]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    84
        off += _fmfsize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    85
        nbsuc, mdsize, flags, pre = _unpack(_fmfixed, cur)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    86
        # read replacement
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    87
        sucs = ()
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    88
        if nbsuc:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    89
            s = (_fnodesize * nbsuc)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    90
            cur = data[off:off + s]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    91
            sucs = _unpack(_fmnode * nbsuc, cur)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    92
            off += s
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    93
        # read metadata
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    94
        # (metadata will be decoded on demand)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    95
        metadata = data[off:off + mdsize]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    96
        if len(metadata) != mdsize:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    97
            raise util.Abort(_('parsing obsolete marker: metadata is too '
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    98
                               'short, %d bytes expected, got %d')
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
    99
                             % (len(metadata), mdsize))
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   100
        off += mdsize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   101
        yield (pre, sucs, flags, metadata)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   102
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   103
def encodemeta(meta):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   104
    """Return encoded metadata string to string mapping.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   105
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   106
    Assume no ':' in key and no '\0' in both key and value."""
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   107
    for key, value in meta.iteritems():
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   108
        if ':' in key or '\0' in key:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   109
            raise ValueError("':' and '\0' are forbidden in metadata key'")
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   110
        if '\0' in value:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   111
            raise ValueError("':' are forbidden in metadata value'")
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   112
    return '\0'.join(['%s:%s' % (k, meta[k]) for k in sorted(meta)])
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   113
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   114
def decodemeta(data):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   115
    """Return string to string dictionary from encoded version."""
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   116
    d = {}
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   117
    for l in data.split('\0'):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   118
        if l:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   119
            key, value = l.split(':')
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   120
            d[key] = value
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   121
    return d
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   122
17072
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   123
class marker(object):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   124
    """Wrap obsolete marker raw data"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   125
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   126
    def __init__(self, repo, data):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   127
        # the repo argument will be used to create changectx in later version
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   128
        self._repo = repo
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   129
        self._data = data
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   130
        self._decodedmeta = None
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   131
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   132
    def precnode(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   133
        """Precursor changeset node identifier"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   134
        return self._data[0]
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   135
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   136
    def succnodes(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   137
        """List of successor changesets node identifiers"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   138
        return self._data[1]
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   139
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   140
    def metadata(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   141
        """Decoded metadata dictionary"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   142
        if self._decodedmeta is None:
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   143
            self._decodedmeta = decodemeta(self._data[3])
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   144
        return self._decodedmeta
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   145
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   146
    def date(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   147
        """Creation date as (unixtime, offset)"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   148
        parts = self.metadata()['date'].split(' ')
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   149
        return (float(parts[0]), int(parts[1]))
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
   150
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   151
class obsstore(object):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   152
    """Store obsolete markers
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   153
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   154
    Markers can be accessed with two mappings:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   155
    - precursors: old -> set(new)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   156
    - successors: new -> set(old)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   157
    """
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   158
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
   159
    def __init__(self, sopener):
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   160
        self._all = []
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   161
        # new markers to serialize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   162
        self.precursors = {}
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   163
        self.successors = {}
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
   164
        self.sopener = sopener
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   165
        data = sopener.tryread('obsstore')
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   166
        if data:
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   167
            for marker in _readmarkers(data):
f1b7683f3f95 obsolete: move obsolete markers read/write logic to obsstore object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17117
diff changeset
   168
                self._load(marker)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   169
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   170
    def __iter__(self):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   171
        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
   172
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   173
    def __nonzero__(self):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   174
        return bool(self._all)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   175
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   176
    def create(self, transaction, prec, succs=(), flag=0, metadata=None):
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   177
        """obsolete: add a new obsolete marker
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   178
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   179
        * ensuring it is hashable
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   180
        * check mandatory metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   181
        * encode metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   182
        """
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   183
        if metadata is None:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   184
            metadata = {}
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   185
        if len(prec) != 20:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   186
            raise ValueError(prec)
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   187
        for succ in succs:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   188
            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
   189
                raise ValueError(succ)
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   190
        marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata))
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   191
        self.add(transaction, marker)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   192
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   193
    def add(self, transaction, marker):
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   194
        """Add a new marker to the store"""
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   195
        if marker not in self._all:
17125
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   196
            f = self.sopener('obsstore', '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
   197
            try:
17195
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   198
                # Whether the file's current position is at the begin or at
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   199
                # the end after opening a file for appending is implementation
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   200
                # defined. So we must seek to the end before calling tell(),
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   201
                # or we may get a zero offset for non-zero sized files on
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   202
                # some platforms (issue3543).
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   203
                f.seek(0, os.SEEK_END)
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   204
                offset = f.tell()
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   205
                transaction.add('obsstore', offset)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   206
                if offset == 0:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   207
                    # new file add version header
17125
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   208
                    f.write(_pack('>B', _fmversion))
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   209
                _writemarkers(f.write, [marker])
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   210
            finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   211
                # 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
   212
                # 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
   213
                f.close()
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   214
            self._load(marker)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   215
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   216
    def mergemarkers(self, transation, data):
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   217
        other = _readmarkers(data)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   218
        local = set(self._all)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   219
        new = [m for m in other if m not in local]
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   220
        for marker in new:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   221
            # XXX: N marker == N x (open, write, close)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   222
            # we should write them all at once
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   223
            self.add(transation, marker)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   224
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   225
    def _load(self, marker):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   226
        self._all.append(marker)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   227
        pre, sucs = marker[:2]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   228
        self.precursors.setdefault(pre, set()).add(marker)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   229
        for suc in sucs:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   230
            self.successors.setdefault(suc, set()).add(marker)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   231
17125
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   232
def _writemarkers(write, markers):
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   233
    # Kept separate from flushmarkers(), it will be reused for
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   234
    # markers exchange.
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   235
    for marker in markers:
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   236
        pre, sucs, flags, metadata = marker
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   237
        nbsuc = len(sucs)
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   238
        format = _fmfixed + (_fmnode * nbsuc)
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   239
        data = [nbsuc, len(metadata), flags, pre]
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   240
        data.extend(sucs)
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   241
        write(_pack(format, *data))
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   242
        write(metadata)
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   243
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   244
def listmarkers(repo):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   245
    """List markers over pushkey"""
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   246
    if not repo.obsstore:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   247
        return {}
17125
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   248
    data = [_pack('>B', _fmversion)]
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   249
    _writemarkers(data.append, repo.obsstore)
95d785ccb4e5 obsolete: append new markers to obsstore file instead of rewriting everything
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17124
diff changeset
   250
    return {'dump': base85.b85encode(''.join(data))}
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   251
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   252
def pushmarker(repo, key, old, new):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   253
    """Push markers over pushkey"""
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   254
    if key != 'dump':
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   255
        repo.ui.warn(_('unknown key: %r') % key)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   256
        return 0
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   257
    if old:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   258
        repo.ui.warn(_('unexpected old value') % key)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   259
        return 0
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   260
    data = base85.b85decode(new)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   261
    lock = repo.lock()
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   262
    try:
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   263
        tr = repo.transaction('pushkey: obsolete markers')
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   264
        try:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   265
            repo.obsstore.mergemarkers(tr, data)
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   266
            tr.close()
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   267
            return 1
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   268
        finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   269
            tr.release()
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   270
    finally:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   271
        lock.release()
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   272
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   273
def allmarkers(repo):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   274
    """all obsolete markers known in a repository"""
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   275
    for markerdata in repo.obsstore:
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   276
        yield marker(repo, markerdata)
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   277
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   278
def precursormarkers(ctx):
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   279
    """obsolete marker making this changeset obsolete"""
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   280
    for data in ctx._repo.obsstore.precursors.get(ctx.node(), ()):
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   281
        yield marker(ctx._repo, data)
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   282
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   283
def successormarkers(ctx):
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   284
    """obsolete marker marking this changeset as a successors"""
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   285
    for data in ctx._repo.obsstore.successors.get(ctx.node(), ()):
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   286
        yield marker(ctx._repo, data)
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
   287