annotate mercurial/obsolete.py @ 17826:46e1a4e24225

obsolete: rename `anysuccessors` into `allsuccessors` The "any" prefix looks like it returned a boolean. `allsuccessors` is more accurate.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 19 Oct 2012 00:30:11 +0200
parents 3cc06457f15e
children 612db9d7e76a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
23 The old obsoleted changeset is called "precursor" and possible replacements are
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
24 called "successors". Markers that used changeset X as a precursors are called
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
25 "successor markers of X" because they hold information about the successors of
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
26 X. Markers that use changeset Y as a successors are call "precursor markers of
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
27 Y" because they hold information about the precursors of Y.
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
28
17775
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
29 Examples:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
30
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
31 - When changeset A is replacement by a changeset A', one marker is stored:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
32
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
33 (A, (A'))
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
34
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
35 - When changesets A and B are folded into a new changeset C two markers are
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
36 stored:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
37
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
38 (A, (C,)) and (B, (C,))
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
39
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
40 - When changeset A is simply "pruned" from the graph, a marker in create:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
41
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
42 (A, ())
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
43
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
44 - When changeset A is split into B and C, a single marker are used:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
45
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
46 (A, (C, C))
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
47
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
48 We use a single marker to distinct the "split" case from the "divergence"
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
49 case. If two independants operation rewrite the same changeset A in to A' and
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
50 A'' when have an error case: divergent rewriting. We can detect it because
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
51 two markers will be created independently:
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
52
13744acc4ad7 obsolete: add example of marker usage in the documentation
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17774
diff changeset
53 (A, (B,)) and (A, (C,))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
54
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
55 Format
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
56 ------
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 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
59 '.hg/store/obsstore'.
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 The file starts with a version header:
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 - 1 unsigned byte: version number, starting at zero.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
64
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
65
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
66 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
67
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
68 - 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
69
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
70 - 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
71
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
72 - 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
73 markers common operations, to avoid repeated decoding of metadata
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
74 entries.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
75
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
76 - 20 bytes: obsoleted changeset identifier.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
77
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
78 - N*20 bytes: new changesets identifiers.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
79
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
80 - 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
81 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
82 additional encoding. Keys cannot contain '\0' or ':' and values
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
83 cannot contain '\0'.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
84 """
17200
19f5dec2d61f obsolete: os.SEEK_END first appeared in Python 2.5
Adrian Buehlmann <adrian@cadifra.com>
parents: 17195
diff changeset
85 import struct
17774
0496d4f73cf4 obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17537
diff changeset
86 import util, base85, node
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
87 from i18n import _
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
88
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
89 _pack = struct.pack
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
90 _unpack = struct.unpack
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
91
17429
72fa4ef2245f declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents: 17426
diff changeset
92 _SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5
72fa4ef2245f declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents: 17426
diff changeset
93
17424
e7cfe3587ea4 fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents: 17405
diff changeset
94 # the obsolete feature is not mature enough to be enabled by default.
17296
a1f8869f2eee obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17295
diff changeset
95 # you have to rely on third party extension extension to enable this.
a1f8869f2eee obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17295
diff changeset
96 _enabled = False
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
97
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
98 # data used for parsing and writing
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
99 _fmversion = 0
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
100 _fmfixed = '>BIB20s'
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
101 _fmnode = '20s'
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
102 _fmfsize = struct.calcsize(_fmfixed)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
103 _fnodesize = struct.calcsize(_fmnode)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
104
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
105 def _readmarkers(data):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
106 """Read and enumerate markers from raw data"""
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
107 off = 0
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
108 diskversion = _unpack('>B', data[off:off + 1])[0]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
109 off += 1
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
110 if diskversion != _fmversion:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
111 raise util.Abort(_('parsing obsolete marker: unknown version %r')
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
112 % diskversion)
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 # Loop on markers
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
115 l = len(data)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
116 while off + _fmfsize <= l:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
117 # read fixed part
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
118 cur = data[off:off + _fmfsize]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
119 off += _fmfsize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
120 nbsuc, mdsize, flags, pre = _unpack(_fmfixed, cur)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
121 # read replacement
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
122 sucs = ()
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
123 if nbsuc:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
124 s = (_fnodesize * nbsuc)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
125 cur = data[off:off + s]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
126 sucs = _unpack(_fmnode * nbsuc, cur)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
127 off += s
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
128 # read metadata
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
129 # (metadata will be decoded on demand)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
130 metadata = data[off:off + mdsize]
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
131 if len(metadata) != mdsize:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
132 raise util.Abort(_('parsing obsolete marker: metadata is too '
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
133 'short, %d bytes expected, got %d')
17253
67f56ff5afcd obsolete: fix decoding error message arguments
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17220
diff changeset
134 % (mdsize, len(metadata)))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
135 off += mdsize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
136 yield (pre, sucs, flags, metadata)
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
137
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
138 def encodemeta(meta):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
139 """Return encoded metadata string to string mapping.
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
140
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
141 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
142 for key, value in meta.iteritems():
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
143 if ':' in key or '\0' in key:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
144 raise ValueError("':' and '\0' are forbidden in metadata key'")
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
145 if '\0' in value:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
146 raise ValueError("':' are forbidden in metadata value'")
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
147 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
148
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
149 def decodemeta(data):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
150 """Return string to string dictionary from encoded version."""
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
151 d = {}
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
152 for l in data.split('\0'):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
153 if l:
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
154 key, value = l.split(':')
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
155 d[key] = value
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
156 return d
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
157
17072
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
158 class marker(object):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
159 """Wrap obsolete marker raw data"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
160
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
161 def __init__(self, repo, data):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
162 # 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
163 self._repo = repo
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
164 self._data = data
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
165 self._decodedmeta = None
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
166
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
167 def precnode(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
168 """Precursor changeset node identifier"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
169 return self._data[0]
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
170
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
171 def succnodes(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
172 """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
173 return self._data[1]
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
174
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
175 def metadata(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
176 """Decoded metadata dictionary"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
177 if self._decodedmeta is None:
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
178 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
179 return self._decodedmeta
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
180
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
181 def date(self):
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
182 """Creation date as (unixtime, offset)"""
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
183 parts = self.metadata()['date'].split(' ')
517af63ba382 obsolete: helper class to access obsolete marker data
Pierre-Yves.David@ens-lyon.org
parents: 17071
diff changeset
184 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
185
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
186 class obsstore(object):
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
187 """Store obsolete markers
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
188
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
189 Markers can be accessed with two mappings:
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
190 - precursors[x] -> set(markers on precursors edges of x)
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
191 - successors[x] -> set(markers on successors edges of x)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
192 """
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
193
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
194 def __init__(self, sopener):
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
195 # caches for various obsolescence related cache
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
196 self.caches = {}
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
197 self._all = []
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
198 # new markers to serialize
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
199 self.precursors = {}
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
200 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
201 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
202 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
203 if data:
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
204 self._load(_readmarkers(data))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
205
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
206 def __iter__(self):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
207 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
208
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
209 def __nonzero__(self):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
210 return bool(self._all)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
211
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
212 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
213 """obsolete: add a new obsolete marker
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
214
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
215 * ensuring it is hashable
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
216 * check mandatory metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
217 * encode metadata
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
218 """
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
219 if metadata is None:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
220 metadata = {}
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
221 if len(prec) != 20:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
222 raise ValueError(prec)
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
223 for succ in succs:
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
224 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
225 raise ValueError(succ)
17071
11f26e2669aa command: creation of obsolete marker
Pierre-Yves.David@ens-lyon.org
parents: 17070
diff changeset
226 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
227 self.add(transaction, [marker])
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
228
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
229 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
230 """Add new markers to the store
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
231
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
232 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
233 Return the number of new marker."""
17296
a1f8869f2eee obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17295
diff changeset
234 if not _enabled:
a1f8869f2eee obsolete: introduce an `_enabled` switch to disable the feature by default
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17295
diff changeset
235 raise util.Abort('obsolete feature is not enabled on this repo')
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
236 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
237 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
238 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
239 try:
17195
48c232873a54 obsolete: add seek to end of file before calling tell (issue3543)
Adrian Buehlmann <adrian@cadifra.com>
parents: 17126
diff changeset
240 # 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
241 # 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
242 # 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
243 # 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
244 # some platforms (issue3543).
17429
72fa4ef2245f declare local constants instead of using magic values and comments
Mads Kiilerich <mads@kiilerich.com>
parents: 17426
diff changeset
245 f.seek(0, _SEEK_END)
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
246 offset = f.tell()
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
247 transaction.add('obsstore', offset)
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
248 # 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
249 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
250 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
251 finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
252 # 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
253 # 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
254 f.close()
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
255 self._load(new)
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
256 # new marker *may* have changed several set. invalidate the cache.
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
257 self.caches.clear()
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
258 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
259
17524
a736e1e15e46 spelling: transaction
timeless@mozdev.org
parents: 17516
diff changeset
260 def mergemarkers(self, transaction, data):
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
261 markers = _readmarkers(data)
17524
a736e1e15e46 spelling: transaction
timeless@mozdev.org
parents: 17516
diff changeset
262 self.add(transaction, markers)
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
263
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
264 def _load(self, markers):
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
265 for mark in markers:
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
266 self._all.append(mark)
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
267 pre, sucs = mark[:2]
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
268 self.successors.setdefault(pre, set()).add(mark)
17220
bdac214a4705 obsolete: obsstore.add now takes a list of markers.
Pierre-Yves.David@ens-lyon.org
parents: 17219
diff changeset
269 for suc in sucs:
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
270 self.precursors.setdefault(suc, set()).add(mark)
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
271 if node.nullid in self.precursors:
17774
0496d4f73cf4 obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17537
diff changeset
272 raise util.Abort(_('bad obsolescence marker detected: '
0496d4f73cf4 obsolete: cheap detection of nullid as successors
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17537
diff changeset
273 'invalid successors nullid'))
17070
ad0d6c2b3279 obsolete: introduction of obsolete markers
Pierre-Yves.David@ens-lyon.org
parents:
diff changeset
274
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
275 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
276 # 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
277 # markers exchange.
17219
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
278 if addheader:
494a970f68de obsolete: refactor writemarkers to only encode them
Pierre-Yves.David@ens-lyon.org
parents: 17213
diff changeset
279 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
280 for marker in markers:
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
281 yield _encodeonemarker(marker)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
282
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
283
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
284 def _encodeonemarker(marker):
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
285 pre, sucs, flags, metadata = marker
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
286 nbsuc = len(sucs)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
287 format = _fmfixed + (_fmnode * nbsuc)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
288 data = [nbsuc, len(metadata), flags, pre]
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
289 data.extend(sucs)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
290 return _pack(format, *data) + metadata
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
291
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
292 # arbitrary picked to fit into 8K limit from HTTP server
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
293 # you have to take in account:
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
294 # - the version header
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
295 # - the base85 encoding
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
296 _maxpayload = 5300
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
297
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
298 def listmarkers(repo):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
299 """List markers over pushkey"""
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
300 if not repo.obsstore:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
301 return {}
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
302 keys = {}
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
303 parts = []
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
304 currentlen = _maxpayload * 2 # ensure we create a new part
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
305 for marker in repo.obsstore:
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
306 nextdata = _encodeonemarker(marker)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
307 if (len(nextdata) + currentlen > _maxpayload):
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
308 currentpart = []
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
309 currentlen = 0
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
310 parts.append(currentpart)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
311 currentpart.append(nextdata)
17304
0368fc55d572 obsolete: properly increment currentlen when building pushkey payload
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17298
diff changeset
312 currentlen += len(nextdata)
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
313 for idx, part in enumerate(reversed(parts)):
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
314 data = ''.join([_pack('>B', _fmversion)] + part)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
315 keys['dump%i' % idx] = base85.b85encode(data)
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
316 return keys
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
317
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
318 def pushmarker(repo, key, old, new):
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
319 """Push markers over pushkey"""
17295
1f08ecc7febb pushkey: splits obsolete marker exchange into multiple keys
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17253
diff changeset
320 if not key.startswith('dump'):
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
321 repo.ui.warn(_('unknown key: %r') % key)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
322 return 0
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
323 if old:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
324 repo.ui.warn(_('unexpected old value') % key)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
325 return 0
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
326 data = base85.b85decode(new)
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
327 lock = repo.lock()
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
328 try:
17126
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
329 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
330 try:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
331 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
332 tr.close()
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
333 return 1
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
334 finally:
8fa8717b47b6 obsolete: write obsolete marker inside a transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17125
diff changeset
335 tr.release()
17075
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
336 finally:
28ed1c4511ce obsolete: exchange obsolete marker over pushkey
Pierre-Yves.David@ens-lyon.org
parents: 17073
diff changeset
337 lock.release()
17073
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
338
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
339 def allmarkers(repo):
3a79a5682af1 obsolete: add easy way to iterate over obsolete marker object
Pierre-Yves.David@ens-lyon.org
parents: 17072
diff changeset
340 """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
341 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
342 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
343
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
344 def precursormarkers(ctx):
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
345 """obsolete marker marking this changeset as a successors"""
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
346 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
347 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
348
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
349 def successormarkers(ctx):
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
350 """obsolete marker making this changeset obsolete"""
17076
75f4180509a4 obsolete: function and method to access some obsolete data
Pierre-Yves.David@ens-lyon.org
parents: 17075
diff changeset
351 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
352 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
353
17826
46e1a4e24225 obsolete: rename `anysuccessors` into `allsuccessors`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17825
diff changeset
354 def allsuccessors(obsstore, node):
17213
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
355 """Yield every successor of <node>
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
356
17537
31f32a96e1e3 Merge spelling fixes
Bryan O'Sullivan <bryano@fb.com>
parents: 17474 17524
diff changeset
357 This is a linear yield unsuited to detecting split changesets."""
17213
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
358 remaining = set([node])
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
359 seen = set(remaining)
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
360 while remaining:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
361 current = remaining.pop()
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
362 yield current
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
363 for mark in obsstore.successors.get(current, ()):
17213
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
364 for suc in mark[1]:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
365 if suc not in seen:
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
366 seen.add(suc)
7eb5aa1f83fd obsolete: add an any successors function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17200
diff changeset
367 remaining.add(suc)
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
368
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
369 # mapping of 'set-name' -> <function to computer this set>
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
370 cachefuncs = {}
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
371 def cachefor(name):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
372 """Decorator to register a function as computing the cache for a set"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
373 def decorator(func):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
374 assert name not in cachefuncs
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
375 cachefuncs[name] = func
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
376 return func
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
377 return decorator
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
378
17825
3cc06457f15e obsolete: rename `getobscache` into `getrevs`
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 17776
diff changeset
379 def getrevs(repo, name):
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
380 """Return the set of revision that belong to the <name> set
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
381
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
382 Such access may compute the set and cache it for future use"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
383 if not repo.obsstore:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
384 return ()
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
385 if name not in repo.obsstore.caches:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
386 repo.obsstore.caches[name] = cachefuncs[name](repo)
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
387 return repo.obsstore.caches[name]
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
388
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
389 # To be simple we need to invalidate obsolescence cache when:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
390 #
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
391 # - new changeset is added:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
392 # - public phase is changed
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
393 # - obsolescence marker are added
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
394 # - strip is used a repo
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
395 def clearobscaches(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
396 """Remove all obsolescence related cache from a repo
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
397
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
398 This remove all cache in obsstore is the obsstore already exist on the
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
399 repo.
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
400
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
401 (We could be smarter here given the exact event that trigger the cache
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
402 clearing)"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
403 # only clear cache is there is obsstore data in this repo
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
404 if 'obsstore' in repo._filecache:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
405 repo.obsstore.caches.clear()
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
406
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
407 @cachefor('obsolete')
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
408 def _computeobsoleteset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
409 """the set of obsolete revisions"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
410 obs = set()
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
411 nm = repo.changelog.nodemap
17776
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
412 for node in repo.obsstore.successors:
072812e9f570 obsolete: flip `obstore.successors` and `obsolete.precursors`
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17775
diff changeset
413 rev = nm.get(node)
17469
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
414 if rev is not None:
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
415 obs.add(rev)
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
416 return set(repo.revs('%ld - public()', obs))
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
417
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
418 @cachefor('unstable')
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
419 def _computeunstableset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
420 """the set of non obsolete revisions with obsolete parents"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
421 return set(repo.revs('(obsolete()::) - obsolete()'))
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
422
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
423 @cachefor('suspended')
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
424 def _computesuspendedset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
425 """the set of obsolete parents with non obsolete descendants"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
426 return set(repo.revs('obsolete() and obsolete()::unstable()'))
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
427
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
428 @cachefor('extinct')
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
429 def _computeextinctset(repo):
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
430 """the set of obsolete parents without non obsolete descendants"""
fb72eec7efd8 obsolete: introduce caches for all meaningful sets
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17429
diff changeset
431 return set(repo.revs('obsolete() - obsolete()::unstable()'))
17474
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
432
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
433 def createmarkers(repo, relations, flag=0, metadata=None):
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
434 """Add obsolete markers between changesets in a repo
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
435
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
436 <relations> must be an iterable of (<old>, (<new>, ...)) tuple.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
437 `old` and `news` are changectx.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
438
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
439 Trying to obsolete a public changeset will raise an exception.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
440
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
441 Current user and date are used except if specified otherwise in the
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
442 metadata attribute.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
443
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
444 This function operates within a transaction of its own, but does
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
445 not take any lock on the repo.
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
446 """
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
447 # prepare metadata
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
448 if metadata is None:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
449 metadata = {}
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
450 if 'date' not in metadata:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
451 metadata['date'] = '%i %i' % util.makedate()
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
452 if 'user' not in metadata:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
453 metadata['user'] = repo.ui.username()
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
454 tr = repo.transaction('add-obsolescence-marker')
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
455 try:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
456 for prec, sucs in relations:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
457 if not prec.mutable():
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
458 raise util.Abort("cannot obsolete immutable changeset: %s"
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
459 % prec)
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
460 nprec = prec.node()
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
461 nsucs = tuple(s.node() for s in sucs)
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
462 if nprec in nsucs:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
463 raise util.Abort("changeset %s cannot obsolete itself" % prec)
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
464 repo.obsstore.create(tr, nprec, nsucs, flag, metadata)
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
465 tr.close()
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
466 finally:
f85816af6294 obsolete: add a high level function to create an obsolete marker
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 17469
diff changeset
467 tr.release()