mercurial/obsolete.py
author Pierre-Yves.David@ens-lyon.org
Fri, 13 Jul 2012 22:15:11 +0200
changeset 17220 bdac214a4705
parent 17219 494a970f68de
child 17253 67f56ff5afcd
permissions -rw-r--r--
obsolete: obsstore.add now takes a list of markers. This allow efficient IO and it greatly simplify the merging of markers.
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
"""
17200
19f5dec2d61f obsolete: os.SEEK_END first appeared in Python 2.5
Adrian Buehlmann <adrian@cadifra.com>
parents: 17195
diff changeset
    54
import 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:
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   167
            self._load(_readmarkers(data))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   168
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   169
    def __iter__(self):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
   170
        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
   171
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   172
    def __nonzero__(self):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   173
        return bool(self._all)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   174
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   175
    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
   176
        """obsolete: add a new obsolete marker
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   177
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   178
        * ensuring it is hashable
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   179
        * check mandatory metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   180
        * encode metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   181
        """
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   182
        if metadata is None:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   183
            metadata = {}
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   184
        if len(prec) != 20:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   185
            raise ValueError(prec)
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   186
        for succ in succs:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   187
            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
   188
                raise ValueError(succ)
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
   189
        marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata))
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   190
        self.add(transaction, [marker])
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   191
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   192
    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
   193
        """Add new markers to the store
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   194
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   195
        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
   196
        Return the number of new marker."""
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   197
        new = [m for m in markers if m not in self._all]
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   198
        if new:
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
   199
            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
   200
            try:
17195
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
   201
                # 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
   202
                # 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
   203
                # 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
   204
                # 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
   205
                # some platforms (issue3543).
17200
19f5dec2d61f obsolete: os.SEEK_END first appeared in Python 2.5
Adrian Buehlmann <adrian@cadifra.com>
parents: 17195
diff changeset
   206
                f.seek(0, 2) # 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
   207
                offset = f.tell()
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   208
                transaction.add('obsstore', offset)
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   209
                # offset == 0: new file - add the version header
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   210
                for bytes in _encodemarkers(new, offset == 0):
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   211
                    f.write(bytes)
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   212
            finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   213
                # 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
   214
                # 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
   215
                f.close()
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   216
            self._load(new)
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   217
        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
   218
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
   219
    def mergemarkers(self, transation, data):
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   220
        markers = _readmarkers(data)
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   221
        self.add(transation, markers)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   222
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   223
    def _load(self, markers):
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   224
        for mark in markers:
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   225
            self._all.append(mark)
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   226
            pre, sucs = mark[:2]
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   227
            self.precursors.setdefault(pre, set()).add(mark)
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   228
            for suc in sucs:
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
   229
                self.successors.setdefault(suc, set()).add(mark)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
   230
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   231
def _encodemarkers(markers, addheader=False):
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
    # 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
   233
    # markers exchange.
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   234
    if addheader:
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   235
        yield _pack('>B', _fmversion)
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
   236
    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
   237
        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
   238
        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
   239
        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
   240
        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
   241
        data.extend(sucs)
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   242
        yield _pack(format, *data)
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   243
        yield metadata
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   244
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   245
def listmarkers(repo):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   246
    """List markers over pushkey"""
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   247
    if not repo.obsstore:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
   248
        return {}
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   249
    markers = _encodemarkers(repo.obsstore, True)
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
   250
    return {'dump': base85.b85encode(''.join(markers))}
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
17213
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   288
def anysuccessors(obsstore, node):
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   289
    """Yield every successor of <node>
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   290
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   291
    This this a linear yield unsuitable to detect splitted changeset."""
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   292
    remaining = set([node])
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   293
    seen = set(remaining)
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   294
    while remaining:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   295
        current = remaining.pop()
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   296
        yield current
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   297
        for mark in obsstore.precursors.get(current, ()):
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   298
            for suc in mark[1]:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   299
                if suc not in seen:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   300
                    seen.add(suc)
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
   301
                    remaining.add(suc)