##// END OF EJS Templates
obsolete: don't import from .node twice...
av6 -
r49544:48cb4109 default
parent child Browse files
Show More
@@ -1,1150 +1,1146 b''
1 # obsolete.py - obsolete markers handling
1 # obsolete.py - obsolete markers handling
2 #
2 #
3 # Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
3 # Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
4 # Logilab SA <contact@logilab.fr>
4 # Logilab SA <contact@logilab.fr>
5 #
5 #
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 """Obsolete marker handling
9 """Obsolete marker handling
10
10
11 An obsolete marker maps an old changeset to a list of new
11 An obsolete marker maps an old changeset to a list of new
12 changesets. If the list of new changesets is empty, the old changeset
12 changesets. If the list of new changesets is empty, the old changeset
13 is said to be "killed". Otherwise, the old changeset is being
13 is said to be "killed". Otherwise, the old changeset is being
14 "replaced" by the new changesets.
14 "replaced" by the new changesets.
15
15
16 Obsolete markers can be used to record and distribute changeset graph
16 Obsolete markers can be used to record and distribute changeset graph
17 transformations performed by history rewrite operations, and help
17 transformations performed by history rewrite operations, and help
18 building new tools to reconcile conflicting rewrite actions. To
18 building new tools to reconcile conflicting rewrite actions. To
19 facilitate conflict resolution, markers include various annotations
19 facilitate conflict resolution, markers include various annotations
20 besides old and news changeset identifiers, such as creation date or
20 besides old and news changeset identifiers, such as creation date or
21 author name.
21 author name.
22
22
23 The old obsoleted changeset is called a "predecessor" and possible
23 The old obsoleted changeset is called a "predecessor" and possible
24 replacements are called "successors". Markers that used changeset X as
24 replacements are called "successors". Markers that used changeset X as
25 a predecessor are called "successor markers of X" because they hold
25 a predecessor are called "successor markers of X" because they hold
26 information about the successors of X. Markers that use changeset Y as
26 information about the successors of X. Markers that use changeset Y as
27 a successors are call "predecessor markers of Y" because they hold
27 a successors are call "predecessor markers of Y" because they hold
28 information about the predecessors of Y.
28 information about the predecessors of Y.
29
29
30 Examples:
30 Examples:
31
31
32 - When changeset A is replaced by changeset A', one marker is stored:
32 - When changeset A is replaced by changeset A', one marker is stored:
33
33
34 (A, (A',))
34 (A, (A',))
35
35
36 - When changesets A and B are folded into a new changeset C, two markers are
36 - When changesets A and B are folded into a new changeset C, two markers are
37 stored:
37 stored:
38
38
39 (A, (C,)) and (B, (C,))
39 (A, (C,)) and (B, (C,))
40
40
41 - When changeset A is simply "pruned" from the graph, a marker is created:
41 - When changeset A is simply "pruned" from the graph, a marker is created:
42
42
43 (A, ())
43 (A, ())
44
44
45 - When changeset A is split into B and C, a single marker is used:
45 - When changeset A is split into B and C, a single marker is used:
46
46
47 (A, (B, C))
47 (A, (B, C))
48
48
49 We use a single marker to distinguish the "split" case from the "divergence"
49 We use a single marker to distinguish the "split" case from the "divergence"
50 case. If two independent operations rewrite the same changeset A in to A' and
50 case. If two independent operations rewrite the same changeset A in to A' and
51 A'', we have an error case: divergent rewriting. We can detect it because
51 A'', we have an error case: divergent rewriting. We can detect it because
52 two markers will be created independently:
52 two markers will be created independently:
53
53
54 (A, (B,)) and (A, (C,))
54 (A, (B,)) and (A, (C,))
55
55
56 Format
56 Format
57 ------
57 ------
58
58
59 Markers are stored in an append-only file stored in
59 Markers are stored in an append-only file stored in
60 '.hg/store/obsstore'.
60 '.hg/store/obsstore'.
61
61
62 The file starts with a version header:
62 The file starts with a version header:
63
63
64 - 1 unsigned byte: version number, starting at zero.
64 - 1 unsigned byte: version number, starting at zero.
65
65
66 The header is followed by the markers. Marker format depend of the version. See
66 The header is followed by the markers. Marker format depend of the version. See
67 comment associated with each format for details.
67 comment associated with each format for details.
68
68
69 """
69 """
70 from __future__ import absolute_import
70 from __future__ import absolute_import
71
71
72 import errno
72 import errno
73 import struct
73 import struct
74
74
75 from .i18n import _
75 from .i18n import _
76 from .node import (
77 bin,
78 hex,
79 )
80 from .pycompat import getattr
76 from .pycompat import getattr
81 from .node import (
77 from .node import (
82 bin,
78 bin,
83 hex,
79 hex,
84 )
80 )
85 from . import (
81 from . import (
86 encoding,
82 encoding,
87 error,
83 error,
88 obsutil,
84 obsutil,
89 phases,
85 phases,
90 policy,
86 policy,
91 pycompat,
87 pycompat,
92 util,
88 util,
93 )
89 )
94 from .utils import (
90 from .utils import (
95 dateutil,
91 dateutil,
96 hashutil,
92 hashutil,
97 )
93 )
98
94
99 parsers = policy.importmod('parsers')
95 parsers = policy.importmod('parsers')
100
96
101 _pack = struct.pack
97 _pack = struct.pack
102 _unpack = struct.unpack
98 _unpack = struct.unpack
103 _calcsize = struct.calcsize
99 _calcsize = struct.calcsize
104 propertycache = util.propertycache
100 propertycache = util.propertycache
105
101
106 # Options for obsolescence
102 # Options for obsolescence
107 createmarkersopt = b'createmarkers'
103 createmarkersopt = b'createmarkers'
108 allowunstableopt = b'allowunstable'
104 allowunstableopt = b'allowunstable'
109 allowdivergenceopt = b'allowdivergence'
105 allowdivergenceopt = b'allowdivergence'
110 exchangeopt = b'exchange'
106 exchangeopt = b'exchange'
111
107
112
108
113 def _getoptionvalue(repo, option):
109 def _getoptionvalue(repo, option):
114 """Returns True if the given repository has the given obsolete option
110 """Returns True if the given repository has the given obsolete option
115 enabled.
111 enabled.
116 """
112 """
117 configkey = b'evolution.%s' % option
113 configkey = b'evolution.%s' % option
118 newconfig = repo.ui.configbool(b'experimental', configkey)
114 newconfig = repo.ui.configbool(b'experimental', configkey)
119
115
120 # Return the value only if defined
116 # Return the value only if defined
121 if newconfig is not None:
117 if newconfig is not None:
122 return newconfig
118 return newconfig
123
119
124 # Fallback on generic option
120 # Fallback on generic option
125 try:
121 try:
126 return repo.ui.configbool(b'experimental', b'evolution')
122 return repo.ui.configbool(b'experimental', b'evolution')
127 except (error.ConfigError, AttributeError):
123 except (error.ConfigError, AttributeError):
128 # Fallback on old-fashion config
124 # Fallback on old-fashion config
129 # inconsistent config: experimental.evolution
125 # inconsistent config: experimental.evolution
130 result = set(repo.ui.configlist(b'experimental', b'evolution'))
126 result = set(repo.ui.configlist(b'experimental', b'evolution'))
131
127
132 if b'all' in result:
128 if b'all' in result:
133 return True
129 return True
134
130
135 # Temporary hack for next check
131 # Temporary hack for next check
136 newconfig = repo.ui.config(b'experimental', b'evolution.createmarkers')
132 newconfig = repo.ui.config(b'experimental', b'evolution.createmarkers')
137 if newconfig:
133 if newconfig:
138 result.add(b'createmarkers')
134 result.add(b'createmarkers')
139
135
140 return option in result
136 return option in result
141
137
142
138
143 def getoptions(repo):
139 def getoptions(repo):
144 """Returns dicts showing state of obsolescence features."""
140 """Returns dicts showing state of obsolescence features."""
145
141
146 createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
142 createmarkersvalue = _getoptionvalue(repo, createmarkersopt)
147 if createmarkersvalue:
143 if createmarkersvalue:
148 unstablevalue = _getoptionvalue(repo, allowunstableopt)
144 unstablevalue = _getoptionvalue(repo, allowunstableopt)
149 divergencevalue = _getoptionvalue(repo, allowdivergenceopt)
145 divergencevalue = _getoptionvalue(repo, allowdivergenceopt)
150 exchangevalue = _getoptionvalue(repo, exchangeopt)
146 exchangevalue = _getoptionvalue(repo, exchangeopt)
151 else:
147 else:
152 # if we cannot create obsolescence markers, we shouldn't exchange them
148 # if we cannot create obsolescence markers, we shouldn't exchange them
153 # or perform operations that lead to instability or divergence
149 # or perform operations that lead to instability or divergence
154 unstablevalue = False
150 unstablevalue = False
155 divergencevalue = False
151 divergencevalue = False
156 exchangevalue = False
152 exchangevalue = False
157
153
158 return {
154 return {
159 createmarkersopt: createmarkersvalue,
155 createmarkersopt: createmarkersvalue,
160 allowunstableopt: unstablevalue,
156 allowunstableopt: unstablevalue,
161 allowdivergenceopt: divergencevalue,
157 allowdivergenceopt: divergencevalue,
162 exchangeopt: exchangevalue,
158 exchangeopt: exchangevalue,
163 }
159 }
164
160
165
161
166 def isenabled(repo, option):
162 def isenabled(repo, option):
167 """Returns True if the given repository has the given obsolete option
163 """Returns True if the given repository has the given obsolete option
168 enabled.
164 enabled.
169 """
165 """
170 return getoptions(repo)[option]
166 return getoptions(repo)[option]
171
167
172
168
173 # Creating aliases for marker flags because evolve extension looks for
169 # Creating aliases for marker flags because evolve extension looks for
174 # bumpedfix in obsolete.py
170 # bumpedfix in obsolete.py
175 bumpedfix = obsutil.bumpedfix
171 bumpedfix = obsutil.bumpedfix
176 usingsha256 = obsutil.usingsha256
172 usingsha256 = obsutil.usingsha256
177
173
178 ## Parsing and writing of version "0"
174 ## Parsing and writing of version "0"
179 #
175 #
180 # The header is followed by the markers. Each marker is made of:
176 # The header is followed by the markers. Each marker is made of:
181 #
177 #
182 # - 1 uint8 : number of new changesets "N", can be zero.
178 # - 1 uint8 : number of new changesets "N", can be zero.
183 #
179 #
184 # - 1 uint32: metadata size "M" in bytes.
180 # - 1 uint32: metadata size "M" in bytes.
185 #
181 #
186 # - 1 byte: a bit field. It is reserved for flags used in common
182 # - 1 byte: a bit field. It is reserved for flags used in common
187 # obsolete marker operations, to avoid repeated decoding of metadata
183 # obsolete marker operations, to avoid repeated decoding of metadata
188 # entries.
184 # entries.
189 #
185 #
190 # - 20 bytes: obsoleted changeset identifier.
186 # - 20 bytes: obsoleted changeset identifier.
191 #
187 #
192 # - N*20 bytes: new changesets identifiers.
188 # - N*20 bytes: new changesets identifiers.
193 #
189 #
194 # - M bytes: metadata as a sequence of nul-terminated strings. Each
190 # - M bytes: metadata as a sequence of nul-terminated strings. Each
195 # string contains a key and a value, separated by a colon ':', without
191 # string contains a key and a value, separated by a colon ':', without
196 # additional encoding. Keys cannot contain '\0' or ':' and values
192 # additional encoding. Keys cannot contain '\0' or ':' and values
197 # cannot contain '\0'.
193 # cannot contain '\0'.
198 _fm0version = 0
194 _fm0version = 0
199 _fm0fixed = b'>BIB20s'
195 _fm0fixed = b'>BIB20s'
200 _fm0node = b'20s'
196 _fm0node = b'20s'
201 _fm0fsize = _calcsize(_fm0fixed)
197 _fm0fsize = _calcsize(_fm0fixed)
202 _fm0fnodesize = _calcsize(_fm0node)
198 _fm0fnodesize = _calcsize(_fm0node)
203
199
204
200
205 def _fm0readmarkers(data, off, stop):
201 def _fm0readmarkers(data, off, stop):
206 # Loop on markers
202 # Loop on markers
207 while off < stop:
203 while off < stop:
208 # read fixed part
204 # read fixed part
209 cur = data[off : off + _fm0fsize]
205 cur = data[off : off + _fm0fsize]
210 off += _fm0fsize
206 off += _fm0fsize
211 numsuc, mdsize, flags, pre = _unpack(_fm0fixed, cur)
207 numsuc, mdsize, flags, pre = _unpack(_fm0fixed, cur)
212 # read replacement
208 # read replacement
213 sucs = ()
209 sucs = ()
214 if numsuc:
210 if numsuc:
215 s = _fm0fnodesize * numsuc
211 s = _fm0fnodesize * numsuc
216 cur = data[off : off + s]
212 cur = data[off : off + s]
217 sucs = _unpack(_fm0node * numsuc, cur)
213 sucs = _unpack(_fm0node * numsuc, cur)
218 off += s
214 off += s
219 # read metadata
215 # read metadata
220 # (metadata will be decoded on demand)
216 # (metadata will be decoded on demand)
221 metadata = data[off : off + mdsize]
217 metadata = data[off : off + mdsize]
222 if len(metadata) != mdsize:
218 if len(metadata) != mdsize:
223 raise error.Abort(
219 raise error.Abort(
224 _(
220 _(
225 b'parsing obsolete marker: metadata is too '
221 b'parsing obsolete marker: metadata is too '
226 b'short, %d bytes expected, got %d'
222 b'short, %d bytes expected, got %d'
227 )
223 )
228 % (mdsize, len(metadata))
224 % (mdsize, len(metadata))
229 )
225 )
230 off += mdsize
226 off += mdsize
231 metadata = _fm0decodemeta(metadata)
227 metadata = _fm0decodemeta(metadata)
232 try:
228 try:
233 when, offset = metadata.pop(b'date', b'0 0').split(b' ')
229 when, offset = metadata.pop(b'date', b'0 0').split(b' ')
234 date = float(when), int(offset)
230 date = float(when), int(offset)
235 except ValueError:
231 except ValueError:
236 date = (0.0, 0)
232 date = (0.0, 0)
237 parents = None
233 parents = None
238 if b'p2' in metadata:
234 if b'p2' in metadata:
239 parents = (metadata.pop(b'p1', None), metadata.pop(b'p2', None))
235 parents = (metadata.pop(b'p1', None), metadata.pop(b'p2', None))
240 elif b'p1' in metadata:
236 elif b'p1' in metadata:
241 parents = (metadata.pop(b'p1', None),)
237 parents = (metadata.pop(b'p1', None),)
242 elif b'p0' in metadata:
238 elif b'p0' in metadata:
243 parents = ()
239 parents = ()
244 if parents is not None:
240 if parents is not None:
245 try:
241 try:
246 parents = tuple(bin(p) for p in parents)
242 parents = tuple(bin(p) for p in parents)
247 # if parent content is not a nodeid, drop the data
243 # if parent content is not a nodeid, drop the data
248 for p in parents:
244 for p in parents:
249 if len(p) != 20:
245 if len(p) != 20:
250 parents = None
246 parents = None
251 break
247 break
252 except TypeError:
248 except TypeError:
253 # if content cannot be translated to nodeid drop the data.
249 # if content cannot be translated to nodeid drop the data.
254 parents = None
250 parents = None
255
251
256 metadata = tuple(sorted(pycompat.iteritems(metadata)))
252 metadata = tuple(sorted(pycompat.iteritems(metadata)))
257
253
258 yield (pre, sucs, flags, metadata, date, parents)
254 yield (pre, sucs, flags, metadata, date, parents)
259
255
260
256
261 def _fm0encodeonemarker(marker):
257 def _fm0encodeonemarker(marker):
262 pre, sucs, flags, metadata, date, parents = marker
258 pre, sucs, flags, metadata, date, parents = marker
263 if flags & usingsha256:
259 if flags & usingsha256:
264 raise error.Abort(_(b'cannot handle sha256 with old obsstore format'))
260 raise error.Abort(_(b'cannot handle sha256 with old obsstore format'))
265 metadata = dict(metadata)
261 metadata = dict(metadata)
266 time, tz = date
262 time, tz = date
267 metadata[b'date'] = b'%r %i' % (time, tz)
263 metadata[b'date'] = b'%r %i' % (time, tz)
268 if parents is not None:
264 if parents is not None:
269 if not parents:
265 if not parents:
270 # mark that we explicitly recorded no parents
266 # mark that we explicitly recorded no parents
271 metadata[b'p0'] = b''
267 metadata[b'p0'] = b''
272 for i, p in enumerate(parents, 1):
268 for i, p in enumerate(parents, 1):
273 metadata[b'p%i' % i] = hex(p)
269 metadata[b'p%i' % i] = hex(p)
274 metadata = _fm0encodemeta(metadata)
270 metadata = _fm0encodemeta(metadata)
275 numsuc = len(sucs)
271 numsuc = len(sucs)
276 format = _fm0fixed + (_fm0node * numsuc)
272 format = _fm0fixed + (_fm0node * numsuc)
277 data = [numsuc, len(metadata), flags, pre]
273 data = [numsuc, len(metadata), flags, pre]
278 data.extend(sucs)
274 data.extend(sucs)
279 return _pack(format, *data) + metadata
275 return _pack(format, *data) + metadata
280
276
281
277
282 def _fm0encodemeta(meta):
278 def _fm0encodemeta(meta):
283 """Return encoded metadata string to string mapping.
279 """Return encoded metadata string to string mapping.
284
280
285 Assume no ':' in key and no '\0' in both key and value."""
281 Assume no ':' in key and no '\0' in both key and value."""
286 for key, value in pycompat.iteritems(meta):
282 for key, value in pycompat.iteritems(meta):
287 if b':' in key or b'\0' in key:
283 if b':' in key or b'\0' in key:
288 raise ValueError(b"':' and '\0' are forbidden in metadata key'")
284 raise ValueError(b"':' and '\0' are forbidden in metadata key'")
289 if b'\0' in value:
285 if b'\0' in value:
290 raise ValueError(b"':' is forbidden in metadata value'")
286 raise ValueError(b"':' is forbidden in metadata value'")
291 return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)])
287 return b'\0'.join([b'%s:%s' % (k, meta[k]) for k in sorted(meta)])
292
288
293
289
294 def _fm0decodemeta(data):
290 def _fm0decodemeta(data):
295 """Return string to string dictionary from encoded version."""
291 """Return string to string dictionary from encoded version."""
296 d = {}
292 d = {}
297 for l in data.split(b'\0'):
293 for l in data.split(b'\0'):
298 if l:
294 if l:
299 key, value = l.split(b':', 1)
295 key, value = l.split(b':', 1)
300 d[key] = value
296 d[key] = value
301 return d
297 return d
302
298
303
299
304 ## Parsing and writing of version "1"
300 ## Parsing and writing of version "1"
305 #
301 #
306 # The header is followed by the markers. Each marker is made of:
302 # The header is followed by the markers. Each marker is made of:
307 #
303 #
308 # - uint32: total size of the marker (including this field)
304 # - uint32: total size of the marker (including this field)
309 #
305 #
310 # - float64: date in seconds since epoch
306 # - float64: date in seconds since epoch
311 #
307 #
312 # - int16: timezone offset in minutes
308 # - int16: timezone offset in minutes
313 #
309 #
314 # - uint16: a bit field. It is reserved for flags used in common
310 # - uint16: a bit field. It is reserved for flags used in common
315 # obsolete marker operations, to avoid repeated decoding of metadata
311 # obsolete marker operations, to avoid repeated decoding of metadata
316 # entries.
312 # entries.
317 #
313 #
318 # - uint8: number of successors "N", can be zero.
314 # - uint8: number of successors "N", can be zero.
319 #
315 #
320 # - uint8: number of parents "P", can be zero.
316 # - uint8: number of parents "P", can be zero.
321 #
317 #
322 # 0: parents data stored but no parent,
318 # 0: parents data stored but no parent,
323 # 1: one parent stored,
319 # 1: one parent stored,
324 # 2: two parents stored,
320 # 2: two parents stored,
325 # 3: no parent data stored
321 # 3: no parent data stored
326 #
322 #
327 # - uint8: number of metadata entries M
323 # - uint8: number of metadata entries M
328 #
324 #
329 # - 20 or 32 bytes: predecessor changeset identifier.
325 # - 20 or 32 bytes: predecessor changeset identifier.
330 #
326 #
331 # - N*(20 or 32) bytes: successors changesets identifiers.
327 # - N*(20 or 32) bytes: successors changesets identifiers.
332 #
328 #
333 # - P*(20 or 32) bytes: parents of the predecessors changesets.
329 # - P*(20 or 32) bytes: parents of the predecessors changesets.
334 #
330 #
335 # - M*(uint8, uint8): size of all metadata entries (key and value)
331 # - M*(uint8, uint8): size of all metadata entries (key and value)
336 #
332 #
337 # - remaining bytes: the metadata, each (key, value) pair after the other.
333 # - remaining bytes: the metadata, each (key, value) pair after the other.
338 _fm1version = 1
334 _fm1version = 1
339 _fm1fixed = b'>IdhHBBB'
335 _fm1fixed = b'>IdhHBBB'
340 _fm1nodesha1 = b'20s'
336 _fm1nodesha1 = b'20s'
341 _fm1nodesha256 = b'32s'
337 _fm1nodesha256 = b'32s'
342 _fm1nodesha1size = _calcsize(_fm1nodesha1)
338 _fm1nodesha1size = _calcsize(_fm1nodesha1)
343 _fm1nodesha256size = _calcsize(_fm1nodesha256)
339 _fm1nodesha256size = _calcsize(_fm1nodesha256)
344 _fm1fsize = _calcsize(_fm1fixed)
340 _fm1fsize = _calcsize(_fm1fixed)
345 _fm1parentnone = 3
341 _fm1parentnone = 3
346 _fm1parentshift = 14
342 _fm1parentshift = 14
347 _fm1parentmask = _fm1parentnone << _fm1parentshift
343 _fm1parentmask = _fm1parentnone << _fm1parentshift
348 _fm1metapair = b'BB'
344 _fm1metapair = b'BB'
349 _fm1metapairsize = _calcsize(_fm1metapair)
345 _fm1metapairsize = _calcsize(_fm1metapair)
350
346
351
347
352 def _fm1purereadmarkers(data, off, stop):
348 def _fm1purereadmarkers(data, off, stop):
353 # make some global constants local for performance
349 # make some global constants local for performance
354 noneflag = _fm1parentnone
350 noneflag = _fm1parentnone
355 sha2flag = usingsha256
351 sha2flag = usingsha256
356 sha1size = _fm1nodesha1size
352 sha1size = _fm1nodesha1size
357 sha2size = _fm1nodesha256size
353 sha2size = _fm1nodesha256size
358 sha1fmt = _fm1nodesha1
354 sha1fmt = _fm1nodesha1
359 sha2fmt = _fm1nodesha256
355 sha2fmt = _fm1nodesha256
360 metasize = _fm1metapairsize
356 metasize = _fm1metapairsize
361 metafmt = _fm1metapair
357 metafmt = _fm1metapair
362 fsize = _fm1fsize
358 fsize = _fm1fsize
363 unpack = _unpack
359 unpack = _unpack
364
360
365 # Loop on markers
361 # Loop on markers
366 ufixed = struct.Struct(_fm1fixed).unpack
362 ufixed = struct.Struct(_fm1fixed).unpack
367
363
368 while off < stop:
364 while off < stop:
369 # read fixed part
365 # read fixed part
370 o1 = off + fsize
366 o1 = off + fsize
371 t, secs, tz, flags, numsuc, numpar, nummeta = ufixed(data[off:o1])
367 t, secs, tz, flags, numsuc, numpar, nummeta = ufixed(data[off:o1])
372
368
373 if flags & sha2flag:
369 if flags & sha2flag:
374 nodefmt = sha2fmt
370 nodefmt = sha2fmt
375 nodesize = sha2size
371 nodesize = sha2size
376 else:
372 else:
377 nodefmt = sha1fmt
373 nodefmt = sha1fmt
378 nodesize = sha1size
374 nodesize = sha1size
379
375
380 (prec,) = unpack(nodefmt, data[o1 : o1 + nodesize])
376 (prec,) = unpack(nodefmt, data[o1 : o1 + nodesize])
381 o1 += nodesize
377 o1 += nodesize
382
378
383 # read 0 or more successors
379 # read 0 or more successors
384 if numsuc == 1:
380 if numsuc == 1:
385 o2 = o1 + nodesize
381 o2 = o1 + nodesize
386 sucs = (data[o1:o2],)
382 sucs = (data[o1:o2],)
387 else:
383 else:
388 o2 = o1 + nodesize * numsuc
384 o2 = o1 + nodesize * numsuc
389 sucs = unpack(nodefmt * numsuc, data[o1:o2])
385 sucs = unpack(nodefmt * numsuc, data[o1:o2])
390
386
391 # read parents
387 # read parents
392 if numpar == noneflag:
388 if numpar == noneflag:
393 o3 = o2
389 o3 = o2
394 parents = None
390 parents = None
395 elif numpar == 1:
391 elif numpar == 1:
396 o3 = o2 + nodesize
392 o3 = o2 + nodesize
397 parents = (data[o2:o3],)
393 parents = (data[o2:o3],)
398 else:
394 else:
399 o3 = o2 + nodesize * numpar
395 o3 = o2 + nodesize * numpar
400 parents = unpack(nodefmt * numpar, data[o2:o3])
396 parents = unpack(nodefmt * numpar, data[o2:o3])
401
397
402 # read metadata
398 # read metadata
403 off = o3 + metasize * nummeta
399 off = o3 + metasize * nummeta
404 metapairsize = unpack(b'>' + (metafmt * nummeta), data[o3:off])
400 metapairsize = unpack(b'>' + (metafmt * nummeta), data[o3:off])
405 metadata = []
401 metadata = []
406 for idx in pycompat.xrange(0, len(metapairsize), 2):
402 for idx in pycompat.xrange(0, len(metapairsize), 2):
407 o1 = off + metapairsize[idx]
403 o1 = off + metapairsize[idx]
408 o2 = o1 + metapairsize[idx + 1]
404 o2 = o1 + metapairsize[idx + 1]
409 metadata.append((data[off:o1], data[o1:o2]))
405 metadata.append((data[off:o1], data[o1:o2]))
410 off = o2
406 off = o2
411
407
412 yield (prec, sucs, flags, tuple(metadata), (secs, tz * 60), parents)
408 yield (prec, sucs, flags, tuple(metadata), (secs, tz * 60), parents)
413
409
414
410
415 def _fm1encodeonemarker(marker):
411 def _fm1encodeonemarker(marker):
416 pre, sucs, flags, metadata, date, parents = marker
412 pre, sucs, flags, metadata, date, parents = marker
417 # determine node size
413 # determine node size
418 _fm1node = _fm1nodesha1
414 _fm1node = _fm1nodesha1
419 if flags & usingsha256:
415 if flags & usingsha256:
420 _fm1node = _fm1nodesha256
416 _fm1node = _fm1nodesha256
421 numsuc = len(sucs)
417 numsuc = len(sucs)
422 numextranodes = 1 + numsuc
418 numextranodes = 1 + numsuc
423 if parents is None:
419 if parents is None:
424 numpar = _fm1parentnone
420 numpar = _fm1parentnone
425 else:
421 else:
426 numpar = len(parents)
422 numpar = len(parents)
427 numextranodes += numpar
423 numextranodes += numpar
428 formatnodes = _fm1node * numextranodes
424 formatnodes = _fm1node * numextranodes
429 formatmeta = _fm1metapair * len(metadata)
425 formatmeta = _fm1metapair * len(metadata)
430 format = _fm1fixed + formatnodes + formatmeta
426 format = _fm1fixed + formatnodes + formatmeta
431 # tz is stored in minutes so we divide by 60
427 # tz is stored in minutes so we divide by 60
432 tz = date[1] // 60
428 tz = date[1] // 60
433 data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
429 data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
434 data.extend(sucs)
430 data.extend(sucs)
435 if parents is not None:
431 if parents is not None:
436 data.extend(parents)
432 data.extend(parents)
437 totalsize = _calcsize(format)
433 totalsize = _calcsize(format)
438 for key, value in metadata:
434 for key, value in metadata:
439 lk = len(key)
435 lk = len(key)
440 lv = len(value)
436 lv = len(value)
441 if lk > 255:
437 if lk > 255:
442 msg = (
438 msg = (
443 b'obsstore metadata key cannot be longer than 255 bytes'
439 b'obsstore metadata key cannot be longer than 255 bytes'
444 b' (key "%s" is %u bytes)'
440 b' (key "%s" is %u bytes)'
445 ) % (key, lk)
441 ) % (key, lk)
446 raise error.ProgrammingError(msg)
442 raise error.ProgrammingError(msg)
447 if lv > 255:
443 if lv > 255:
448 msg = (
444 msg = (
449 b'obsstore metadata value cannot be longer than 255 bytes'
445 b'obsstore metadata value cannot be longer than 255 bytes'
450 b' (value "%s" for key "%s" is %u bytes)'
446 b' (value "%s" for key "%s" is %u bytes)'
451 ) % (value, key, lv)
447 ) % (value, key, lv)
452 raise error.ProgrammingError(msg)
448 raise error.ProgrammingError(msg)
453 data.append(lk)
449 data.append(lk)
454 data.append(lv)
450 data.append(lv)
455 totalsize += lk + lv
451 totalsize += lk + lv
456 data[0] = totalsize
452 data[0] = totalsize
457 data = [_pack(format, *data)]
453 data = [_pack(format, *data)]
458 for key, value in metadata:
454 for key, value in metadata:
459 data.append(key)
455 data.append(key)
460 data.append(value)
456 data.append(value)
461 return b''.join(data)
457 return b''.join(data)
462
458
463
459
464 def _fm1readmarkers(data, off, stop):
460 def _fm1readmarkers(data, off, stop):
465 native = getattr(parsers, 'fm1readmarkers', None)
461 native = getattr(parsers, 'fm1readmarkers', None)
466 if not native:
462 if not native:
467 return _fm1purereadmarkers(data, off, stop)
463 return _fm1purereadmarkers(data, off, stop)
468 return native(data, off, stop)
464 return native(data, off, stop)
469
465
470
466
471 # mapping to read/write various marker formats
467 # mapping to read/write various marker formats
472 # <version> -> (decoder, encoder)
468 # <version> -> (decoder, encoder)
473 formats = {
469 formats = {
474 _fm0version: (_fm0readmarkers, _fm0encodeonemarker),
470 _fm0version: (_fm0readmarkers, _fm0encodeonemarker),
475 _fm1version: (_fm1readmarkers, _fm1encodeonemarker),
471 _fm1version: (_fm1readmarkers, _fm1encodeonemarker),
476 }
472 }
477
473
478
474
479 def _readmarkerversion(data):
475 def _readmarkerversion(data):
480 return _unpack(b'>B', data[0:1])[0]
476 return _unpack(b'>B', data[0:1])[0]
481
477
482
478
483 @util.nogc
479 @util.nogc
484 def _readmarkers(data, off=None, stop=None):
480 def _readmarkers(data, off=None, stop=None):
485 """Read and enumerate markers from raw data"""
481 """Read and enumerate markers from raw data"""
486 diskversion = _readmarkerversion(data)
482 diskversion = _readmarkerversion(data)
487 if not off:
483 if not off:
488 off = 1 # skip 1 byte version number
484 off = 1 # skip 1 byte version number
489 if stop is None:
485 if stop is None:
490 stop = len(data)
486 stop = len(data)
491 if diskversion not in formats:
487 if diskversion not in formats:
492 msg = _(b'parsing obsolete marker: unknown version %r') % diskversion
488 msg = _(b'parsing obsolete marker: unknown version %r') % diskversion
493 raise error.UnknownVersion(msg, version=diskversion)
489 raise error.UnknownVersion(msg, version=diskversion)
494 return diskversion, formats[diskversion][0](data, off, stop)
490 return diskversion, formats[diskversion][0](data, off, stop)
495
491
496
492
497 def encodeheader(version=_fm0version):
493 def encodeheader(version=_fm0version):
498 return _pack(b'>B', version)
494 return _pack(b'>B', version)
499
495
500
496
501 def encodemarkers(markers, addheader=False, version=_fm0version):
497 def encodemarkers(markers, addheader=False, version=_fm0version):
502 # Kept separate from flushmarkers(), it will be reused for
498 # Kept separate from flushmarkers(), it will be reused for
503 # markers exchange.
499 # markers exchange.
504 encodeone = formats[version][1]
500 encodeone = formats[version][1]
505 if addheader:
501 if addheader:
506 yield encodeheader(version)
502 yield encodeheader(version)
507 for marker in markers:
503 for marker in markers:
508 yield encodeone(marker)
504 yield encodeone(marker)
509
505
510
506
511 @util.nogc
507 @util.nogc
512 def _addsuccessors(successors, markers):
508 def _addsuccessors(successors, markers):
513 for mark in markers:
509 for mark in markers:
514 successors.setdefault(mark[0], set()).add(mark)
510 successors.setdefault(mark[0], set()).add(mark)
515
511
516
512
517 @util.nogc
513 @util.nogc
518 def _addpredecessors(predecessors, markers):
514 def _addpredecessors(predecessors, markers):
519 for mark in markers:
515 for mark in markers:
520 for suc in mark[1]:
516 for suc in mark[1]:
521 predecessors.setdefault(suc, set()).add(mark)
517 predecessors.setdefault(suc, set()).add(mark)
522
518
523
519
524 @util.nogc
520 @util.nogc
525 def _addchildren(children, markers):
521 def _addchildren(children, markers):
526 for mark in markers:
522 for mark in markers:
527 parents = mark[5]
523 parents = mark[5]
528 if parents is not None:
524 if parents is not None:
529 for p in parents:
525 for p in parents:
530 children.setdefault(p, set()).add(mark)
526 children.setdefault(p, set()).add(mark)
531
527
532
528
533 def _checkinvalidmarkers(repo, markers):
529 def _checkinvalidmarkers(repo, markers):
534 """search for marker with invalid data and raise error if needed
530 """search for marker with invalid data and raise error if needed
535
531
536 Exist as a separated function to allow the evolve extension for a more
532 Exist as a separated function to allow the evolve extension for a more
537 subtle handling.
533 subtle handling.
538 """
534 """
539 for mark in markers:
535 for mark in markers:
540 if repo.nullid in mark[1]:
536 if repo.nullid in mark[1]:
541 raise error.Abort(
537 raise error.Abort(
542 _(
538 _(
543 b'bad obsolescence marker detected: '
539 b'bad obsolescence marker detected: '
544 b'invalid successors nullid'
540 b'invalid successors nullid'
545 )
541 )
546 )
542 )
547
543
548
544
549 class obsstore(object):
545 class obsstore(object):
550 """Store obsolete markers
546 """Store obsolete markers
551
547
552 Markers can be accessed with two mappings:
548 Markers can be accessed with two mappings:
553 - predecessors[x] -> set(markers on predecessors edges of x)
549 - predecessors[x] -> set(markers on predecessors edges of x)
554 - successors[x] -> set(markers on successors edges of x)
550 - successors[x] -> set(markers on successors edges of x)
555 - children[x] -> set(markers on predecessors edges of children(x)
551 - children[x] -> set(markers on predecessors edges of children(x)
556 """
552 """
557
553
558 fields = (b'prec', b'succs', b'flag', b'meta', b'date', b'parents')
554 fields = (b'prec', b'succs', b'flag', b'meta', b'date', b'parents')
559 # prec: nodeid, predecessors changesets
555 # prec: nodeid, predecessors changesets
560 # succs: tuple of nodeid, successor changesets (0-N length)
556 # succs: tuple of nodeid, successor changesets (0-N length)
561 # flag: integer, flag field carrying modifier for the markers (see doc)
557 # flag: integer, flag field carrying modifier for the markers (see doc)
562 # meta: binary blob in UTF-8, encoded metadata dictionary
558 # meta: binary blob in UTF-8, encoded metadata dictionary
563 # date: (float, int) tuple, date of marker creation
559 # date: (float, int) tuple, date of marker creation
564 # parents: (tuple of nodeid) or None, parents of predecessors
560 # parents: (tuple of nodeid) or None, parents of predecessors
565 # None is used when no data has been recorded
561 # None is used when no data has been recorded
566
562
567 def __init__(self, repo, svfs, defaultformat=_fm1version, readonly=False):
563 def __init__(self, repo, svfs, defaultformat=_fm1version, readonly=False):
568 # caches for various obsolescence related cache
564 # caches for various obsolescence related cache
569 self.caches = {}
565 self.caches = {}
570 self.svfs = svfs
566 self.svfs = svfs
571 self.repo = repo
567 self.repo = repo
572 self._defaultformat = defaultformat
568 self._defaultformat = defaultformat
573 self._readonly = readonly
569 self._readonly = readonly
574
570
575 def __iter__(self):
571 def __iter__(self):
576 return iter(self._all)
572 return iter(self._all)
577
573
578 def __len__(self):
574 def __len__(self):
579 return len(self._all)
575 return len(self._all)
580
576
581 def __nonzero__(self):
577 def __nonzero__(self):
582 if not self._cached('_all'):
578 if not self._cached('_all'):
583 try:
579 try:
584 return self.svfs.stat(b'obsstore').st_size > 1
580 return self.svfs.stat(b'obsstore').st_size > 1
585 except OSError as inst:
581 except OSError as inst:
586 if inst.errno not in (errno.ENOENT, errno.EINVAL):
582 if inst.errno not in (errno.ENOENT, errno.EINVAL):
587 raise
583 raise
588 # just build an empty _all list if no obsstore exists, which
584 # just build an empty _all list if no obsstore exists, which
589 # avoids further stat() syscalls
585 # avoids further stat() syscalls
590 return bool(self._all)
586 return bool(self._all)
591
587
592 __bool__ = __nonzero__
588 __bool__ = __nonzero__
593
589
594 @property
590 @property
595 def readonly(self):
591 def readonly(self):
596 """True if marker creation is disabled
592 """True if marker creation is disabled
597
593
598 Remove me in the future when obsolete marker is always on."""
594 Remove me in the future when obsolete marker is always on."""
599 return self._readonly
595 return self._readonly
600
596
601 def create(
597 def create(
602 self,
598 self,
603 transaction,
599 transaction,
604 prec,
600 prec,
605 succs=(),
601 succs=(),
606 flag=0,
602 flag=0,
607 parents=None,
603 parents=None,
608 date=None,
604 date=None,
609 metadata=None,
605 metadata=None,
610 ui=None,
606 ui=None,
611 ):
607 ):
612 """obsolete: add a new obsolete marker
608 """obsolete: add a new obsolete marker
613
609
614 * ensuring it is hashable
610 * ensuring it is hashable
615 * check mandatory metadata
611 * check mandatory metadata
616 * encode metadata
612 * encode metadata
617
613
618 If you are a human writing code creating marker you want to use the
614 If you are a human writing code creating marker you want to use the
619 `createmarkers` function in this module instead.
615 `createmarkers` function in this module instead.
620
616
621 return True if a new marker have been added, False if the markers
617 return True if a new marker have been added, False if the markers
622 already existed (no op).
618 already existed (no op).
623 """
619 """
624 flag = int(flag)
620 flag = int(flag)
625 if metadata is None:
621 if metadata is None:
626 metadata = {}
622 metadata = {}
627 if date is None:
623 if date is None:
628 if b'date' in metadata:
624 if b'date' in metadata:
629 # as a courtesy for out-of-tree extensions
625 # as a courtesy for out-of-tree extensions
630 date = dateutil.parsedate(metadata.pop(b'date'))
626 date = dateutil.parsedate(metadata.pop(b'date'))
631 elif ui is not None:
627 elif ui is not None:
632 date = ui.configdate(b'devel', b'default-date')
628 date = ui.configdate(b'devel', b'default-date')
633 if date is None:
629 if date is None:
634 date = dateutil.makedate()
630 date = dateutil.makedate()
635 else:
631 else:
636 date = dateutil.makedate()
632 date = dateutil.makedate()
637 if flag & usingsha256:
633 if flag & usingsha256:
638 if len(prec) != 32:
634 if len(prec) != 32:
639 raise ValueError(prec)
635 raise ValueError(prec)
640 for succ in succs:
636 for succ in succs:
641 if len(succ) != 32:
637 if len(succ) != 32:
642 raise ValueError(succ)
638 raise ValueError(succ)
643 else:
639 else:
644 if len(prec) != 20:
640 if len(prec) != 20:
645 raise ValueError(prec)
641 raise ValueError(prec)
646 for succ in succs:
642 for succ in succs:
647 if len(succ) != 20:
643 if len(succ) != 20:
648 raise ValueError(succ)
644 raise ValueError(succ)
649 if prec in succs:
645 if prec in succs:
650 raise ValueError(
646 raise ValueError(
651 'in-marker cycle with %s' % pycompat.sysstr(hex(prec))
647 'in-marker cycle with %s' % pycompat.sysstr(hex(prec))
652 )
648 )
653
649
654 metadata = tuple(sorted(pycompat.iteritems(metadata)))
650 metadata = tuple(sorted(pycompat.iteritems(metadata)))
655 for k, v in metadata:
651 for k, v in metadata:
656 try:
652 try:
657 # might be better to reject non-ASCII keys
653 # might be better to reject non-ASCII keys
658 k.decode('utf-8')
654 k.decode('utf-8')
659 v.decode('utf-8')
655 v.decode('utf-8')
660 except UnicodeDecodeError:
656 except UnicodeDecodeError:
661 raise error.ProgrammingError(
657 raise error.ProgrammingError(
662 b'obsstore metadata must be valid UTF-8 sequence '
658 b'obsstore metadata must be valid UTF-8 sequence '
663 b'(key = %r, value = %r)'
659 b'(key = %r, value = %r)'
664 % (pycompat.bytestr(k), pycompat.bytestr(v))
660 % (pycompat.bytestr(k), pycompat.bytestr(v))
665 )
661 )
666
662
667 marker = (bytes(prec), tuple(succs), flag, metadata, date, parents)
663 marker = (bytes(prec), tuple(succs), flag, metadata, date, parents)
668 return bool(self.add(transaction, [marker]))
664 return bool(self.add(transaction, [marker]))
669
665
670 def add(self, transaction, markers):
666 def add(self, transaction, markers):
671 """Add new markers to the store
667 """Add new markers to the store
672
668
673 Take care of filtering duplicate.
669 Take care of filtering duplicate.
674 Return the number of new marker."""
670 Return the number of new marker."""
675 if self._readonly:
671 if self._readonly:
676 raise error.Abort(
672 raise error.Abort(
677 _(b'creating obsolete markers is not enabled on this repo')
673 _(b'creating obsolete markers is not enabled on this repo')
678 )
674 )
679 known = set()
675 known = set()
680 getsuccessors = self.successors.get
676 getsuccessors = self.successors.get
681 new = []
677 new = []
682 for m in markers:
678 for m in markers:
683 if m not in getsuccessors(m[0], ()) and m not in known:
679 if m not in getsuccessors(m[0], ()) and m not in known:
684 known.add(m)
680 known.add(m)
685 new.append(m)
681 new.append(m)
686 if new:
682 if new:
687 f = self.svfs(b'obsstore', b'ab')
683 f = self.svfs(b'obsstore', b'ab')
688 try:
684 try:
689 offset = f.tell()
685 offset = f.tell()
690 transaction.add(b'obsstore', offset)
686 transaction.add(b'obsstore', offset)
691 # offset == 0: new file - add the version header
687 # offset == 0: new file - add the version header
692 data = b''.join(encodemarkers(new, offset == 0, self._version))
688 data = b''.join(encodemarkers(new, offset == 0, self._version))
693 f.write(data)
689 f.write(data)
694 finally:
690 finally:
695 # XXX: f.close() == filecache invalidation == obsstore rebuilt.
691 # XXX: f.close() == filecache invalidation == obsstore rebuilt.
696 # call 'filecacheentry.refresh()' here
692 # call 'filecacheentry.refresh()' here
697 f.close()
693 f.close()
698 addedmarkers = transaction.changes.get(b'obsmarkers')
694 addedmarkers = transaction.changes.get(b'obsmarkers')
699 if addedmarkers is not None:
695 if addedmarkers is not None:
700 addedmarkers.update(new)
696 addedmarkers.update(new)
701 self._addmarkers(new, data)
697 self._addmarkers(new, data)
702 # new marker *may* have changed several set. invalidate the cache.
698 # new marker *may* have changed several set. invalidate the cache.
703 self.caches.clear()
699 self.caches.clear()
704 # records the number of new markers for the transaction hooks
700 # records the number of new markers for the transaction hooks
705 previous = int(transaction.hookargs.get(b'new_obsmarkers', b'0'))
701 previous = int(transaction.hookargs.get(b'new_obsmarkers', b'0'))
706 transaction.hookargs[b'new_obsmarkers'] = b'%d' % (previous + len(new))
702 transaction.hookargs[b'new_obsmarkers'] = b'%d' % (previous + len(new))
707 return len(new)
703 return len(new)
708
704
709 def mergemarkers(self, transaction, data):
705 def mergemarkers(self, transaction, data):
710 """merge a binary stream of markers inside the obsstore
706 """merge a binary stream of markers inside the obsstore
711
707
712 Returns the number of new markers added."""
708 Returns the number of new markers added."""
713 version, markers = _readmarkers(data)
709 version, markers = _readmarkers(data)
714 return self.add(transaction, markers)
710 return self.add(transaction, markers)
715
711
716 @propertycache
712 @propertycache
717 def _data(self):
713 def _data(self):
718 return self.svfs.tryread(b'obsstore')
714 return self.svfs.tryread(b'obsstore')
719
715
720 @propertycache
716 @propertycache
721 def _version(self):
717 def _version(self):
722 if len(self._data) >= 1:
718 if len(self._data) >= 1:
723 return _readmarkerversion(self._data)
719 return _readmarkerversion(self._data)
724 else:
720 else:
725 return self._defaultformat
721 return self._defaultformat
726
722
727 @propertycache
723 @propertycache
728 def _all(self):
724 def _all(self):
729 data = self._data
725 data = self._data
730 if not data:
726 if not data:
731 return []
727 return []
732 self._version, markers = _readmarkers(data)
728 self._version, markers = _readmarkers(data)
733 markers = list(markers)
729 markers = list(markers)
734 _checkinvalidmarkers(self.repo, markers)
730 _checkinvalidmarkers(self.repo, markers)
735 return markers
731 return markers
736
732
737 @propertycache
733 @propertycache
738 def successors(self):
734 def successors(self):
739 successors = {}
735 successors = {}
740 _addsuccessors(successors, self._all)
736 _addsuccessors(successors, self._all)
741 return successors
737 return successors
742
738
743 @propertycache
739 @propertycache
744 def predecessors(self):
740 def predecessors(self):
745 predecessors = {}
741 predecessors = {}
746 _addpredecessors(predecessors, self._all)
742 _addpredecessors(predecessors, self._all)
747 return predecessors
743 return predecessors
748
744
749 @propertycache
745 @propertycache
750 def children(self):
746 def children(self):
751 children = {}
747 children = {}
752 _addchildren(children, self._all)
748 _addchildren(children, self._all)
753 return children
749 return children
754
750
755 def _cached(self, attr):
751 def _cached(self, attr):
756 return attr in self.__dict__
752 return attr in self.__dict__
757
753
758 def _addmarkers(self, markers, rawdata):
754 def _addmarkers(self, markers, rawdata):
759 markers = list(markers) # to allow repeated iteration
755 markers = list(markers) # to allow repeated iteration
760 self._data = self._data + rawdata
756 self._data = self._data + rawdata
761 self._all.extend(markers)
757 self._all.extend(markers)
762 if self._cached('successors'):
758 if self._cached('successors'):
763 _addsuccessors(self.successors, markers)
759 _addsuccessors(self.successors, markers)
764 if self._cached('predecessors'):
760 if self._cached('predecessors'):
765 _addpredecessors(self.predecessors, markers)
761 _addpredecessors(self.predecessors, markers)
766 if self._cached('children'):
762 if self._cached('children'):
767 _addchildren(self.children, markers)
763 _addchildren(self.children, markers)
768 _checkinvalidmarkers(self.repo, markers)
764 _checkinvalidmarkers(self.repo, markers)
769
765
770 def relevantmarkers(self, nodes):
766 def relevantmarkers(self, nodes):
771 """return a set of all obsolescence markers relevant to a set of nodes.
767 """return a set of all obsolescence markers relevant to a set of nodes.
772
768
773 "relevant" to a set of nodes mean:
769 "relevant" to a set of nodes mean:
774
770
775 - marker that use this changeset as successor
771 - marker that use this changeset as successor
776 - prune marker of direct children on this changeset
772 - prune marker of direct children on this changeset
777 - recursive application of the two rules on predecessors of these
773 - recursive application of the two rules on predecessors of these
778 markers
774 markers
779
775
780 It is a set so you cannot rely on order."""
776 It is a set so you cannot rely on order."""
781
777
782 pendingnodes = set(nodes)
778 pendingnodes = set(nodes)
783 seenmarkers = set()
779 seenmarkers = set()
784 seennodes = set(pendingnodes)
780 seennodes = set(pendingnodes)
785 precursorsmarkers = self.predecessors
781 precursorsmarkers = self.predecessors
786 succsmarkers = self.successors
782 succsmarkers = self.successors
787 children = self.children
783 children = self.children
788 while pendingnodes:
784 while pendingnodes:
789 direct = set()
785 direct = set()
790 for current in pendingnodes:
786 for current in pendingnodes:
791 direct.update(precursorsmarkers.get(current, ()))
787 direct.update(precursorsmarkers.get(current, ()))
792 pruned = [m for m in children.get(current, ()) if not m[1]]
788 pruned = [m for m in children.get(current, ()) if not m[1]]
793 direct.update(pruned)
789 direct.update(pruned)
794 pruned = [m for m in succsmarkers.get(current, ()) if not m[1]]
790 pruned = [m for m in succsmarkers.get(current, ()) if not m[1]]
795 direct.update(pruned)
791 direct.update(pruned)
796 direct -= seenmarkers
792 direct -= seenmarkers
797 pendingnodes = {m[0] for m in direct}
793 pendingnodes = {m[0] for m in direct}
798 seenmarkers |= direct
794 seenmarkers |= direct
799 pendingnodes -= seennodes
795 pendingnodes -= seennodes
800 seennodes |= pendingnodes
796 seennodes |= pendingnodes
801 return seenmarkers
797 return seenmarkers
802
798
803
799
804 def makestore(ui, repo):
800 def makestore(ui, repo):
805 """Create an obsstore instance from a repo."""
801 """Create an obsstore instance from a repo."""
806 # read default format for new obsstore.
802 # read default format for new obsstore.
807 # developer config: format.obsstore-version
803 # developer config: format.obsstore-version
808 defaultformat = ui.configint(b'format', b'obsstore-version')
804 defaultformat = ui.configint(b'format', b'obsstore-version')
809 # rely on obsstore class default when possible.
805 # rely on obsstore class default when possible.
810 kwargs = {}
806 kwargs = {}
811 if defaultformat is not None:
807 if defaultformat is not None:
812 kwargs['defaultformat'] = defaultformat
808 kwargs['defaultformat'] = defaultformat
813 readonly = not isenabled(repo, createmarkersopt)
809 readonly = not isenabled(repo, createmarkersopt)
814 store = obsstore(repo, repo.svfs, readonly=readonly, **kwargs)
810 store = obsstore(repo, repo.svfs, readonly=readonly, **kwargs)
815 if store and readonly:
811 if store and readonly:
816 ui.warn(
812 ui.warn(
817 _(b'obsolete feature not enabled but %i markers found!\n')
813 _(b'obsolete feature not enabled but %i markers found!\n')
818 % len(list(store))
814 % len(list(store))
819 )
815 )
820 return store
816 return store
821
817
822
818
823 def commonversion(versions):
819 def commonversion(versions):
824 """Return the newest version listed in both versions and our local formats.
820 """Return the newest version listed in both versions and our local formats.
825
821
826 Returns None if no common version exists.
822 Returns None if no common version exists.
827 """
823 """
828 versions.sort(reverse=True)
824 versions.sort(reverse=True)
829 # search for highest version known on both side
825 # search for highest version known on both side
830 for v in versions:
826 for v in versions:
831 if v in formats:
827 if v in formats:
832 return v
828 return v
833 return None
829 return None
834
830
835
831
836 # arbitrary picked to fit into 8K limit from HTTP server
832 # arbitrary picked to fit into 8K limit from HTTP server
837 # you have to take in account:
833 # you have to take in account:
838 # - the version header
834 # - the version header
839 # - the base85 encoding
835 # - the base85 encoding
840 _maxpayload = 5300
836 _maxpayload = 5300
841
837
842
838
843 def _pushkeyescape(markers):
839 def _pushkeyescape(markers):
844 """encode markers into a dict suitable for pushkey exchange
840 """encode markers into a dict suitable for pushkey exchange
845
841
846 - binary data is base85 encoded
842 - binary data is base85 encoded
847 - split in chunks smaller than 5300 bytes"""
843 - split in chunks smaller than 5300 bytes"""
848 keys = {}
844 keys = {}
849 parts = []
845 parts = []
850 currentlen = _maxpayload * 2 # ensure we create a new part
846 currentlen = _maxpayload * 2 # ensure we create a new part
851 for marker in markers:
847 for marker in markers:
852 nextdata = _fm0encodeonemarker(marker)
848 nextdata = _fm0encodeonemarker(marker)
853 if len(nextdata) + currentlen > _maxpayload:
849 if len(nextdata) + currentlen > _maxpayload:
854 currentpart = []
850 currentpart = []
855 currentlen = 0
851 currentlen = 0
856 parts.append(currentpart)
852 parts.append(currentpart)
857 currentpart.append(nextdata)
853 currentpart.append(nextdata)
858 currentlen += len(nextdata)
854 currentlen += len(nextdata)
859 for idx, part in enumerate(reversed(parts)):
855 for idx, part in enumerate(reversed(parts)):
860 data = b''.join([_pack(b'>B', _fm0version)] + part)
856 data = b''.join([_pack(b'>B', _fm0version)] + part)
861 keys[b'dump%i' % idx] = util.b85encode(data)
857 keys[b'dump%i' % idx] = util.b85encode(data)
862 return keys
858 return keys
863
859
864
860
865 def listmarkers(repo):
861 def listmarkers(repo):
866 """List markers over pushkey"""
862 """List markers over pushkey"""
867 if not repo.obsstore:
863 if not repo.obsstore:
868 return {}
864 return {}
869 return _pushkeyescape(sorted(repo.obsstore))
865 return _pushkeyescape(sorted(repo.obsstore))
870
866
871
867
872 def pushmarker(repo, key, old, new):
868 def pushmarker(repo, key, old, new):
873 """Push markers over pushkey"""
869 """Push markers over pushkey"""
874 if not key.startswith(b'dump'):
870 if not key.startswith(b'dump'):
875 repo.ui.warn(_(b'unknown key: %r') % key)
871 repo.ui.warn(_(b'unknown key: %r') % key)
876 return False
872 return False
877 if old:
873 if old:
878 repo.ui.warn(_(b'unexpected old value for %r') % key)
874 repo.ui.warn(_(b'unexpected old value for %r') % key)
879 return False
875 return False
880 data = util.b85decode(new)
876 data = util.b85decode(new)
881 with repo.lock(), repo.transaction(b'pushkey: obsolete markers') as tr:
877 with repo.lock(), repo.transaction(b'pushkey: obsolete markers') as tr:
882 repo.obsstore.mergemarkers(tr, data)
878 repo.obsstore.mergemarkers(tr, data)
883 repo.invalidatevolatilesets()
879 repo.invalidatevolatilesets()
884 return True
880 return True
885
881
886
882
887 # mapping of 'set-name' -> <function to compute this set>
883 # mapping of 'set-name' -> <function to compute this set>
888 cachefuncs = {}
884 cachefuncs = {}
889
885
890
886
891 def cachefor(name):
887 def cachefor(name):
892 """Decorator to register a function as computing the cache for a set"""
888 """Decorator to register a function as computing the cache for a set"""
893
889
894 def decorator(func):
890 def decorator(func):
895 if name in cachefuncs:
891 if name in cachefuncs:
896 msg = b"duplicated registration for volatileset '%s' (existing: %r)"
892 msg = b"duplicated registration for volatileset '%s' (existing: %r)"
897 raise error.ProgrammingError(msg % (name, cachefuncs[name]))
893 raise error.ProgrammingError(msg % (name, cachefuncs[name]))
898 cachefuncs[name] = func
894 cachefuncs[name] = func
899 return func
895 return func
900
896
901 return decorator
897 return decorator
902
898
903
899
904 def getrevs(repo, name):
900 def getrevs(repo, name):
905 """Return the set of revision that belong to the <name> set
901 """Return the set of revision that belong to the <name> set
906
902
907 Such access may compute the set and cache it for future use"""
903 Such access may compute the set and cache it for future use"""
908 repo = repo.unfiltered()
904 repo = repo.unfiltered()
909 with util.timedcm('getrevs %s', name):
905 with util.timedcm('getrevs %s', name):
910 if not repo.obsstore:
906 if not repo.obsstore:
911 return frozenset()
907 return frozenset()
912 if name not in repo.obsstore.caches:
908 if name not in repo.obsstore.caches:
913 repo.obsstore.caches[name] = cachefuncs[name](repo)
909 repo.obsstore.caches[name] = cachefuncs[name](repo)
914 return repo.obsstore.caches[name]
910 return repo.obsstore.caches[name]
915
911
916
912
917 # To be simple we need to invalidate obsolescence cache when:
913 # To be simple we need to invalidate obsolescence cache when:
918 #
914 #
919 # - new changeset is added:
915 # - new changeset is added:
920 # - public phase is changed
916 # - public phase is changed
921 # - obsolescence marker are added
917 # - obsolescence marker are added
922 # - strip is used a repo
918 # - strip is used a repo
923 def clearobscaches(repo):
919 def clearobscaches(repo):
924 """Remove all obsolescence related cache from a repo
920 """Remove all obsolescence related cache from a repo
925
921
926 This remove all cache in obsstore is the obsstore already exist on the
922 This remove all cache in obsstore is the obsstore already exist on the
927 repo.
923 repo.
928
924
929 (We could be smarter here given the exact event that trigger the cache
925 (We could be smarter here given the exact event that trigger the cache
930 clearing)"""
926 clearing)"""
931 # only clear cache is there is obsstore data in this repo
927 # only clear cache is there is obsstore data in this repo
932 if b'obsstore' in repo._filecache:
928 if b'obsstore' in repo._filecache:
933 repo.obsstore.caches.clear()
929 repo.obsstore.caches.clear()
934
930
935
931
936 def _mutablerevs(repo):
932 def _mutablerevs(repo):
937 """the set of mutable revision in the repository"""
933 """the set of mutable revision in the repository"""
938 return repo._phasecache.getrevset(repo, phases.mutablephases)
934 return repo._phasecache.getrevset(repo, phases.mutablephases)
939
935
940
936
941 @cachefor(b'obsolete')
937 @cachefor(b'obsolete')
942 def _computeobsoleteset(repo):
938 def _computeobsoleteset(repo):
943 """the set of obsolete revisions"""
939 """the set of obsolete revisions"""
944 getnode = repo.changelog.node
940 getnode = repo.changelog.node
945 notpublic = _mutablerevs(repo)
941 notpublic = _mutablerevs(repo)
946 isobs = repo.obsstore.successors.__contains__
942 isobs = repo.obsstore.successors.__contains__
947 obs = {r for r in notpublic if isobs(getnode(r))}
943 obs = {r for r in notpublic if isobs(getnode(r))}
948 return obs
944 return obs
949
945
950
946
951 @cachefor(b'orphan')
947 @cachefor(b'orphan')
952 def _computeorphanset(repo):
948 def _computeorphanset(repo):
953 """the set of non obsolete revisions with obsolete parents"""
949 """the set of non obsolete revisions with obsolete parents"""
954 pfunc = repo.changelog.parentrevs
950 pfunc = repo.changelog.parentrevs
955 mutable = _mutablerevs(repo)
951 mutable = _mutablerevs(repo)
956 obsolete = getrevs(repo, b'obsolete')
952 obsolete = getrevs(repo, b'obsolete')
957 others = mutable - obsolete
953 others = mutable - obsolete
958 unstable = set()
954 unstable = set()
959 for r in sorted(others):
955 for r in sorted(others):
960 # A rev is unstable if one of its parent is obsolete or unstable
956 # A rev is unstable if one of its parent is obsolete or unstable
961 # this works since we traverse following growing rev order
957 # this works since we traverse following growing rev order
962 for p in pfunc(r):
958 for p in pfunc(r):
963 if p in obsolete or p in unstable:
959 if p in obsolete or p in unstable:
964 unstable.add(r)
960 unstable.add(r)
965 break
961 break
966 return unstable
962 return unstable
967
963
968
964
969 @cachefor(b'suspended')
965 @cachefor(b'suspended')
970 def _computesuspendedset(repo):
966 def _computesuspendedset(repo):
971 """the set of obsolete parents with non obsolete descendants"""
967 """the set of obsolete parents with non obsolete descendants"""
972 suspended = repo.changelog.ancestors(getrevs(repo, b'orphan'))
968 suspended = repo.changelog.ancestors(getrevs(repo, b'orphan'))
973 return {r for r in getrevs(repo, b'obsolete') if r in suspended}
969 return {r for r in getrevs(repo, b'obsolete') if r in suspended}
974
970
975
971
976 @cachefor(b'extinct')
972 @cachefor(b'extinct')
977 def _computeextinctset(repo):
973 def _computeextinctset(repo):
978 """the set of obsolete parents without non obsolete descendants"""
974 """the set of obsolete parents without non obsolete descendants"""
979 return getrevs(repo, b'obsolete') - getrevs(repo, b'suspended')
975 return getrevs(repo, b'obsolete') - getrevs(repo, b'suspended')
980
976
981
977
982 @cachefor(b'phasedivergent')
978 @cachefor(b'phasedivergent')
983 def _computephasedivergentset(repo):
979 def _computephasedivergentset(repo):
984 """the set of revs trying to obsolete public revisions"""
980 """the set of revs trying to obsolete public revisions"""
985 bumped = set()
981 bumped = set()
986 # util function (avoid attribute lookup in the loop)
982 # util function (avoid attribute lookup in the loop)
987 phase = repo._phasecache.phase # would be faster to grab the full list
983 phase = repo._phasecache.phase # would be faster to grab the full list
988 public = phases.public
984 public = phases.public
989 cl = repo.changelog
985 cl = repo.changelog
990 torev = cl.index.get_rev
986 torev = cl.index.get_rev
991 tonode = cl.node
987 tonode = cl.node
992 obsstore = repo.obsstore
988 obsstore = repo.obsstore
993 for rev in repo.revs(b'(not public()) and (not obsolete())'):
989 for rev in repo.revs(b'(not public()) and (not obsolete())'):
994 # We only evaluate mutable, non-obsolete revision
990 # We only evaluate mutable, non-obsolete revision
995 node = tonode(rev)
991 node = tonode(rev)
996 # (future) A cache of predecessors may worth if split is very common
992 # (future) A cache of predecessors may worth if split is very common
997 for pnode in obsutil.allpredecessors(
993 for pnode in obsutil.allpredecessors(
998 obsstore, [node], ignoreflags=bumpedfix
994 obsstore, [node], ignoreflags=bumpedfix
999 ):
995 ):
1000 prev = torev(pnode) # unfiltered! but so is phasecache
996 prev = torev(pnode) # unfiltered! but so is phasecache
1001 if (prev is not None) and (phase(repo, prev) <= public):
997 if (prev is not None) and (phase(repo, prev) <= public):
1002 # we have a public predecessor
998 # we have a public predecessor
1003 bumped.add(rev)
999 bumped.add(rev)
1004 break # Next draft!
1000 break # Next draft!
1005 return bumped
1001 return bumped
1006
1002
1007
1003
1008 @cachefor(b'contentdivergent')
1004 @cachefor(b'contentdivergent')
1009 def _computecontentdivergentset(repo):
1005 def _computecontentdivergentset(repo):
1010 """the set of rev that compete to be the final successors of some revision."""
1006 """the set of rev that compete to be the final successors of some revision."""
1011 divergent = set()
1007 divergent = set()
1012 obsstore = repo.obsstore
1008 obsstore = repo.obsstore
1013 newermap = {}
1009 newermap = {}
1014 tonode = repo.changelog.node
1010 tonode = repo.changelog.node
1015 for rev in repo.revs(b'(not public()) - obsolete()'):
1011 for rev in repo.revs(b'(not public()) - obsolete()'):
1016 node = tonode(rev)
1012 node = tonode(rev)
1017 mark = obsstore.predecessors.get(node, ())
1013 mark = obsstore.predecessors.get(node, ())
1018 toprocess = set(mark)
1014 toprocess = set(mark)
1019 seen = set()
1015 seen = set()
1020 while toprocess:
1016 while toprocess:
1021 prec = toprocess.pop()[0]
1017 prec = toprocess.pop()[0]
1022 if prec in seen:
1018 if prec in seen:
1023 continue # emergency cycle hanging prevention
1019 continue # emergency cycle hanging prevention
1024 seen.add(prec)
1020 seen.add(prec)
1025 if prec not in newermap:
1021 if prec not in newermap:
1026 obsutil.successorssets(repo, prec, cache=newermap)
1022 obsutil.successorssets(repo, prec, cache=newermap)
1027 newer = [n for n in newermap[prec] if n]
1023 newer = [n for n in newermap[prec] if n]
1028 if len(newer) > 1:
1024 if len(newer) > 1:
1029 divergent.add(rev)
1025 divergent.add(rev)
1030 break
1026 break
1031 toprocess.update(obsstore.predecessors.get(prec, ()))
1027 toprocess.update(obsstore.predecessors.get(prec, ()))
1032 return divergent
1028 return divergent
1033
1029
1034
1030
1035 def makefoldid(relation, user):
1031 def makefoldid(relation, user):
1036
1032
1037 folddigest = hashutil.sha1(user)
1033 folddigest = hashutil.sha1(user)
1038 for p in relation[0] + relation[1]:
1034 for p in relation[0] + relation[1]:
1039 folddigest.update(b'%d' % p.rev())
1035 folddigest.update(b'%d' % p.rev())
1040 folddigest.update(p.node())
1036 folddigest.update(p.node())
1041 # Since fold only has to compete against fold for the same successors, it
1037 # Since fold only has to compete against fold for the same successors, it
1042 # seems fine to use a small ID. Smaller ID save space.
1038 # seems fine to use a small ID. Smaller ID save space.
1043 return hex(folddigest.digest())[:8]
1039 return hex(folddigest.digest())[:8]
1044
1040
1045
1041
1046 def createmarkers(
1042 def createmarkers(
1047 repo, relations, flag=0, date=None, metadata=None, operation=None
1043 repo, relations, flag=0, date=None, metadata=None, operation=None
1048 ):
1044 ):
1049 """Add obsolete markers between changesets in a repo
1045 """Add obsolete markers between changesets in a repo
1050
1046
1051 <relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
1047 <relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
1052 tuple. `old` and `news` are changectx. metadata is an optional dictionary
1048 tuple. `old` and `news` are changectx. metadata is an optional dictionary
1053 containing metadata for this marker only. It is merged with the global
1049 containing metadata for this marker only. It is merged with the global
1054 metadata specified through the `metadata` argument of this function.
1050 metadata specified through the `metadata` argument of this function.
1055 Any string values in metadata must be UTF-8 bytes.
1051 Any string values in metadata must be UTF-8 bytes.
1056
1052
1057 Trying to obsolete a public changeset will raise an exception.
1053 Trying to obsolete a public changeset will raise an exception.
1058
1054
1059 Current user and date are used except if specified otherwise in the
1055 Current user and date are used except if specified otherwise in the
1060 metadata attribute.
1056 metadata attribute.
1061
1057
1062 This function operates within a transaction of its own, but does
1058 This function operates within a transaction of its own, but does
1063 not take any lock on the repo.
1059 not take any lock on the repo.
1064 """
1060 """
1065 # prepare metadata
1061 # prepare metadata
1066 if metadata is None:
1062 if metadata is None:
1067 metadata = {}
1063 metadata = {}
1068 if b'user' not in metadata:
1064 if b'user' not in metadata:
1069 luser = (
1065 luser = (
1070 repo.ui.config(b'devel', b'user.obsmarker') or repo.ui.username()
1066 repo.ui.config(b'devel', b'user.obsmarker') or repo.ui.username()
1071 )
1067 )
1072 metadata[b'user'] = encoding.fromlocal(luser)
1068 metadata[b'user'] = encoding.fromlocal(luser)
1073
1069
1074 # Operation metadata handling
1070 # Operation metadata handling
1075 useoperation = repo.ui.configbool(
1071 useoperation = repo.ui.configbool(
1076 b'experimental', b'evolution.track-operation'
1072 b'experimental', b'evolution.track-operation'
1077 )
1073 )
1078 if useoperation and operation:
1074 if useoperation and operation:
1079 metadata[b'operation'] = operation
1075 metadata[b'operation'] = operation
1080
1076
1081 # Effect flag metadata handling
1077 # Effect flag metadata handling
1082 saveeffectflag = repo.ui.configbool(
1078 saveeffectflag = repo.ui.configbool(
1083 b'experimental', b'evolution.effect-flags'
1079 b'experimental', b'evolution.effect-flags'
1084 )
1080 )
1085
1081
1086 with repo.transaction(b'add-obsolescence-marker') as tr:
1082 with repo.transaction(b'add-obsolescence-marker') as tr:
1087 markerargs = []
1083 markerargs = []
1088 for rel in relations:
1084 for rel in relations:
1089 predecessors = rel[0]
1085 predecessors = rel[0]
1090 if not isinstance(predecessors, tuple):
1086 if not isinstance(predecessors, tuple):
1091 # preserve compat with old API until all caller are migrated
1087 # preserve compat with old API until all caller are migrated
1092 predecessors = (predecessors,)
1088 predecessors = (predecessors,)
1093 if len(predecessors) > 1 and len(rel[1]) != 1:
1089 if len(predecessors) > 1 and len(rel[1]) != 1:
1094 msg = b'Fold markers can only have 1 successors, not %d'
1090 msg = b'Fold markers can only have 1 successors, not %d'
1095 raise error.ProgrammingError(msg % len(rel[1]))
1091 raise error.ProgrammingError(msg % len(rel[1]))
1096 foldid = None
1092 foldid = None
1097 foldsize = len(predecessors)
1093 foldsize = len(predecessors)
1098 if 1 < foldsize:
1094 if 1 < foldsize:
1099 foldid = makefoldid(rel, metadata[b'user'])
1095 foldid = makefoldid(rel, metadata[b'user'])
1100 for foldidx, prec in enumerate(predecessors, 1):
1096 for foldidx, prec in enumerate(predecessors, 1):
1101 sucs = rel[1]
1097 sucs = rel[1]
1102 localmetadata = metadata.copy()
1098 localmetadata = metadata.copy()
1103 if len(rel) > 2:
1099 if len(rel) > 2:
1104 localmetadata.update(rel[2])
1100 localmetadata.update(rel[2])
1105 if foldid is not None:
1101 if foldid is not None:
1106 localmetadata[b'fold-id'] = foldid
1102 localmetadata[b'fold-id'] = foldid
1107 localmetadata[b'fold-idx'] = b'%d' % foldidx
1103 localmetadata[b'fold-idx'] = b'%d' % foldidx
1108 localmetadata[b'fold-size'] = b'%d' % foldsize
1104 localmetadata[b'fold-size'] = b'%d' % foldsize
1109
1105
1110 if not prec.mutable():
1106 if not prec.mutable():
1111 raise error.Abort(
1107 raise error.Abort(
1112 _(b"cannot obsolete public changeset: %s") % prec,
1108 _(b"cannot obsolete public changeset: %s") % prec,
1113 hint=b"see 'hg help phases' for details",
1109 hint=b"see 'hg help phases' for details",
1114 )
1110 )
1115 nprec = prec.node()
1111 nprec = prec.node()
1116 nsucs = tuple(s.node() for s in sucs)
1112 nsucs = tuple(s.node() for s in sucs)
1117 npare = None
1113 npare = None
1118 if not nsucs:
1114 if not nsucs:
1119 npare = tuple(p.node() for p in prec.parents())
1115 npare = tuple(p.node() for p in prec.parents())
1120 if nprec in nsucs:
1116 if nprec in nsucs:
1121 raise error.Abort(
1117 raise error.Abort(
1122 _(b"changeset %s cannot obsolete itself") % prec
1118 _(b"changeset %s cannot obsolete itself") % prec
1123 )
1119 )
1124
1120
1125 # Effect flag can be different by relation
1121 # Effect flag can be different by relation
1126 if saveeffectflag:
1122 if saveeffectflag:
1127 # The effect flag is saved in a versioned field name for
1123 # The effect flag is saved in a versioned field name for
1128 # future evolution
1124 # future evolution
1129 effectflag = obsutil.geteffectflag(prec, sucs)
1125 effectflag = obsutil.geteffectflag(prec, sucs)
1130 localmetadata[obsutil.EFFECTFLAGFIELD] = b"%d" % effectflag
1126 localmetadata[obsutil.EFFECTFLAGFIELD] = b"%d" % effectflag
1131
1127
1132 # Creating the marker causes the hidden cache to become
1128 # Creating the marker causes the hidden cache to become
1133 # invalid, which causes recomputation when we ask for
1129 # invalid, which causes recomputation when we ask for
1134 # prec.parents() above. Resulting in n^2 behavior. So let's
1130 # prec.parents() above. Resulting in n^2 behavior. So let's
1135 # prepare all of the args first, then create the markers.
1131 # prepare all of the args first, then create the markers.
1136 markerargs.append((nprec, nsucs, npare, localmetadata))
1132 markerargs.append((nprec, nsucs, npare, localmetadata))
1137
1133
1138 for args in markerargs:
1134 for args in markerargs:
1139 nprec, nsucs, npare, localmetadata = args
1135 nprec, nsucs, npare, localmetadata = args
1140 repo.obsstore.create(
1136 repo.obsstore.create(
1141 tr,
1137 tr,
1142 nprec,
1138 nprec,
1143 nsucs,
1139 nsucs,
1144 flag,
1140 flag,
1145 parents=npare,
1141 parents=npare,
1146 date=date,
1142 date=date,
1147 metadata=localmetadata,
1143 metadata=localmetadata,
1148 ui=repo.ui,
1144 ui=repo.ui,
1149 )
1145 )
1150 repo.filteredrevcache.clear()
1146 repo.filteredrevcache.clear()
General Comments 0
You need to be logged in to leave comments. Login now