Show More
@@ -1,2248 +1,2250 b'' | |||
|
1 | 1 | # debugcommands.py - command processing for debug* commands |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2016 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import difflib |
|
11 | 11 | import errno |
|
12 | 12 | import operator |
|
13 | 13 | import os |
|
14 | 14 | import random |
|
15 | 15 | import socket |
|
16 | 16 | import string |
|
17 | 17 | import sys |
|
18 | 18 | import tempfile |
|
19 | 19 | import time |
|
20 | 20 | |
|
21 | 21 | from .i18n import _ |
|
22 | 22 | from .node import ( |
|
23 | 23 | bin, |
|
24 | 24 | hex, |
|
25 | 25 | nullhex, |
|
26 | 26 | nullid, |
|
27 | 27 | nullrev, |
|
28 | 28 | short, |
|
29 | 29 | ) |
|
30 | 30 | from . import ( |
|
31 | 31 | bundle2, |
|
32 | 32 | changegroup, |
|
33 | 33 | cmdutil, |
|
34 | 34 | color, |
|
35 | 35 | context, |
|
36 | 36 | dagparser, |
|
37 | 37 | dagutil, |
|
38 | 38 | encoding, |
|
39 | 39 | error, |
|
40 | 40 | exchange, |
|
41 | 41 | extensions, |
|
42 | 42 | filemerge, |
|
43 | 43 | fileset, |
|
44 | 44 | formatter, |
|
45 | 45 | hg, |
|
46 | 46 | localrepo, |
|
47 | 47 | lock as lockmod, |
|
48 | 48 | merge as mergemod, |
|
49 | 49 | obsolete, |
|
50 | 50 | obsutil, |
|
51 | 51 | phases, |
|
52 | 52 | policy, |
|
53 | 53 | pvec, |
|
54 | 54 | pycompat, |
|
55 | 55 | registrar, |
|
56 | 56 | repair, |
|
57 | 57 | revlog, |
|
58 | 58 | revset, |
|
59 | 59 | revsetlang, |
|
60 | 60 | scmutil, |
|
61 | 61 | setdiscovery, |
|
62 | 62 | simplemerge, |
|
63 | 63 | smartset, |
|
64 | 64 | sslutil, |
|
65 | 65 | streamclone, |
|
66 | 66 | templater, |
|
67 | 67 | treediscovery, |
|
68 | 68 | upgrade, |
|
69 | 69 | util, |
|
70 | 70 | vfs as vfsmod, |
|
71 | 71 | ) |
|
72 | 72 | |
|
73 | 73 | release = lockmod.release |
|
74 | 74 | |
|
75 | 75 | command = registrar.command() |
|
76 | 76 | |
|
77 | 77 | @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True) |
|
78 | 78 | def debugancestor(ui, repo, *args): |
|
79 | 79 | """find the ancestor revision of two revisions in a given index""" |
|
80 | 80 | if len(args) == 3: |
|
81 | 81 | index, rev1, rev2 = args |
|
82 | 82 | r = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False), index) |
|
83 | 83 | lookup = r.lookup |
|
84 | 84 | elif len(args) == 2: |
|
85 | 85 | if not repo: |
|
86 | 86 | raise error.Abort(_('there is no Mercurial repository here ' |
|
87 | 87 | '(.hg not found)')) |
|
88 | 88 | rev1, rev2 = args |
|
89 | 89 | r = repo.changelog |
|
90 | 90 | lookup = repo.lookup |
|
91 | 91 | else: |
|
92 | 92 | raise error.Abort(_('either two or three arguments required')) |
|
93 | 93 | a = r.ancestor(lookup(rev1), lookup(rev2)) |
|
94 | 94 | ui.write('%d:%s\n' % (r.rev(a), hex(a))) |
|
95 | 95 | |
|
96 | 96 | @command('debugapplystreamclonebundle', [], 'FILE') |
|
97 | 97 | def debugapplystreamclonebundle(ui, repo, fname): |
|
98 | 98 | """apply a stream clone bundle file""" |
|
99 | 99 | f = hg.openpath(ui, fname) |
|
100 | 100 | gen = exchange.readbundle(ui, f, fname) |
|
101 | 101 | gen.apply(repo) |
|
102 | 102 | |
|
103 | 103 | @command('debugbuilddag', |
|
104 | 104 | [('m', 'mergeable-file', None, _('add single file mergeable changes')), |
|
105 | 105 | ('o', 'overwritten-file', None, _('add single file all revs overwrite')), |
|
106 | 106 | ('n', 'new-file', None, _('add new file at each rev'))], |
|
107 | 107 | _('[OPTION]... [TEXT]')) |
|
108 | 108 | def debugbuilddag(ui, repo, text=None, |
|
109 | 109 | mergeable_file=False, |
|
110 | 110 | overwritten_file=False, |
|
111 | 111 | new_file=False): |
|
112 | 112 | """builds a repo with a given DAG from scratch in the current empty repo |
|
113 | 113 | |
|
114 | 114 | The description of the DAG is read from stdin if not given on the |
|
115 | 115 | command line. |
|
116 | 116 | |
|
117 | 117 | Elements: |
|
118 | 118 | |
|
119 | 119 | - "+n" is a linear run of n nodes based on the current default parent |
|
120 | 120 | - "." is a single node based on the current default parent |
|
121 | 121 | - "$" resets the default parent to null (implied at the start); |
|
122 | 122 | otherwise the default parent is always the last node created |
|
123 | 123 | - "<p" sets the default parent to the backref p |
|
124 | 124 | - "*p" is a fork at parent p, which is a backref |
|
125 | 125 | - "*p1/p2" is a merge of parents p1 and p2, which are backrefs |
|
126 | 126 | - "/p2" is a merge of the preceding node and p2 |
|
127 | 127 | - ":tag" defines a local tag for the preceding node |
|
128 | 128 | - "@branch" sets the named branch for subsequent nodes |
|
129 | 129 | - "#...\\n" is a comment up to the end of the line |
|
130 | 130 | |
|
131 | 131 | Whitespace between the above elements is ignored. |
|
132 | 132 | |
|
133 | 133 | A backref is either |
|
134 | 134 | |
|
135 | 135 | - a number n, which references the node curr-n, where curr is the current |
|
136 | 136 | node, or |
|
137 | 137 | - the name of a local tag you placed earlier using ":tag", or |
|
138 | 138 | - empty to denote the default parent. |
|
139 | 139 | |
|
140 | 140 | All string valued-elements are either strictly alphanumeric, or must |
|
141 | 141 | be enclosed in double quotes ("..."), with "\\" as escape character. |
|
142 | 142 | """ |
|
143 | 143 | |
|
144 | 144 | if text is None: |
|
145 | 145 | ui.status(_("reading DAG from stdin\n")) |
|
146 | 146 | text = ui.fin.read() |
|
147 | 147 | |
|
148 | 148 | cl = repo.changelog |
|
149 | 149 | if len(cl) > 0: |
|
150 | 150 | raise error.Abort(_('repository is not empty')) |
|
151 | 151 | |
|
152 | 152 | # determine number of revs in DAG |
|
153 | 153 | total = 0 |
|
154 | 154 | for type, data in dagparser.parsedag(text): |
|
155 | 155 | if type == 'n': |
|
156 | 156 | total += 1 |
|
157 | 157 | |
|
158 | 158 | if mergeable_file: |
|
159 | 159 | linesperrev = 2 |
|
160 | 160 | # make a file with k lines per rev |
|
161 | 161 | initialmergedlines = [str(i) for i in xrange(0, total * linesperrev)] |
|
162 | 162 | initialmergedlines.append("") |
|
163 | 163 | |
|
164 | 164 | tags = [] |
|
165 | 165 | |
|
166 | 166 | wlock = lock = tr = None |
|
167 | 167 | try: |
|
168 | 168 | wlock = repo.wlock() |
|
169 | 169 | lock = repo.lock() |
|
170 | 170 | tr = repo.transaction("builddag") |
|
171 | 171 | |
|
172 | 172 | at = -1 |
|
173 | 173 | atbranch = 'default' |
|
174 | 174 | nodeids = [] |
|
175 | 175 | id = 0 |
|
176 | 176 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
177 | 177 | for type, data in dagparser.parsedag(text): |
|
178 | 178 | if type == 'n': |
|
179 | 179 | ui.note(('node %s\n' % str(data))) |
|
180 | 180 | id, ps = data |
|
181 | 181 | |
|
182 | 182 | files = [] |
|
183 | 183 | fctxs = {} |
|
184 | 184 | |
|
185 | 185 | p2 = None |
|
186 | 186 | if mergeable_file: |
|
187 | 187 | fn = "mf" |
|
188 | 188 | p1 = repo[ps[0]] |
|
189 | 189 | if len(ps) > 1: |
|
190 | 190 | p2 = repo[ps[1]] |
|
191 | 191 | pa = p1.ancestor(p2) |
|
192 | 192 | base, local, other = [x[fn].data() for x in (pa, p1, |
|
193 | 193 | p2)] |
|
194 | 194 | m3 = simplemerge.Merge3Text(base, local, other) |
|
195 | 195 | ml = [l.strip() for l in m3.merge_lines()] |
|
196 | 196 | ml.append("") |
|
197 | 197 | elif at > 0: |
|
198 | 198 | ml = p1[fn].data().split("\n") |
|
199 | 199 | else: |
|
200 | 200 | ml = initialmergedlines |
|
201 | 201 | ml[id * linesperrev] += " r%i" % id |
|
202 | 202 | mergedtext = "\n".join(ml) |
|
203 | 203 | files.append(fn) |
|
204 | 204 | fctxs[fn] = context.memfilectx(repo, fn, mergedtext) |
|
205 | 205 | |
|
206 | 206 | if overwritten_file: |
|
207 | 207 | fn = "of" |
|
208 | 208 | files.append(fn) |
|
209 | 209 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
210 | 210 | |
|
211 | 211 | if new_file: |
|
212 | 212 | fn = "nf%i" % id |
|
213 | 213 | files.append(fn) |
|
214 | 214 | fctxs[fn] = context.memfilectx(repo, fn, "r%i\n" % id) |
|
215 | 215 | if len(ps) > 1: |
|
216 | 216 | if not p2: |
|
217 | 217 | p2 = repo[ps[1]] |
|
218 | 218 | for fn in p2: |
|
219 | 219 | if fn.startswith("nf"): |
|
220 | 220 | files.append(fn) |
|
221 | 221 | fctxs[fn] = p2[fn] |
|
222 | 222 | |
|
223 | 223 | def fctxfn(repo, cx, path): |
|
224 | 224 | return fctxs.get(path) |
|
225 | 225 | |
|
226 | 226 | if len(ps) == 0 or ps[0] < 0: |
|
227 | 227 | pars = [None, None] |
|
228 | 228 | elif len(ps) == 1: |
|
229 | 229 | pars = [nodeids[ps[0]], None] |
|
230 | 230 | else: |
|
231 | 231 | pars = [nodeids[p] for p in ps] |
|
232 | 232 | cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn, |
|
233 | 233 | date=(id, 0), |
|
234 | 234 | user="debugbuilddag", |
|
235 | 235 | extra={'branch': atbranch}) |
|
236 | 236 | nodeid = repo.commitctx(cx) |
|
237 | 237 | nodeids.append(nodeid) |
|
238 | 238 | at = id |
|
239 | 239 | elif type == 'l': |
|
240 | 240 | id, name = data |
|
241 | 241 | ui.note(('tag %s\n' % name)) |
|
242 | 242 | tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name)) |
|
243 | 243 | elif type == 'a': |
|
244 | 244 | ui.note(('branch %s\n' % data)) |
|
245 | 245 | atbranch = data |
|
246 | 246 | ui.progress(_('building'), id, unit=_('revisions'), total=total) |
|
247 | 247 | tr.close() |
|
248 | 248 | |
|
249 | 249 | if tags: |
|
250 | 250 | repo.vfs.write("localtags", "".join(tags)) |
|
251 | 251 | finally: |
|
252 | 252 | ui.progress(_('building'), None) |
|
253 | 253 | release(tr, lock, wlock) |
|
254 | 254 | |
|
255 | 255 | def _debugchangegroup(ui, gen, all=None, indent=0, **opts): |
|
256 | 256 | indent_string = ' ' * indent |
|
257 | 257 | if all: |
|
258 | 258 | ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n") |
|
259 | 259 | % indent_string) |
|
260 | 260 | |
|
261 | 261 | def showchunks(named): |
|
262 | 262 | ui.write("\n%s%s\n" % (indent_string, named)) |
|
263 | 263 | chain = None |
|
264 | 264 | for chunkdata in iter(lambda: gen.deltachunk(chain), {}): |
|
265 | 265 | node = chunkdata['node'] |
|
266 | 266 | p1 = chunkdata['p1'] |
|
267 | 267 | p2 = chunkdata['p2'] |
|
268 | 268 | cs = chunkdata['cs'] |
|
269 | 269 | deltabase = chunkdata['deltabase'] |
|
270 | 270 | delta = chunkdata['delta'] |
|
271 | 271 | ui.write("%s%s %s %s %s %s %s\n" % |
|
272 | 272 | (indent_string, hex(node), hex(p1), hex(p2), |
|
273 | 273 | hex(cs), hex(deltabase), len(delta))) |
|
274 | 274 | chain = node |
|
275 | 275 | |
|
276 | 276 | chunkdata = gen.changelogheader() |
|
277 | 277 | showchunks("changelog") |
|
278 | 278 | chunkdata = gen.manifestheader() |
|
279 | 279 | showchunks("manifest") |
|
280 | 280 | for chunkdata in iter(gen.filelogheader, {}): |
|
281 | 281 | fname = chunkdata['filename'] |
|
282 | 282 | showchunks(fname) |
|
283 | 283 | else: |
|
284 | 284 | if isinstance(gen, bundle2.unbundle20): |
|
285 | 285 | raise error.Abort(_('use debugbundle2 for this file')) |
|
286 | 286 | chunkdata = gen.changelogheader() |
|
287 | 287 | chain = None |
|
288 | 288 | for chunkdata in iter(lambda: gen.deltachunk(chain), {}): |
|
289 | 289 | node = chunkdata['node'] |
|
290 | 290 | ui.write("%s%s\n" % (indent_string, hex(node))) |
|
291 | 291 | chain = node |
|
292 | 292 | |
|
293 | 293 | def _debugobsmarkers(ui, part, indent=0, **opts): |
|
294 | 294 | """display version and markers contained in 'data'""" |
|
295 | 295 | opts = pycompat.byteskwargs(opts) |
|
296 | 296 | data = part.read() |
|
297 | 297 | indent_string = ' ' * indent |
|
298 | 298 | try: |
|
299 | 299 | version, markers = obsolete._readmarkers(data) |
|
300 | 300 | except error.UnknownVersion as exc: |
|
301 | 301 | msg = "%sunsupported version: %s (%d bytes)\n" |
|
302 | 302 | msg %= indent_string, exc.version, len(data) |
|
303 | 303 | ui.write(msg) |
|
304 | 304 | else: |
|
305 | 305 | msg = "%sversion: %s (%d bytes)\n" |
|
306 | 306 | msg %= indent_string, version, len(data) |
|
307 | 307 | ui.write(msg) |
|
308 | 308 | fm = ui.formatter('debugobsolete', opts) |
|
309 | 309 | for rawmarker in sorted(markers): |
|
310 | 310 | m = obsutil.marker(None, rawmarker) |
|
311 | 311 | fm.startitem() |
|
312 | 312 | fm.plain(indent_string) |
|
313 | 313 | cmdutil.showmarker(fm, m) |
|
314 | 314 | fm.end() |
|
315 | 315 | |
|
316 | 316 | def _debugphaseheads(ui, data, indent=0): |
|
317 | 317 | """display version and markers contained in 'data'""" |
|
318 | 318 | indent_string = ' ' * indent |
|
319 | 319 | headsbyphase = bundle2._readphaseheads(data) |
|
320 | 320 | for phase in phases.allphases: |
|
321 | 321 | for head in headsbyphase[phase]: |
|
322 | 322 | ui.write(indent_string) |
|
323 | 323 | ui.write('%s %s\n' % (hex(head), phases.phasenames[phase])) |
|
324 | 324 | |
|
325 | 325 | def _debugbundle2(ui, gen, all=None, **opts): |
|
326 | 326 | """lists the contents of a bundle2""" |
|
327 | 327 | if not isinstance(gen, bundle2.unbundle20): |
|
328 | 328 | raise error.Abort(_('not a bundle2 file')) |
|
329 | 329 | ui.write(('Stream params: %s\n' % repr(gen.params))) |
|
330 | 330 | parttypes = opts.get(r'part_type', []) |
|
331 | 331 | for part in gen.iterparts(): |
|
332 | 332 | if parttypes and part.type not in parttypes: |
|
333 | 333 | continue |
|
334 | 334 | ui.write('%s -- %r\n' % (part.type, repr(part.params))) |
|
335 | 335 | if part.type == 'changegroup': |
|
336 | 336 | version = part.params.get('version', '01') |
|
337 | 337 | cg = changegroup.getunbundler(version, part, 'UN') |
|
338 | 338 | _debugchangegroup(ui, cg, all=all, indent=4, **opts) |
|
339 | 339 | if part.type == 'obsmarkers': |
|
340 | 340 | _debugobsmarkers(ui, part, indent=4, **opts) |
|
341 | 341 | if part.type == 'phase-heads': |
|
342 | 342 | _debugphaseheads(ui, part, indent=4) |
|
343 | 343 | |
|
344 | 344 | @command('debugbundle', |
|
345 | 345 | [('a', 'all', None, _('show all details')), |
|
346 | 346 | ('', 'part-type', [], _('show only the named part type')), |
|
347 | 347 | ('', 'spec', None, _('print the bundlespec of the bundle'))], |
|
348 | 348 | _('FILE'), |
|
349 | 349 | norepo=True) |
|
350 | 350 | def debugbundle(ui, bundlepath, all=None, spec=None, **opts): |
|
351 | 351 | """lists the contents of a bundle""" |
|
352 | 352 | with hg.openpath(ui, bundlepath) as f: |
|
353 | 353 | if spec: |
|
354 | 354 | spec = exchange.getbundlespec(ui, f) |
|
355 | 355 | ui.write('%s\n' % spec) |
|
356 | 356 | return |
|
357 | 357 | |
|
358 | 358 | gen = exchange.readbundle(ui, f, bundlepath) |
|
359 | 359 | if isinstance(gen, bundle2.unbundle20): |
|
360 | 360 | return _debugbundle2(ui, gen, all=all, **opts) |
|
361 | 361 | _debugchangegroup(ui, gen, all=all, **opts) |
|
362 | 362 | |
|
363 | 363 | @command('debugcheckstate', [], '') |
|
364 | 364 | def debugcheckstate(ui, repo): |
|
365 | 365 | """validate the correctness of the current dirstate""" |
|
366 | 366 | parent1, parent2 = repo.dirstate.parents() |
|
367 | 367 | m1 = repo[parent1].manifest() |
|
368 | 368 | m2 = repo[parent2].manifest() |
|
369 | 369 | errors = 0 |
|
370 | 370 | for f in repo.dirstate: |
|
371 | 371 | state = repo.dirstate[f] |
|
372 | 372 | if state in "nr" and f not in m1: |
|
373 | 373 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
374 | 374 | errors += 1 |
|
375 | 375 | if state in "a" and f in m1: |
|
376 | 376 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
377 | 377 | errors += 1 |
|
378 | 378 | if state in "m" and f not in m1 and f not in m2: |
|
379 | 379 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
380 | 380 | (f, state)) |
|
381 | 381 | errors += 1 |
|
382 | 382 | for f in m1: |
|
383 | 383 | state = repo.dirstate[f] |
|
384 | 384 | if state not in "nrm": |
|
385 | 385 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
386 | 386 | errors += 1 |
|
387 | 387 | if errors: |
|
388 | 388 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
389 | 389 | raise error.Abort(error) |
|
390 | 390 | |
|
391 | 391 | @command('debugcolor', |
|
392 | 392 | [('', 'style', None, _('show all configured styles'))], |
|
393 | 393 | 'hg debugcolor') |
|
394 | 394 | def debugcolor(ui, repo, **opts): |
|
395 | 395 | """show available color, effects or style""" |
|
396 | 396 | ui.write(('color mode: %s\n') % ui._colormode) |
|
397 | 397 | if opts.get(r'style'): |
|
398 | 398 | return _debugdisplaystyle(ui) |
|
399 | 399 | else: |
|
400 | 400 | return _debugdisplaycolor(ui) |
|
401 | 401 | |
|
402 | 402 | def _debugdisplaycolor(ui): |
|
403 | 403 | ui = ui.copy() |
|
404 | 404 | ui._styles.clear() |
|
405 | 405 | for effect in color._activeeffects(ui).keys(): |
|
406 | 406 | ui._styles[effect] = effect |
|
407 | 407 | if ui._terminfoparams: |
|
408 | 408 | for k, v in ui.configitems('color'): |
|
409 | 409 | if k.startswith('color.'): |
|
410 | 410 | ui._styles[k] = k[6:] |
|
411 | 411 | elif k.startswith('terminfo.'): |
|
412 | 412 | ui._styles[k] = k[9:] |
|
413 | 413 | ui.write(_('available colors:\n')) |
|
414 | 414 | # sort label with a '_' after the other to group '_background' entry. |
|
415 | 415 | items = sorted(ui._styles.items(), |
|
416 | 416 | key=lambda i: ('_' in i[0], i[0], i[1])) |
|
417 | 417 | for colorname, label in items: |
|
418 | 418 | ui.write(('%s\n') % colorname, label=label) |
|
419 | 419 | |
|
420 | 420 | def _debugdisplaystyle(ui): |
|
421 | 421 | ui.write(_('available style:\n')) |
|
422 | 422 | width = max(len(s) for s in ui._styles) |
|
423 | 423 | for label, effects in sorted(ui._styles.items()): |
|
424 | 424 | ui.write('%s' % label, label=label) |
|
425 | 425 | if effects: |
|
426 | 426 | # 50 |
|
427 | 427 | ui.write(': ') |
|
428 | 428 | ui.write(' ' * (max(0, width - len(label)))) |
|
429 | 429 | ui.write(', '.join(ui.label(e, e) for e in effects.split())) |
|
430 | 430 | ui.write('\n') |
|
431 | 431 | |
|
432 | 432 | @command('debugcreatestreamclonebundle', [], 'FILE') |
|
433 | 433 | def debugcreatestreamclonebundle(ui, repo, fname): |
|
434 | 434 | """create a stream clone bundle file |
|
435 | 435 | |
|
436 | 436 | Stream bundles are special bundles that are essentially archives of |
|
437 | 437 | revlog files. They are commonly used for cloning very quickly. |
|
438 | 438 | """ |
|
439 | 439 | # TODO we may want to turn this into an abort when this functionality |
|
440 | 440 | # is moved into `hg bundle`. |
|
441 | 441 | if phases.hassecret(repo): |
|
442 | 442 | ui.warn(_('(warning: stream clone bundle will contain secret ' |
|
443 | 443 | 'revisions)\n')) |
|
444 | 444 | |
|
445 | 445 | requirements, gen = streamclone.generatebundlev1(repo) |
|
446 | 446 | changegroup.writechunks(ui, gen, fname) |
|
447 | 447 | |
|
448 | 448 | ui.write(_('bundle requirements: %s\n') % ', '.join(sorted(requirements))) |
|
449 | 449 | |
|
450 | 450 | @command('debugdag', |
|
451 | 451 | [('t', 'tags', None, _('use tags as labels')), |
|
452 | 452 | ('b', 'branches', None, _('annotate with branch names')), |
|
453 | 453 | ('', 'dots', None, _('use dots for runs')), |
|
454 | 454 | ('s', 'spaces', None, _('separate elements by spaces'))], |
|
455 | 455 | _('[OPTION]... [FILE [REV]...]'), |
|
456 | 456 | optionalrepo=True) |
|
457 | 457 | def debugdag(ui, repo, file_=None, *revs, **opts): |
|
458 | 458 | """format the changelog or an index DAG as a concise textual description |
|
459 | 459 | |
|
460 | 460 | If you pass a revlog index, the revlog's DAG is emitted. If you list |
|
461 | 461 | revision numbers, they get labeled in the output as rN. |
|
462 | 462 | |
|
463 | 463 | Otherwise, the changelog DAG of the current repo is emitted. |
|
464 | 464 | """ |
|
465 | 465 | spaces = opts.get(r'spaces') |
|
466 | 466 | dots = opts.get(r'dots') |
|
467 | 467 | if file_: |
|
468 | 468 | rlog = revlog.revlog(vfsmod.vfs(pycompat.getcwd(), audit=False), |
|
469 | 469 | file_) |
|
470 | 470 | revs = set((int(r) for r in revs)) |
|
471 | 471 | def events(): |
|
472 | 472 | for r in rlog: |
|
473 | 473 | yield 'n', (r, list(p for p in rlog.parentrevs(r) |
|
474 | 474 | if p != -1)) |
|
475 | 475 | if r in revs: |
|
476 | 476 | yield 'l', (r, "r%i" % r) |
|
477 | 477 | elif repo: |
|
478 | 478 | cl = repo.changelog |
|
479 | 479 | tags = opts.get(r'tags') |
|
480 | 480 | branches = opts.get(r'branches') |
|
481 | 481 | if tags: |
|
482 | 482 | labels = {} |
|
483 | 483 | for l, n in repo.tags().items(): |
|
484 | 484 | labels.setdefault(cl.rev(n), []).append(l) |
|
485 | 485 | def events(): |
|
486 | 486 | b = "default" |
|
487 | 487 | for r in cl: |
|
488 | 488 | if branches: |
|
489 | 489 | newb = cl.read(cl.node(r))[5]['branch'] |
|
490 | 490 | if newb != b: |
|
491 | 491 | yield 'a', newb |
|
492 | 492 | b = newb |
|
493 | 493 | yield 'n', (r, list(p for p in cl.parentrevs(r) |
|
494 | 494 | if p != -1)) |
|
495 | 495 | if tags: |
|
496 | 496 | ls = labels.get(r) |
|
497 | 497 | if ls: |
|
498 | 498 | for l in ls: |
|
499 | 499 | yield 'l', (r, l) |
|
500 | 500 | else: |
|
501 | 501 | raise error.Abort(_('need repo for changelog dag')) |
|
502 | 502 | |
|
503 | 503 | for line in dagparser.dagtextlines(events(), |
|
504 | 504 | addspaces=spaces, |
|
505 | 505 | wraplabels=True, |
|
506 | 506 | wrapannotations=True, |
|
507 | 507 | wrapnonlinear=dots, |
|
508 | 508 | usedots=dots, |
|
509 | 509 | maxlinewidth=70): |
|
510 | 510 | ui.write(line) |
|
511 | 511 | ui.write("\n") |
|
512 | 512 | |
|
513 | 513 | @command('debugdata', cmdutil.debugrevlogopts, _('-c|-m|FILE REV')) |
|
514 | 514 | def debugdata(ui, repo, file_, rev=None, **opts): |
|
515 | 515 | """dump the contents of a data file revision""" |
|
516 | 516 | opts = pycompat.byteskwargs(opts) |
|
517 | 517 | if opts.get('changelog') or opts.get('manifest') or opts.get('dir'): |
|
518 | 518 | if rev is not None: |
|
519 | 519 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
520 | 520 | file_, rev = None, file_ |
|
521 | 521 | elif rev is None: |
|
522 | 522 | raise error.CommandError('debugdata', _('invalid arguments')) |
|
523 | 523 | r = cmdutil.openrevlog(repo, 'debugdata', file_, opts) |
|
524 | 524 | try: |
|
525 | 525 | ui.write(r.revision(r.lookup(rev), raw=True)) |
|
526 | 526 | except KeyError: |
|
527 | 527 | raise error.Abort(_('invalid revision identifier %s') % rev) |
|
528 | 528 | |
|
529 | 529 | @command('debugdate', |
|
530 | 530 | [('e', 'extended', None, _('try extended date formats'))], |
|
531 | 531 | _('[-e] DATE [RANGE]'), |
|
532 | 532 | norepo=True, optionalrepo=True) |
|
533 | 533 | def debugdate(ui, date, range=None, **opts): |
|
534 | 534 | """parse and display a date""" |
|
535 | 535 | if opts[r"extended"]: |
|
536 | 536 | d = util.parsedate(date, util.extendeddateformats) |
|
537 | 537 | else: |
|
538 | 538 | d = util.parsedate(date) |
|
539 | 539 | ui.write(("internal: %s %s\n") % d) |
|
540 | 540 | ui.write(("standard: %s\n") % util.datestr(d)) |
|
541 | 541 | if range: |
|
542 | 542 | m = util.matchdate(range) |
|
543 | 543 | ui.write(("match: %s\n") % m(d[0])) |
|
544 | 544 | |
|
545 | 545 | @command('debugdeltachain', |
|
546 | 546 | cmdutil.debugrevlogopts + cmdutil.formatteropts, |
|
547 | 547 | _('-c|-m|FILE'), |
|
548 | 548 | optionalrepo=True) |
|
549 | 549 | def debugdeltachain(ui, repo, file_=None, **opts): |
|
550 | 550 | """dump information about delta chains in a revlog |
|
551 | 551 | |
|
552 | 552 | Output can be templatized. Available template keywords are: |
|
553 | 553 | |
|
554 | 554 | :``rev``: revision number |
|
555 | 555 | :``chainid``: delta chain identifier (numbered by unique base) |
|
556 | 556 | :``chainlen``: delta chain length to this revision |
|
557 | 557 | :``prevrev``: previous revision in delta chain |
|
558 | 558 | :``deltatype``: role of delta / how it was computed |
|
559 | 559 | :``compsize``: compressed size of revision |
|
560 | 560 | :``uncompsize``: uncompressed size of revision |
|
561 | 561 | :``chainsize``: total size of compressed revisions in chain |
|
562 | 562 | :``chainratio``: total chain size divided by uncompressed revision size |
|
563 | 563 | (new delta chains typically start at ratio 2.00) |
|
564 | 564 | :``lindist``: linear distance from base revision in delta chain to end |
|
565 | 565 | of this revision |
|
566 | 566 | :``extradist``: total size of revisions not part of this delta chain from |
|
567 | 567 | base of delta chain to end of this revision; a measurement |
|
568 | 568 | of how much extra data we need to read/seek across to read |
|
569 | 569 | the delta chain for this revision |
|
570 | 570 | :``extraratio``: extradist divided by chainsize; another representation of |
|
571 | 571 | how much unrelated data is needed to load this delta chain |
|
572 | 572 | """ |
|
573 | 573 | opts = pycompat.byteskwargs(opts) |
|
574 | 574 | r = cmdutil.openrevlog(repo, 'debugdeltachain', file_, opts) |
|
575 | 575 | index = r.index |
|
576 | 576 | generaldelta = r.version & revlog.FLAG_GENERALDELTA |
|
577 | 577 | |
|
578 | 578 | def revinfo(rev): |
|
579 | 579 | e = index[rev] |
|
580 | 580 | compsize = e[1] |
|
581 | 581 | uncompsize = e[2] |
|
582 | 582 | chainsize = 0 |
|
583 | 583 | |
|
584 | 584 | if generaldelta: |
|
585 | 585 | if e[3] == e[5]: |
|
586 | 586 | deltatype = 'p1' |
|
587 | 587 | elif e[3] == e[6]: |
|
588 | 588 | deltatype = 'p2' |
|
589 | 589 | elif e[3] == rev - 1: |
|
590 | 590 | deltatype = 'prev' |
|
591 | 591 | elif e[3] == rev: |
|
592 | 592 | deltatype = 'base' |
|
593 | 593 | else: |
|
594 | 594 | deltatype = 'other' |
|
595 | 595 | else: |
|
596 | 596 | if e[3] == rev: |
|
597 | 597 | deltatype = 'base' |
|
598 | 598 | else: |
|
599 | 599 | deltatype = 'prev' |
|
600 | 600 | |
|
601 | 601 | chain = r._deltachain(rev)[0] |
|
602 | 602 | for iterrev in chain: |
|
603 | 603 | e = index[iterrev] |
|
604 | 604 | chainsize += e[1] |
|
605 | 605 | |
|
606 | 606 | return compsize, uncompsize, deltatype, chain, chainsize |
|
607 | 607 | |
|
608 | 608 | fm = ui.formatter('debugdeltachain', opts) |
|
609 | 609 | |
|
610 | 610 | fm.plain(' rev chain# chainlen prev delta ' |
|
611 | 611 | 'size rawsize chainsize ratio lindist extradist ' |
|
612 | 612 | 'extraratio\n') |
|
613 | 613 | |
|
614 | 614 | chainbases = {} |
|
615 | 615 | for rev in r: |
|
616 | 616 | comp, uncomp, deltatype, chain, chainsize = revinfo(rev) |
|
617 | 617 | chainbase = chain[0] |
|
618 | 618 | chainid = chainbases.setdefault(chainbase, len(chainbases) + 1) |
|
619 | 619 | basestart = r.start(chainbase) |
|
620 | 620 | revstart = r.start(rev) |
|
621 | 621 | lineardist = revstart + comp - basestart |
|
622 | 622 | extradist = lineardist - chainsize |
|
623 | 623 | try: |
|
624 | 624 | prevrev = chain[-2] |
|
625 | 625 | except IndexError: |
|
626 | 626 | prevrev = -1 |
|
627 | 627 | |
|
628 | 628 | chainratio = float(chainsize) / float(uncomp) |
|
629 | 629 | extraratio = float(extradist) / float(chainsize) |
|
630 | 630 | |
|
631 | 631 | fm.startitem() |
|
632 | 632 | fm.write('rev chainid chainlen prevrev deltatype compsize ' |
|
633 | 633 | 'uncompsize chainsize chainratio lindist extradist ' |
|
634 | 634 | 'extraratio', |
|
635 | 635 | '%7d %7d %8d %8d %7s %10d %10d %10d %9.5f %9d %9d %10.5f\n', |
|
636 | 636 | rev, chainid, len(chain), prevrev, deltatype, comp, |
|
637 | 637 | uncomp, chainsize, chainratio, lineardist, extradist, |
|
638 | 638 | extraratio, |
|
639 | 639 | rev=rev, chainid=chainid, chainlen=len(chain), |
|
640 | 640 | prevrev=prevrev, deltatype=deltatype, compsize=comp, |
|
641 | 641 | uncompsize=uncomp, chainsize=chainsize, |
|
642 | 642 | chainratio=chainratio, lindist=lineardist, |
|
643 | 643 | extradist=extradist, extraratio=extraratio) |
|
644 | 644 | |
|
645 | 645 | fm.end() |
|
646 | 646 | |
|
647 | 647 | @command('debugdirstate|debugstate', |
|
648 | 648 | [('', 'nodates', None, _('do not display the saved mtime')), |
|
649 | 649 | ('', 'datesort', None, _('sort by saved mtime'))], |
|
650 | 650 | _('[OPTION]...')) |
|
651 | 651 | def debugstate(ui, repo, **opts): |
|
652 | 652 | """show the contents of the current dirstate""" |
|
653 | 653 | |
|
654 | 654 | nodates = opts.get(r'nodates') |
|
655 | 655 | datesort = opts.get(r'datesort') |
|
656 | 656 | |
|
657 | 657 | timestr = "" |
|
658 | 658 | if datesort: |
|
659 | 659 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename |
|
660 | 660 | else: |
|
661 | 661 | keyfunc = None # sort by filename |
|
662 | 662 | for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc): |
|
663 | 663 | if ent[3] == -1: |
|
664 | 664 | timestr = 'unset ' |
|
665 | 665 | elif nodates: |
|
666 | 666 | timestr = 'set ' |
|
667 | 667 | else: |
|
668 | 668 | timestr = time.strftime("%Y-%m-%d %H:%M:%S ", |
|
669 | 669 | time.localtime(ent[3])) |
|
670 | 670 | if ent[1] & 0o20000: |
|
671 | 671 | mode = 'lnk' |
|
672 | 672 | else: |
|
673 | 673 | mode = '%3o' % (ent[1] & 0o777 & ~util.umask) |
|
674 | 674 | ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
|
675 | 675 | for f in repo.dirstate.copies(): |
|
676 | 676 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
|
677 | 677 | |
|
678 | 678 | @command('debugdiscovery', |
|
679 | 679 | [('', 'old', None, _('use old-style discovery')), |
|
680 | 680 | ('', 'nonheads', None, |
|
681 | 681 | _('use old-style discovery with non-heads included')), |
|
682 | 682 | ] + cmdutil.remoteopts, |
|
683 | 683 | _('[-l REV] [-r REV] [-b BRANCH]... [OTHER]')) |
|
684 | 684 | def debugdiscovery(ui, repo, remoteurl="default", **opts): |
|
685 | 685 | """runs the changeset discovery protocol in isolation""" |
|
686 | 686 | opts = pycompat.byteskwargs(opts) |
|
687 | 687 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl), |
|
688 | 688 | opts.get('branch')) |
|
689 | 689 | remote = hg.peer(repo, opts, remoteurl) |
|
690 | 690 | ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl)) |
|
691 | 691 | |
|
692 | 692 | # make sure tests are repeatable |
|
693 | 693 | random.seed(12323) |
|
694 | 694 | |
|
695 | 695 | def doit(localheads, remoteheads, remote=remote): |
|
696 | 696 | if opts.get('old'): |
|
697 | 697 | if localheads: |
|
698 | 698 | raise error.Abort('cannot use localheads with old style ' |
|
699 | 699 | 'discovery') |
|
700 | 700 | if not util.safehasattr(remote, 'branches'): |
|
701 | 701 | # enable in-client legacy support |
|
702 | 702 | remote = localrepo.locallegacypeer(remote.local()) |
|
703 | 703 | common, _in, hds = treediscovery.findcommonincoming(repo, remote, |
|
704 | 704 | force=True) |
|
705 | 705 | common = set(common) |
|
706 | 706 | if not opts.get('nonheads'): |
|
707 | 707 | ui.write(("unpruned common: %s\n") % |
|
708 | 708 | " ".join(sorted(short(n) for n in common))) |
|
709 | 709 | dag = dagutil.revlogdag(repo.changelog) |
|
710 | 710 | all = dag.ancestorset(dag.internalizeall(common)) |
|
711 | 711 | common = dag.externalizeall(dag.headsetofconnecteds(all)) |
|
712 | 712 | else: |
|
713 | 713 | common, any, hds = setdiscovery.findcommonheads(ui, repo, remote) |
|
714 | 714 | common = set(common) |
|
715 | 715 | rheads = set(hds) |
|
716 | 716 | lheads = set(repo.heads()) |
|
717 | 717 | ui.write(("common heads: %s\n") % |
|
718 | 718 | " ".join(sorted(short(n) for n in common))) |
|
719 | 719 | if lheads <= common: |
|
720 | 720 | ui.write(("local is subset\n")) |
|
721 | 721 | elif rheads <= common: |
|
722 | 722 | ui.write(("remote is subset\n")) |
|
723 | 723 | |
|
724 | 724 | serverlogs = opts.get('serverlog') |
|
725 | 725 | if serverlogs: |
|
726 | 726 | for filename in serverlogs: |
|
727 | 727 | with open(filename, 'r') as logfile: |
|
728 | 728 | line = logfile.readline() |
|
729 | 729 | while line: |
|
730 | 730 | parts = line.strip().split(';') |
|
731 | 731 | op = parts[1] |
|
732 | 732 | if op == 'cg': |
|
733 | 733 | pass |
|
734 | 734 | elif op == 'cgss': |
|
735 | 735 | doit(parts[2].split(' '), parts[3].split(' ')) |
|
736 | 736 | elif op == 'unb': |
|
737 | 737 | doit(parts[3].split(' '), parts[2].split(' ')) |
|
738 | 738 | line = logfile.readline() |
|
739 | 739 | else: |
|
740 | 740 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, |
|
741 | 741 | opts.get('remote_head')) |
|
742 | 742 | localrevs = opts.get('local_head') |
|
743 | 743 | doit(localrevs, remoterevs) |
|
744 | 744 | |
|
745 | 745 | @command('debugextensions', cmdutil.formatteropts, [], norepo=True) |
|
746 | 746 | def debugextensions(ui, **opts): |
|
747 | 747 | '''show information about active extensions''' |
|
748 | 748 | opts = pycompat.byteskwargs(opts) |
|
749 | 749 | exts = extensions.extensions(ui) |
|
750 | 750 | hgver = util.version() |
|
751 | 751 | fm = ui.formatter('debugextensions', opts) |
|
752 | 752 | for extname, extmod in sorted(exts, key=operator.itemgetter(0)): |
|
753 | 753 | isinternal = extensions.ismoduleinternal(extmod) |
|
754 | 754 | extsource = pycompat.fsencode(extmod.__file__) |
|
755 | 755 | if isinternal: |
|
756 | 756 | exttestedwith = [] # never expose magic string to users |
|
757 | 757 | else: |
|
758 | 758 | exttestedwith = getattr(extmod, 'testedwith', '').split() |
|
759 | 759 | extbuglink = getattr(extmod, 'buglink', None) |
|
760 | 760 | |
|
761 | 761 | fm.startitem() |
|
762 | 762 | |
|
763 | 763 | if ui.quiet or ui.verbose: |
|
764 | 764 | fm.write('name', '%s\n', extname) |
|
765 | 765 | else: |
|
766 | 766 | fm.write('name', '%s', extname) |
|
767 | 767 | if isinternal or hgver in exttestedwith: |
|
768 | 768 | fm.plain('\n') |
|
769 | 769 | elif not exttestedwith: |
|
770 | 770 | fm.plain(_(' (untested!)\n')) |
|
771 | 771 | else: |
|
772 | 772 | lasttestedversion = exttestedwith[-1] |
|
773 | 773 | fm.plain(' (%s!)\n' % lasttestedversion) |
|
774 | 774 | |
|
775 | 775 | fm.condwrite(ui.verbose and extsource, 'source', |
|
776 | 776 | _(' location: %s\n'), extsource or "") |
|
777 | 777 | |
|
778 | 778 | if ui.verbose: |
|
779 | 779 | fm.plain(_(' bundled: %s\n') % ['no', 'yes'][isinternal]) |
|
780 | 780 | fm.data(bundled=isinternal) |
|
781 | 781 | |
|
782 | 782 | fm.condwrite(ui.verbose and exttestedwith, 'testedwith', |
|
783 | 783 | _(' tested with: %s\n'), |
|
784 | 784 | fm.formatlist(exttestedwith, name='ver')) |
|
785 | 785 | |
|
786 | 786 | fm.condwrite(ui.verbose and extbuglink, 'buglink', |
|
787 | 787 | _(' bug reporting: %s\n'), extbuglink or "") |
|
788 | 788 | |
|
789 | 789 | fm.end() |
|
790 | 790 | |
|
791 | 791 | @command('debugfileset', |
|
792 | 792 | [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))], |
|
793 | 793 | _('[-r REV] FILESPEC')) |
|
794 | 794 | def debugfileset(ui, repo, expr, **opts): |
|
795 | 795 | '''parse and apply a fileset specification''' |
|
796 | 796 | ctx = scmutil.revsingle(repo, opts.get(r'rev'), None) |
|
797 | 797 | if ui.verbose: |
|
798 | 798 | tree = fileset.parse(expr) |
|
799 | 799 | ui.note(fileset.prettyformat(tree), "\n") |
|
800 | 800 | |
|
801 | 801 | for f in ctx.getfileset(expr): |
|
802 | 802 | ui.write("%s\n" % f) |
|
803 | 803 | |
|
804 | 804 | @command('debugfsinfo', [], _('[PATH]'), norepo=True) |
|
805 | 805 | def debugfsinfo(ui, path="."): |
|
806 | 806 | """show information detected about current filesystem""" |
|
807 | 807 | ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no')) |
|
808 | 808 | ui.write(('fstype: %s\n') % (util.getfstype(path) or '(unknown)')) |
|
809 | 809 | ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no')) |
|
810 | 810 | ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no')) |
|
811 | 811 | casesensitive = '(unknown)' |
|
812 | 812 | try: |
|
813 | 813 | with tempfile.NamedTemporaryFile(prefix='.debugfsinfo', dir=path) as f: |
|
814 | 814 | casesensitive = util.fscasesensitive(f.name) and 'yes' or 'no' |
|
815 | 815 | except OSError: |
|
816 | 816 | pass |
|
817 | 817 | ui.write(('case-sensitive: %s\n') % casesensitive) |
|
818 | 818 | |
|
819 | 819 | @command('debuggetbundle', |
|
820 | 820 | [('H', 'head', [], _('id of head node'), _('ID')), |
|
821 | 821 | ('C', 'common', [], _('id of common node'), _('ID')), |
|
822 | 822 | ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))], |
|
823 | 823 | _('REPO FILE [-H|-C ID]...'), |
|
824 | 824 | norepo=True) |
|
825 | 825 | def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts): |
|
826 | 826 | """retrieves a bundle from a repo |
|
827 | 827 | |
|
828 | 828 | Every ID must be a full-length hex node id string. Saves the bundle to the |
|
829 | 829 | given file. |
|
830 | 830 | """ |
|
831 | 831 | opts = pycompat.byteskwargs(opts) |
|
832 | 832 | repo = hg.peer(ui, opts, repopath) |
|
833 | 833 | if not repo.capable('getbundle'): |
|
834 | 834 | raise error.Abort("getbundle() not supported by target repository") |
|
835 | 835 | args = {} |
|
836 | 836 | if common: |
|
837 | 837 | args[r'common'] = [bin(s) for s in common] |
|
838 | 838 | if head: |
|
839 | 839 | args[r'heads'] = [bin(s) for s in head] |
|
840 | 840 | # TODO: get desired bundlecaps from command line. |
|
841 | 841 | args[r'bundlecaps'] = None |
|
842 | 842 | bundle = repo.getbundle('debug', **args) |
|
843 | 843 | |
|
844 | 844 | bundletype = opts.get('type', 'bzip2').lower() |
|
845 | 845 | btypes = {'none': 'HG10UN', |
|
846 | 846 | 'bzip2': 'HG10BZ', |
|
847 | 847 | 'gzip': 'HG10GZ', |
|
848 | 848 | 'bundle2': 'HG20'} |
|
849 | 849 | bundletype = btypes.get(bundletype) |
|
850 | 850 | if bundletype not in bundle2.bundletypes: |
|
851 | 851 | raise error.Abort(_('unknown bundle type specified with --type')) |
|
852 | 852 | bundle2.writebundle(ui, bundle, bundlepath, bundletype) |
|
853 | 853 | |
|
854 | 854 | @command('debugignore', [], '[FILE]') |
|
855 | 855 | def debugignore(ui, repo, *files, **opts): |
|
856 | 856 | """display the combined ignore pattern and information about ignored files |
|
857 | 857 | |
|
858 | 858 | With no argument display the combined ignore pattern. |
|
859 | 859 | |
|
860 | 860 | Given space separated file names, shows if the given file is ignored and |
|
861 | 861 | if so, show the ignore rule (file and line number) that matched it. |
|
862 | 862 | """ |
|
863 | 863 | ignore = repo.dirstate._ignore |
|
864 | 864 | if not files: |
|
865 | 865 | # Show all the patterns |
|
866 | 866 | ui.write("%s\n" % repr(ignore)) |
|
867 | 867 | else: |
|
868 | 868 | for f in files: |
|
869 | 869 | nf = util.normpath(f) |
|
870 | 870 | ignored = None |
|
871 | 871 | ignoredata = None |
|
872 | 872 | if nf != '.': |
|
873 | 873 | if ignore(nf): |
|
874 | 874 | ignored = nf |
|
875 | 875 | ignoredata = repo.dirstate._ignorefileandline(nf) |
|
876 | 876 | else: |
|
877 | 877 | for p in util.finddirs(nf): |
|
878 | 878 | if ignore(p): |
|
879 | 879 | ignored = p |
|
880 | 880 | ignoredata = repo.dirstate._ignorefileandline(p) |
|
881 | 881 | break |
|
882 | 882 | if ignored: |
|
883 | 883 | if ignored == nf: |
|
884 | 884 | ui.write(_("%s is ignored\n") % f) |
|
885 | 885 | else: |
|
886 | 886 | ui.write(_("%s is ignored because of " |
|
887 | 887 | "containing folder %s\n") |
|
888 | 888 | % (f, ignored)) |
|
889 | 889 | ignorefile, lineno, line = ignoredata |
|
890 | 890 | ui.write(_("(ignore rule in %s, line %d: '%s')\n") |
|
891 | 891 | % (ignorefile, lineno, line)) |
|
892 | 892 | else: |
|
893 | 893 | ui.write(_("%s is not ignored\n") % f) |
|
894 | 894 | |
|
895 | 895 | @command('debugindex', cmdutil.debugrevlogopts + |
|
896 | 896 | [('f', 'format', 0, _('revlog format'), _('FORMAT'))], |
|
897 | 897 | _('[-f FORMAT] -c|-m|FILE'), |
|
898 | 898 | optionalrepo=True) |
|
899 | 899 | def debugindex(ui, repo, file_=None, **opts): |
|
900 | 900 | """dump the contents of an index file""" |
|
901 | 901 | opts = pycompat.byteskwargs(opts) |
|
902 | 902 | r = cmdutil.openrevlog(repo, 'debugindex', file_, opts) |
|
903 | 903 | format = opts.get('format', 0) |
|
904 | 904 | if format not in (0, 1): |
|
905 | 905 | raise error.Abort(_("unknown format %d") % format) |
|
906 | 906 | |
|
907 | 907 | generaldelta = r.version & revlog.FLAG_GENERALDELTA |
|
908 | 908 | if generaldelta: |
|
909 | 909 | basehdr = ' delta' |
|
910 | 910 | else: |
|
911 | 911 | basehdr = ' base' |
|
912 | 912 | |
|
913 | 913 | if ui.debugflag: |
|
914 | 914 | shortfn = hex |
|
915 | 915 | else: |
|
916 | 916 | shortfn = short |
|
917 | 917 | |
|
918 | 918 | # There might not be anything in r, so have a sane default |
|
919 | 919 | idlen = 12 |
|
920 | 920 | for i in r: |
|
921 | 921 | idlen = len(shortfn(r.node(i))) |
|
922 | 922 | break |
|
923 | 923 | |
|
924 | 924 | if format == 0: |
|
925 | 925 | ui.write((" rev offset length " + basehdr + " linkrev" |
|
926 | 926 | " %s %s p2\n") % ("nodeid".ljust(idlen), "p1".ljust(idlen))) |
|
927 | 927 | elif format == 1: |
|
928 | 928 | ui.write((" rev flag offset length" |
|
929 | 929 | " size " + basehdr + " link p1 p2" |
|
930 | 930 | " %s\n") % "nodeid".rjust(idlen)) |
|
931 | 931 | |
|
932 | 932 | for i in r: |
|
933 | 933 | node = r.node(i) |
|
934 | 934 | if generaldelta: |
|
935 | 935 | base = r.deltaparent(i) |
|
936 | 936 | else: |
|
937 | 937 | base = r.chainbase(i) |
|
938 | 938 | if format == 0: |
|
939 | 939 | try: |
|
940 | 940 | pp = r.parents(node) |
|
941 | 941 | except Exception: |
|
942 | 942 | pp = [nullid, nullid] |
|
943 | 943 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
944 | 944 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
945 | 945 | shortfn(node), shortfn(pp[0]), shortfn(pp[1]))) |
|
946 | 946 | elif format == 1: |
|
947 | 947 | pr = r.parentrevs(i) |
|
948 | 948 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
949 | 949 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
950 | 950 | base, r.linkrev(i), pr[0], pr[1], shortfn(node))) |
|
951 | 951 | |
|
952 | 952 | @command('debugindexdot', cmdutil.debugrevlogopts, |
|
953 | 953 | _('-c|-m|FILE'), optionalrepo=True) |
|
954 | 954 | def debugindexdot(ui, repo, file_=None, **opts): |
|
955 | 955 | """dump an index DAG as a graphviz dot file""" |
|
956 | 956 | opts = pycompat.byteskwargs(opts) |
|
957 | 957 | r = cmdutil.openrevlog(repo, 'debugindexdot', file_, opts) |
|
958 | 958 | ui.write(("digraph G {\n")) |
|
959 | 959 | for i in r: |
|
960 | 960 | node = r.node(i) |
|
961 | 961 | pp = r.parents(node) |
|
962 | 962 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
963 | 963 | if pp[1] != nullid: |
|
964 | 964 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
965 | 965 | ui.write("}\n") |
|
966 | 966 | |
|
967 | 967 | @command('debuginstall', [] + cmdutil.formatteropts, '', norepo=True) |
|
968 | 968 | def debuginstall(ui, **opts): |
|
969 | 969 | '''test Mercurial installation |
|
970 | 970 | |
|
971 | 971 | Returns 0 on success. |
|
972 | 972 | ''' |
|
973 | 973 | opts = pycompat.byteskwargs(opts) |
|
974 | 974 | |
|
975 | 975 | def writetemp(contents): |
|
976 | 976 | (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-") |
|
977 | 977 | f = os.fdopen(fd, pycompat.sysstr("wb")) |
|
978 | 978 | f.write(contents) |
|
979 | 979 | f.close() |
|
980 | 980 | return name |
|
981 | 981 | |
|
982 | 982 | problems = 0 |
|
983 | 983 | |
|
984 | 984 | fm = ui.formatter('debuginstall', opts) |
|
985 | 985 | fm.startitem() |
|
986 | 986 | |
|
987 | 987 | # encoding |
|
988 | 988 | fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding) |
|
989 | 989 | err = None |
|
990 | 990 | try: |
|
991 | 991 | encoding.fromlocal("test") |
|
992 | 992 | except error.Abort as inst: |
|
993 | 993 | err = inst |
|
994 | 994 | problems += 1 |
|
995 | 995 | fm.condwrite(err, 'encodingerror', _(" %s\n" |
|
996 | 996 | " (check that your locale is properly set)\n"), err) |
|
997 | 997 | |
|
998 | 998 | # Python |
|
999 | 999 | fm.write('pythonexe', _("checking Python executable (%s)\n"), |
|
1000 | 1000 | pycompat.sysexecutable) |
|
1001 | 1001 | fm.write('pythonver', _("checking Python version (%s)\n"), |
|
1002 | 1002 | ("%d.%d.%d" % sys.version_info[:3])) |
|
1003 | 1003 | fm.write('pythonlib', _("checking Python lib (%s)...\n"), |
|
1004 | 1004 | os.path.dirname(pycompat.fsencode(os.__file__))) |
|
1005 | 1005 | |
|
1006 | 1006 | security = set(sslutil.supportedprotocols) |
|
1007 | 1007 | if sslutil.hassni: |
|
1008 | 1008 | security.add('sni') |
|
1009 | 1009 | |
|
1010 | 1010 | fm.write('pythonsecurity', _("checking Python security support (%s)\n"), |
|
1011 | 1011 | fm.formatlist(sorted(security), name='protocol', |
|
1012 | 1012 | fmt='%s', sep=',')) |
|
1013 | 1013 | |
|
1014 | 1014 | # These are warnings, not errors. So don't increment problem count. This |
|
1015 | 1015 | # may change in the future. |
|
1016 | 1016 | if 'tls1.2' not in security: |
|
1017 | 1017 | fm.plain(_(' TLS 1.2 not supported by Python install; ' |
|
1018 | 1018 | 'network connections lack modern security\n')) |
|
1019 | 1019 | if 'sni' not in security: |
|
1020 | 1020 | fm.plain(_(' SNI not supported by Python install; may have ' |
|
1021 | 1021 | 'connectivity issues with some servers\n')) |
|
1022 | 1022 | |
|
1023 | 1023 | # TODO print CA cert info |
|
1024 | 1024 | |
|
1025 | 1025 | # hg version |
|
1026 | 1026 | hgver = util.version() |
|
1027 | 1027 | fm.write('hgver', _("checking Mercurial version (%s)\n"), |
|
1028 | 1028 | hgver.split('+')[0]) |
|
1029 | 1029 | fm.write('hgverextra', _("checking Mercurial custom build (%s)\n"), |
|
1030 | 1030 | '+'.join(hgver.split('+')[1:])) |
|
1031 | 1031 | |
|
1032 | 1032 | # compiled modules |
|
1033 | 1033 | fm.write('hgmodulepolicy', _("checking module policy (%s)\n"), |
|
1034 | 1034 | policy.policy) |
|
1035 | 1035 | fm.write('hgmodules', _("checking installed modules (%s)...\n"), |
|
1036 | 1036 | os.path.dirname(pycompat.fsencode(__file__))) |
|
1037 | 1037 | |
|
1038 | 1038 | if policy.policy in ('c', 'allow'): |
|
1039 | 1039 | err = None |
|
1040 | 1040 | try: |
|
1041 | 1041 | from .cext import ( |
|
1042 | 1042 | base85, |
|
1043 | 1043 | bdiff, |
|
1044 | 1044 | mpatch, |
|
1045 | 1045 | osutil, |
|
1046 | 1046 | ) |
|
1047 | 1047 | dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes |
|
1048 | 1048 | except Exception as inst: |
|
1049 | 1049 | err = inst |
|
1050 | 1050 | problems += 1 |
|
1051 | 1051 | fm.condwrite(err, 'extensionserror', " %s\n", err) |
|
1052 | 1052 | |
|
1053 | 1053 | compengines = util.compengines._engines.values() |
|
1054 | 1054 | fm.write('compengines', _('checking registered compression engines (%s)\n'), |
|
1055 | 1055 | fm.formatlist(sorted(e.name() for e in compengines), |
|
1056 | 1056 | name='compengine', fmt='%s', sep=', ')) |
|
1057 | 1057 | fm.write('compenginesavail', _('checking available compression engines ' |
|
1058 | 1058 | '(%s)\n'), |
|
1059 | 1059 | fm.formatlist(sorted(e.name() for e in compengines |
|
1060 | 1060 | if e.available()), |
|
1061 | 1061 | name='compengine', fmt='%s', sep=', ')) |
|
1062 | 1062 | wirecompengines = util.compengines.supportedwireengines(util.SERVERROLE) |
|
1063 | 1063 | fm.write('compenginesserver', _('checking available compression engines ' |
|
1064 | 1064 | 'for wire protocol (%s)\n'), |
|
1065 | 1065 | fm.formatlist([e.name() for e in wirecompengines |
|
1066 | 1066 | if e.wireprotosupport()], |
|
1067 | 1067 | name='compengine', fmt='%s', sep=', ')) |
|
1068 | 1068 | |
|
1069 | 1069 | # templates |
|
1070 | 1070 | p = templater.templatepaths() |
|
1071 | 1071 | fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p)) |
|
1072 | 1072 | fm.condwrite(not p, '', _(" no template directories found\n")) |
|
1073 | 1073 | if p: |
|
1074 | 1074 | m = templater.templatepath("map-cmdline.default") |
|
1075 | 1075 | if m: |
|
1076 | 1076 | # template found, check if it is working |
|
1077 | 1077 | err = None |
|
1078 | 1078 | try: |
|
1079 | 1079 | templater.templater.frommapfile(m) |
|
1080 | 1080 | except Exception as inst: |
|
1081 | 1081 | err = inst |
|
1082 | 1082 | p = None |
|
1083 | 1083 | fm.condwrite(err, 'defaulttemplateerror', " %s\n", err) |
|
1084 | 1084 | else: |
|
1085 | 1085 | p = None |
|
1086 | 1086 | fm.condwrite(p, 'defaulttemplate', |
|
1087 | 1087 | _("checking default template (%s)\n"), m) |
|
1088 | 1088 | fm.condwrite(not m, 'defaulttemplatenotfound', |
|
1089 | 1089 | _(" template '%s' not found\n"), "default") |
|
1090 | 1090 | if not p: |
|
1091 | 1091 | problems += 1 |
|
1092 | 1092 | fm.condwrite(not p, '', |
|
1093 | 1093 | _(" (templates seem to have been installed incorrectly)\n")) |
|
1094 | 1094 | |
|
1095 | 1095 | # editor |
|
1096 | 1096 | editor = ui.geteditor() |
|
1097 | 1097 | editor = util.expandpath(editor) |
|
1098 | 1098 | fm.write('editor', _("checking commit editor... (%s)\n"), editor) |
|
1099 | 1099 | cmdpath = util.findexe(pycompat.shlexsplit(editor)[0]) |
|
1100 | 1100 | fm.condwrite(not cmdpath and editor == 'vi', 'vinotfound', |
|
1101 | 1101 | _(" No commit editor set and can't find %s in PATH\n" |
|
1102 | 1102 | " (specify a commit editor in your configuration" |
|
1103 | 1103 | " file)\n"), not cmdpath and editor == 'vi' and editor) |
|
1104 | 1104 | fm.condwrite(not cmdpath and editor != 'vi', 'editornotfound', |
|
1105 | 1105 | _(" Can't find editor '%s' in PATH\n" |
|
1106 | 1106 | " (specify a commit editor in your configuration" |
|
1107 | 1107 | " file)\n"), not cmdpath and editor) |
|
1108 | 1108 | if not cmdpath and editor != 'vi': |
|
1109 | 1109 | problems += 1 |
|
1110 | 1110 | |
|
1111 | 1111 | # check username |
|
1112 | 1112 | username = None |
|
1113 | 1113 | err = None |
|
1114 | 1114 | try: |
|
1115 | 1115 | username = ui.username() |
|
1116 | 1116 | except error.Abort as e: |
|
1117 | 1117 | err = e |
|
1118 | 1118 | problems += 1 |
|
1119 | 1119 | |
|
1120 | 1120 | fm.condwrite(username, 'username', _("checking username (%s)\n"), username) |
|
1121 | 1121 | fm.condwrite(err, 'usernameerror', _("checking username...\n %s\n" |
|
1122 | 1122 | " (specify a username in your configuration file)\n"), err) |
|
1123 | 1123 | |
|
1124 | 1124 | fm.condwrite(not problems, '', |
|
1125 | 1125 | _("no problems detected\n")) |
|
1126 | 1126 | if not problems: |
|
1127 | 1127 | fm.data(problems=problems) |
|
1128 | 1128 | fm.condwrite(problems, 'problems', |
|
1129 | 1129 | _("%d problems detected," |
|
1130 | 1130 | " please check your install!\n"), problems) |
|
1131 | 1131 | fm.end() |
|
1132 | 1132 | |
|
1133 | 1133 | return problems |
|
1134 | 1134 | |
|
1135 | 1135 | @command('debugknown', [], _('REPO ID...'), norepo=True) |
|
1136 | 1136 | def debugknown(ui, repopath, *ids, **opts): |
|
1137 | 1137 | """test whether node ids are known to a repo |
|
1138 | 1138 | |
|
1139 | 1139 | Every ID must be a full-length hex node id string. Returns a list of 0s |
|
1140 | 1140 | and 1s indicating unknown/known. |
|
1141 | 1141 | """ |
|
1142 | 1142 | opts = pycompat.byteskwargs(opts) |
|
1143 | 1143 | repo = hg.peer(ui, opts, repopath) |
|
1144 | 1144 | if not repo.capable('known'): |
|
1145 | 1145 | raise error.Abort("known() not supported by target repository") |
|
1146 | 1146 | flags = repo.known([bin(s) for s in ids]) |
|
1147 | 1147 | ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags]))) |
|
1148 | 1148 | |
|
1149 | 1149 | @command('debuglabelcomplete', [], _('LABEL...')) |
|
1150 | 1150 | def debuglabelcomplete(ui, repo, *args): |
|
1151 | 1151 | '''backwards compatibility with old bash completion scripts (DEPRECATED)''' |
|
1152 | 1152 | debugnamecomplete(ui, repo, *args) |
|
1153 | 1153 | |
|
1154 | 1154 | @command('debuglocks', |
|
1155 | 1155 | [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')), |
|
1156 | 1156 | ('W', 'force-wlock', None, |
|
1157 | 1157 | _('free the working state lock (DANGEROUS)'))], |
|
1158 | 1158 | _('[OPTION]...')) |
|
1159 | 1159 | def debuglocks(ui, repo, **opts): |
|
1160 | 1160 | """show or modify state of locks |
|
1161 | 1161 | |
|
1162 | 1162 | By default, this command will show which locks are held. This |
|
1163 | 1163 | includes the user and process holding the lock, the amount of time |
|
1164 | 1164 | the lock has been held, and the machine name where the process is |
|
1165 | 1165 | running if it's not local. |
|
1166 | 1166 | |
|
1167 | 1167 | Locks protect the integrity of Mercurial's data, so should be |
|
1168 | 1168 | treated with care. System crashes or other interruptions may cause |
|
1169 | 1169 | locks to not be properly released, though Mercurial will usually |
|
1170 | 1170 | detect and remove such stale locks automatically. |
|
1171 | 1171 | |
|
1172 | 1172 | However, detecting stale locks may not always be possible (for |
|
1173 | 1173 | instance, on a shared filesystem). Removing locks may also be |
|
1174 | 1174 | blocked by filesystem permissions. |
|
1175 | 1175 | |
|
1176 | 1176 | Returns 0 if no locks are held. |
|
1177 | 1177 | |
|
1178 | 1178 | """ |
|
1179 | 1179 | |
|
1180 | 1180 | if opts.get(r'force_lock'): |
|
1181 | 1181 | repo.svfs.unlink('lock') |
|
1182 | 1182 | if opts.get(r'force_wlock'): |
|
1183 | 1183 | repo.vfs.unlink('wlock') |
|
1184 | 1184 | if opts.get(r'force_lock') or opts.get(r'force_lock'): |
|
1185 | 1185 | return 0 |
|
1186 | 1186 | |
|
1187 | 1187 | now = time.time() |
|
1188 | 1188 | held = 0 |
|
1189 | 1189 | |
|
1190 | 1190 | def report(vfs, name, method): |
|
1191 | 1191 | # this causes stale locks to get reaped for more accurate reporting |
|
1192 | 1192 | try: |
|
1193 | 1193 | l = method(False) |
|
1194 | 1194 | except error.LockHeld: |
|
1195 | 1195 | l = None |
|
1196 | 1196 | |
|
1197 | 1197 | if l: |
|
1198 | 1198 | l.release() |
|
1199 | 1199 | else: |
|
1200 | 1200 | try: |
|
1201 | 1201 | stat = vfs.lstat(name) |
|
1202 | 1202 | age = now - stat.st_mtime |
|
1203 | 1203 | user = util.username(stat.st_uid) |
|
1204 | 1204 | locker = vfs.readlock(name) |
|
1205 | 1205 | if ":" in locker: |
|
1206 | 1206 | host, pid = locker.split(':') |
|
1207 | 1207 | if host == socket.gethostname(): |
|
1208 | 1208 | locker = 'user %s, process %s' % (user, pid) |
|
1209 | 1209 | else: |
|
1210 | 1210 | locker = 'user %s, process %s, host %s' \ |
|
1211 | 1211 | % (user, pid, host) |
|
1212 | 1212 | ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age)) |
|
1213 | 1213 | return 1 |
|
1214 | 1214 | except OSError as e: |
|
1215 | 1215 | if e.errno != errno.ENOENT: |
|
1216 | 1216 | raise |
|
1217 | 1217 | |
|
1218 | 1218 | ui.write(("%-6s free\n") % (name + ":")) |
|
1219 | 1219 | return 0 |
|
1220 | 1220 | |
|
1221 | 1221 | held += report(repo.svfs, "lock", repo.lock) |
|
1222 | 1222 | held += report(repo.vfs, "wlock", repo.wlock) |
|
1223 | 1223 | |
|
1224 | 1224 | return held |
|
1225 | 1225 | |
|
1226 | 1226 | @command('debugmergestate', [], '') |
|
1227 | 1227 | def debugmergestate(ui, repo, *args): |
|
1228 | 1228 | """print merge state |
|
1229 | 1229 | |
|
1230 | 1230 | Use --verbose to print out information about whether v1 or v2 merge state |
|
1231 | 1231 | was chosen.""" |
|
1232 | 1232 | def _hashornull(h): |
|
1233 | 1233 | if h == nullhex: |
|
1234 | 1234 | return 'null' |
|
1235 | 1235 | else: |
|
1236 | 1236 | return h |
|
1237 | 1237 | |
|
1238 | 1238 | def printrecords(version): |
|
1239 | 1239 | ui.write(('* version %s records\n') % version) |
|
1240 | 1240 | if version == 1: |
|
1241 | 1241 | records = v1records |
|
1242 | 1242 | else: |
|
1243 | 1243 | records = v2records |
|
1244 | 1244 | |
|
1245 | 1245 | for rtype, record in records: |
|
1246 | 1246 | # pretty print some record types |
|
1247 | 1247 | if rtype == 'L': |
|
1248 | 1248 | ui.write(('local: %s\n') % record) |
|
1249 | 1249 | elif rtype == 'O': |
|
1250 | 1250 | ui.write(('other: %s\n') % record) |
|
1251 | 1251 | elif rtype == 'm': |
|
1252 | 1252 | driver, mdstate = record.split('\0', 1) |
|
1253 | 1253 | ui.write(('merge driver: %s (state "%s")\n') |
|
1254 | 1254 | % (driver, mdstate)) |
|
1255 | 1255 | elif rtype in 'FDC': |
|
1256 | 1256 | r = record.split('\0') |
|
1257 | 1257 | f, state, hash, lfile, afile, anode, ofile = r[0:7] |
|
1258 | 1258 | if version == 1: |
|
1259 | 1259 | onode = 'not stored in v1 format' |
|
1260 | 1260 | flags = r[7] |
|
1261 | 1261 | else: |
|
1262 | 1262 | onode, flags = r[7:9] |
|
1263 | 1263 | ui.write(('file: %s (record type "%s", state "%s", hash %s)\n') |
|
1264 | 1264 | % (f, rtype, state, _hashornull(hash))) |
|
1265 | 1265 | ui.write((' local path: %s (flags "%s")\n') % (lfile, flags)) |
|
1266 | 1266 | ui.write((' ancestor path: %s (node %s)\n') |
|
1267 | 1267 | % (afile, _hashornull(anode))) |
|
1268 | 1268 | ui.write((' other path: %s (node %s)\n') |
|
1269 | 1269 | % (ofile, _hashornull(onode))) |
|
1270 | 1270 | elif rtype == 'f': |
|
1271 | 1271 | filename, rawextras = record.split('\0', 1) |
|
1272 | 1272 | extras = rawextras.split('\0') |
|
1273 | 1273 | i = 0 |
|
1274 | 1274 | extrastrings = [] |
|
1275 | 1275 | while i < len(extras): |
|
1276 | 1276 | extrastrings.append('%s = %s' % (extras[i], extras[i + 1])) |
|
1277 | 1277 | i += 2 |
|
1278 | 1278 | |
|
1279 | 1279 | ui.write(('file extras: %s (%s)\n') |
|
1280 | 1280 | % (filename, ', '.join(extrastrings))) |
|
1281 | 1281 | elif rtype == 'l': |
|
1282 | 1282 | labels = record.split('\0', 2) |
|
1283 | 1283 | labels = [l for l in labels if len(l) > 0] |
|
1284 | 1284 | ui.write(('labels:\n')) |
|
1285 | 1285 | ui.write((' local: %s\n' % labels[0])) |
|
1286 | 1286 | ui.write((' other: %s\n' % labels[1])) |
|
1287 | 1287 | if len(labels) > 2: |
|
1288 | 1288 | ui.write((' base: %s\n' % labels[2])) |
|
1289 | 1289 | else: |
|
1290 | 1290 | ui.write(('unrecognized entry: %s\t%s\n') |
|
1291 | 1291 | % (rtype, record.replace('\0', '\t'))) |
|
1292 | 1292 | |
|
1293 | 1293 | # Avoid mergestate.read() since it may raise an exception for unsupported |
|
1294 | 1294 | # merge state records. We shouldn't be doing this, but this is OK since this |
|
1295 | 1295 | # command is pretty low-level. |
|
1296 | 1296 | ms = mergemod.mergestate(repo) |
|
1297 | 1297 | |
|
1298 | 1298 | # sort so that reasonable information is on top |
|
1299 | 1299 | v1records = ms._readrecordsv1() |
|
1300 | 1300 | v2records = ms._readrecordsv2() |
|
1301 | 1301 | order = 'LOml' |
|
1302 | 1302 | def key(r): |
|
1303 | 1303 | idx = order.find(r[0]) |
|
1304 | 1304 | if idx == -1: |
|
1305 | 1305 | return (1, r[1]) |
|
1306 | 1306 | else: |
|
1307 | 1307 | return (0, idx) |
|
1308 | 1308 | v1records.sort(key=key) |
|
1309 | 1309 | v2records.sort(key=key) |
|
1310 | 1310 | |
|
1311 | 1311 | if not v1records and not v2records: |
|
1312 | 1312 | ui.write(('no merge state found\n')) |
|
1313 | 1313 | elif not v2records: |
|
1314 | 1314 | ui.note(('no version 2 merge state\n')) |
|
1315 | 1315 | printrecords(1) |
|
1316 | 1316 | elif ms._v1v2match(v1records, v2records): |
|
1317 | 1317 | ui.note(('v1 and v2 states match: using v2\n')) |
|
1318 | 1318 | printrecords(2) |
|
1319 | 1319 | else: |
|
1320 | 1320 | ui.note(('v1 and v2 states mismatch: using v1\n')) |
|
1321 | 1321 | printrecords(1) |
|
1322 | 1322 | if ui.verbose: |
|
1323 | 1323 | printrecords(2) |
|
1324 | 1324 | |
|
1325 | 1325 | @command('debugnamecomplete', [], _('NAME...')) |
|
1326 | 1326 | def debugnamecomplete(ui, repo, *args): |
|
1327 | 1327 | '''complete "names" - tags, open branch names, bookmark names''' |
|
1328 | 1328 | |
|
1329 | 1329 | names = set() |
|
1330 | 1330 | # since we previously only listed open branches, we will handle that |
|
1331 | 1331 | # specially (after this for loop) |
|
1332 | 1332 | for name, ns in repo.names.iteritems(): |
|
1333 | 1333 | if name != 'branches': |
|
1334 | 1334 | names.update(ns.listnames(repo)) |
|
1335 | 1335 | names.update(tag for (tag, heads, tip, closed) |
|
1336 | 1336 | in repo.branchmap().iterbranches() if not closed) |
|
1337 | 1337 | completions = set() |
|
1338 | 1338 | if not args: |
|
1339 | 1339 | args = [''] |
|
1340 | 1340 | for a in args: |
|
1341 | 1341 | completions.update(n for n in names if n.startswith(a)) |
|
1342 | 1342 | ui.write('\n'.join(sorted(completions))) |
|
1343 | 1343 | ui.write('\n') |
|
1344 | 1344 | |
|
1345 | 1345 | @command('debugobsolete', |
|
1346 | 1346 | [('', 'flags', 0, _('markers flag')), |
|
1347 | 1347 | ('', 'record-parents', False, |
|
1348 | 1348 | _('record parent information for the precursor')), |
|
1349 | 1349 | ('r', 'rev', [], _('display markers relevant to REV')), |
|
1350 | 1350 | ('', 'exclusive', False, _('restrict display to markers only ' |
|
1351 | 1351 | 'relevant to REV')), |
|
1352 | 1352 | ('', 'index', False, _('display index of the marker')), |
|
1353 | 1353 | ('', 'delete', [], _('delete markers specified by indices')), |
|
1354 | 1354 | ] + cmdutil.commitopts2 + cmdutil.formatteropts, |
|
1355 | 1355 | _('[OBSOLETED [REPLACEMENT ...]]')) |
|
1356 | 1356 | def debugobsolete(ui, repo, precursor=None, *successors, **opts): |
|
1357 | 1357 | """create arbitrary obsolete marker |
|
1358 | 1358 | |
|
1359 | 1359 | With no arguments, displays the list of obsolescence markers.""" |
|
1360 | 1360 | |
|
1361 | 1361 | opts = pycompat.byteskwargs(opts) |
|
1362 | 1362 | |
|
1363 | 1363 | def parsenodeid(s): |
|
1364 | 1364 | try: |
|
1365 | 1365 | # We do not use revsingle/revrange functions here to accept |
|
1366 | 1366 | # arbitrary node identifiers, possibly not present in the |
|
1367 | 1367 | # local repository. |
|
1368 | 1368 | n = bin(s) |
|
1369 | 1369 | if len(n) != len(nullid): |
|
1370 | 1370 | raise TypeError() |
|
1371 | 1371 | return n |
|
1372 | 1372 | except TypeError: |
|
1373 | 1373 | raise error.Abort('changeset references must be full hexadecimal ' |
|
1374 | 1374 | 'node identifiers') |
|
1375 | 1375 | |
|
1376 | 1376 | if opts.get('delete'): |
|
1377 | 1377 | indices = [] |
|
1378 | 1378 | for v in opts.get('delete'): |
|
1379 | 1379 | try: |
|
1380 | 1380 | indices.append(int(v)) |
|
1381 | 1381 | except ValueError: |
|
1382 | 1382 | raise error.Abort(_('invalid index value: %r') % v, |
|
1383 | 1383 | hint=_('use integers for indices')) |
|
1384 | 1384 | |
|
1385 | 1385 | if repo.currenttransaction(): |
|
1386 | 1386 | raise error.Abort(_('cannot delete obsmarkers in the middle ' |
|
1387 | 1387 | 'of transaction.')) |
|
1388 | 1388 | |
|
1389 | 1389 | with repo.lock(): |
|
1390 | 1390 | n = repair.deleteobsmarkers(repo.obsstore, indices) |
|
1391 | 1391 | ui.write(_('deleted %i obsolescence markers\n') % n) |
|
1392 | 1392 | |
|
1393 | 1393 | return |
|
1394 | 1394 | |
|
1395 | 1395 | if precursor is not None: |
|
1396 | 1396 | if opts['rev']: |
|
1397 | 1397 | raise error.Abort('cannot select revision when creating marker') |
|
1398 | 1398 | metadata = {} |
|
1399 | 1399 | metadata['user'] = opts['user'] or ui.username() |
|
1400 | 1400 | succs = tuple(parsenodeid(succ) for succ in successors) |
|
1401 | 1401 | l = repo.lock() |
|
1402 | 1402 | try: |
|
1403 | 1403 | tr = repo.transaction('debugobsolete') |
|
1404 | 1404 | try: |
|
1405 | 1405 | date = opts.get('date') |
|
1406 | 1406 | if date: |
|
1407 | 1407 | date = util.parsedate(date) |
|
1408 | 1408 | else: |
|
1409 | 1409 | date = None |
|
1410 | 1410 | prec = parsenodeid(precursor) |
|
1411 | 1411 | parents = None |
|
1412 | 1412 | if opts['record_parents']: |
|
1413 | 1413 | if prec not in repo.unfiltered(): |
|
1414 | 1414 | raise error.Abort('cannot used --record-parents on ' |
|
1415 | 1415 | 'unknown changesets') |
|
1416 | 1416 | parents = repo.unfiltered()[prec].parents() |
|
1417 | 1417 | parents = tuple(p.node() for p in parents) |
|
1418 | 1418 | repo.obsstore.create(tr, prec, succs, opts['flags'], |
|
1419 | 1419 | parents=parents, date=date, |
|
1420 | 1420 | metadata=metadata, ui=ui) |
|
1421 | 1421 | tr.close() |
|
1422 | 1422 | except ValueError as exc: |
|
1423 | 1423 | raise error.Abort(_('bad obsmarker input: %s') % exc) |
|
1424 | 1424 | finally: |
|
1425 | 1425 | tr.release() |
|
1426 | 1426 | finally: |
|
1427 | 1427 | l.release() |
|
1428 | 1428 | else: |
|
1429 | 1429 | if opts['rev']: |
|
1430 | 1430 | revs = scmutil.revrange(repo, opts['rev']) |
|
1431 | 1431 | nodes = [repo[r].node() for r in revs] |
|
1432 | 1432 | markers = list(obsutil.getmarkers(repo, nodes=nodes, |
|
1433 | 1433 | exclusive=opts['exclusive'])) |
|
1434 | 1434 | markers.sort(key=lambda x: x._data) |
|
1435 | 1435 | else: |
|
1436 | 1436 | markers = obsutil.getmarkers(repo) |
|
1437 | 1437 | |
|
1438 | 1438 | markerstoiter = markers |
|
1439 | 1439 | isrelevant = lambda m: True |
|
1440 | 1440 | if opts.get('rev') and opts.get('index'): |
|
1441 | 1441 | markerstoiter = obsutil.getmarkers(repo) |
|
1442 | 1442 | markerset = set(markers) |
|
1443 | 1443 | isrelevant = lambda m: m in markerset |
|
1444 | 1444 | |
|
1445 | 1445 | fm = ui.formatter('debugobsolete', opts) |
|
1446 | 1446 | for i, m in enumerate(markerstoiter): |
|
1447 | 1447 | if not isrelevant(m): |
|
1448 | 1448 | # marker can be irrelevant when we're iterating over a set |
|
1449 | 1449 | # of markers (markerstoiter) which is bigger than the set |
|
1450 | 1450 | # of markers we want to display (markers) |
|
1451 | 1451 | # this can happen if both --index and --rev options are |
|
1452 | 1452 | # provided and thus we need to iterate over all of the markers |
|
1453 | 1453 | # to get the correct indices, but only display the ones that |
|
1454 | 1454 | # are relevant to --rev value |
|
1455 | 1455 | continue |
|
1456 | 1456 | fm.startitem() |
|
1457 | 1457 | ind = i if opts.get('index') else None |
|
1458 | 1458 | cmdutil.showmarker(fm, m, index=ind) |
|
1459 | 1459 | fm.end() |
|
1460 | 1460 | |
|
1461 | 1461 | @command('debugpathcomplete', |
|
1462 | 1462 | [('f', 'full', None, _('complete an entire path')), |
|
1463 | 1463 | ('n', 'normal', None, _('show only normal files')), |
|
1464 | 1464 | ('a', 'added', None, _('show only added files')), |
|
1465 | 1465 | ('r', 'removed', None, _('show only removed files'))], |
|
1466 | 1466 | _('FILESPEC...')) |
|
1467 | 1467 | def debugpathcomplete(ui, repo, *specs, **opts): |
|
1468 | 1468 | '''complete part or all of a tracked path |
|
1469 | 1469 | |
|
1470 | 1470 | This command supports shells that offer path name completion. It |
|
1471 | 1471 | currently completes only files already known to the dirstate. |
|
1472 | 1472 | |
|
1473 | 1473 | Completion extends only to the next path segment unless |
|
1474 | 1474 | --full is specified, in which case entire paths are used.''' |
|
1475 | 1475 | |
|
1476 | 1476 | def complete(path, acceptable): |
|
1477 | 1477 | dirstate = repo.dirstate |
|
1478 | 1478 | spec = os.path.normpath(os.path.join(pycompat.getcwd(), path)) |
|
1479 | 1479 | rootdir = repo.root + pycompat.ossep |
|
1480 | 1480 | if spec != repo.root and not spec.startswith(rootdir): |
|
1481 | 1481 | return [], [] |
|
1482 | 1482 | if os.path.isdir(spec): |
|
1483 | 1483 | spec += '/' |
|
1484 | 1484 | spec = spec[len(rootdir):] |
|
1485 | 1485 | fixpaths = pycompat.ossep != '/' |
|
1486 | 1486 | if fixpaths: |
|
1487 | 1487 | spec = spec.replace(pycompat.ossep, '/') |
|
1488 | 1488 | speclen = len(spec) |
|
1489 | 1489 | fullpaths = opts[r'full'] |
|
1490 | 1490 | files, dirs = set(), set() |
|
1491 | 1491 | adddir, addfile = dirs.add, files.add |
|
1492 | 1492 | for f, st in dirstate.iteritems(): |
|
1493 | 1493 | if f.startswith(spec) and st[0] in acceptable: |
|
1494 | 1494 | if fixpaths: |
|
1495 | 1495 | f = f.replace('/', pycompat.ossep) |
|
1496 | 1496 | if fullpaths: |
|
1497 | 1497 | addfile(f) |
|
1498 | 1498 | continue |
|
1499 | 1499 | s = f.find(pycompat.ossep, speclen) |
|
1500 | 1500 | if s >= 0: |
|
1501 | 1501 | adddir(f[:s]) |
|
1502 | 1502 | else: |
|
1503 | 1503 | addfile(f) |
|
1504 | 1504 | return files, dirs |
|
1505 | 1505 | |
|
1506 | 1506 | acceptable = '' |
|
1507 | 1507 | if opts[r'normal']: |
|
1508 | 1508 | acceptable += 'nm' |
|
1509 | 1509 | if opts[r'added']: |
|
1510 | 1510 | acceptable += 'a' |
|
1511 | 1511 | if opts[r'removed']: |
|
1512 | 1512 | acceptable += 'r' |
|
1513 | 1513 | cwd = repo.getcwd() |
|
1514 | 1514 | if not specs: |
|
1515 | 1515 | specs = ['.'] |
|
1516 | 1516 | |
|
1517 | 1517 | files, dirs = set(), set() |
|
1518 | 1518 | for spec in specs: |
|
1519 | 1519 | f, d = complete(spec, acceptable or 'nmar') |
|
1520 | 1520 | files.update(f) |
|
1521 | 1521 | dirs.update(d) |
|
1522 | 1522 | files.update(dirs) |
|
1523 | 1523 | ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files))) |
|
1524 | 1524 | ui.write('\n') |
|
1525 | 1525 | |
|
1526 | 1526 | @command('debugpickmergetool', |
|
1527 | 1527 | [('r', 'rev', '', _('check for files in this revision'), _('REV')), |
|
1528 | 1528 | ('', 'changedelete', None, _('emulate merging change and delete')), |
|
1529 | 1529 | ] + cmdutil.walkopts + cmdutil.mergetoolopts, |
|
1530 | 1530 | _('[PATTERN]...'), |
|
1531 | 1531 | inferrepo=True) |
|
1532 | 1532 | def debugpickmergetool(ui, repo, *pats, **opts): |
|
1533 | 1533 | """examine which merge tool is chosen for specified file |
|
1534 | 1534 | |
|
1535 | 1535 | As described in :hg:`help merge-tools`, Mercurial examines |
|
1536 | 1536 | configurations below in this order to decide which merge tool is |
|
1537 | 1537 | chosen for specified file. |
|
1538 | 1538 | |
|
1539 | 1539 | 1. ``--tool`` option |
|
1540 | 1540 | 2. ``HGMERGE`` environment variable |
|
1541 | 1541 | 3. configurations in ``merge-patterns`` section |
|
1542 | 1542 | 4. configuration of ``ui.merge`` |
|
1543 | 1543 | 5. configurations in ``merge-tools`` section |
|
1544 | 1544 | 6. ``hgmerge`` tool (for historical reason only) |
|
1545 | 1545 | 7. default tool for fallback (``:merge`` or ``:prompt``) |
|
1546 | 1546 | |
|
1547 | 1547 | This command writes out examination result in the style below:: |
|
1548 | 1548 | |
|
1549 | 1549 | FILE = MERGETOOL |
|
1550 | 1550 | |
|
1551 | 1551 | By default, all files known in the first parent context of the |
|
1552 | 1552 | working directory are examined. Use file patterns and/or -I/-X |
|
1553 | 1553 | options to limit target files. -r/--rev is also useful to examine |
|
1554 | 1554 | files in another context without actual updating to it. |
|
1555 | 1555 | |
|
1556 | 1556 | With --debug, this command shows warning messages while matching |
|
1557 | 1557 | against ``merge-patterns`` and so on, too. It is recommended to |
|
1558 | 1558 | use this option with explicit file patterns and/or -I/-X options, |
|
1559 | 1559 | because this option increases amount of output per file according |
|
1560 | 1560 | to configurations in hgrc. |
|
1561 | 1561 | |
|
1562 | 1562 | With -v/--verbose, this command shows configurations below at |
|
1563 | 1563 | first (only if specified). |
|
1564 | 1564 | |
|
1565 | 1565 | - ``--tool`` option |
|
1566 | 1566 | - ``HGMERGE`` environment variable |
|
1567 | 1567 | - configuration of ``ui.merge`` |
|
1568 | 1568 | |
|
1569 | 1569 | If merge tool is chosen before matching against |
|
1570 | 1570 | ``merge-patterns``, this command can't show any helpful |
|
1571 | 1571 | information, even with --debug. In such case, information above is |
|
1572 | 1572 | useful to know why a merge tool is chosen. |
|
1573 | 1573 | """ |
|
1574 | 1574 | opts = pycompat.byteskwargs(opts) |
|
1575 | 1575 | overrides = {} |
|
1576 | 1576 | if opts['tool']: |
|
1577 | 1577 | overrides[('ui', 'forcemerge')] = opts['tool'] |
|
1578 | 1578 | ui.note(('with --tool %r\n') % (opts['tool'])) |
|
1579 | 1579 | |
|
1580 | 1580 | with ui.configoverride(overrides, 'debugmergepatterns'): |
|
1581 | 1581 | hgmerge = encoding.environ.get("HGMERGE") |
|
1582 | 1582 | if hgmerge is not None: |
|
1583 | 1583 | ui.note(('with HGMERGE=%r\n') % (hgmerge)) |
|
1584 | 1584 | uimerge = ui.config("ui", "merge") |
|
1585 | 1585 | if uimerge: |
|
1586 | 1586 | ui.note(('with ui.merge=%r\n') % (uimerge)) |
|
1587 | 1587 | |
|
1588 | 1588 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1589 | 1589 | m = scmutil.match(ctx, pats, opts) |
|
1590 | 1590 | changedelete = opts['changedelete'] |
|
1591 | 1591 | for path in ctx.walk(m): |
|
1592 | 1592 | fctx = ctx[path] |
|
1593 | 1593 | try: |
|
1594 | 1594 | if not ui.debugflag: |
|
1595 | 1595 | ui.pushbuffer(error=True) |
|
1596 | 1596 | tool, toolpath = filemerge._picktool(repo, ui, path, |
|
1597 | 1597 | fctx.isbinary(), |
|
1598 | 1598 | 'l' in fctx.flags(), |
|
1599 | 1599 | changedelete) |
|
1600 | 1600 | finally: |
|
1601 | 1601 | if not ui.debugflag: |
|
1602 | 1602 | ui.popbuffer() |
|
1603 | 1603 | ui.write(('%s = %s\n') % (path, tool)) |
|
1604 | 1604 | |
|
1605 | 1605 | @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True) |
|
1606 | 1606 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): |
|
1607 | 1607 | '''access the pushkey key/value protocol |
|
1608 | 1608 | |
|
1609 | 1609 | With two args, list the keys in the given namespace. |
|
1610 | 1610 | |
|
1611 | 1611 | With five args, set a key to new if it currently is set to old. |
|
1612 | 1612 | Reports success or failure. |
|
1613 | 1613 | ''' |
|
1614 | 1614 | |
|
1615 | 1615 | target = hg.peer(ui, {}, repopath) |
|
1616 | 1616 | if keyinfo: |
|
1617 | 1617 | key, old, new = keyinfo |
|
1618 | 1618 | r = target.pushkey(namespace, key, old, new) |
|
1619 | 1619 | ui.status(str(r) + '\n') |
|
1620 | 1620 | return not r |
|
1621 | 1621 | else: |
|
1622 | 1622 | for k, v in sorted(target.listkeys(namespace).iteritems()): |
|
1623 | 1623 | ui.write("%s\t%s\n" % (util.escapestr(k), |
|
1624 | 1624 | util.escapestr(v))) |
|
1625 | 1625 | |
|
1626 | 1626 | @command('debugpvec', [], _('A B')) |
|
1627 | 1627 | def debugpvec(ui, repo, a, b=None): |
|
1628 | 1628 | ca = scmutil.revsingle(repo, a) |
|
1629 | 1629 | cb = scmutil.revsingle(repo, b) |
|
1630 | 1630 | pa = pvec.ctxpvec(ca) |
|
1631 | 1631 | pb = pvec.ctxpvec(cb) |
|
1632 | 1632 | if pa == pb: |
|
1633 | 1633 | rel = "=" |
|
1634 | 1634 | elif pa > pb: |
|
1635 | 1635 | rel = ">" |
|
1636 | 1636 | elif pa < pb: |
|
1637 | 1637 | rel = "<" |
|
1638 | 1638 | elif pa | pb: |
|
1639 | 1639 | rel = "|" |
|
1640 | 1640 | ui.write(_("a: %s\n") % pa) |
|
1641 | 1641 | ui.write(_("b: %s\n") % pb) |
|
1642 | 1642 | ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) |
|
1643 | 1643 | ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") % |
|
1644 | 1644 | (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec), |
|
1645 | 1645 | pa.distance(pb), rel)) |
|
1646 | 1646 | |
|
1647 | 1647 | @command('debugrebuilddirstate|debugrebuildstate', |
|
1648 | 1648 | [('r', 'rev', '', _('revision to rebuild to'), _('REV')), |
|
1649 | 1649 | ('', 'minimal', None, _('only rebuild files that are inconsistent with ' |
|
1650 | 1650 | 'the working copy parent')), |
|
1651 | 1651 | ], |
|
1652 | 1652 | _('[-r REV]')) |
|
1653 | 1653 | def debugrebuilddirstate(ui, repo, rev, **opts): |
|
1654 | 1654 | """rebuild the dirstate as it would look like for the given revision |
|
1655 | 1655 | |
|
1656 | 1656 | If no revision is specified the first current parent will be used. |
|
1657 | 1657 | |
|
1658 | 1658 | The dirstate will be set to the files of the given revision. |
|
1659 | 1659 | The actual working directory content or existing dirstate |
|
1660 | 1660 | information such as adds or removes is not considered. |
|
1661 | 1661 | |
|
1662 | 1662 | ``minimal`` will only rebuild the dirstate status for files that claim to be |
|
1663 | 1663 | tracked but are not in the parent manifest, or that exist in the parent |
|
1664 | 1664 | manifest but are not in the dirstate. It will not change adds, removes, or |
|
1665 | 1665 | modified files that are in the working copy parent. |
|
1666 | 1666 | |
|
1667 | 1667 | One use of this command is to make the next :hg:`status` invocation |
|
1668 | 1668 | check the actual file content. |
|
1669 | 1669 | """ |
|
1670 | 1670 | ctx = scmutil.revsingle(repo, rev) |
|
1671 | 1671 | with repo.wlock(): |
|
1672 | 1672 | dirstate = repo.dirstate |
|
1673 | 1673 | changedfiles = None |
|
1674 | 1674 | # See command doc for what minimal does. |
|
1675 | 1675 | if opts.get(r'minimal'): |
|
1676 | 1676 | manifestfiles = set(ctx.manifest().keys()) |
|
1677 | 1677 | dirstatefiles = set(dirstate) |
|
1678 | 1678 | manifestonly = manifestfiles - dirstatefiles |
|
1679 | 1679 | dsonly = dirstatefiles - manifestfiles |
|
1680 | 1680 | dsnotadded = set(f for f in dsonly if dirstate[f] != 'a') |
|
1681 | 1681 | changedfiles = manifestonly | dsnotadded |
|
1682 | 1682 | |
|
1683 | 1683 | dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles) |
|
1684 | 1684 | |
|
1685 | 1685 | @command('debugrebuildfncache', [], '') |
|
1686 | 1686 | def debugrebuildfncache(ui, repo): |
|
1687 | 1687 | """rebuild the fncache file""" |
|
1688 | 1688 | repair.rebuildfncache(ui, repo) |
|
1689 | 1689 | |
|
1690 | 1690 | @command('debugrename', |
|
1691 | 1691 | [('r', 'rev', '', _('revision to debug'), _('REV'))], |
|
1692 | 1692 | _('[-r REV] FILE')) |
|
1693 | 1693 | def debugrename(ui, repo, file1, *pats, **opts): |
|
1694 | 1694 | """dump rename information""" |
|
1695 | 1695 | |
|
1696 | 1696 | opts = pycompat.byteskwargs(opts) |
|
1697 | 1697 | ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
1698 | 1698 | m = scmutil.match(ctx, (file1,) + pats, opts) |
|
1699 | 1699 | for abs in ctx.walk(m): |
|
1700 | 1700 | fctx = ctx[abs] |
|
1701 | 1701 | o = fctx.filelog().renamed(fctx.filenode()) |
|
1702 | 1702 | rel = m.rel(abs) |
|
1703 | 1703 | if o: |
|
1704 | 1704 | ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) |
|
1705 | 1705 | else: |
|
1706 | 1706 | ui.write(_("%s not renamed\n") % rel) |
|
1707 | 1707 | |
|
1708 | 1708 | @command('debugrevlog', cmdutil.debugrevlogopts + |
|
1709 | 1709 | [('d', 'dump', False, _('dump index data'))], |
|
1710 | 1710 | _('-c|-m|FILE'), |
|
1711 | 1711 | optionalrepo=True) |
|
1712 | 1712 | def debugrevlog(ui, repo, file_=None, **opts): |
|
1713 | 1713 | """show data and statistics about a revlog""" |
|
1714 | 1714 | opts = pycompat.byteskwargs(opts) |
|
1715 | 1715 | r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts) |
|
1716 | 1716 | |
|
1717 | 1717 | if opts.get("dump"): |
|
1718 | 1718 | numrevs = len(r) |
|
1719 | 1719 | ui.write(("# rev p1rev p2rev start end deltastart base p1 p2" |
|
1720 | 1720 | " rawsize totalsize compression heads chainlen\n")) |
|
1721 | 1721 | ts = 0 |
|
1722 | 1722 | heads = set() |
|
1723 | 1723 | |
|
1724 | 1724 | for rev in xrange(numrevs): |
|
1725 | 1725 | dbase = r.deltaparent(rev) |
|
1726 | 1726 | if dbase == -1: |
|
1727 | 1727 | dbase = rev |
|
1728 | 1728 | cbase = r.chainbase(rev) |
|
1729 | 1729 | clen = r.chainlen(rev) |
|
1730 | 1730 | p1, p2 = r.parentrevs(rev) |
|
1731 | 1731 | rs = r.rawsize(rev) |
|
1732 | 1732 | ts = ts + rs |
|
1733 | 1733 | heads -= set(r.parentrevs(rev)) |
|
1734 | 1734 | heads.add(rev) |
|
1735 | 1735 | try: |
|
1736 | 1736 | compression = ts / r.end(rev) |
|
1737 | 1737 | except ZeroDivisionError: |
|
1738 | 1738 | compression = 0 |
|
1739 | 1739 | ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d " |
|
1740 | 1740 | "%11d %5d %8d\n" % |
|
1741 | 1741 | (rev, p1, p2, r.start(rev), r.end(rev), |
|
1742 | 1742 | r.start(dbase), r.start(cbase), |
|
1743 | 1743 | r.start(p1), r.start(p2), |
|
1744 | 1744 | rs, ts, compression, len(heads), clen)) |
|
1745 | 1745 | return 0 |
|
1746 | 1746 | |
|
1747 | 1747 | v = r.version |
|
1748 | 1748 | format = v & 0xFFFF |
|
1749 | 1749 | flags = [] |
|
1750 | 1750 | gdelta = False |
|
1751 | 1751 | if v & revlog.FLAG_INLINE_DATA: |
|
1752 | 1752 | flags.append('inline') |
|
1753 | 1753 | if v & revlog.FLAG_GENERALDELTA: |
|
1754 | 1754 | gdelta = True |
|
1755 | 1755 | flags.append('generaldelta') |
|
1756 | 1756 | if not flags: |
|
1757 | 1757 | flags = ['(none)'] |
|
1758 | 1758 | |
|
1759 | 1759 | nummerges = 0 |
|
1760 | 1760 | numfull = 0 |
|
1761 | 1761 | numprev = 0 |
|
1762 | 1762 | nump1 = 0 |
|
1763 | 1763 | nump2 = 0 |
|
1764 | 1764 | numother = 0 |
|
1765 | 1765 | nump1prev = 0 |
|
1766 | 1766 | nump2prev = 0 |
|
1767 | 1767 | chainlengths = [] |
|
1768 | 1768 | chainbases = [] |
|
1769 | 1769 | chainspans = [] |
|
1770 | 1770 | |
|
1771 | 1771 | datasize = [None, 0, 0] |
|
1772 | 1772 | fullsize = [None, 0, 0] |
|
1773 | 1773 | deltasize = [None, 0, 0] |
|
1774 | 1774 | chunktypecounts = {} |
|
1775 | 1775 | chunktypesizes = {} |
|
1776 | 1776 | |
|
1777 | 1777 | def addsize(size, l): |
|
1778 | 1778 | if l[0] is None or size < l[0]: |
|
1779 | 1779 | l[0] = size |
|
1780 | 1780 | if size > l[1]: |
|
1781 | 1781 | l[1] = size |
|
1782 | 1782 | l[2] += size |
|
1783 | 1783 | |
|
1784 | 1784 | numrevs = len(r) |
|
1785 | 1785 | for rev in xrange(numrevs): |
|
1786 | 1786 | p1, p2 = r.parentrevs(rev) |
|
1787 | 1787 | delta = r.deltaparent(rev) |
|
1788 | 1788 | if format > 0: |
|
1789 | 1789 | addsize(r.rawsize(rev), datasize) |
|
1790 | 1790 | if p2 != nullrev: |
|
1791 | 1791 | nummerges += 1 |
|
1792 | 1792 | size = r.length(rev) |
|
1793 | 1793 | if delta == nullrev: |
|
1794 | 1794 | chainlengths.append(0) |
|
1795 | 1795 | chainbases.append(r.start(rev)) |
|
1796 | 1796 | chainspans.append(size) |
|
1797 | 1797 | numfull += 1 |
|
1798 | 1798 | addsize(size, fullsize) |
|
1799 | 1799 | else: |
|
1800 | 1800 | chainlengths.append(chainlengths[delta] + 1) |
|
1801 | 1801 | baseaddr = chainbases[delta] |
|
1802 | 1802 | revaddr = r.start(rev) |
|
1803 | 1803 | chainbases.append(baseaddr) |
|
1804 | 1804 | chainspans.append((revaddr - baseaddr) + size) |
|
1805 | 1805 | addsize(size, deltasize) |
|
1806 | 1806 | if delta == rev - 1: |
|
1807 | 1807 | numprev += 1 |
|
1808 | 1808 | if delta == p1: |
|
1809 | 1809 | nump1prev += 1 |
|
1810 | 1810 | elif delta == p2: |
|
1811 | 1811 | nump2prev += 1 |
|
1812 | 1812 | elif delta == p1: |
|
1813 | 1813 | nump1 += 1 |
|
1814 | 1814 | elif delta == p2: |
|
1815 | 1815 | nump2 += 1 |
|
1816 | 1816 | elif delta != nullrev: |
|
1817 | 1817 | numother += 1 |
|
1818 | 1818 | |
|
1819 | 1819 | # Obtain data on the raw chunks in the revlog. |
|
1820 | 1820 | segment = r._getsegmentforrevs(rev, rev)[1] |
|
1821 | 1821 | if segment: |
|
1822 | 1822 | chunktype = bytes(segment[0:1]) |
|
1823 | 1823 | else: |
|
1824 | 1824 | chunktype = 'empty' |
|
1825 | 1825 | |
|
1826 | 1826 | if chunktype not in chunktypecounts: |
|
1827 | 1827 | chunktypecounts[chunktype] = 0 |
|
1828 | 1828 | chunktypesizes[chunktype] = 0 |
|
1829 | 1829 | |
|
1830 | 1830 | chunktypecounts[chunktype] += 1 |
|
1831 | 1831 | chunktypesizes[chunktype] += size |
|
1832 | 1832 | |
|
1833 | 1833 | # Adjust size min value for empty cases |
|
1834 | 1834 | for size in (datasize, fullsize, deltasize): |
|
1835 | 1835 | if size[0] is None: |
|
1836 | 1836 | size[0] = 0 |
|
1837 | 1837 | |
|
1838 | 1838 | numdeltas = numrevs - numfull |
|
1839 | 1839 | numoprev = numprev - nump1prev - nump2prev |
|
1840 | 1840 | totalrawsize = datasize[2] |
|
1841 | 1841 | datasize[2] /= numrevs |
|
1842 | 1842 | fulltotal = fullsize[2] |
|
1843 | 1843 | fullsize[2] /= numfull |
|
1844 | 1844 | deltatotal = deltasize[2] |
|
1845 | 1845 | if numrevs - numfull > 0: |
|
1846 | 1846 | deltasize[2] /= numrevs - numfull |
|
1847 | 1847 | totalsize = fulltotal + deltatotal |
|
1848 | 1848 | avgchainlen = sum(chainlengths) / numrevs |
|
1849 | 1849 | maxchainlen = max(chainlengths) |
|
1850 | 1850 | maxchainspan = max(chainspans) |
|
1851 | 1851 | compratio = 1 |
|
1852 | 1852 | if totalsize: |
|
1853 | 1853 | compratio = totalrawsize / totalsize |
|
1854 | 1854 | |
|
1855 | 1855 | basedfmtstr = '%%%dd\n' |
|
1856 | 1856 | basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n' |
|
1857 | 1857 | |
|
1858 | 1858 | def dfmtstr(max): |
|
1859 | 1859 | return basedfmtstr % len(str(max)) |
|
1860 | 1860 | def pcfmtstr(max, padding=0): |
|
1861 | 1861 | return basepcfmtstr % (len(str(max)), ' ' * padding) |
|
1862 | 1862 | |
|
1863 | 1863 | def pcfmt(value, total): |
|
1864 | 1864 | if total: |
|
1865 | 1865 | return (value, 100 * float(value) / total) |
|
1866 | 1866 | else: |
|
1867 | 1867 | return value, 100.0 |
|
1868 | 1868 | |
|
1869 | 1869 | ui.write(('format : %d\n') % format) |
|
1870 | 1870 | ui.write(('flags : %s\n') % ', '.join(flags)) |
|
1871 | 1871 | |
|
1872 | 1872 | ui.write('\n') |
|
1873 | 1873 | fmt = pcfmtstr(totalsize) |
|
1874 | 1874 | fmt2 = dfmtstr(totalsize) |
|
1875 | 1875 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
1876 | 1876 | ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs)) |
|
1877 | 1877 | ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs)) |
|
1878 | 1878 | ui.write(('revisions : ') + fmt2 % numrevs) |
|
1879 | 1879 | ui.write((' full : ') + fmt % pcfmt(numfull, numrevs)) |
|
1880 | 1880 | ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs)) |
|
1881 | 1881 | ui.write(('revision size : ') + fmt2 % totalsize) |
|
1882 | 1882 | ui.write((' full : ') + fmt % pcfmt(fulltotal, totalsize)) |
|
1883 | 1883 | ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize)) |
|
1884 | 1884 | |
|
1885 | 1885 | def fmtchunktype(chunktype): |
|
1886 | 1886 | if chunktype == 'empty': |
|
1887 | 1887 | return ' %s : ' % chunktype |
|
1888 | 1888 | elif chunktype in pycompat.bytestr(string.ascii_letters): |
|
1889 | 1889 | return ' 0x%s (%s) : ' % (hex(chunktype), chunktype) |
|
1890 | 1890 | else: |
|
1891 | 1891 | return ' 0x%s : ' % hex(chunktype) |
|
1892 | 1892 | |
|
1893 | 1893 | ui.write('\n') |
|
1894 | 1894 | ui.write(('chunks : ') + fmt2 % numrevs) |
|
1895 | 1895 | for chunktype in sorted(chunktypecounts): |
|
1896 | 1896 | ui.write(fmtchunktype(chunktype)) |
|
1897 | 1897 | ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs)) |
|
1898 | 1898 | ui.write(('chunks size : ') + fmt2 % totalsize) |
|
1899 | 1899 | for chunktype in sorted(chunktypecounts): |
|
1900 | 1900 | ui.write(fmtchunktype(chunktype)) |
|
1901 | 1901 | ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize)) |
|
1902 | 1902 | |
|
1903 | 1903 | ui.write('\n') |
|
1904 | 1904 | fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio)) |
|
1905 | 1905 | ui.write(('avg chain length : ') + fmt % avgchainlen) |
|
1906 | 1906 | ui.write(('max chain length : ') + fmt % maxchainlen) |
|
1907 | 1907 | ui.write(('max chain reach : ') + fmt % maxchainspan) |
|
1908 | 1908 | ui.write(('compression ratio : ') + fmt % compratio) |
|
1909 | 1909 | |
|
1910 | 1910 | if format > 0: |
|
1911 | 1911 | ui.write('\n') |
|
1912 | 1912 | ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n') |
|
1913 | 1913 | % tuple(datasize)) |
|
1914 | 1914 | ui.write(('full revision size (min/max/avg) : %d / %d / %d\n') |
|
1915 | 1915 | % tuple(fullsize)) |
|
1916 | 1916 | ui.write(('delta size (min/max/avg) : %d / %d / %d\n') |
|
1917 | 1917 | % tuple(deltasize)) |
|
1918 | 1918 | |
|
1919 | 1919 | if numdeltas > 0: |
|
1920 | 1920 | ui.write('\n') |
|
1921 | 1921 | fmt = pcfmtstr(numdeltas) |
|
1922 | 1922 | fmt2 = pcfmtstr(numdeltas, 4) |
|
1923 | 1923 | ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas)) |
|
1924 | 1924 | if numprev > 0: |
|
1925 | 1925 | ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev, |
|
1926 | 1926 | numprev)) |
|
1927 | 1927 | ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev, |
|
1928 | 1928 | numprev)) |
|
1929 | 1929 | ui.write((' other : ') + fmt2 % pcfmt(numoprev, |
|
1930 | 1930 | numprev)) |
|
1931 | 1931 | if gdelta: |
|
1932 | 1932 | ui.write(('deltas against p1 : ') |
|
1933 | 1933 | + fmt % pcfmt(nump1, numdeltas)) |
|
1934 | 1934 | ui.write(('deltas against p2 : ') |
|
1935 | 1935 | + fmt % pcfmt(nump2, numdeltas)) |
|
1936 | 1936 | ui.write(('deltas against other : ') + fmt % pcfmt(numother, |
|
1937 | 1937 | numdeltas)) |
|
1938 | 1938 | |
|
1939 | 1939 | @command('debugrevspec', |
|
1940 | 1940 | [('', 'optimize', None, |
|
1941 | 1941 | _('print parsed tree after optimizing (DEPRECATED)')), |
|
1942 | 1942 | ('', 'show-revs', True, _('print list of result revisions (default)')), |
|
1943 | 1943 | ('s', 'show-set', None, _('print internal representation of result set')), |
|
1944 | 1944 | ('p', 'show-stage', [], |
|
1945 | 1945 | _('print parsed tree at the given stage'), _('NAME')), |
|
1946 | 1946 | ('', 'no-optimized', False, _('evaluate tree without optimization')), |
|
1947 | 1947 | ('', 'verify-optimized', False, _('verify optimized result')), |
|
1948 | 1948 | ], |
|
1949 | 1949 | ('REVSPEC')) |
|
1950 | 1950 | def debugrevspec(ui, repo, expr, **opts): |
|
1951 | 1951 | """parse and apply a revision specification |
|
1952 | 1952 | |
|
1953 | 1953 | Use -p/--show-stage option to print the parsed tree at the given stages. |
|
1954 | 1954 | Use -p all to print tree at every stage. |
|
1955 | 1955 | |
|
1956 | 1956 | Use --no-show-revs option with -s or -p to print only the set |
|
1957 | 1957 | representation or the parsed tree respectively. |
|
1958 | 1958 | |
|
1959 | 1959 | Use --verify-optimized to compare the optimized result with the unoptimized |
|
1960 | 1960 | one. Returns 1 if the optimized result differs. |
|
1961 | 1961 | """ |
|
1962 | 1962 | opts = pycompat.byteskwargs(opts) |
|
1963 | aliases = ui.configitems('revsetalias') | |
|
1963 | 1964 | stages = [ |
|
1964 | 1965 | ('parsed', lambda tree: tree), |
|
1965 |
('expanded', lambda tree: revsetlang.expandaliases( |
|
|
1966 | ('expanded', lambda tree: revsetlang.expandaliases(tree, aliases, | |
|
1967 | ui.warn)), | |
|
1966 | 1968 | ('concatenated', revsetlang.foldconcat), |
|
1967 | 1969 | ('analyzed', revsetlang.analyze), |
|
1968 | 1970 | ('optimized', revsetlang.optimize), |
|
1969 | 1971 | ] |
|
1970 | 1972 | if opts['no_optimized']: |
|
1971 | 1973 | stages = stages[:-1] |
|
1972 | 1974 | if opts['verify_optimized'] and opts['no_optimized']: |
|
1973 | 1975 | raise error.Abort(_('cannot use --verify-optimized with ' |
|
1974 | 1976 | '--no-optimized')) |
|
1975 | 1977 | stagenames = set(n for n, f in stages) |
|
1976 | 1978 | |
|
1977 | 1979 | showalways = set() |
|
1978 | 1980 | showchanged = set() |
|
1979 | 1981 | if ui.verbose and not opts['show_stage']: |
|
1980 | 1982 | # show parsed tree by --verbose (deprecated) |
|
1981 | 1983 | showalways.add('parsed') |
|
1982 | 1984 | showchanged.update(['expanded', 'concatenated']) |
|
1983 | 1985 | if opts['optimize']: |
|
1984 | 1986 | showalways.add('optimized') |
|
1985 | 1987 | if opts['show_stage'] and opts['optimize']: |
|
1986 | 1988 | raise error.Abort(_('cannot use --optimize with --show-stage')) |
|
1987 | 1989 | if opts['show_stage'] == ['all']: |
|
1988 | 1990 | showalways.update(stagenames) |
|
1989 | 1991 | else: |
|
1990 | 1992 | for n in opts['show_stage']: |
|
1991 | 1993 | if n not in stagenames: |
|
1992 | 1994 | raise error.Abort(_('invalid stage name: %s') % n) |
|
1993 | 1995 | showalways.update(opts['show_stage']) |
|
1994 | 1996 | |
|
1995 | 1997 | treebystage = {} |
|
1996 | 1998 | printedtree = None |
|
1997 | 1999 | tree = revsetlang.parse(expr, lookup=repo.__contains__) |
|
1998 | 2000 | for n, f in stages: |
|
1999 | 2001 | treebystage[n] = tree = f(tree) |
|
2000 | 2002 | if n in showalways or (n in showchanged and tree != printedtree): |
|
2001 | 2003 | if opts['show_stage'] or n != 'parsed': |
|
2002 | 2004 | ui.write(("* %s:\n") % n) |
|
2003 | 2005 | ui.write(revsetlang.prettyformat(tree), "\n") |
|
2004 | 2006 | printedtree = tree |
|
2005 | 2007 | |
|
2006 | 2008 | if opts['verify_optimized']: |
|
2007 | 2009 | arevs = revset.makematcher(treebystage['analyzed'])(repo) |
|
2008 | 2010 | brevs = revset.makematcher(treebystage['optimized'])(repo) |
|
2009 | 2011 | if opts['show_set'] or (opts['show_set'] is None and ui.verbose): |
|
2010 | 2012 | ui.write(("* analyzed set:\n"), smartset.prettyformat(arevs), "\n") |
|
2011 | 2013 | ui.write(("* optimized set:\n"), smartset.prettyformat(brevs), "\n") |
|
2012 | 2014 | arevs = list(arevs) |
|
2013 | 2015 | brevs = list(brevs) |
|
2014 | 2016 | if arevs == brevs: |
|
2015 | 2017 | return 0 |
|
2016 | 2018 | ui.write(('--- analyzed\n'), label='diff.file_a') |
|
2017 | 2019 | ui.write(('+++ optimized\n'), label='diff.file_b') |
|
2018 | 2020 | sm = difflib.SequenceMatcher(None, arevs, brevs) |
|
2019 | 2021 | for tag, alo, ahi, blo, bhi in sm.get_opcodes(): |
|
2020 | 2022 | if tag in ('delete', 'replace'): |
|
2021 | 2023 | for c in arevs[alo:ahi]: |
|
2022 | 2024 | ui.write('-%s\n' % c, label='diff.deleted') |
|
2023 | 2025 | if tag in ('insert', 'replace'): |
|
2024 | 2026 | for c in brevs[blo:bhi]: |
|
2025 | 2027 | ui.write('+%s\n' % c, label='diff.inserted') |
|
2026 | 2028 | if tag == 'equal': |
|
2027 | 2029 | for c in arevs[alo:ahi]: |
|
2028 | 2030 | ui.write(' %s\n' % c) |
|
2029 | 2031 | return 1 |
|
2030 | 2032 | |
|
2031 | 2033 | func = revset.makematcher(tree) |
|
2032 | 2034 | revs = func(repo) |
|
2033 | 2035 | if opts['show_set'] or (opts['show_set'] is None and ui.verbose): |
|
2034 | 2036 | ui.write(("* set:\n"), smartset.prettyformat(revs), "\n") |
|
2035 | 2037 | if not opts['show_revs']: |
|
2036 | 2038 | return |
|
2037 | 2039 | for c in revs: |
|
2038 | 2040 | ui.write("%s\n" % c) |
|
2039 | 2041 | |
|
2040 | 2042 | @command('debugsetparents', [], _('REV1 [REV2]')) |
|
2041 | 2043 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
2042 | 2044 | """manually set the parents of the current working directory |
|
2043 | 2045 | |
|
2044 | 2046 | This is useful for writing repository conversion tools, but should |
|
2045 | 2047 | be used with care. For example, neither the working directory nor the |
|
2046 | 2048 | dirstate is updated, so file status may be incorrect after running this |
|
2047 | 2049 | command. |
|
2048 | 2050 | |
|
2049 | 2051 | Returns 0 on success. |
|
2050 | 2052 | """ |
|
2051 | 2053 | |
|
2052 | 2054 | r1 = scmutil.revsingle(repo, rev1).node() |
|
2053 | 2055 | r2 = scmutil.revsingle(repo, rev2, 'null').node() |
|
2054 | 2056 | |
|
2055 | 2057 | with repo.wlock(): |
|
2056 | 2058 | repo.setparents(r1, r2) |
|
2057 | 2059 | |
|
2058 | 2060 | @command('debugsub', |
|
2059 | 2061 | [('r', 'rev', '', |
|
2060 | 2062 | _('revision to check'), _('REV'))], |
|
2061 | 2063 | _('[-r REV] [REV]')) |
|
2062 | 2064 | def debugsub(ui, repo, rev=None): |
|
2063 | 2065 | ctx = scmutil.revsingle(repo, rev, None) |
|
2064 | 2066 | for k, v in sorted(ctx.substate.items()): |
|
2065 | 2067 | ui.write(('path %s\n') % k) |
|
2066 | 2068 | ui.write((' source %s\n') % v[0]) |
|
2067 | 2069 | ui.write((' revision %s\n') % v[1]) |
|
2068 | 2070 | |
|
2069 | 2071 | @command('debugsuccessorssets', |
|
2070 | 2072 | [('', 'closest', False, _('return closest successors sets only'))], |
|
2071 | 2073 | _('[REV]')) |
|
2072 | 2074 | def debugsuccessorssets(ui, repo, *revs, **opts): |
|
2073 | 2075 | """show set of successors for revision |
|
2074 | 2076 | |
|
2075 | 2077 | A successors set of changeset A is a consistent group of revisions that |
|
2076 | 2078 | succeed A. It contains non-obsolete changesets only unless closests |
|
2077 | 2079 | successors set is set. |
|
2078 | 2080 | |
|
2079 | 2081 | In most cases a changeset A has a single successors set containing a single |
|
2080 | 2082 | successor (changeset A replaced by A'). |
|
2081 | 2083 | |
|
2082 | 2084 | A changeset that is made obsolete with no successors are called "pruned". |
|
2083 | 2085 | Such changesets have no successors sets at all. |
|
2084 | 2086 | |
|
2085 | 2087 | A changeset that has been "split" will have a successors set containing |
|
2086 | 2088 | more than one successor. |
|
2087 | 2089 | |
|
2088 | 2090 | A changeset that has been rewritten in multiple different ways is called |
|
2089 | 2091 | "divergent". Such changesets have multiple successor sets (each of which |
|
2090 | 2092 | may also be split, i.e. have multiple successors). |
|
2091 | 2093 | |
|
2092 | 2094 | Results are displayed as follows:: |
|
2093 | 2095 | |
|
2094 | 2096 | <rev1> |
|
2095 | 2097 | <successors-1A> |
|
2096 | 2098 | <rev2> |
|
2097 | 2099 | <successors-2A> |
|
2098 | 2100 | <successors-2B1> <successors-2B2> <successors-2B3> |
|
2099 | 2101 | |
|
2100 | 2102 | Here rev2 has two possible (i.e. divergent) successors sets. The first |
|
2101 | 2103 | holds one element, whereas the second holds three (i.e. the changeset has |
|
2102 | 2104 | been split). |
|
2103 | 2105 | """ |
|
2104 | 2106 | # passed to successorssets caching computation from one call to another |
|
2105 | 2107 | cache = {} |
|
2106 | 2108 | ctx2str = str |
|
2107 | 2109 | node2str = short |
|
2108 | 2110 | if ui.debug(): |
|
2109 | 2111 | def ctx2str(ctx): |
|
2110 | 2112 | return ctx.hex() |
|
2111 | 2113 | node2str = hex |
|
2112 | 2114 | for rev in scmutil.revrange(repo, revs): |
|
2113 | 2115 | ctx = repo[rev] |
|
2114 | 2116 | ui.write('%s\n'% ctx2str(ctx)) |
|
2115 | 2117 | for succsset in obsutil.successorssets(repo, ctx.node(), |
|
2116 | 2118 | closest=opts['closest'], |
|
2117 | 2119 | cache=cache): |
|
2118 | 2120 | if succsset: |
|
2119 | 2121 | ui.write(' ') |
|
2120 | 2122 | ui.write(node2str(succsset[0])) |
|
2121 | 2123 | for node in succsset[1:]: |
|
2122 | 2124 | ui.write(' ') |
|
2123 | 2125 | ui.write(node2str(node)) |
|
2124 | 2126 | ui.write('\n') |
|
2125 | 2127 | |
|
2126 | 2128 | @command('debugtemplate', |
|
2127 | 2129 | [('r', 'rev', [], _('apply template on changesets'), _('REV')), |
|
2128 | 2130 | ('D', 'define', [], _('define template keyword'), _('KEY=VALUE'))], |
|
2129 | 2131 | _('[-r REV]... [-D KEY=VALUE]... TEMPLATE'), |
|
2130 | 2132 | optionalrepo=True) |
|
2131 | 2133 | def debugtemplate(ui, repo, tmpl, **opts): |
|
2132 | 2134 | """parse and apply a template |
|
2133 | 2135 | |
|
2134 | 2136 | If -r/--rev is given, the template is processed as a log template and |
|
2135 | 2137 | applied to the given changesets. Otherwise, it is processed as a generic |
|
2136 | 2138 | template. |
|
2137 | 2139 | |
|
2138 | 2140 | Use --verbose to print the parsed tree. |
|
2139 | 2141 | """ |
|
2140 | 2142 | revs = None |
|
2141 | 2143 | if opts[r'rev']: |
|
2142 | 2144 | if repo is None: |
|
2143 | 2145 | raise error.RepoError(_('there is no Mercurial repository here ' |
|
2144 | 2146 | '(.hg not found)')) |
|
2145 | 2147 | revs = scmutil.revrange(repo, opts[r'rev']) |
|
2146 | 2148 | |
|
2147 | 2149 | props = {} |
|
2148 | 2150 | for d in opts[r'define']: |
|
2149 | 2151 | try: |
|
2150 | 2152 | k, v = (e.strip() for e in d.split('=', 1)) |
|
2151 | 2153 | if not k or k == 'ui': |
|
2152 | 2154 | raise ValueError |
|
2153 | 2155 | props[k] = v |
|
2154 | 2156 | except ValueError: |
|
2155 | 2157 | raise error.Abort(_('malformed keyword definition: %s') % d) |
|
2156 | 2158 | |
|
2157 | 2159 | if ui.verbose: |
|
2158 | 2160 | aliases = ui.configitems('templatealias') |
|
2159 | 2161 | tree = templater.parse(tmpl) |
|
2160 | 2162 | ui.note(templater.prettyformat(tree), '\n') |
|
2161 | 2163 | newtree = templater.expandaliases(tree, aliases) |
|
2162 | 2164 | if newtree != tree: |
|
2163 | 2165 | ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n') |
|
2164 | 2166 | |
|
2165 | 2167 | if revs is None: |
|
2166 | 2168 | t = formatter.maketemplater(ui, tmpl) |
|
2167 | 2169 | props['ui'] = ui |
|
2168 | 2170 | ui.write(t.render(props)) |
|
2169 | 2171 | else: |
|
2170 | 2172 | displayer = cmdutil.makelogtemplater(ui, repo, tmpl) |
|
2171 | 2173 | for r in revs: |
|
2172 | 2174 | displayer.show(repo[r], **pycompat.strkwargs(props)) |
|
2173 | 2175 | displayer.close() |
|
2174 | 2176 | |
|
2175 | 2177 | @command('debugupdatecaches', []) |
|
2176 | 2178 | def debugupdatecaches(ui, repo, *pats, **opts): |
|
2177 | 2179 | """warm all known caches in the repository""" |
|
2178 | 2180 | with repo.wlock(): |
|
2179 | 2181 | with repo.lock(): |
|
2180 | 2182 | repo.updatecaches() |
|
2181 | 2183 | |
|
2182 | 2184 | @command('debugupgraderepo', [ |
|
2183 | 2185 | ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')), |
|
2184 | 2186 | ('', 'run', False, _('performs an upgrade')), |
|
2185 | 2187 | ]) |
|
2186 | 2188 | def debugupgraderepo(ui, repo, run=False, optimize=None): |
|
2187 | 2189 | """upgrade a repository to use different features |
|
2188 | 2190 | |
|
2189 | 2191 | If no arguments are specified, the repository is evaluated for upgrade |
|
2190 | 2192 | and a list of problems and potential optimizations is printed. |
|
2191 | 2193 | |
|
2192 | 2194 | With ``--run``, a repository upgrade is performed. Behavior of the upgrade |
|
2193 | 2195 | can be influenced via additional arguments. More details will be provided |
|
2194 | 2196 | by the command output when run without ``--run``. |
|
2195 | 2197 | |
|
2196 | 2198 | During the upgrade, the repository will be locked and no writes will be |
|
2197 | 2199 | allowed. |
|
2198 | 2200 | |
|
2199 | 2201 | At the end of the upgrade, the repository may not be readable while new |
|
2200 | 2202 | repository data is swapped in. This window will be as long as it takes to |
|
2201 | 2203 | rename some directories inside the ``.hg`` directory. On most machines, this |
|
2202 | 2204 | should complete almost instantaneously and the chances of a consumer being |
|
2203 | 2205 | unable to access the repository should be low. |
|
2204 | 2206 | """ |
|
2205 | 2207 | return upgrade.upgraderepo(ui, repo, run=run, optimize=optimize) |
|
2206 | 2208 | |
|
2207 | 2209 | @command('debugwalk', cmdutil.walkopts, _('[OPTION]... [FILE]...'), |
|
2208 | 2210 | inferrepo=True) |
|
2209 | 2211 | def debugwalk(ui, repo, *pats, **opts): |
|
2210 | 2212 | """show how files match on given patterns""" |
|
2211 | 2213 | opts = pycompat.byteskwargs(opts) |
|
2212 | 2214 | m = scmutil.match(repo[None], pats, opts) |
|
2213 | 2215 | ui.write(('matcher: %r\n' % m)) |
|
2214 | 2216 | items = list(repo[None].walk(m)) |
|
2215 | 2217 | if not items: |
|
2216 | 2218 | return |
|
2217 | 2219 | f = lambda fn: fn |
|
2218 | 2220 | if ui.configbool('ui', 'slash') and pycompat.ossep != '/': |
|
2219 | 2221 | f = lambda fn: util.normpath(fn) |
|
2220 | 2222 | fmt = 'f %%-%ds %%-%ds %%s' % ( |
|
2221 | 2223 | max([len(abs) for abs in items]), |
|
2222 | 2224 | max([len(m.rel(abs)) for abs in items])) |
|
2223 | 2225 | for abs in items: |
|
2224 | 2226 | line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') |
|
2225 | 2227 | ui.write("%s\n" % line.rstrip()) |
|
2226 | 2228 | |
|
2227 | 2229 | @command('debugwireargs', |
|
2228 | 2230 | [('', 'three', '', 'three'), |
|
2229 | 2231 | ('', 'four', '', 'four'), |
|
2230 | 2232 | ('', 'five', '', 'five'), |
|
2231 | 2233 | ] + cmdutil.remoteopts, |
|
2232 | 2234 | _('REPO [OPTIONS]... [ONE [TWO]]'), |
|
2233 | 2235 | norepo=True) |
|
2234 | 2236 | def debugwireargs(ui, repopath, *vals, **opts): |
|
2235 | 2237 | opts = pycompat.byteskwargs(opts) |
|
2236 | 2238 | repo = hg.peer(ui, opts, repopath) |
|
2237 | 2239 | for opt in cmdutil.remoteopts: |
|
2238 | 2240 | del opts[opt[1]] |
|
2239 | 2241 | args = {} |
|
2240 | 2242 | for k, v in opts.iteritems(): |
|
2241 | 2243 | if v: |
|
2242 | 2244 | args[k] = v |
|
2243 | 2245 | # run twice to check that we don't mess up the stream for the next command |
|
2244 | 2246 | res1 = repo.debugwireargs(*vals, **args) |
|
2245 | 2247 | res2 = repo.debugwireargs(*vals, **args) |
|
2246 | 2248 | ui.write("%s\n" % res1) |
|
2247 | 2249 | if res1 != res2: |
|
2248 | 2250 | ui.warn("%s\n" % res2) |
@@ -1,2137 +1,2140 b'' | |||
|
1 | 1 | # localrepo.py - read/write repository class for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import errno |
|
11 | 11 | import hashlib |
|
12 | 12 | import inspect |
|
13 | 13 | import os |
|
14 | 14 | import random |
|
15 | 15 | import time |
|
16 | 16 | import weakref |
|
17 | 17 | |
|
18 | 18 | from .i18n import _ |
|
19 | 19 | from .node import ( |
|
20 | 20 | hex, |
|
21 | 21 | nullid, |
|
22 | 22 | short, |
|
23 | 23 | ) |
|
24 | 24 | from . import ( |
|
25 | 25 | bookmarks, |
|
26 | 26 | branchmap, |
|
27 | 27 | bundle2, |
|
28 | 28 | changegroup, |
|
29 | 29 | changelog, |
|
30 | 30 | color, |
|
31 | 31 | context, |
|
32 | 32 | dirstate, |
|
33 | 33 | dirstateguard, |
|
34 | 34 | encoding, |
|
35 | 35 | error, |
|
36 | 36 | exchange, |
|
37 | 37 | extensions, |
|
38 | 38 | filelog, |
|
39 | 39 | hook, |
|
40 | 40 | lock as lockmod, |
|
41 | 41 | manifest, |
|
42 | 42 | match as matchmod, |
|
43 | 43 | merge as mergemod, |
|
44 | 44 | mergeutil, |
|
45 | 45 | namespaces, |
|
46 | 46 | obsolete, |
|
47 | 47 | pathutil, |
|
48 | 48 | peer, |
|
49 | 49 | phases, |
|
50 | 50 | pushkey, |
|
51 | 51 | pycompat, |
|
52 | 52 | repoview, |
|
53 | 53 | revset, |
|
54 | 54 | revsetlang, |
|
55 | 55 | scmutil, |
|
56 | 56 | store, |
|
57 | 57 | subrepo, |
|
58 | 58 | tags as tagsmod, |
|
59 | 59 | transaction, |
|
60 | 60 | txnutil, |
|
61 | 61 | util, |
|
62 | 62 | vfs as vfsmod, |
|
63 | 63 | ) |
|
64 | 64 | |
|
65 | 65 | release = lockmod.release |
|
66 | 66 | urlerr = util.urlerr |
|
67 | 67 | urlreq = util.urlreq |
|
68 | 68 | |
|
69 | 69 | # set of (path, vfs-location) tuples. vfs-location is: |
|
70 | 70 | # - 'plain for vfs relative paths |
|
71 | 71 | # - '' for svfs relative paths |
|
72 | 72 | _cachedfiles = set() |
|
73 | 73 | |
|
74 | 74 | class _basefilecache(scmutil.filecache): |
|
75 | 75 | """All filecache usage on repo are done for logic that should be unfiltered |
|
76 | 76 | """ |
|
77 | 77 | def __get__(self, repo, type=None): |
|
78 | 78 | if repo is None: |
|
79 | 79 | return self |
|
80 | 80 | return super(_basefilecache, self).__get__(repo.unfiltered(), type) |
|
81 | 81 | def __set__(self, repo, value): |
|
82 | 82 | return super(_basefilecache, self).__set__(repo.unfiltered(), value) |
|
83 | 83 | def __delete__(self, repo): |
|
84 | 84 | return super(_basefilecache, self).__delete__(repo.unfiltered()) |
|
85 | 85 | |
|
86 | 86 | class repofilecache(_basefilecache): |
|
87 | 87 | """filecache for files in .hg but outside of .hg/store""" |
|
88 | 88 | def __init__(self, *paths): |
|
89 | 89 | super(repofilecache, self).__init__(*paths) |
|
90 | 90 | for path in paths: |
|
91 | 91 | _cachedfiles.add((path, 'plain')) |
|
92 | 92 | |
|
93 | 93 | def join(self, obj, fname): |
|
94 | 94 | return obj.vfs.join(fname) |
|
95 | 95 | |
|
96 | 96 | class storecache(_basefilecache): |
|
97 | 97 | """filecache for files in the store""" |
|
98 | 98 | def __init__(self, *paths): |
|
99 | 99 | super(storecache, self).__init__(*paths) |
|
100 | 100 | for path in paths: |
|
101 | 101 | _cachedfiles.add((path, '')) |
|
102 | 102 | |
|
103 | 103 | def join(self, obj, fname): |
|
104 | 104 | return obj.sjoin(fname) |
|
105 | 105 | |
|
106 | 106 | class unfilteredpropertycache(util.propertycache): |
|
107 | 107 | """propertycache that apply to unfiltered repo only""" |
|
108 | 108 | |
|
109 | 109 | def __get__(self, repo, type=None): |
|
110 | 110 | unfi = repo.unfiltered() |
|
111 | 111 | if unfi is repo: |
|
112 | 112 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
113 | 113 | return getattr(unfi, self.name) |
|
114 | 114 | |
|
115 | 115 | class filteredpropertycache(util.propertycache): |
|
116 | 116 | """propertycache that must take filtering in account""" |
|
117 | 117 | |
|
118 | 118 | def cachevalue(self, obj, value): |
|
119 | 119 | object.__setattr__(obj, self.name, value) |
|
120 | 120 | |
|
121 | 121 | |
|
122 | 122 | def hasunfilteredcache(repo, name): |
|
123 | 123 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
124 | 124 | return name in vars(repo.unfiltered()) |
|
125 | 125 | |
|
126 | 126 | def unfilteredmethod(orig): |
|
127 | 127 | """decorate method that always need to be run on unfiltered version""" |
|
128 | 128 | def wrapper(repo, *args, **kwargs): |
|
129 | 129 | return orig(repo.unfiltered(), *args, **kwargs) |
|
130 | 130 | return wrapper |
|
131 | 131 | |
|
132 | 132 | moderncaps = {'lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
133 | 133 | 'unbundle'} |
|
134 | 134 | legacycaps = moderncaps.union({'changegroupsubset'}) |
|
135 | 135 | |
|
136 | 136 | class localpeer(peer.peerrepository): |
|
137 | 137 | '''peer for a local repo; reflects only the most recent API''' |
|
138 | 138 | |
|
139 | 139 | def __init__(self, repo, caps=None): |
|
140 | 140 | if caps is None: |
|
141 | 141 | caps = moderncaps.copy() |
|
142 | 142 | peer.peerrepository.__init__(self) |
|
143 | 143 | self._repo = repo.filtered('served') |
|
144 | 144 | self.ui = repo.ui |
|
145 | 145 | self._caps = repo._restrictcapabilities(caps) |
|
146 | 146 | self.requirements = repo.requirements |
|
147 | 147 | self.supportedformats = repo.supportedformats |
|
148 | 148 | |
|
149 | 149 | def close(self): |
|
150 | 150 | self._repo.close() |
|
151 | 151 | |
|
152 | 152 | def _capabilities(self): |
|
153 | 153 | return self._caps |
|
154 | 154 | |
|
155 | 155 | def local(self): |
|
156 | 156 | return self._repo |
|
157 | 157 | |
|
158 | 158 | def canpush(self): |
|
159 | 159 | return True |
|
160 | 160 | |
|
161 | 161 | def url(self): |
|
162 | 162 | return self._repo.url() |
|
163 | 163 | |
|
164 | 164 | def lookup(self, key): |
|
165 | 165 | return self._repo.lookup(key) |
|
166 | 166 | |
|
167 | 167 | def branchmap(self): |
|
168 | 168 | return self._repo.branchmap() |
|
169 | 169 | |
|
170 | 170 | def heads(self): |
|
171 | 171 | return self._repo.heads() |
|
172 | 172 | |
|
173 | 173 | def known(self, nodes): |
|
174 | 174 | return self._repo.known(nodes) |
|
175 | 175 | |
|
176 | 176 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
177 | 177 | **kwargs): |
|
178 | 178 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
179 | 179 | common=common, bundlecaps=bundlecaps, |
|
180 | 180 | **kwargs) |
|
181 | 181 | cb = util.chunkbuffer(chunks) |
|
182 | 182 | |
|
183 | 183 | if exchange.bundle2requested(bundlecaps): |
|
184 | 184 | # When requesting a bundle2, getbundle returns a stream to make the |
|
185 | 185 | # wire level function happier. We need to build a proper object |
|
186 | 186 | # from it in local peer. |
|
187 | 187 | return bundle2.getunbundler(self.ui, cb) |
|
188 | 188 | else: |
|
189 | 189 | return changegroup.getunbundler('01', cb, None) |
|
190 | 190 | |
|
191 | 191 | # TODO We might want to move the next two calls into legacypeer and add |
|
192 | 192 | # unbundle instead. |
|
193 | 193 | |
|
194 | 194 | def unbundle(self, cg, heads, url): |
|
195 | 195 | """apply a bundle on a repo |
|
196 | 196 | |
|
197 | 197 | This function handles the repo locking itself.""" |
|
198 | 198 | try: |
|
199 | 199 | try: |
|
200 | 200 | cg = exchange.readbundle(self.ui, cg, None) |
|
201 | 201 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
202 | 202 | if util.safehasattr(ret, 'getchunks'): |
|
203 | 203 | # This is a bundle20 object, turn it into an unbundler. |
|
204 | 204 | # This little dance should be dropped eventually when the |
|
205 | 205 | # API is finally improved. |
|
206 | 206 | stream = util.chunkbuffer(ret.getchunks()) |
|
207 | 207 | ret = bundle2.getunbundler(self.ui, stream) |
|
208 | 208 | return ret |
|
209 | 209 | except Exception as exc: |
|
210 | 210 | # If the exception contains output salvaged from a bundle2 |
|
211 | 211 | # reply, we need to make sure it is printed before continuing |
|
212 | 212 | # to fail. So we build a bundle2 with such output and consume |
|
213 | 213 | # it directly. |
|
214 | 214 | # |
|
215 | 215 | # This is not very elegant but allows a "simple" solution for |
|
216 | 216 | # issue4594 |
|
217 | 217 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
218 | 218 | if output: |
|
219 | 219 | bundler = bundle2.bundle20(self._repo.ui) |
|
220 | 220 | for out in output: |
|
221 | 221 | bundler.addpart(out) |
|
222 | 222 | stream = util.chunkbuffer(bundler.getchunks()) |
|
223 | 223 | b = bundle2.getunbundler(self.ui, stream) |
|
224 | 224 | bundle2.processbundle(self._repo, b) |
|
225 | 225 | raise |
|
226 | 226 | except error.PushRaced as exc: |
|
227 | 227 | raise error.ResponseError(_('push failed:'), str(exc)) |
|
228 | 228 | |
|
229 | 229 | def lock(self): |
|
230 | 230 | return self._repo.lock() |
|
231 | 231 | |
|
232 | 232 | def pushkey(self, namespace, key, old, new): |
|
233 | 233 | return self._repo.pushkey(namespace, key, old, new) |
|
234 | 234 | |
|
235 | 235 | def listkeys(self, namespace): |
|
236 | 236 | return self._repo.listkeys(namespace) |
|
237 | 237 | |
|
238 | 238 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
239 | 239 | '''used to test argument passing over the wire''' |
|
240 | 240 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
241 | 241 | |
|
242 | 242 | class locallegacypeer(localpeer): |
|
243 | 243 | '''peer extension which implements legacy methods too; used for tests with |
|
244 | 244 | restricted capabilities''' |
|
245 | 245 | |
|
246 | 246 | def __init__(self, repo): |
|
247 | 247 | localpeer.__init__(self, repo, caps=legacycaps) |
|
248 | 248 | |
|
249 | 249 | def branches(self, nodes): |
|
250 | 250 | return self._repo.branches(nodes) |
|
251 | 251 | |
|
252 | 252 | def between(self, pairs): |
|
253 | 253 | return self._repo.between(pairs) |
|
254 | 254 | |
|
255 | 255 | def changegroup(self, basenodes, source): |
|
256 | 256 | return changegroup.changegroup(self._repo, basenodes, source) |
|
257 | 257 | |
|
258 | 258 | def changegroupsubset(self, bases, heads, source): |
|
259 | 259 | return changegroup.changegroupsubset(self._repo, bases, heads, source) |
|
260 | 260 | |
|
261 | 261 | # Increment the sub-version when the revlog v2 format changes to lock out old |
|
262 | 262 | # clients. |
|
263 | 263 | REVLOGV2_REQUIREMENT = 'exp-revlogv2.0' |
|
264 | 264 | |
|
265 | 265 | class localrepository(object): |
|
266 | 266 | |
|
267 | 267 | supportedformats = { |
|
268 | 268 | 'revlogv1', |
|
269 | 269 | 'generaldelta', |
|
270 | 270 | 'treemanifest', |
|
271 | 271 | 'manifestv2', |
|
272 | 272 | REVLOGV2_REQUIREMENT, |
|
273 | 273 | } |
|
274 | 274 | _basesupported = supportedformats | { |
|
275 | 275 | 'store', |
|
276 | 276 | 'fncache', |
|
277 | 277 | 'shared', |
|
278 | 278 | 'relshared', |
|
279 | 279 | 'dotencode', |
|
280 | 280 | } |
|
281 | 281 | openerreqs = { |
|
282 | 282 | 'revlogv1', |
|
283 | 283 | 'generaldelta', |
|
284 | 284 | 'treemanifest', |
|
285 | 285 | 'manifestv2', |
|
286 | 286 | } |
|
287 | 287 | |
|
288 | 288 | # a list of (ui, featureset) functions. |
|
289 | 289 | # only functions defined in module of enabled extensions are invoked |
|
290 | 290 | featuresetupfuncs = set() |
|
291 | 291 | |
|
292 | 292 | def __init__(self, baseui, path, create=False): |
|
293 | 293 | self.requirements = set() |
|
294 | 294 | self.filtername = None |
|
295 | 295 | # wvfs: rooted at the repository root, used to access the working copy |
|
296 | 296 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
297 | 297 | # vfs: rooted at .hg, used to access repo files outside of .hg/store |
|
298 | 298 | self.vfs = None |
|
299 | 299 | # svfs: usually rooted at .hg/store, used to access repository history |
|
300 | 300 | # If this is a shared repository, this vfs may point to another |
|
301 | 301 | # repository's .hg/store directory. |
|
302 | 302 | self.svfs = None |
|
303 | 303 | self.root = self.wvfs.base |
|
304 | 304 | self.path = self.wvfs.join(".hg") |
|
305 | 305 | self.origroot = path |
|
306 | 306 | # These auditor are not used by the vfs, |
|
307 | 307 | # only used when writing this comment: basectx.match |
|
308 | 308 | self.auditor = pathutil.pathauditor(self.root, self._checknested) |
|
309 | 309 | self.nofsauditor = pathutil.pathauditor(self.root, self._checknested, |
|
310 | 310 | realfs=False) |
|
311 | 311 | self.vfs = vfsmod.vfs(self.path) |
|
312 | 312 | self.baseui = baseui |
|
313 | 313 | self.ui = baseui.copy() |
|
314 | 314 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
315 | 315 | # A list of callback to shape the phase if no data were found. |
|
316 | 316 | # Callback are in the form: func(repo, roots) --> processed root. |
|
317 | 317 | # This list it to be filled by extension during repo setup |
|
318 | 318 | self._phasedefaults = [] |
|
319 | 319 | try: |
|
320 | 320 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) |
|
321 | 321 | self._loadextensions() |
|
322 | 322 | except IOError: |
|
323 | 323 | pass |
|
324 | 324 | |
|
325 | 325 | if self.featuresetupfuncs: |
|
326 | 326 | self.supported = set(self._basesupported) # use private copy |
|
327 | 327 | extmods = set(m.__name__ for n, m |
|
328 | 328 | in extensions.extensions(self.ui)) |
|
329 | 329 | for setupfunc in self.featuresetupfuncs: |
|
330 | 330 | if setupfunc.__module__ in extmods: |
|
331 | 331 | setupfunc(self.ui, self.supported) |
|
332 | 332 | else: |
|
333 | 333 | self.supported = self._basesupported |
|
334 | 334 | color.setup(self.ui) |
|
335 | 335 | |
|
336 | 336 | # Add compression engines. |
|
337 | 337 | for name in util.compengines: |
|
338 | 338 | engine = util.compengines[name] |
|
339 | 339 | if engine.revlogheader(): |
|
340 | 340 | self.supported.add('exp-compression-%s' % name) |
|
341 | 341 | |
|
342 | 342 | if not self.vfs.isdir(): |
|
343 | 343 | if create: |
|
344 | 344 | self.requirements = newreporequirements(self) |
|
345 | 345 | |
|
346 | 346 | if not self.wvfs.exists(): |
|
347 | 347 | self.wvfs.makedirs() |
|
348 | 348 | self.vfs.makedir(notindexed=True) |
|
349 | 349 | |
|
350 | 350 | if 'store' in self.requirements: |
|
351 | 351 | self.vfs.mkdir("store") |
|
352 | 352 | |
|
353 | 353 | # create an invalid changelog |
|
354 | 354 | self.vfs.append( |
|
355 | 355 | "00changelog.i", |
|
356 | 356 | '\0\0\0\2' # represents revlogv2 |
|
357 | 357 | ' dummy changelog to prevent using the old repo layout' |
|
358 | 358 | ) |
|
359 | 359 | else: |
|
360 | 360 | raise error.RepoError(_("repository %s not found") % path) |
|
361 | 361 | elif create: |
|
362 | 362 | raise error.RepoError(_("repository %s already exists") % path) |
|
363 | 363 | else: |
|
364 | 364 | try: |
|
365 | 365 | self.requirements = scmutil.readrequires( |
|
366 | 366 | self.vfs, self.supported) |
|
367 | 367 | except IOError as inst: |
|
368 | 368 | if inst.errno != errno.ENOENT: |
|
369 | 369 | raise |
|
370 | 370 | |
|
371 | 371 | self.sharedpath = self.path |
|
372 | 372 | try: |
|
373 | 373 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') |
|
374 | 374 | if 'relshared' in self.requirements: |
|
375 | 375 | sharedpath = self.vfs.join(sharedpath) |
|
376 | 376 | vfs = vfsmod.vfs(sharedpath, realpath=True) |
|
377 | 377 | s = vfs.base |
|
378 | 378 | if not vfs.exists(): |
|
379 | 379 | raise error.RepoError( |
|
380 | 380 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
381 | 381 | self.sharedpath = s |
|
382 | 382 | except IOError as inst: |
|
383 | 383 | if inst.errno != errno.ENOENT: |
|
384 | 384 | raise |
|
385 | 385 | |
|
386 | 386 | self.store = store.store( |
|
387 | 387 | self.requirements, self.sharedpath, vfsmod.vfs) |
|
388 | 388 | self.spath = self.store.path |
|
389 | 389 | self.svfs = self.store.vfs |
|
390 | 390 | self.sjoin = self.store.join |
|
391 | 391 | self.vfs.createmode = self.store.createmode |
|
392 | 392 | self._applyopenerreqs() |
|
393 | 393 | if create: |
|
394 | 394 | self._writerequirements() |
|
395 | 395 | |
|
396 | 396 | self._dirstatevalidatewarned = False |
|
397 | 397 | |
|
398 | 398 | self._branchcaches = {} |
|
399 | 399 | self._revbranchcache = None |
|
400 | 400 | self.filterpats = {} |
|
401 | 401 | self._datafilters = {} |
|
402 | 402 | self._transref = self._lockref = self._wlockref = None |
|
403 | 403 | |
|
404 | 404 | # A cache for various files under .hg/ that tracks file changes, |
|
405 | 405 | # (used by the filecache decorator) |
|
406 | 406 | # |
|
407 | 407 | # Maps a property name to its util.filecacheentry |
|
408 | 408 | self._filecache = {} |
|
409 | 409 | |
|
410 | 410 | # hold sets of revision to be filtered |
|
411 | 411 | # should be cleared when something might have changed the filter value: |
|
412 | 412 | # - new changesets, |
|
413 | 413 | # - phase change, |
|
414 | 414 | # - new obsolescence marker, |
|
415 | 415 | # - working directory parent change, |
|
416 | 416 | # - bookmark changes |
|
417 | 417 | self.filteredrevcache = {} |
|
418 | 418 | |
|
419 | 419 | # post-dirstate-status hooks |
|
420 | 420 | self._postdsstatus = [] |
|
421 | 421 | |
|
422 | 422 | # generic mapping between names and nodes |
|
423 | 423 | self.names = namespaces.namespaces() |
|
424 | 424 | |
|
425 | 425 | # Key to signature value. |
|
426 | 426 | self._sparsesignaturecache = {} |
|
427 | 427 | # Signature to cached matcher instance. |
|
428 | 428 | self._sparsematchercache = {} |
|
429 | 429 | |
|
430 | 430 | def close(self): |
|
431 | 431 | self._writecaches() |
|
432 | 432 | |
|
433 | 433 | def _loadextensions(self): |
|
434 | 434 | extensions.loadall(self.ui) |
|
435 | 435 | |
|
436 | 436 | def _writecaches(self): |
|
437 | 437 | if self._revbranchcache: |
|
438 | 438 | self._revbranchcache.write() |
|
439 | 439 | |
|
440 | 440 | def _restrictcapabilities(self, caps): |
|
441 | 441 | if self.ui.configbool('experimental', 'bundle2-advertise', True): |
|
442 | 442 | caps = set(caps) |
|
443 | 443 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self)) |
|
444 | 444 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
445 | 445 | return caps |
|
446 | 446 | |
|
447 | 447 | def _applyopenerreqs(self): |
|
448 | 448 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
449 | 449 | if r in self.openerreqs) |
|
450 | 450 | # experimental config: format.chunkcachesize |
|
451 | 451 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
452 | 452 | if chunkcachesize is not None: |
|
453 | 453 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
454 | 454 | # experimental config: format.maxchainlen |
|
455 | 455 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
456 | 456 | if maxchainlen is not None: |
|
457 | 457 | self.svfs.options['maxchainlen'] = maxchainlen |
|
458 | 458 | # experimental config: format.manifestcachesize |
|
459 | 459 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
460 | 460 | if manifestcachesize is not None: |
|
461 | 461 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
462 | 462 | # experimental config: format.aggressivemergedeltas |
|
463 | 463 | aggressivemergedeltas = self.ui.configbool('format', |
|
464 | 464 | 'aggressivemergedeltas') |
|
465 | 465 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
466 | 466 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) |
|
467 | 467 | chainspan = self.ui.configbytes('experimental', 'maxdeltachainspan', -1) |
|
468 | 468 | if 0 <= chainspan: |
|
469 | 469 | self.svfs.options['maxdeltachainspan'] = chainspan |
|
470 | 470 | |
|
471 | 471 | for r in self.requirements: |
|
472 | 472 | if r.startswith('exp-compression-'): |
|
473 | 473 | self.svfs.options['compengine'] = r[len('exp-compression-'):] |
|
474 | 474 | |
|
475 | 475 | # TODO move "revlogv2" to openerreqs once finalized. |
|
476 | 476 | if REVLOGV2_REQUIREMENT in self.requirements: |
|
477 | 477 | self.svfs.options['revlogv2'] = True |
|
478 | 478 | |
|
479 | 479 | def _writerequirements(self): |
|
480 | 480 | scmutil.writerequires(self.vfs, self.requirements) |
|
481 | 481 | |
|
482 | 482 | def _checknested(self, path): |
|
483 | 483 | """Determine if path is a legal nested repository.""" |
|
484 | 484 | if not path.startswith(self.root): |
|
485 | 485 | return False |
|
486 | 486 | subpath = path[len(self.root) + 1:] |
|
487 | 487 | normsubpath = util.pconvert(subpath) |
|
488 | 488 | |
|
489 | 489 | # XXX: Checking against the current working copy is wrong in |
|
490 | 490 | # the sense that it can reject things like |
|
491 | 491 | # |
|
492 | 492 | # $ hg cat -r 10 sub/x.txt |
|
493 | 493 | # |
|
494 | 494 | # if sub/ is no longer a subrepository in the working copy |
|
495 | 495 | # parent revision. |
|
496 | 496 | # |
|
497 | 497 | # However, it can of course also allow things that would have |
|
498 | 498 | # been rejected before, such as the above cat command if sub/ |
|
499 | 499 | # is a subrepository now, but was a normal directory before. |
|
500 | 500 | # The old path auditor would have rejected by mistake since it |
|
501 | 501 | # panics when it sees sub/.hg/. |
|
502 | 502 | # |
|
503 | 503 | # All in all, checking against the working copy seems sensible |
|
504 | 504 | # since we want to prevent access to nested repositories on |
|
505 | 505 | # the filesystem *now*. |
|
506 | 506 | ctx = self[None] |
|
507 | 507 | parts = util.splitpath(subpath) |
|
508 | 508 | while parts: |
|
509 | 509 | prefix = '/'.join(parts) |
|
510 | 510 | if prefix in ctx.substate: |
|
511 | 511 | if prefix == normsubpath: |
|
512 | 512 | return True |
|
513 | 513 | else: |
|
514 | 514 | sub = ctx.sub(prefix) |
|
515 | 515 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
516 | 516 | else: |
|
517 | 517 | parts.pop() |
|
518 | 518 | return False |
|
519 | 519 | |
|
520 | 520 | def peer(self): |
|
521 | 521 | return localpeer(self) # not cached to avoid reference cycle |
|
522 | 522 | |
|
523 | 523 | def unfiltered(self): |
|
524 | 524 | """Return unfiltered version of the repository |
|
525 | 525 | |
|
526 | 526 | Intended to be overwritten by filtered repo.""" |
|
527 | 527 | return self |
|
528 | 528 | |
|
529 | 529 | def filtered(self, name): |
|
530 | 530 | """Return a filtered version of a repository""" |
|
531 | 531 | # build a new class with the mixin and the current class |
|
532 | 532 | # (possibly subclass of the repo) |
|
533 | 533 | class filteredrepo(repoview.repoview, self.unfiltered().__class__): |
|
534 | 534 | pass |
|
535 | 535 | return filteredrepo(self, name) |
|
536 | 536 | |
|
537 | 537 | @repofilecache('bookmarks', 'bookmarks.current') |
|
538 | 538 | def _bookmarks(self): |
|
539 | 539 | return bookmarks.bmstore(self) |
|
540 | 540 | |
|
541 | 541 | @property |
|
542 | 542 | def _activebookmark(self): |
|
543 | 543 | return self._bookmarks.active |
|
544 | 544 | |
|
545 | 545 | # _phaserevs and _phasesets depend on changelog. what we need is to |
|
546 | 546 | # call _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
547 | 547 | # can't be easily expressed in filecache mechanism. |
|
548 | 548 | @storecache('phaseroots', '00changelog.i') |
|
549 | 549 | def _phasecache(self): |
|
550 | 550 | return phases.phasecache(self, self._phasedefaults) |
|
551 | 551 | |
|
552 | 552 | @storecache('obsstore') |
|
553 | 553 | def obsstore(self): |
|
554 | 554 | return obsolete.makestore(self.ui, self) |
|
555 | 555 | |
|
556 | 556 | @storecache('00changelog.i') |
|
557 | 557 | def changelog(self): |
|
558 | 558 | return changelog.changelog(self.svfs, |
|
559 | 559 | trypending=txnutil.mayhavepending(self.root)) |
|
560 | 560 | |
|
561 | 561 | def _constructmanifest(self): |
|
562 | 562 | # This is a temporary function while we migrate from manifest to |
|
563 | 563 | # manifestlog. It allows bundlerepo and unionrepo to intercept the |
|
564 | 564 | # manifest creation. |
|
565 | 565 | return manifest.manifestrevlog(self.svfs) |
|
566 | 566 | |
|
567 | 567 | @storecache('00manifest.i') |
|
568 | 568 | def manifestlog(self): |
|
569 | 569 | return manifest.manifestlog(self.svfs, self) |
|
570 | 570 | |
|
571 | 571 | @repofilecache('dirstate') |
|
572 | 572 | def dirstate(self): |
|
573 | 573 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
574 | 574 | self._dirstatevalidate) |
|
575 | 575 | |
|
576 | 576 | def _dirstatevalidate(self, node): |
|
577 | 577 | try: |
|
578 | 578 | self.changelog.rev(node) |
|
579 | 579 | return node |
|
580 | 580 | except error.LookupError: |
|
581 | 581 | if not self._dirstatevalidatewarned: |
|
582 | 582 | self._dirstatevalidatewarned = True |
|
583 | 583 | self.ui.warn(_("warning: ignoring unknown" |
|
584 | 584 | " working parent %s!\n") % short(node)) |
|
585 | 585 | return nullid |
|
586 | 586 | |
|
587 | 587 | def __getitem__(self, changeid): |
|
588 | 588 | if changeid is None: |
|
589 | 589 | return context.workingctx(self) |
|
590 | 590 | if isinstance(changeid, slice): |
|
591 | 591 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
592 | 592 | return [context.changectx(self, i) |
|
593 | 593 | for i in xrange(*changeid.indices(len(self))) |
|
594 | 594 | if i not in self.changelog.filteredrevs] |
|
595 | 595 | try: |
|
596 | 596 | return context.changectx(self, changeid) |
|
597 | 597 | except error.WdirUnsupported: |
|
598 | 598 | return context.workingctx(self) |
|
599 | 599 | |
|
600 | 600 | def __contains__(self, changeid): |
|
601 | 601 | """True if the given changeid exists |
|
602 | 602 | |
|
603 | 603 | error.LookupError is raised if an ambiguous node specified. |
|
604 | 604 | """ |
|
605 | 605 | try: |
|
606 | 606 | self[changeid] |
|
607 | 607 | return True |
|
608 | 608 | except error.RepoLookupError: |
|
609 | 609 | return False |
|
610 | 610 | |
|
611 | 611 | def __nonzero__(self): |
|
612 | 612 | return True |
|
613 | 613 | |
|
614 | 614 | __bool__ = __nonzero__ |
|
615 | 615 | |
|
616 | 616 | def __len__(self): |
|
617 | 617 | return len(self.changelog) |
|
618 | 618 | |
|
619 | 619 | def __iter__(self): |
|
620 | 620 | return iter(self.changelog) |
|
621 | 621 | |
|
622 | 622 | def revs(self, expr, *args): |
|
623 | 623 | '''Find revisions matching a revset. |
|
624 | 624 | |
|
625 | 625 | The revset is specified as a string ``expr`` that may contain |
|
626 | 626 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
627 | 627 | |
|
628 | 628 | Revset aliases from the configuration are not expanded. To expand |
|
629 | 629 | user aliases, consider calling ``scmutil.revrange()`` or |
|
630 | 630 | ``repo.anyrevs([expr], user=True)``. |
|
631 | 631 | |
|
632 | 632 | Returns a revset.abstractsmartset, which is a list-like interface |
|
633 | 633 | that contains integer revisions. |
|
634 | 634 | ''' |
|
635 | 635 | expr = revsetlang.formatspec(expr, *args) |
|
636 | 636 | m = revset.match(None, expr) |
|
637 | 637 | return m(self) |
|
638 | 638 | |
|
639 | 639 | def set(self, expr, *args): |
|
640 | 640 | '''Find revisions matching a revset and emit changectx instances. |
|
641 | 641 | |
|
642 | 642 | This is a convenience wrapper around ``revs()`` that iterates the |
|
643 | 643 | result and is a generator of changectx instances. |
|
644 | 644 | |
|
645 | 645 | Revset aliases from the configuration are not expanded. To expand |
|
646 | 646 | user aliases, consider calling ``scmutil.revrange()``. |
|
647 | 647 | ''' |
|
648 | 648 | for r in self.revs(expr, *args): |
|
649 | 649 | yield self[r] |
|
650 | 650 | |
|
651 | def anyrevs(self, specs, user=False): | |
|
651 | def anyrevs(self, specs, user=False, localalias=None): | |
|
652 | 652 | '''Find revisions matching one of the given revsets. |
|
653 | 653 | |
|
654 | 654 | Revset aliases from the configuration are not expanded by default. To |
|
655 | expand user aliases, specify ``user=True``. | |
|
655 | expand user aliases, specify ``user=True``. To provide some local | |
|
656 | definitions overriding user aliases, set ``localalias`` to | |
|
657 | ``{name: definitionstring}``. | |
|
656 | 658 | ''' |
|
657 | 659 | if user: |
|
658 |
m = revset.matchany(self.ui, specs, repo=self |
|
|
660 | m = revset.matchany(self.ui, specs, repo=self, | |
|
661 | localalias=localalias) | |
|
659 | 662 | else: |
|
660 | m = revset.matchany(None, specs) | |
|
663 | m = revset.matchany(None, specs, localalias=localalias) | |
|
661 | 664 | return m(self) |
|
662 | 665 | |
|
663 | 666 | def url(self): |
|
664 | 667 | return 'file:' + self.root |
|
665 | 668 | |
|
666 | 669 | def hook(self, name, throw=False, **args): |
|
667 | 670 | """Call a hook, passing this repo instance. |
|
668 | 671 | |
|
669 | 672 | This a convenience method to aid invoking hooks. Extensions likely |
|
670 | 673 | won't call this unless they have registered a custom hook or are |
|
671 | 674 | replacing code that is expected to call a hook. |
|
672 | 675 | """ |
|
673 | 676 | return hook.hook(self.ui, self, name, throw, **args) |
|
674 | 677 | |
|
675 | 678 | @filteredpropertycache |
|
676 | 679 | def _tagscache(self): |
|
677 | 680 | '''Returns a tagscache object that contains various tags related |
|
678 | 681 | caches.''' |
|
679 | 682 | |
|
680 | 683 | # This simplifies its cache management by having one decorated |
|
681 | 684 | # function (this one) and the rest simply fetch things from it. |
|
682 | 685 | class tagscache(object): |
|
683 | 686 | def __init__(self): |
|
684 | 687 | # These two define the set of tags for this repository. tags |
|
685 | 688 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
686 | 689 | # 'local'. (Global tags are defined by .hgtags across all |
|
687 | 690 | # heads, and local tags are defined in .hg/localtags.) |
|
688 | 691 | # They constitute the in-memory cache of tags. |
|
689 | 692 | self.tags = self.tagtypes = None |
|
690 | 693 | |
|
691 | 694 | self.nodetagscache = self.tagslist = None |
|
692 | 695 | |
|
693 | 696 | cache = tagscache() |
|
694 | 697 | cache.tags, cache.tagtypes = self._findtags() |
|
695 | 698 | |
|
696 | 699 | return cache |
|
697 | 700 | |
|
698 | 701 | def tags(self): |
|
699 | 702 | '''return a mapping of tag to node''' |
|
700 | 703 | t = {} |
|
701 | 704 | if self.changelog.filteredrevs: |
|
702 | 705 | tags, tt = self._findtags() |
|
703 | 706 | else: |
|
704 | 707 | tags = self._tagscache.tags |
|
705 | 708 | for k, v in tags.iteritems(): |
|
706 | 709 | try: |
|
707 | 710 | # ignore tags to unknown nodes |
|
708 | 711 | self.changelog.rev(v) |
|
709 | 712 | t[k] = v |
|
710 | 713 | except (error.LookupError, ValueError): |
|
711 | 714 | pass |
|
712 | 715 | return t |
|
713 | 716 | |
|
714 | 717 | def _findtags(self): |
|
715 | 718 | '''Do the hard work of finding tags. Return a pair of dicts |
|
716 | 719 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
717 | 720 | maps tag name to a string like \'global\' or \'local\'. |
|
718 | 721 | Subclasses or extensions are free to add their own tags, but |
|
719 | 722 | should be aware that the returned dicts will be retained for the |
|
720 | 723 | duration of the localrepo object.''' |
|
721 | 724 | |
|
722 | 725 | # XXX what tagtype should subclasses/extensions use? Currently |
|
723 | 726 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
724 | 727 | # Should each extension invent its own tag type? Should there |
|
725 | 728 | # be one tagtype for all such "virtual" tags? Or is the status |
|
726 | 729 | # quo fine? |
|
727 | 730 | |
|
728 | 731 | |
|
729 | 732 | # map tag name to (node, hist) |
|
730 | 733 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
731 | 734 | # map tag name to tag type |
|
732 | 735 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
733 | 736 | |
|
734 | 737 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
735 | 738 | |
|
736 | 739 | # Build the return dicts. Have to re-encode tag names because |
|
737 | 740 | # the tags module always uses UTF-8 (in order not to lose info |
|
738 | 741 | # writing to the cache), but the rest of Mercurial wants them in |
|
739 | 742 | # local encoding. |
|
740 | 743 | tags = {} |
|
741 | 744 | for (name, (node, hist)) in alltags.iteritems(): |
|
742 | 745 | if node != nullid: |
|
743 | 746 | tags[encoding.tolocal(name)] = node |
|
744 | 747 | tags['tip'] = self.changelog.tip() |
|
745 | 748 | tagtypes = dict([(encoding.tolocal(name), value) |
|
746 | 749 | for (name, value) in tagtypes.iteritems()]) |
|
747 | 750 | return (tags, tagtypes) |
|
748 | 751 | |
|
749 | 752 | def tagtype(self, tagname): |
|
750 | 753 | ''' |
|
751 | 754 | return the type of the given tag. result can be: |
|
752 | 755 | |
|
753 | 756 | 'local' : a local tag |
|
754 | 757 | 'global' : a global tag |
|
755 | 758 | None : tag does not exist |
|
756 | 759 | ''' |
|
757 | 760 | |
|
758 | 761 | return self._tagscache.tagtypes.get(tagname) |
|
759 | 762 | |
|
760 | 763 | def tagslist(self): |
|
761 | 764 | '''return a list of tags ordered by revision''' |
|
762 | 765 | if not self._tagscache.tagslist: |
|
763 | 766 | l = [] |
|
764 | 767 | for t, n in self.tags().iteritems(): |
|
765 | 768 | l.append((self.changelog.rev(n), t, n)) |
|
766 | 769 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
767 | 770 | |
|
768 | 771 | return self._tagscache.tagslist |
|
769 | 772 | |
|
770 | 773 | def nodetags(self, node): |
|
771 | 774 | '''return the tags associated with a node''' |
|
772 | 775 | if not self._tagscache.nodetagscache: |
|
773 | 776 | nodetagscache = {} |
|
774 | 777 | for t, n in self._tagscache.tags.iteritems(): |
|
775 | 778 | nodetagscache.setdefault(n, []).append(t) |
|
776 | 779 | for tags in nodetagscache.itervalues(): |
|
777 | 780 | tags.sort() |
|
778 | 781 | self._tagscache.nodetagscache = nodetagscache |
|
779 | 782 | return self._tagscache.nodetagscache.get(node, []) |
|
780 | 783 | |
|
781 | 784 | def nodebookmarks(self, node): |
|
782 | 785 | """return the list of bookmarks pointing to the specified node""" |
|
783 | 786 | marks = [] |
|
784 | 787 | for bookmark, n in self._bookmarks.iteritems(): |
|
785 | 788 | if n == node: |
|
786 | 789 | marks.append(bookmark) |
|
787 | 790 | return sorted(marks) |
|
788 | 791 | |
|
789 | 792 | def branchmap(self): |
|
790 | 793 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
791 | 794 | ordered by increasing revision number''' |
|
792 | 795 | branchmap.updatecache(self) |
|
793 | 796 | return self._branchcaches[self.filtername] |
|
794 | 797 | |
|
795 | 798 | @unfilteredmethod |
|
796 | 799 | def revbranchcache(self): |
|
797 | 800 | if not self._revbranchcache: |
|
798 | 801 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
799 | 802 | return self._revbranchcache |
|
800 | 803 | |
|
801 | 804 | def branchtip(self, branch, ignoremissing=False): |
|
802 | 805 | '''return the tip node for a given branch |
|
803 | 806 | |
|
804 | 807 | If ignoremissing is True, then this method will not raise an error. |
|
805 | 808 | This is helpful for callers that only expect None for a missing branch |
|
806 | 809 | (e.g. namespace). |
|
807 | 810 | |
|
808 | 811 | ''' |
|
809 | 812 | try: |
|
810 | 813 | return self.branchmap().branchtip(branch) |
|
811 | 814 | except KeyError: |
|
812 | 815 | if not ignoremissing: |
|
813 | 816 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
814 | 817 | else: |
|
815 | 818 | pass |
|
816 | 819 | |
|
817 | 820 | def lookup(self, key): |
|
818 | 821 | return self[key].node() |
|
819 | 822 | |
|
820 | 823 | def lookupbranch(self, key, remote=None): |
|
821 | 824 | repo = remote or self |
|
822 | 825 | if key in repo.branchmap(): |
|
823 | 826 | return key |
|
824 | 827 | |
|
825 | 828 | repo = (remote and remote.local()) and remote or self |
|
826 | 829 | return repo[key].branch() |
|
827 | 830 | |
|
828 | 831 | def known(self, nodes): |
|
829 | 832 | cl = self.changelog |
|
830 | 833 | nm = cl.nodemap |
|
831 | 834 | filtered = cl.filteredrevs |
|
832 | 835 | result = [] |
|
833 | 836 | for n in nodes: |
|
834 | 837 | r = nm.get(n) |
|
835 | 838 | resp = not (r is None or r in filtered) |
|
836 | 839 | result.append(resp) |
|
837 | 840 | return result |
|
838 | 841 | |
|
839 | 842 | def local(self): |
|
840 | 843 | return self |
|
841 | 844 | |
|
842 | 845 | def publishing(self): |
|
843 | 846 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
844 | 847 | # so that we don't finalize changes shared between users via ssh or nfs |
|
845 | 848 | return self.ui.configbool('phases', 'publish', True, untrusted=True) |
|
846 | 849 | |
|
847 | 850 | def cancopy(self): |
|
848 | 851 | # so statichttprepo's override of local() works |
|
849 | 852 | if not self.local(): |
|
850 | 853 | return False |
|
851 | 854 | if not self.publishing(): |
|
852 | 855 | return True |
|
853 | 856 | # if publishing we can't copy if there is filtered content |
|
854 | 857 | return not self.filtered('visible').changelog.filteredrevs |
|
855 | 858 | |
|
856 | 859 | def shared(self): |
|
857 | 860 | '''the type of shared repository (None if not shared)''' |
|
858 | 861 | if self.sharedpath != self.path: |
|
859 | 862 | return 'store' |
|
860 | 863 | return None |
|
861 | 864 | |
|
862 | 865 | def wjoin(self, f, *insidef): |
|
863 | 866 | return self.vfs.reljoin(self.root, f, *insidef) |
|
864 | 867 | |
|
865 | 868 | def file(self, f): |
|
866 | 869 | if f[0] == '/': |
|
867 | 870 | f = f[1:] |
|
868 | 871 | return filelog.filelog(self.svfs, f) |
|
869 | 872 | |
|
870 | 873 | def changectx(self, changeid): |
|
871 | 874 | return self[changeid] |
|
872 | 875 | |
|
873 | 876 | def setparents(self, p1, p2=nullid): |
|
874 | 877 | with self.dirstate.parentchange(): |
|
875 | 878 | copies = self.dirstate.setparents(p1, p2) |
|
876 | 879 | pctx = self[p1] |
|
877 | 880 | if copies: |
|
878 | 881 | # Adjust copy records, the dirstate cannot do it, it |
|
879 | 882 | # requires access to parents manifests. Preserve them |
|
880 | 883 | # only for entries added to first parent. |
|
881 | 884 | for f in copies: |
|
882 | 885 | if f not in pctx and copies[f] in pctx: |
|
883 | 886 | self.dirstate.copy(copies[f], f) |
|
884 | 887 | if p2 == nullid: |
|
885 | 888 | for f, s in sorted(self.dirstate.copies().items()): |
|
886 | 889 | if f not in pctx and s not in pctx: |
|
887 | 890 | self.dirstate.copy(None, f) |
|
888 | 891 | |
|
889 | 892 | def filectx(self, path, changeid=None, fileid=None): |
|
890 | 893 | """changeid can be a changeset revision, node, or tag. |
|
891 | 894 | fileid can be a file revision or node.""" |
|
892 | 895 | return context.filectx(self, path, changeid, fileid) |
|
893 | 896 | |
|
894 | 897 | def getcwd(self): |
|
895 | 898 | return self.dirstate.getcwd() |
|
896 | 899 | |
|
897 | 900 | def pathto(self, f, cwd=None): |
|
898 | 901 | return self.dirstate.pathto(f, cwd) |
|
899 | 902 | |
|
900 | 903 | def _loadfilter(self, filter): |
|
901 | 904 | if filter not in self.filterpats: |
|
902 | 905 | l = [] |
|
903 | 906 | for pat, cmd in self.ui.configitems(filter): |
|
904 | 907 | if cmd == '!': |
|
905 | 908 | continue |
|
906 | 909 | mf = matchmod.match(self.root, '', [pat]) |
|
907 | 910 | fn = None |
|
908 | 911 | params = cmd |
|
909 | 912 | for name, filterfn in self._datafilters.iteritems(): |
|
910 | 913 | if cmd.startswith(name): |
|
911 | 914 | fn = filterfn |
|
912 | 915 | params = cmd[len(name):].lstrip() |
|
913 | 916 | break |
|
914 | 917 | if not fn: |
|
915 | 918 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
916 | 919 | # Wrap old filters not supporting keyword arguments |
|
917 | 920 | if not inspect.getargspec(fn)[2]: |
|
918 | 921 | oldfn = fn |
|
919 | 922 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
920 | 923 | l.append((mf, fn, params)) |
|
921 | 924 | self.filterpats[filter] = l |
|
922 | 925 | return self.filterpats[filter] |
|
923 | 926 | |
|
924 | 927 | def _filter(self, filterpats, filename, data): |
|
925 | 928 | for mf, fn, cmd in filterpats: |
|
926 | 929 | if mf(filename): |
|
927 | 930 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
928 | 931 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
929 | 932 | break |
|
930 | 933 | |
|
931 | 934 | return data |
|
932 | 935 | |
|
933 | 936 | @unfilteredpropertycache |
|
934 | 937 | def _encodefilterpats(self): |
|
935 | 938 | return self._loadfilter('encode') |
|
936 | 939 | |
|
937 | 940 | @unfilteredpropertycache |
|
938 | 941 | def _decodefilterpats(self): |
|
939 | 942 | return self._loadfilter('decode') |
|
940 | 943 | |
|
941 | 944 | def adddatafilter(self, name, filter): |
|
942 | 945 | self._datafilters[name] = filter |
|
943 | 946 | |
|
944 | 947 | def wread(self, filename): |
|
945 | 948 | if self.wvfs.islink(filename): |
|
946 | 949 | data = self.wvfs.readlink(filename) |
|
947 | 950 | else: |
|
948 | 951 | data = self.wvfs.read(filename) |
|
949 | 952 | return self._filter(self._encodefilterpats, filename, data) |
|
950 | 953 | |
|
951 | 954 | def wwrite(self, filename, data, flags, backgroundclose=False): |
|
952 | 955 | """write ``data`` into ``filename`` in the working directory |
|
953 | 956 | |
|
954 | 957 | This returns length of written (maybe decoded) data. |
|
955 | 958 | """ |
|
956 | 959 | data = self._filter(self._decodefilterpats, filename, data) |
|
957 | 960 | if 'l' in flags: |
|
958 | 961 | self.wvfs.symlink(data, filename) |
|
959 | 962 | else: |
|
960 | 963 | self.wvfs.write(filename, data, backgroundclose=backgroundclose) |
|
961 | 964 | if 'x' in flags: |
|
962 | 965 | self.wvfs.setflags(filename, False, True) |
|
963 | 966 | return len(data) |
|
964 | 967 | |
|
965 | 968 | def wwritedata(self, filename, data): |
|
966 | 969 | return self._filter(self._decodefilterpats, filename, data) |
|
967 | 970 | |
|
968 | 971 | def currenttransaction(self): |
|
969 | 972 | """return the current transaction or None if non exists""" |
|
970 | 973 | if self._transref: |
|
971 | 974 | tr = self._transref() |
|
972 | 975 | else: |
|
973 | 976 | tr = None |
|
974 | 977 | |
|
975 | 978 | if tr and tr.running(): |
|
976 | 979 | return tr |
|
977 | 980 | return None |
|
978 | 981 | |
|
979 | 982 | def transaction(self, desc, report=None): |
|
980 | 983 | if (self.ui.configbool('devel', 'all-warnings') |
|
981 | 984 | or self.ui.configbool('devel', 'check-locks')): |
|
982 | 985 | if self._currentlock(self._lockref) is None: |
|
983 | 986 | raise error.ProgrammingError('transaction requires locking') |
|
984 | 987 | tr = self.currenttransaction() |
|
985 | 988 | if tr is not None: |
|
986 | 989 | return tr.nest() |
|
987 | 990 | |
|
988 | 991 | # abort here if the journal already exists |
|
989 | 992 | if self.svfs.exists("journal"): |
|
990 | 993 | raise error.RepoError( |
|
991 | 994 | _("abandoned transaction found"), |
|
992 | 995 | hint=_("run 'hg recover' to clean up transaction")) |
|
993 | 996 | |
|
994 | 997 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
995 | 998 | ha = hex(hashlib.sha1(idbase).digest()) |
|
996 | 999 | txnid = 'TXN:' + ha |
|
997 | 1000 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
998 | 1001 | |
|
999 | 1002 | self._writejournal(desc) |
|
1000 | 1003 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
1001 | 1004 | if report: |
|
1002 | 1005 | rp = report |
|
1003 | 1006 | else: |
|
1004 | 1007 | rp = self.ui.warn |
|
1005 | 1008 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
1006 | 1009 | # we must avoid cyclic reference between repo and transaction. |
|
1007 | 1010 | reporef = weakref.ref(self) |
|
1008 | 1011 | # Code to track tag movement |
|
1009 | 1012 | # |
|
1010 | 1013 | # Since tags are all handled as file content, it is actually quite hard |
|
1011 | 1014 | # to track these movement from a code perspective. So we fallback to a |
|
1012 | 1015 | # tracking at the repository level. One could envision to track changes |
|
1013 | 1016 | # to the '.hgtags' file through changegroup apply but that fails to |
|
1014 | 1017 | # cope with case where transaction expose new heads without changegroup |
|
1015 | 1018 | # being involved (eg: phase movement). |
|
1016 | 1019 | # |
|
1017 | 1020 | # For now, We gate the feature behind a flag since this likely comes |
|
1018 | 1021 | # with performance impacts. The current code run more often than needed |
|
1019 | 1022 | # and do not use caches as much as it could. The current focus is on |
|
1020 | 1023 | # the behavior of the feature so we disable it by default. The flag |
|
1021 | 1024 | # will be removed when we are happy with the performance impact. |
|
1022 | 1025 | # |
|
1023 | 1026 | # Once this feature is no longer experimental move the following |
|
1024 | 1027 | # documentation to the appropriate help section: |
|
1025 | 1028 | # |
|
1026 | 1029 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
1027 | 1030 | # tags (new or changed or deleted tags). In addition the details of |
|
1028 | 1031 | # these changes are made available in a file at: |
|
1029 | 1032 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
1030 | 1033 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
1031 | 1034 | # might exist from a previous transaction even if no tag were touched |
|
1032 | 1035 | # in this one. Changes are recorded in a line base format:: |
|
1033 | 1036 | # |
|
1034 | 1037 | # <action> <hex-node> <tag-name>\n |
|
1035 | 1038 | # |
|
1036 | 1039 | # Actions are defined as follow: |
|
1037 | 1040 | # "-R": tag is removed, |
|
1038 | 1041 | # "+A": tag is added, |
|
1039 | 1042 | # "-M": tag is moved (old value), |
|
1040 | 1043 | # "+M": tag is moved (new value), |
|
1041 | 1044 | tracktags = lambda x: None |
|
1042 | 1045 | # experimental config: experimental.hook-track-tags |
|
1043 | 1046 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags', |
|
1044 | 1047 | False) |
|
1045 | 1048 | if desc != 'strip' and shouldtracktags: |
|
1046 | 1049 | oldheads = self.changelog.headrevs() |
|
1047 | 1050 | def tracktags(tr2): |
|
1048 | 1051 | repo = reporef() |
|
1049 | 1052 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1050 | 1053 | newheads = repo.changelog.headrevs() |
|
1051 | 1054 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1052 | 1055 | # notes: we compare lists here. |
|
1053 | 1056 | # As we do it only once buiding set would not be cheaper |
|
1054 | 1057 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1055 | 1058 | if changes: |
|
1056 | 1059 | tr2.hookargs['tag_moved'] = '1' |
|
1057 | 1060 | with repo.vfs('changes/tags.changes', 'w', |
|
1058 | 1061 | atomictemp=True) as changesfile: |
|
1059 | 1062 | # note: we do not register the file to the transaction |
|
1060 | 1063 | # because we needs it to still exist on the transaction |
|
1061 | 1064 | # is close (for txnclose hooks) |
|
1062 | 1065 | tagsmod.writediff(changesfile, changes) |
|
1063 | 1066 | def validate(tr2): |
|
1064 | 1067 | """will run pre-closing hooks""" |
|
1065 | 1068 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1066 | 1069 | # path for now |
|
1067 | 1070 | # |
|
1068 | 1071 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1069 | 1072 | # dict is copied before these run. In addition we needs the data |
|
1070 | 1073 | # available to in memory hooks too. |
|
1071 | 1074 | # |
|
1072 | 1075 | # Moreover, we also need to make sure this runs before txnclose |
|
1073 | 1076 | # hooks and there is no "pending" mechanism that would execute |
|
1074 | 1077 | # logic only if hooks are about to run. |
|
1075 | 1078 | # |
|
1076 | 1079 | # Fixing this limitation of the transaction is also needed to track |
|
1077 | 1080 | # other families of changes (bookmarks, phases, obsolescence). |
|
1078 | 1081 | # |
|
1079 | 1082 | # This will have to be fixed before we remove the experimental |
|
1080 | 1083 | # gating. |
|
1081 | 1084 | tracktags(tr2) |
|
1082 | 1085 | reporef().hook('pretxnclose', throw=True, |
|
1083 | 1086 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1084 | 1087 | def releasefn(tr, success): |
|
1085 | 1088 | repo = reporef() |
|
1086 | 1089 | if success: |
|
1087 | 1090 | # this should be explicitly invoked here, because |
|
1088 | 1091 | # in-memory changes aren't written out at closing |
|
1089 | 1092 | # transaction, if tr.addfilegenerator (via |
|
1090 | 1093 | # dirstate.write or so) isn't invoked while |
|
1091 | 1094 | # transaction running |
|
1092 | 1095 | repo.dirstate.write(None) |
|
1093 | 1096 | else: |
|
1094 | 1097 | # discard all changes (including ones already written |
|
1095 | 1098 | # out) in this transaction |
|
1096 | 1099 | repo.dirstate.restorebackup(None, prefix='journal.') |
|
1097 | 1100 | |
|
1098 | 1101 | repo.invalidate(clearfilecache=True) |
|
1099 | 1102 | |
|
1100 | 1103 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1101 | 1104 | "journal", |
|
1102 | 1105 | "undo", |
|
1103 | 1106 | aftertrans(renames), |
|
1104 | 1107 | self.store.createmode, |
|
1105 | 1108 | validator=validate, |
|
1106 | 1109 | releasefn=releasefn, |
|
1107 | 1110 | checkambigfiles=_cachedfiles) |
|
1108 | 1111 | tr.changes['revs'] = set() |
|
1109 | 1112 | tr.changes['obsmarkers'] = set() |
|
1110 | 1113 | |
|
1111 | 1114 | tr.hookargs['txnid'] = txnid |
|
1112 | 1115 | # note: writing the fncache only during finalize mean that the file is |
|
1113 | 1116 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1114 | 1117 | # this is not expected to break anything that happen during the hooks. |
|
1115 | 1118 | tr.addfinalize('flush-fncache', self.store.write) |
|
1116 | 1119 | def txnclosehook(tr2): |
|
1117 | 1120 | """To be run if transaction is successful, will schedule a hook run |
|
1118 | 1121 | """ |
|
1119 | 1122 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1120 | 1123 | # This reduces memory consumption when there are multiple |
|
1121 | 1124 | # transactions per lock. This can likely go away if issue5045 |
|
1122 | 1125 | # fixes the function accumulation. |
|
1123 | 1126 | hookargs = tr2.hookargs |
|
1124 | 1127 | |
|
1125 | 1128 | def hook(): |
|
1126 | 1129 | reporef().hook('txnclose', throw=False, txnname=desc, |
|
1127 | 1130 | **pycompat.strkwargs(hookargs)) |
|
1128 | 1131 | reporef()._afterlock(hook) |
|
1129 | 1132 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1130 | 1133 | tr.addpostclose('warms-cache', self._buildcacheupdater(tr)) |
|
1131 | 1134 | def txnaborthook(tr2): |
|
1132 | 1135 | """To be run if transaction is aborted |
|
1133 | 1136 | """ |
|
1134 | 1137 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1135 | 1138 | **tr2.hookargs) |
|
1136 | 1139 | tr.addabort('txnabort-hook', txnaborthook) |
|
1137 | 1140 | # avoid eager cache invalidation. in-memory data should be identical |
|
1138 | 1141 | # to stored data if transaction has no error. |
|
1139 | 1142 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1140 | 1143 | self._transref = weakref.ref(tr) |
|
1141 | 1144 | return tr |
|
1142 | 1145 | |
|
1143 | 1146 | def _journalfiles(self): |
|
1144 | 1147 | return ((self.svfs, 'journal'), |
|
1145 | 1148 | (self.vfs, 'journal.dirstate'), |
|
1146 | 1149 | (self.vfs, 'journal.branch'), |
|
1147 | 1150 | (self.vfs, 'journal.desc'), |
|
1148 | 1151 | (self.vfs, 'journal.bookmarks'), |
|
1149 | 1152 | (self.svfs, 'journal.phaseroots')) |
|
1150 | 1153 | |
|
1151 | 1154 | def undofiles(self): |
|
1152 | 1155 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1153 | 1156 | |
|
1154 | 1157 | @unfilteredmethod |
|
1155 | 1158 | def _writejournal(self, desc): |
|
1156 | 1159 | self.dirstate.savebackup(None, prefix='journal.') |
|
1157 | 1160 | self.vfs.write("journal.branch", |
|
1158 | 1161 | encoding.fromlocal(self.dirstate.branch())) |
|
1159 | 1162 | self.vfs.write("journal.desc", |
|
1160 | 1163 | "%d\n%s\n" % (len(self), desc)) |
|
1161 | 1164 | self.vfs.write("journal.bookmarks", |
|
1162 | 1165 | self.vfs.tryread("bookmarks")) |
|
1163 | 1166 | self.svfs.write("journal.phaseroots", |
|
1164 | 1167 | self.svfs.tryread("phaseroots")) |
|
1165 | 1168 | |
|
1166 | 1169 | def recover(self): |
|
1167 | 1170 | with self.lock(): |
|
1168 | 1171 | if self.svfs.exists("journal"): |
|
1169 | 1172 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1170 | 1173 | vfsmap = {'': self.svfs, |
|
1171 | 1174 | 'plain': self.vfs,} |
|
1172 | 1175 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1173 | 1176 | self.ui.warn, |
|
1174 | 1177 | checkambigfiles=_cachedfiles) |
|
1175 | 1178 | self.invalidate() |
|
1176 | 1179 | return True |
|
1177 | 1180 | else: |
|
1178 | 1181 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1179 | 1182 | return False |
|
1180 | 1183 | |
|
1181 | 1184 | def rollback(self, dryrun=False, force=False): |
|
1182 | 1185 | wlock = lock = dsguard = None |
|
1183 | 1186 | try: |
|
1184 | 1187 | wlock = self.wlock() |
|
1185 | 1188 | lock = self.lock() |
|
1186 | 1189 | if self.svfs.exists("undo"): |
|
1187 | 1190 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
1188 | 1191 | |
|
1189 | 1192 | return self._rollback(dryrun, force, dsguard) |
|
1190 | 1193 | else: |
|
1191 | 1194 | self.ui.warn(_("no rollback information available\n")) |
|
1192 | 1195 | return 1 |
|
1193 | 1196 | finally: |
|
1194 | 1197 | release(dsguard, lock, wlock) |
|
1195 | 1198 | |
|
1196 | 1199 | @unfilteredmethod # Until we get smarter cache management |
|
1197 | 1200 | def _rollback(self, dryrun, force, dsguard): |
|
1198 | 1201 | ui = self.ui |
|
1199 | 1202 | try: |
|
1200 | 1203 | args = self.vfs.read('undo.desc').splitlines() |
|
1201 | 1204 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1202 | 1205 | if len(args) >= 3: |
|
1203 | 1206 | detail = args[2] |
|
1204 | 1207 | oldtip = oldlen - 1 |
|
1205 | 1208 | |
|
1206 | 1209 | if detail and ui.verbose: |
|
1207 | 1210 | msg = (_('repository tip rolled back to revision %d' |
|
1208 | 1211 | ' (undo %s: %s)\n') |
|
1209 | 1212 | % (oldtip, desc, detail)) |
|
1210 | 1213 | else: |
|
1211 | 1214 | msg = (_('repository tip rolled back to revision %d' |
|
1212 | 1215 | ' (undo %s)\n') |
|
1213 | 1216 | % (oldtip, desc)) |
|
1214 | 1217 | except IOError: |
|
1215 | 1218 | msg = _('rolling back unknown transaction\n') |
|
1216 | 1219 | desc = None |
|
1217 | 1220 | |
|
1218 | 1221 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1219 | 1222 | raise error.Abort( |
|
1220 | 1223 | _('rollback of last commit while not checked out ' |
|
1221 | 1224 | 'may lose data'), hint=_('use -f to force')) |
|
1222 | 1225 | |
|
1223 | 1226 | ui.status(msg) |
|
1224 | 1227 | if dryrun: |
|
1225 | 1228 | return 0 |
|
1226 | 1229 | |
|
1227 | 1230 | parents = self.dirstate.parents() |
|
1228 | 1231 | self.destroying() |
|
1229 | 1232 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1230 | 1233 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn, |
|
1231 | 1234 | checkambigfiles=_cachedfiles) |
|
1232 | 1235 | if self.vfs.exists('undo.bookmarks'): |
|
1233 | 1236 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
1234 | 1237 | if self.svfs.exists('undo.phaseroots'): |
|
1235 | 1238 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
1236 | 1239 | self.invalidate() |
|
1237 | 1240 | |
|
1238 | 1241 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1239 | 1242 | parents[1] not in self.changelog.nodemap) |
|
1240 | 1243 | if parentgone: |
|
1241 | 1244 | # prevent dirstateguard from overwriting already restored one |
|
1242 | 1245 | dsguard.close() |
|
1243 | 1246 | |
|
1244 | 1247 | self.dirstate.restorebackup(None, prefix='undo.') |
|
1245 | 1248 | try: |
|
1246 | 1249 | branch = self.vfs.read('undo.branch') |
|
1247 | 1250 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1248 | 1251 | except IOError: |
|
1249 | 1252 | ui.warn(_('named branch could not be reset: ' |
|
1250 | 1253 | 'current branch is still \'%s\'\n') |
|
1251 | 1254 | % self.dirstate.branch()) |
|
1252 | 1255 | |
|
1253 | 1256 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
1254 | 1257 | if len(parents) > 1: |
|
1255 | 1258 | ui.status(_('working directory now based on ' |
|
1256 | 1259 | 'revisions %d and %d\n') % parents) |
|
1257 | 1260 | else: |
|
1258 | 1261 | ui.status(_('working directory now based on ' |
|
1259 | 1262 | 'revision %d\n') % parents) |
|
1260 | 1263 | mergemod.mergestate.clean(self, self['.'].node()) |
|
1261 | 1264 | |
|
1262 | 1265 | # TODO: if we know which new heads may result from this rollback, pass |
|
1263 | 1266 | # them to destroy(), which will prevent the branchhead cache from being |
|
1264 | 1267 | # invalidated. |
|
1265 | 1268 | self.destroyed() |
|
1266 | 1269 | return 0 |
|
1267 | 1270 | |
|
1268 | 1271 | def _buildcacheupdater(self, newtransaction): |
|
1269 | 1272 | """called during transaction to build the callback updating cache |
|
1270 | 1273 | |
|
1271 | 1274 | Lives on the repository to help extension who might want to augment |
|
1272 | 1275 | this logic. For this purpose, the created transaction is passed to the |
|
1273 | 1276 | method. |
|
1274 | 1277 | """ |
|
1275 | 1278 | # we must avoid cyclic reference between repo and transaction. |
|
1276 | 1279 | reporef = weakref.ref(self) |
|
1277 | 1280 | def updater(tr): |
|
1278 | 1281 | repo = reporef() |
|
1279 | 1282 | repo.updatecaches(tr) |
|
1280 | 1283 | return updater |
|
1281 | 1284 | |
|
1282 | 1285 | @unfilteredmethod |
|
1283 | 1286 | def updatecaches(self, tr=None): |
|
1284 | 1287 | """warm appropriate caches |
|
1285 | 1288 | |
|
1286 | 1289 | If this function is called after a transaction closed. The transaction |
|
1287 | 1290 | will be available in the 'tr' argument. This can be used to selectively |
|
1288 | 1291 | update caches relevant to the changes in that transaction. |
|
1289 | 1292 | """ |
|
1290 | 1293 | if tr is not None and tr.hookargs.get('source') == 'strip': |
|
1291 | 1294 | # During strip, many caches are invalid but |
|
1292 | 1295 | # later call to `destroyed` will refresh them. |
|
1293 | 1296 | return |
|
1294 | 1297 | |
|
1295 | 1298 | if tr is None or tr.changes['revs']: |
|
1296 | 1299 | # updating the unfiltered branchmap should refresh all the others, |
|
1297 | 1300 | self.ui.debug('updating the branch cache\n') |
|
1298 | 1301 | branchmap.updatecache(self.filtered('served')) |
|
1299 | 1302 | |
|
1300 | 1303 | def invalidatecaches(self): |
|
1301 | 1304 | |
|
1302 | 1305 | if '_tagscache' in vars(self): |
|
1303 | 1306 | # can't use delattr on proxy |
|
1304 | 1307 | del self.__dict__['_tagscache'] |
|
1305 | 1308 | |
|
1306 | 1309 | self.unfiltered()._branchcaches.clear() |
|
1307 | 1310 | self.invalidatevolatilesets() |
|
1308 | 1311 | self._sparsesignaturecache.clear() |
|
1309 | 1312 | |
|
1310 | 1313 | def invalidatevolatilesets(self): |
|
1311 | 1314 | self.filteredrevcache.clear() |
|
1312 | 1315 | obsolete.clearobscaches(self) |
|
1313 | 1316 | |
|
1314 | 1317 | def invalidatedirstate(self): |
|
1315 | 1318 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1316 | 1319 | to check if it was modified since the last time it was read, |
|
1317 | 1320 | rereading it if it has. |
|
1318 | 1321 | |
|
1319 | 1322 | This is different to dirstate.invalidate() that it doesn't always |
|
1320 | 1323 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1321 | 1324 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1322 | 1325 | known good state).''' |
|
1323 | 1326 | if hasunfilteredcache(self, 'dirstate'): |
|
1324 | 1327 | for k in self.dirstate._filecache: |
|
1325 | 1328 | try: |
|
1326 | 1329 | delattr(self.dirstate, k) |
|
1327 | 1330 | except AttributeError: |
|
1328 | 1331 | pass |
|
1329 | 1332 | delattr(self.unfiltered(), 'dirstate') |
|
1330 | 1333 | |
|
1331 | 1334 | def invalidate(self, clearfilecache=False): |
|
1332 | 1335 | '''Invalidates both store and non-store parts other than dirstate |
|
1333 | 1336 | |
|
1334 | 1337 | If a transaction is running, invalidation of store is omitted, |
|
1335 | 1338 | because discarding in-memory changes might cause inconsistency |
|
1336 | 1339 | (e.g. incomplete fncache causes unintentional failure, but |
|
1337 | 1340 | redundant one doesn't). |
|
1338 | 1341 | ''' |
|
1339 | 1342 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1340 | 1343 | for k in list(self._filecache.keys()): |
|
1341 | 1344 | # dirstate is invalidated separately in invalidatedirstate() |
|
1342 | 1345 | if k == 'dirstate': |
|
1343 | 1346 | continue |
|
1344 | 1347 | |
|
1345 | 1348 | if clearfilecache: |
|
1346 | 1349 | del self._filecache[k] |
|
1347 | 1350 | try: |
|
1348 | 1351 | delattr(unfiltered, k) |
|
1349 | 1352 | except AttributeError: |
|
1350 | 1353 | pass |
|
1351 | 1354 | self.invalidatecaches() |
|
1352 | 1355 | if not self.currenttransaction(): |
|
1353 | 1356 | # TODO: Changing contents of store outside transaction |
|
1354 | 1357 | # causes inconsistency. We should make in-memory store |
|
1355 | 1358 | # changes detectable, and abort if changed. |
|
1356 | 1359 | self.store.invalidatecaches() |
|
1357 | 1360 | |
|
1358 | 1361 | def invalidateall(self): |
|
1359 | 1362 | '''Fully invalidates both store and non-store parts, causing the |
|
1360 | 1363 | subsequent operation to reread any outside changes.''' |
|
1361 | 1364 | # extension should hook this to invalidate its caches |
|
1362 | 1365 | self.invalidate() |
|
1363 | 1366 | self.invalidatedirstate() |
|
1364 | 1367 | |
|
1365 | 1368 | @unfilteredmethod |
|
1366 | 1369 | def _refreshfilecachestats(self, tr): |
|
1367 | 1370 | """Reload stats of cached files so that they are flagged as valid""" |
|
1368 | 1371 | for k, ce in self._filecache.items(): |
|
1369 | 1372 | if k == 'dirstate' or k not in self.__dict__: |
|
1370 | 1373 | continue |
|
1371 | 1374 | ce.refresh() |
|
1372 | 1375 | |
|
1373 | 1376 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1374 | 1377 | inheritchecker=None, parentenvvar=None): |
|
1375 | 1378 | parentlock = None |
|
1376 | 1379 | # the contents of parentenvvar are used by the underlying lock to |
|
1377 | 1380 | # determine whether it can be inherited |
|
1378 | 1381 | if parentenvvar is not None: |
|
1379 | 1382 | parentlock = encoding.environ.get(parentenvvar) |
|
1380 | 1383 | try: |
|
1381 | 1384 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, |
|
1382 | 1385 | acquirefn=acquirefn, desc=desc, |
|
1383 | 1386 | inheritchecker=inheritchecker, |
|
1384 | 1387 | parentlock=parentlock) |
|
1385 | 1388 | except error.LockHeld as inst: |
|
1386 | 1389 | if not wait: |
|
1387 | 1390 | raise |
|
1388 | 1391 | # show more details for new-style locks |
|
1389 | 1392 | if ':' in inst.locker: |
|
1390 | 1393 | host, pid = inst.locker.split(":", 1) |
|
1391 | 1394 | self.ui.warn( |
|
1392 | 1395 | _("waiting for lock on %s held by process %r " |
|
1393 | 1396 | "on host %r\n") % (desc, pid, host)) |
|
1394 | 1397 | else: |
|
1395 | 1398 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
1396 | 1399 | (desc, inst.locker)) |
|
1397 | 1400 | # default to 600 seconds timeout |
|
1398 | 1401 | l = lockmod.lock(vfs, lockname, |
|
1399 | 1402 | int(self.ui.config("ui", "timeout", "600")), |
|
1400 | 1403 | releasefn=releasefn, acquirefn=acquirefn, |
|
1401 | 1404 | desc=desc) |
|
1402 | 1405 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
1403 | 1406 | return l |
|
1404 | 1407 | |
|
1405 | 1408 | def _afterlock(self, callback): |
|
1406 | 1409 | """add a callback to be run when the repository is fully unlocked |
|
1407 | 1410 | |
|
1408 | 1411 | The callback will be executed when the outermost lock is released |
|
1409 | 1412 | (with wlock being higher level than 'lock').""" |
|
1410 | 1413 | for ref in (self._wlockref, self._lockref): |
|
1411 | 1414 | l = ref and ref() |
|
1412 | 1415 | if l and l.held: |
|
1413 | 1416 | l.postrelease.append(callback) |
|
1414 | 1417 | break |
|
1415 | 1418 | else: # no lock have been found. |
|
1416 | 1419 | callback() |
|
1417 | 1420 | |
|
1418 | 1421 | def lock(self, wait=True): |
|
1419 | 1422 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1420 | 1423 | to the lock. Use this before modifying the store (e.g. committing or |
|
1421 | 1424 | stripping). If you are opening a transaction, get a lock as well.) |
|
1422 | 1425 | |
|
1423 | 1426 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1424 | 1427 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1425 | 1428 | l = self._currentlock(self._lockref) |
|
1426 | 1429 | if l is not None: |
|
1427 | 1430 | l.lock() |
|
1428 | 1431 | return l |
|
1429 | 1432 | |
|
1430 | 1433 | l = self._lock(self.svfs, "lock", wait, None, |
|
1431 | 1434 | self.invalidate, _('repository %s') % self.origroot) |
|
1432 | 1435 | self._lockref = weakref.ref(l) |
|
1433 | 1436 | return l |
|
1434 | 1437 | |
|
1435 | 1438 | def _wlockchecktransaction(self): |
|
1436 | 1439 | if self.currenttransaction() is not None: |
|
1437 | 1440 | raise error.LockInheritanceContractViolation( |
|
1438 | 1441 | 'wlock cannot be inherited in the middle of a transaction') |
|
1439 | 1442 | |
|
1440 | 1443 | def wlock(self, wait=True): |
|
1441 | 1444 | '''Lock the non-store parts of the repository (everything under |
|
1442 | 1445 | .hg except .hg/store) and return a weak reference to the lock. |
|
1443 | 1446 | |
|
1444 | 1447 | Use this before modifying files in .hg. |
|
1445 | 1448 | |
|
1446 | 1449 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1447 | 1450 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1448 | 1451 | l = self._wlockref and self._wlockref() |
|
1449 | 1452 | if l is not None and l.held: |
|
1450 | 1453 | l.lock() |
|
1451 | 1454 | return l |
|
1452 | 1455 | |
|
1453 | 1456 | # We do not need to check for non-waiting lock acquisition. Such |
|
1454 | 1457 | # acquisition would not cause dead-lock as they would just fail. |
|
1455 | 1458 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1456 | 1459 | or self.ui.configbool('devel', 'check-locks')): |
|
1457 | 1460 | if self._currentlock(self._lockref) is not None: |
|
1458 | 1461 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1459 | 1462 | |
|
1460 | 1463 | def unlock(): |
|
1461 | 1464 | if self.dirstate.pendingparentchange(): |
|
1462 | 1465 | self.dirstate.invalidate() |
|
1463 | 1466 | else: |
|
1464 | 1467 | self.dirstate.write(None) |
|
1465 | 1468 | |
|
1466 | 1469 | self._filecache['dirstate'].refresh() |
|
1467 | 1470 | |
|
1468 | 1471 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1469 | 1472 | self.invalidatedirstate, _('working directory of %s') % |
|
1470 | 1473 | self.origroot, |
|
1471 | 1474 | inheritchecker=self._wlockchecktransaction, |
|
1472 | 1475 | parentenvvar='HG_WLOCK_LOCKER') |
|
1473 | 1476 | self._wlockref = weakref.ref(l) |
|
1474 | 1477 | return l |
|
1475 | 1478 | |
|
1476 | 1479 | def _currentlock(self, lockref): |
|
1477 | 1480 | """Returns the lock if it's held, or None if it's not.""" |
|
1478 | 1481 | if lockref is None: |
|
1479 | 1482 | return None |
|
1480 | 1483 | l = lockref() |
|
1481 | 1484 | if l is None or not l.held: |
|
1482 | 1485 | return None |
|
1483 | 1486 | return l |
|
1484 | 1487 | |
|
1485 | 1488 | def currentwlock(self): |
|
1486 | 1489 | """Returns the wlock if it's held, or None if it's not.""" |
|
1487 | 1490 | return self._currentlock(self._wlockref) |
|
1488 | 1491 | |
|
1489 | 1492 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1490 | 1493 | """ |
|
1491 | 1494 | commit an individual file as part of a larger transaction |
|
1492 | 1495 | """ |
|
1493 | 1496 | |
|
1494 | 1497 | fname = fctx.path() |
|
1495 | 1498 | fparent1 = manifest1.get(fname, nullid) |
|
1496 | 1499 | fparent2 = manifest2.get(fname, nullid) |
|
1497 | 1500 | if isinstance(fctx, context.filectx): |
|
1498 | 1501 | node = fctx.filenode() |
|
1499 | 1502 | if node in [fparent1, fparent2]: |
|
1500 | 1503 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1501 | 1504 | if manifest1.flags(fname) != fctx.flags(): |
|
1502 | 1505 | changelist.append(fname) |
|
1503 | 1506 | return node |
|
1504 | 1507 | |
|
1505 | 1508 | flog = self.file(fname) |
|
1506 | 1509 | meta = {} |
|
1507 | 1510 | copy = fctx.renamed() |
|
1508 | 1511 | if copy and copy[0] != fname: |
|
1509 | 1512 | # Mark the new revision of this file as a copy of another |
|
1510 | 1513 | # file. This copy data will effectively act as a parent |
|
1511 | 1514 | # of this new revision. If this is a merge, the first |
|
1512 | 1515 | # parent will be the nullid (meaning "look up the copy data") |
|
1513 | 1516 | # and the second one will be the other parent. For example: |
|
1514 | 1517 | # |
|
1515 | 1518 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1516 | 1519 | # \ / rev2 renames foo to bar and changes it |
|
1517 | 1520 | # \- 2 -/ rev3 should have bar with all changes and |
|
1518 | 1521 | # should record that bar descends from |
|
1519 | 1522 | # bar in rev2 and foo in rev1 |
|
1520 | 1523 | # |
|
1521 | 1524 | # this allows this merge to succeed: |
|
1522 | 1525 | # |
|
1523 | 1526 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1524 | 1527 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1525 | 1528 | # \- 2 --- 4 as the merge base |
|
1526 | 1529 | # |
|
1527 | 1530 | |
|
1528 | 1531 | cfname = copy[0] |
|
1529 | 1532 | crev = manifest1.get(cfname) |
|
1530 | 1533 | newfparent = fparent2 |
|
1531 | 1534 | |
|
1532 | 1535 | if manifest2: # branch merge |
|
1533 | 1536 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1534 | 1537 | if cfname in manifest2: |
|
1535 | 1538 | crev = manifest2[cfname] |
|
1536 | 1539 | newfparent = fparent1 |
|
1537 | 1540 | |
|
1538 | 1541 | # Here, we used to search backwards through history to try to find |
|
1539 | 1542 | # where the file copy came from if the source of a copy was not in |
|
1540 | 1543 | # the parent directory. However, this doesn't actually make sense to |
|
1541 | 1544 | # do (what does a copy from something not in your working copy even |
|
1542 | 1545 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1543 | 1546 | # the user that copy information was dropped, so if they didn't |
|
1544 | 1547 | # expect this outcome it can be fixed, but this is the correct |
|
1545 | 1548 | # behavior in this circumstance. |
|
1546 | 1549 | |
|
1547 | 1550 | if crev: |
|
1548 | 1551 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1549 | 1552 | meta["copy"] = cfname |
|
1550 | 1553 | meta["copyrev"] = hex(crev) |
|
1551 | 1554 | fparent1, fparent2 = nullid, newfparent |
|
1552 | 1555 | else: |
|
1553 | 1556 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1554 | 1557 | "copied from '%s'!\n") % (fname, cfname)) |
|
1555 | 1558 | |
|
1556 | 1559 | elif fparent1 == nullid: |
|
1557 | 1560 | fparent1, fparent2 = fparent2, nullid |
|
1558 | 1561 | elif fparent2 != nullid: |
|
1559 | 1562 | # is one parent an ancestor of the other? |
|
1560 | 1563 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1561 | 1564 | if fparent1 in fparentancestors: |
|
1562 | 1565 | fparent1, fparent2 = fparent2, nullid |
|
1563 | 1566 | elif fparent2 in fparentancestors: |
|
1564 | 1567 | fparent2 = nullid |
|
1565 | 1568 | |
|
1566 | 1569 | # is the file changed? |
|
1567 | 1570 | text = fctx.data() |
|
1568 | 1571 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1569 | 1572 | changelist.append(fname) |
|
1570 | 1573 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1571 | 1574 | # are just the flags changed during merge? |
|
1572 | 1575 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1573 | 1576 | changelist.append(fname) |
|
1574 | 1577 | |
|
1575 | 1578 | return fparent1 |
|
1576 | 1579 | |
|
1577 | 1580 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
1578 | 1581 | """check for commit arguments that aren't committable""" |
|
1579 | 1582 | if match.isexact() or match.prefix(): |
|
1580 | 1583 | matched = set(status.modified + status.added + status.removed) |
|
1581 | 1584 | |
|
1582 | 1585 | for f in match.files(): |
|
1583 | 1586 | f = self.dirstate.normalize(f) |
|
1584 | 1587 | if f == '.' or f in matched or f in wctx.substate: |
|
1585 | 1588 | continue |
|
1586 | 1589 | if f in status.deleted: |
|
1587 | 1590 | fail(f, _('file not found!')) |
|
1588 | 1591 | if f in vdirs: # visited directory |
|
1589 | 1592 | d = f + '/' |
|
1590 | 1593 | for mf in matched: |
|
1591 | 1594 | if mf.startswith(d): |
|
1592 | 1595 | break |
|
1593 | 1596 | else: |
|
1594 | 1597 | fail(f, _("no match under directory!")) |
|
1595 | 1598 | elif f not in self.dirstate: |
|
1596 | 1599 | fail(f, _("file not tracked!")) |
|
1597 | 1600 | |
|
1598 | 1601 | @unfilteredmethod |
|
1599 | 1602 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1600 | 1603 | editor=False, extra=None): |
|
1601 | 1604 | """Add a new revision to current repository. |
|
1602 | 1605 | |
|
1603 | 1606 | Revision information is gathered from the working directory, |
|
1604 | 1607 | match can be used to filter the committed files. If editor is |
|
1605 | 1608 | supplied, it is called to get a commit message. |
|
1606 | 1609 | """ |
|
1607 | 1610 | if extra is None: |
|
1608 | 1611 | extra = {} |
|
1609 | 1612 | |
|
1610 | 1613 | def fail(f, msg): |
|
1611 | 1614 | raise error.Abort('%s: %s' % (f, msg)) |
|
1612 | 1615 | |
|
1613 | 1616 | if not match: |
|
1614 | 1617 | match = matchmod.always(self.root, '') |
|
1615 | 1618 | |
|
1616 | 1619 | if not force: |
|
1617 | 1620 | vdirs = [] |
|
1618 | 1621 | match.explicitdir = vdirs.append |
|
1619 | 1622 | match.bad = fail |
|
1620 | 1623 | |
|
1621 | 1624 | wlock = lock = tr = None |
|
1622 | 1625 | try: |
|
1623 | 1626 | wlock = self.wlock() |
|
1624 | 1627 | lock = self.lock() # for recent changelog (see issue4368) |
|
1625 | 1628 | |
|
1626 | 1629 | wctx = self[None] |
|
1627 | 1630 | merge = len(wctx.parents()) > 1 |
|
1628 | 1631 | |
|
1629 | 1632 | if not force and merge and not match.always(): |
|
1630 | 1633 | raise error.Abort(_('cannot partially commit a merge ' |
|
1631 | 1634 | '(do not specify files or patterns)')) |
|
1632 | 1635 | |
|
1633 | 1636 | status = self.status(match=match, clean=force) |
|
1634 | 1637 | if force: |
|
1635 | 1638 | status.modified.extend(status.clean) # mq may commit clean files |
|
1636 | 1639 | |
|
1637 | 1640 | # check subrepos |
|
1638 | 1641 | subs = [] |
|
1639 | 1642 | commitsubs = set() |
|
1640 | 1643 | newstate = wctx.substate.copy() |
|
1641 | 1644 | # only manage subrepos and .hgsubstate if .hgsub is present |
|
1642 | 1645 | if '.hgsub' in wctx: |
|
1643 | 1646 | # we'll decide whether to track this ourselves, thanks |
|
1644 | 1647 | for c in status.modified, status.added, status.removed: |
|
1645 | 1648 | if '.hgsubstate' in c: |
|
1646 | 1649 | c.remove('.hgsubstate') |
|
1647 | 1650 | |
|
1648 | 1651 | # compare current state to last committed state |
|
1649 | 1652 | # build new substate based on last committed state |
|
1650 | 1653 | oldstate = wctx.p1().substate |
|
1651 | 1654 | for s in sorted(newstate.keys()): |
|
1652 | 1655 | if not match(s): |
|
1653 | 1656 | # ignore working copy, use old state if present |
|
1654 | 1657 | if s in oldstate: |
|
1655 | 1658 | newstate[s] = oldstate[s] |
|
1656 | 1659 | continue |
|
1657 | 1660 | if not force: |
|
1658 | 1661 | raise error.Abort( |
|
1659 | 1662 | _("commit with new subrepo %s excluded") % s) |
|
1660 | 1663 | dirtyreason = wctx.sub(s).dirtyreason(True) |
|
1661 | 1664 | if dirtyreason: |
|
1662 | 1665 | if not self.ui.configbool('ui', 'commitsubrepos'): |
|
1663 | 1666 | raise error.Abort(dirtyreason, |
|
1664 | 1667 | hint=_("use --subrepos for recursive commit")) |
|
1665 | 1668 | subs.append(s) |
|
1666 | 1669 | commitsubs.add(s) |
|
1667 | 1670 | else: |
|
1668 | 1671 | bs = wctx.sub(s).basestate() |
|
1669 | 1672 | newstate[s] = (newstate[s][0], bs, newstate[s][2]) |
|
1670 | 1673 | if oldstate.get(s, (None, None, None))[1] != bs: |
|
1671 | 1674 | subs.append(s) |
|
1672 | 1675 | |
|
1673 | 1676 | # check for removed subrepos |
|
1674 | 1677 | for p in wctx.parents(): |
|
1675 | 1678 | r = [s for s in p.substate if s not in newstate] |
|
1676 | 1679 | subs += [s for s in r if match(s)] |
|
1677 | 1680 | if subs: |
|
1678 | 1681 | if (not match('.hgsub') and |
|
1679 | 1682 | '.hgsub' in (wctx.modified() + wctx.added())): |
|
1680 | 1683 | raise error.Abort( |
|
1681 | 1684 | _("can't commit subrepos without .hgsub")) |
|
1682 | 1685 | status.modified.insert(0, '.hgsubstate') |
|
1683 | 1686 | |
|
1684 | 1687 | elif '.hgsub' in status.removed: |
|
1685 | 1688 | # clean up .hgsubstate when .hgsub is removed |
|
1686 | 1689 | if ('.hgsubstate' in wctx and |
|
1687 | 1690 | '.hgsubstate' not in (status.modified + status.added + |
|
1688 | 1691 | status.removed)): |
|
1689 | 1692 | status.removed.insert(0, '.hgsubstate') |
|
1690 | 1693 | |
|
1691 | 1694 | # make sure all explicit patterns are matched |
|
1692 | 1695 | if not force: |
|
1693 | 1696 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
1694 | 1697 | |
|
1695 | 1698 | cctx = context.workingcommitctx(self, status, |
|
1696 | 1699 | text, user, date, extra) |
|
1697 | 1700 | |
|
1698 | 1701 | # internal config: ui.allowemptycommit |
|
1699 | 1702 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1700 | 1703 | or extra.get('close') or merge or cctx.files() |
|
1701 | 1704 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1702 | 1705 | if not allowemptycommit: |
|
1703 | 1706 | return None |
|
1704 | 1707 | |
|
1705 | 1708 | if merge and cctx.deleted(): |
|
1706 | 1709 | raise error.Abort(_("cannot commit merge with missing files")) |
|
1707 | 1710 | |
|
1708 | 1711 | ms = mergemod.mergestate.read(self) |
|
1709 | 1712 | mergeutil.checkunresolved(ms) |
|
1710 | 1713 | |
|
1711 | 1714 | if editor: |
|
1712 | 1715 | cctx._text = editor(self, cctx, subs) |
|
1713 | 1716 | edited = (text != cctx._text) |
|
1714 | 1717 | |
|
1715 | 1718 | # Save commit message in case this transaction gets rolled back |
|
1716 | 1719 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1717 | 1720 | # the assumption that the user will use the same editor again. |
|
1718 | 1721 | msgfn = self.savecommitmessage(cctx._text) |
|
1719 | 1722 | |
|
1720 | 1723 | # commit subs and write new state |
|
1721 | 1724 | if subs: |
|
1722 | 1725 | for s in sorted(commitsubs): |
|
1723 | 1726 | sub = wctx.sub(s) |
|
1724 | 1727 | self.ui.status(_('committing subrepository %s\n') % |
|
1725 | 1728 | subrepo.subrelpath(sub)) |
|
1726 | 1729 | sr = sub.commit(cctx._text, user, date) |
|
1727 | 1730 | newstate[s] = (newstate[s][0], sr) |
|
1728 | 1731 | subrepo.writestate(self, newstate) |
|
1729 | 1732 | |
|
1730 | 1733 | p1, p2 = self.dirstate.parents() |
|
1731 | 1734 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1732 | 1735 | try: |
|
1733 | 1736 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1734 | 1737 | parent2=hookp2) |
|
1735 | 1738 | tr = self.transaction('commit') |
|
1736 | 1739 | ret = self.commitctx(cctx, True) |
|
1737 | 1740 | except: # re-raises |
|
1738 | 1741 | if edited: |
|
1739 | 1742 | self.ui.write( |
|
1740 | 1743 | _('note: commit message saved in %s\n') % msgfn) |
|
1741 | 1744 | raise |
|
1742 | 1745 | # update bookmarks, dirstate and mergestate |
|
1743 | 1746 | bookmarks.update(self, [p1, p2], ret) |
|
1744 | 1747 | cctx.markcommitted(ret) |
|
1745 | 1748 | ms.reset() |
|
1746 | 1749 | tr.close() |
|
1747 | 1750 | |
|
1748 | 1751 | finally: |
|
1749 | 1752 | lockmod.release(tr, lock, wlock) |
|
1750 | 1753 | |
|
1751 | 1754 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1752 | 1755 | # hack for command that use a temporary commit (eg: histedit) |
|
1753 | 1756 | # temporary commit got stripped before hook release |
|
1754 | 1757 | if self.changelog.hasnode(ret): |
|
1755 | 1758 | self.hook("commit", node=node, parent1=parent1, |
|
1756 | 1759 | parent2=parent2) |
|
1757 | 1760 | self._afterlock(commithook) |
|
1758 | 1761 | return ret |
|
1759 | 1762 | |
|
1760 | 1763 | @unfilteredmethod |
|
1761 | 1764 | def commitctx(self, ctx, error=False): |
|
1762 | 1765 | """Add a new revision to current repository. |
|
1763 | 1766 | Revision information is passed via the context argument. |
|
1764 | 1767 | """ |
|
1765 | 1768 | |
|
1766 | 1769 | tr = None |
|
1767 | 1770 | p1, p2 = ctx.p1(), ctx.p2() |
|
1768 | 1771 | user = ctx.user() |
|
1769 | 1772 | |
|
1770 | 1773 | lock = self.lock() |
|
1771 | 1774 | try: |
|
1772 | 1775 | tr = self.transaction("commit") |
|
1773 | 1776 | trp = weakref.proxy(tr) |
|
1774 | 1777 | |
|
1775 | 1778 | if ctx.manifestnode(): |
|
1776 | 1779 | # reuse an existing manifest revision |
|
1777 | 1780 | mn = ctx.manifestnode() |
|
1778 | 1781 | files = ctx.files() |
|
1779 | 1782 | elif ctx.files(): |
|
1780 | 1783 | m1ctx = p1.manifestctx() |
|
1781 | 1784 | m2ctx = p2.manifestctx() |
|
1782 | 1785 | mctx = m1ctx.copy() |
|
1783 | 1786 | |
|
1784 | 1787 | m = mctx.read() |
|
1785 | 1788 | m1 = m1ctx.read() |
|
1786 | 1789 | m2 = m2ctx.read() |
|
1787 | 1790 | |
|
1788 | 1791 | # check in files |
|
1789 | 1792 | added = [] |
|
1790 | 1793 | changed = [] |
|
1791 | 1794 | removed = list(ctx.removed()) |
|
1792 | 1795 | linkrev = len(self) |
|
1793 | 1796 | self.ui.note(_("committing files:\n")) |
|
1794 | 1797 | for f in sorted(ctx.modified() + ctx.added()): |
|
1795 | 1798 | self.ui.note(f + "\n") |
|
1796 | 1799 | try: |
|
1797 | 1800 | fctx = ctx[f] |
|
1798 | 1801 | if fctx is None: |
|
1799 | 1802 | removed.append(f) |
|
1800 | 1803 | else: |
|
1801 | 1804 | added.append(f) |
|
1802 | 1805 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
1803 | 1806 | trp, changed) |
|
1804 | 1807 | m.setflag(f, fctx.flags()) |
|
1805 | 1808 | except OSError as inst: |
|
1806 | 1809 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1807 | 1810 | raise |
|
1808 | 1811 | except IOError as inst: |
|
1809 | 1812 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1810 | 1813 | if error or errcode and errcode != errno.ENOENT: |
|
1811 | 1814 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1812 | 1815 | raise |
|
1813 | 1816 | |
|
1814 | 1817 | # update manifest |
|
1815 | 1818 | self.ui.note(_("committing manifest\n")) |
|
1816 | 1819 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
1817 | 1820 | drop = [f for f in removed if f in m] |
|
1818 | 1821 | for f in drop: |
|
1819 | 1822 | del m[f] |
|
1820 | 1823 | mn = mctx.write(trp, linkrev, |
|
1821 | 1824 | p1.manifestnode(), p2.manifestnode(), |
|
1822 | 1825 | added, drop) |
|
1823 | 1826 | files = changed + removed |
|
1824 | 1827 | else: |
|
1825 | 1828 | mn = p1.manifestnode() |
|
1826 | 1829 | files = [] |
|
1827 | 1830 | |
|
1828 | 1831 | # update changelog |
|
1829 | 1832 | self.ui.note(_("committing changelog\n")) |
|
1830 | 1833 | self.changelog.delayupdate(tr) |
|
1831 | 1834 | n = self.changelog.add(mn, files, ctx.description(), |
|
1832 | 1835 | trp, p1.node(), p2.node(), |
|
1833 | 1836 | user, ctx.date(), ctx.extra().copy()) |
|
1834 | 1837 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
1835 | 1838 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
1836 | 1839 | parent2=xp2) |
|
1837 | 1840 | # set the new commit is proper phase |
|
1838 | 1841 | targetphase = subrepo.newcommitphase(self.ui, ctx) |
|
1839 | 1842 | if targetphase: |
|
1840 | 1843 | # retract boundary do not alter parent changeset. |
|
1841 | 1844 | # if a parent have higher the resulting phase will |
|
1842 | 1845 | # be compliant anyway |
|
1843 | 1846 | # |
|
1844 | 1847 | # if minimal phase was 0 we don't need to retract anything |
|
1845 | 1848 | phases.retractboundary(self, tr, targetphase, [n]) |
|
1846 | 1849 | tr.close() |
|
1847 | 1850 | return n |
|
1848 | 1851 | finally: |
|
1849 | 1852 | if tr: |
|
1850 | 1853 | tr.release() |
|
1851 | 1854 | lock.release() |
|
1852 | 1855 | |
|
1853 | 1856 | @unfilteredmethod |
|
1854 | 1857 | def destroying(self): |
|
1855 | 1858 | '''Inform the repository that nodes are about to be destroyed. |
|
1856 | 1859 | Intended for use by strip and rollback, so there's a common |
|
1857 | 1860 | place for anything that has to be done before destroying history. |
|
1858 | 1861 | |
|
1859 | 1862 | This is mostly useful for saving state that is in memory and waiting |
|
1860 | 1863 | to be flushed when the current lock is released. Because a call to |
|
1861 | 1864 | destroyed is imminent, the repo will be invalidated causing those |
|
1862 | 1865 | changes to stay in memory (waiting for the next unlock), or vanish |
|
1863 | 1866 | completely. |
|
1864 | 1867 | ''' |
|
1865 | 1868 | # When using the same lock to commit and strip, the phasecache is left |
|
1866 | 1869 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
1867 | 1870 | # causing those changes to disappear. |
|
1868 | 1871 | if '_phasecache' in vars(self): |
|
1869 | 1872 | self._phasecache.write() |
|
1870 | 1873 | |
|
1871 | 1874 | @unfilteredmethod |
|
1872 | 1875 | def destroyed(self): |
|
1873 | 1876 | '''Inform the repository that nodes have been destroyed. |
|
1874 | 1877 | Intended for use by strip and rollback, so there's a common |
|
1875 | 1878 | place for anything that has to be done after destroying history. |
|
1876 | 1879 | ''' |
|
1877 | 1880 | # When one tries to: |
|
1878 | 1881 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
1879 | 1882 | # 2) use phasecache somewhere (e.g. commit) |
|
1880 | 1883 | # |
|
1881 | 1884 | # then 2) will fail because the phasecache contains nodes that were |
|
1882 | 1885 | # removed. We can either remove phasecache from the filecache, |
|
1883 | 1886 | # causing it to reload next time it is accessed, or simply filter |
|
1884 | 1887 | # the removed nodes now and write the updated cache. |
|
1885 | 1888 | self._phasecache.filterunknown(self) |
|
1886 | 1889 | self._phasecache.write() |
|
1887 | 1890 | |
|
1888 | 1891 | # refresh all repository caches |
|
1889 | 1892 | self.updatecaches() |
|
1890 | 1893 | |
|
1891 | 1894 | # Ensure the persistent tag cache is updated. Doing it now |
|
1892 | 1895 | # means that the tag cache only has to worry about destroyed |
|
1893 | 1896 | # heads immediately after a strip/rollback. That in turn |
|
1894 | 1897 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
1895 | 1898 | # and node) always means no nodes have been added or destroyed. |
|
1896 | 1899 | |
|
1897 | 1900 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
1898 | 1901 | # head, refresh the tag cache, then immediately add a new head. |
|
1899 | 1902 | # But I think doing it this way is necessary for the "instant |
|
1900 | 1903 | # tag cache retrieval" case to work. |
|
1901 | 1904 | self.invalidate() |
|
1902 | 1905 | |
|
1903 | 1906 | def walk(self, match, node=None): |
|
1904 | 1907 | ''' |
|
1905 | 1908 | walk recursively through the directory tree or a given |
|
1906 | 1909 | changeset, finding all files matched by the match |
|
1907 | 1910 | function |
|
1908 | 1911 | ''' |
|
1909 | 1912 | self.ui.deprecwarn('use repo[node].walk instead of repo.walk', '4.3') |
|
1910 | 1913 | return self[node].walk(match) |
|
1911 | 1914 | |
|
1912 | 1915 | def status(self, node1='.', node2=None, match=None, |
|
1913 | 1916 | ignored=False, clean=False, unknown=False, |
|
1914 | 1917 | listsubrepos=False): |
|
1915 | 1918 | '''a convenience method that calls node1.status(node2)''' |
|
1916 | 1919 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
1917 | 1920 | listsubrepos) |
|
1918 | 1921 | |
|
1919 | 1922 | def addpostdsstatus(self, ps): |
|
1920 | 1923 | """Add a callback to run within the wlock, at the point at which status |
|
1921 | 1924 | fixups happen. |
|
1922 | 1925 | |
|
1923 | 1926 | On status completion, callback(wctx, status) will be called with the |
|
1924 | 1927 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
1925 | 1928 | couldn't be grabbed. |
|
1926 | 1929 | |
|
1927 | 1930 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
1928 | 1931 | it might change in the meanwhile. Instead, they should access the |
|
1929 | 1932 | dirstate via wctx.repo().dirstate. |
|
1930 | 1933 | |
|
1931 | 1934 | This list is emptied out after each status run -- extensions should |
|
1932 | 1935 | make sure it adds to this list each time dirstate.status is called. |
|
1933 | 1936 | Extensions should also make sure they don't call this for statuses |
|
1934 | 1937 | that don't involve the dirstate. |
|
1935 | 1938 | """ |
|
1936 | 1939 | |
|
1937 | 1940 | # The list is located here for uniqueness reasons -- it is actually |
|
1938 | 1941 | # managed by the workingctx, but that isn't unique per-repo. |
|
1939 | 1942 | self._postdsstatus.append(ps) |
|
1940 | 1943 | |
|
1941 | 1944 | def postdsstatus(self): |
|
1942 | 1945 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
1943 | 1946 | return self._postdsstatus |
|
1944 | 1947 | |
|
1945 | 1948 | def clearpostdsstatus(self): |
|
1946 | 1949 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
1947 | 1950 | del self._postdsstatus[:] |
|
1948 | 1951 | |
|
1949 | 1952 | def heads(self, start=None): |
|
1950 | 1953 | if start is None: |
|
1951 | 1954 | cl = self.changelog |
|
1952 | 1955 | headrevs = reversed(cl.headrevs()) |
|
1953 | 1956 | return [cl.node(rev) for rev in headrevs] |
|
1954 | 1957 | |
|
1955 | 1958 | heads = self.changelog.heads(start) |
|
1956 | 1959 | # sort the output in rev descending order |
|
1957 | 1960 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
1958 | 1961 | |
|
1959 | 1962 | def branchheads(self, branch=None, start=None, closed=False): |
|
1960 | 1963 | '''return a (possibly filtered) list of heads for the given branch |
|
1961 | 1964 | |
|
1962 | 1965 | Heads are returned in topological order, from newest to oldest. |
|
1963 | 1966 | If branch is None, use the dirstate branch. |
|
1964 | 1967 | If start is not None, return only heads reachable from start. |
|
1965 | 1968 | If closed is True, return heads that are marked as closed as well. |
|
1966 | 1969 | ''' |
|
1967 | 1970 | if branch is None: |
|
1968 | 1971 | branch = self[None].branch() |
|
1969 | 1972 | branches = self.branchmap() |
|
1970 | 1973 | if branch not in branches: |
|
1971 | 1974 | return [] |
|
1972 | 1975 | # the cache returns heads ordered lowest to highest |
|
1973 | 1976 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
1974 | 1977 | if start is not None: |
|
1975 | 1978 | # filter out the heads that cannot be reached from startrev |
|
1976 | 1979 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1977 | 1980 | bheads = [h for h in bheads if h in fbheads] |
|
1978 | 1981 | return bheads |
|
1979 | 1982 | |
|
1980 | 1983 | def branches(self, nodes): |
|
1981 | 1984 | if not nodes: |
|
1982 | 1985 | nodes = [self.changelog.tip()] |
|
1983 | 1986 | b = [] |
|
1984 | 1987 | for n in nodes: |
|
1985 | 1988 | t = n |
|
1986 | 1989 | while True: |
|
1987 | 1990 | p = self.changelog.parents(n) |
|
1988 | 1991 | if p[1] != nullid or p[0] == nullid: |
|
1989 | 1992 | b.append((t, n, p[0], p[1])) |
|
1990 | 1993 | break |
|
1991 | 1994 | n = p[0] |
|
1992 | 1995 | return b |
|
1993 | 1996 | |
|
1994 | 1997 | def between(self, pairs): |
|
1995 | 1998 | r = [] |
|
1996 | 1999 | |
|
1997 | 2000 | for top, bottom in pairs: |
|
1998 | 2001 | n, l, i = top, [], 0 |
|
1999 | 2002 | f = 1 |
|
2000 | 2003 | |
|
2001 | 2004 | while n != bottom and n != nullid: |
|
2002 | 2005 | p = self.changelog.parents(n)[0] |
|
2003 | 2006 | if i == f: |
|
2004 | 2007 | l.append(n) |
|
2005 | 2008 | f = f * 2 |
|
2006 | 2009 | n = p |
|
2007 | 2010 | i += 1 |
|
2008 | 2011 | |
|
2009 | 2012 | r.append(l) |
|
2010 | 2013 | |
|
2011 | 2014 | return r |
|
2012 | 2015 | |
|
2013 | 2016 | def checkpush(self, pushop): |
|
2014 | 2017 | """Extensions can override this function if additional checks have |
|
2015 | 2018 | to be performed before pushing, or call it if they override push |
|
2016 | 2019 | command. |
|
2017 | 2020 | """ |
|
2018 | 2021 | pass |
|
2019 | 2022 | |
|
2020 | 2023 | @unfilteredpropertycache |
|
2021 | 2024 | def prepushoutgoinghooks(self): |
|
2022 | 2025 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
2023 | 2026 | methods, which are called before pushing changesets. |
|
2024 | 2027 | """ |
|
2025 | 2028 | return util.hooks() |
|
2026 | 2029 | |
|
2027 | 2030 | def pushkey(self, namespace, key, old, new): |
|
2028 | 2031 | try: |
|
2029 | 2032 | tr = self.currenttransaction() |
|
2030 | 2033 | hookargs = {} |
|
2031 | 2034 | if tr is not None: |
|
2032 | 2035 | hookargs.update(tr.hookargs) |
|
2033 | 2036 | hookargs['namespace'] = namespace |
|
2034 | 2037 | hookargs['key'] = key |
|
2035 | 2038 | hookargs['old'] = old |
|
2036 | 2039 | hookargs['new'] = new |
|
2037 | 2040 | self.hook('prepushkey', throw=True, **hookargs) |
|
2038 | 2041 | except error.HookAbort as exc: |
|
2039 | 2042 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
2040 | 2043 | if exc.hint: |
|
2041 | 2044 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
2042 | 2045 | return False |
|
2043 | 2046 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
2044 | 2047 | ret = pushkey.push(self, namespace, key, old, new) |
|
2045 | 2048 | def runhook(): |
|
2046 | 2049 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
2047 | 2050 | ret=ret) |
|
2048 | 2051 | self._afterlock(runhook) |
|
2049 | 2052 | return ret |
|
2050 | 2053 | |
|
2051 | 2054 | def listkeys(self, namespace): |
|
2052 | 2055 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
2053 | 2056 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
2054 | 2057 | values = pushkey.list(self, namespace) |
|
2055 | 2058 | self.hook('listkeys', namespace=namespace, values=values) |
|
2056 | 2059 | return values |
|
2057 | 2060 | |
|
2058 | 2061 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
2059 | 2062 | '''used to test argument passing over the wire''' |
|
2060 | 2063 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
2061 | 2064 | |
|
2062 | 2065 | def savecommitmessage(self, text): |
|
2063 | 2066 | fp = self.vfs('last-message.txt', 'wb') |
|
2064 | 2067 | try: |
|
2065 | 2068 | fp.write(text) |
|
2066 | 2069 | finally: |
|
2067 | 2070 | fp.close() |
|
2068 | 2071 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
2069 | 2072 | |
|
2070 | 2073 | # used to avoid circular references so destructors work |
|
2071 | 2074 | def aftertrans(files): |
|
2072 | 2075 | renamefiles = [tuple(t) for t in files] |
|
2073 | 2076 | def a(): |
|
2074 | 2077 | for vfs, src, dest in renamefiles: |
|
2075 | 2078 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
2076 | 2079 | # leaving both src and dest on disk. delete dest to make sure |
|
2077 | 2080 | # the rename couldn't be such a no-op. |
|
2078 | 2081 | vfs.tryunlink(dest) |
|
2079 | 2082 | try: |
|
2080 | 2083 | vfs.rename(src, dest) |
|
2081 | 2084 | except OSError: # journal file does not yet exist |
|
2082 | 2085 | pass |
|
2083 | 2086 | return a |
|
2084 | 2087 | |
|
2085 | 2088 | def undoname(fn): |
|
2086 | 2089 | base, name = os.path.split(fn) |
|
2087 | 2090 | assert name.startswith('journal') |
|
2088 | 2091 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
2089 | 2092 | |
|
2090 | 2093 | def instance(ui, path, create): |
|
2091 | 2094 | return localrepository(ui, util.urllocalpath(path), create) |
|
2092 | 2095 | |
|
2093 | 2096 | def islocal(path): |
|
2094 | 2097 | return True |
|
2095 | 2098 | |
|
2096 | 2099 | def newreporequirements(repo): |
|
2097 | 2100 | """Determine the set of requirements for a new local repository. |
|
2098 | 2101 | |
|
2099 | 2102 | Extensions can wrap this function to specify custom requirements for |
|
2100 | 2103 | new repositories. |
|
2101 | 2104 | """ |
|
2102 | 2105 | ui = repo.ui |
|
2103 | 2106 | requirements = {'revlogv1'} |
|
2104 | 2107 | if ui.configbool('format', 'usestore'): |
|
2105 | 2108 | requirements.add('store') |
|
2106 | 2109 | if ui.configbool('format', 'usefncache'): |
|
2107 | 2110 | requirements.add('fncache') |
|
2108 | 2111 | if ui.configbool('format', 'dotencode'): |
|
2109 | 2112 | requirements.add('dotencode') |
|
2110 | 2113 | |
|
2111 | 2114 | compengine = ui.config('experimental', 'format.compression', 'zlib') |
|
2112 | 2115 | if compengine not in util.compengines: |
|
2113 | 2116 | raise error.Abort(_('compression engine %s defined by ' |
|
2114 | 2117 | 'experimental.format.compression not available') % |
|
2115 | 2118 | compengine, |
|
2116 | 2119 | hint=_('run "hg debuginstall" to list available ' |
|
2117 | 2120 | 'compression engines')) |
|
2118 | 2121 | |
|
2119 | 2122 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2120 | 2123 | if compengine != 'zlib': |
|
2121 | 2124 | requirements.add('exp-compression-%s' % compengine) |
|
2122 | 2125 | |
|
2123 | 2126 | if scmutil.gdinitconfig(ui): |
|
2124 | 2127 | requirements.add('generaldelta') |
|
2125 | 2128 | if ui.configbool('experimental', 'treemanifest', False): |
|
2126 | 2129 | requirements.add('treemanifest') |
|
2127 | 2130 | if ui.configbool('experimental', 'manifestv2', False): |
|
2128 | 2131 | requirements.add('manifestv2') |
|
2129 | 2132 | |
|
2130 | 2133 | revlogv2 = ui.config('experimental', 'revlogv2') |
|
2131 | 2134 | if revlogv2 == 'enable-unstable-format-and-corrupt-my-data': |
|
2132 | 2135 | requirements.remove('revlogv1') |
|
2133 | 2136 | # generaldelta is implied by revlogv2. |
|
2134 | 2137 | requirements.discard('generaldelta') |
|
2135 | 2138 | requirements.add(REVLOGV2_REQUIREMENT) |
|
2136 | 2139 | |
|
2137 | 2140 | return requirements |
@@ -1,2054 +1,2064 b'' | |||
|
1 | 1 | # revset.py - revision set queries for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import re |
|
11 | 11 | |
|
12 | 12 | from .i18n import _ |
|
13 | 13 | from . import ( |
|
14 | 14 | dagop, |
|
15 | 15 | destutil, |
|
16 | 16 | encoding, |
|
17 | 17 | error, |
|
18 | 18 | hbisect, |
|
19 | 19 | match as matchmod, |
|
20 | 20 | node, |
|
21 | 21 | obsolete as obsmod, |
|
22 | 22 | pathutil, |
|
23 | 23 | phases, |
|
24 | 24 | registrar, |
|
25 | 25 | repoview, |
|
26 | 26 | revsetlang, |
|
27 | 27 | scmutil, |
|
28 | 28 | smartset, |
|
29 | 29 | util, |
|
30 | 30 | ) |
|
31 | 31 | |
|
32 | 32 | # helpers for processing parsed tree |
|
33 | 33 | getsymbol = revsetlang.getsymbol |
|
34 | 34 | getstring = revsetlang.getstring |
|
35 | 35 | getinteger = revsetlang.getinteger |
|
36 | 36 | getboolean = revsetlang.getboolean |
|
37 | 37 | getlist = revsetlang.getlist |
|
38 | 38 | getrange = revsetlang.getrange |
|
39 | 39 | getargs = revsetlang.getargs |
|
40 | 40 | getargsdict = revsetlang.getargsdict |
|
41 | 41 | |
|
42 | 42 | # constants used as an argument of match() and matchany() |
|
43 | 43 | anyorder = revsetlang.anyorder |
|
44 | 44 | defineorder = revsetlang.defineorder |
|
45 | 45 | followorder = revsetlang.followorder |
|
46 | 46 | |
|
47 | 47 | baseset = smartset.baseset |
|
48 | 48 | generatorset = smartset.generatorset |
|
49 | 49 | spanset = smartset.spanset |
|
50 | 50 | fullreposet = smartset.fullreposet |
|
51 | 51 | |
|
52 | 52 | # helpers |
|
53 | 53 | |
|
54 | 54 | def getset(repo, subset, x): |
|
55 | 55 | if not x: |
|
56 | 56 | raise error.ParseError(_("missing argument")) |
|
57 | 57 | return methods[x[0]](repo, subset, *x[1:]) |
|
58 | 58 | |
|
59 | 59 | def _getrevsource(repo, r): |
|
60 | 60 | extra = repo[r].extra() |
|
61 | 61 | for label in ('source', 'transplant_source', 'rebase_source'): |
|
62 | 62 | if label in extra: |
|
63 | 63 | try: |
|
64 | 64 | return repo[extra[label]].rev() |
|
65 | 65 | except error.RepoLookupError: |
|
66 | 66 | pass |
|
67 | 67 | return None |
|
68 | 68 | |
|
69 | 69 | # operator methods |
|
70 | 70 | |
|
71 | 71 | def stringset(repo, subset, x): |
|
72 | 72 | x = scmutil.intrev(repo[x]) |
|
73 | 73 | if (x in subset |
|
74 | 74 | or x == node.nullrev and isinstance(subset, fullreposet)): |
|
75 | 75 | return baseset([x]) |
|
76 | 76 | return baseset() |
|
77 | 77 | |
|
78 | 78 | def rangeset(repo, subset, x, y, order): |
|
79 | 79 | m = getset(repo, fullreposet(repo), x) |
|
80 | 80 | n = getset(repo, fullreposet(repo), y) |
|
81 | 81 | |
|
82 | 82 | if not m or not n: |
|
83 | 83 | return baseset() |
|
84 | 84 | return _makerangeset(repo, subset, m.first(), n.last(), order) |
|
85 | 85 | |
|
86 | 86 | def rangeall(repo, subset, x, order): |
|
87 | 87 | assert x is None |
|
88 | 88 | return _makerangeset(repo, subset, 0, len(repo) - 1, order) |
|
89 | 89 | |
|
90 | 90 | def rangepre(repo, subset, y, order): |
|
91 | 91 | # ':y' can't be rewritten to '0:y' since '0' may be hidden |
|
92 | 92 | n = getset(repo, fullreposet(repo), y) |
|
93 | 93 | if not n: |
|
94 | 94 | return baseset() |
|
95 | 95 | return _makerangeset(repo, subset, 0, n.last(), order) |
|
96 | 96 | |
|
97 | 97 | def rangepost(repo, subset, x, order): |
|
98 | 98 | m = getset(repo, fullreposet(repo), x) |
|
99 | 99 | if not m: |
|
100 | 100 | return baseset() |
|
101 | 101 | return _makerangeset(repo, subset, m.first(), len(repo) - 1, order) |
|
102 | 102 | |
|
103 | 103 | def _makerangeset(repo, subset, m, n, order): |
|
104 | 104 | if m == n: |
|
105 | 105 | r = baseset([m]) |
|
106 | 106 | elif n == node.wdirrev: |
|
107 | 107 | r = spanset(repo, m, len(repo)) + baseset([n]) |
|
108 | 108 | elif m == node.wdirrev: |
|
109 | 109 | r = baseset([m]) + spanset(repo, len(repo) - 1, n - 1) |
|
110 | 110 | elif m < n: |
|
111 | 111 | r = spanset(repo, m, n + 1) |
|
112 | 112 | else: |
|
113 | 113 | r = spanset(repo, m, n - 1) |
|
114 | 114 | |
|
115 | 115 | if order == defineorder: |
|
116 | 116 | return r & subset |
|
117 | 117 | else: |
|
118 | 118 | # carrying the sorting over when possible would be more efficient |
|
119 | 119 | return subset & r |
|
120 | 120 | |
|
121 | 121 | def dagrange(repo, subset, x, y, order): |
|
122 | 122 | r = fullreposet(repo) |
|
123 | 123 | xs = dagop.reachableroots(repo, getset(repo, r, x), getset(repo, r, y), |
|
124 | 124 | includepath=True) |
|
125 | 125 | return subset & xs |
|
126 | 126 | |
|
127 | 127 | def andset(repo, subset, x, y, order): |
|
128 | 128 | return getset(repo, getset(repo, subset, x), y) |
|
129 | 129 | |
|
130 | 130 | def differenceset(repo, subset, x, y, order): |
|
131 | 131 | return getset(repo, subset, x) - getset(repo, subset, y) |
|
132 | 132 | |
|
133 | 133 | def _orsetlist(repo, subset, xs): |
|
134 | 134 | assert xs |
|
135 | 135 | if len(xs) == 1: |
|
136 | 136 | return getset(repo, subset, xs[0]) |
|
137 | 137 | p = len(xs) // 2 |
|
138 | 138 | a = _orsetlist(repo, subset, xs[:p]) |
|
139 | 139 | b = _orsetlist(repo, subset, xs[p:]) |
|
140 | 140 | return a + b |
|
141 | 141 | |
|
142 | 142 | def orset(repo, subset, x, order): |
|
143 | 143 | xs = getlist(x) |
|
144 | 144 | if order == followorder: |
|
145 | 145 | # slow path to take the subset order |
|
146 | 146 | return subset & _orsetlist(repo, fullreposet(repo), xs) |
|
147 | 147 | else: |
|
148 | 148 | return _orsetlist(repo, subset, xs) |
|
149 | 149 | |
|
150 | 150 | def notset(repo, subset, x, order): |
|
151 | 151 | return subset - getset(repo, subset, x) |
|
152 | 152 | |
|
153 | 153 | def listset(repo, subset, *xs): |
|
154 | 154 | raise error.ParseError(_("can't use a list in this context"), |
|
155 | 155 | hint=_('see hg help "revsets.x or y"')) |
|
156 | 156 | |
|
157 | 157 | def keyvaluepair(repo, subset, k, v): |
|
158 | 158 | raise error.ParseError(_("can't use a key-value pair in this context")) |
|
159 | 159 | |
|
160 | 160 | def func(repo, subset, a, b, order): |
|
161 | 161 | f = getsymbol(a) |
|
162 | 162 | if f in symbols: |
|
163 | 163 | func = symbols[f] |
|
164 | 164 | if getattr(func, '_takeorder', False): |
|
165 | 165 | return func(repo, subset, b, order) |
|
166 | 166 | return func(repo, subset, b) |
|
167 | 167 | |
|
168 | 168 | keep = lambda fn: getattr(fn, '__doc__', None) is not None |
|
169 | 169 | |
|
170 | 170 | syms = [s for (s, fn) in symbols.items() if keep(fn)] |
|
171 | 171 | raise error.UnknownIdentifier(f, syms) |
|
172 | 172 | |
|
173 | 173 | # functions |
|
174 | 174 | |
|
175 | 175 | # symbols are callables like: |
|
176 | 176 | # fn(repo, subset, x) |
|
177 | 177 | # with: |
|
178 | 178 | # repo - current repository instance |
|
179 | 179 | # subset - of revisions to be examined |
|
180 | 180 | # x - argument in tree form |
|
181 | 181 | symbols = {} |
|
182 | 182 | |
|
183 | 183 | # symbols which can't be used for a DoS attack for any given input |
|
184 | 184 | # (e.g. those which accept regexes as plain strings shouldn't be included) |
|
185 | 185 | # functions that just return a lot of changesets (like all) don't count here |
|
186 | 186 | safesymbols = set() |
|
187 | 187 | |
|
188 | 188 | predicate = registrar.revsetpredicate() |
|
189 | 189 | |
|
190 | 190 | @predicate('_destupdate') |
|
191 | 191 | def _destupdate(repo, subset, x): |
|
192 | 192 | # experimental revset for update destination |
|
193 | 193 | args = getargsdict(x, 'limit', 'clean') |
|
194 | 194 | return subset & baseset([destutil.destupdate(repo, **args)[0]]) |
|
195 | 195 | |
|
196 | 196 | @predicate('_destmerge') |
|
197 | 197 | def _destmerge(repo, subset, x): |
|
198 | 198 | # experimental revset for merge destination |
|
199 | 199 | sourceset = None |
|
200 | 200 | if x is not None: |
|
201 | 201 | sourceset = getset(repo, fullreposet(repo), x) |
|
202 | 202 | return subset & baseset([destutil.destmerge(repo, sourceset=sourceset)]) |
|
203 | 203 | |
|
204 | 204 | @predicate('adds(pattern)', safe=True) |
|
205 | 205 | def adds(repo, subset, x): |
|
206 | 206 | """Changesets that add a file matching pattern. |
|
207 | 207 | |
|
208 | 208 | The pattern without explicit kind like ``glob:`` is expected to be |
|
209 | 209 | relative to the current directory and match against a file or a |
|
210 | 210 | directory. |
|
211 | 211 | """ |
|
212 | 212 | # i18n: "adds" is a keyword |
|
213 | 213 | pat = getstring(x, _("adds requires a pattern")) |
|
214 | 214 | return checkstatus(repo, subset, pat, 1) |
|
215 | 215 | |
|
216 | 216 | @predicate('ancestor(*changeset)', safe=True) |
|
217 | 217 | def ancestor(repo, subset, x): |
|
218 | 218 | """A greatest common ancestor of the changesets. |
|
219 | 219 | |
|
220 | 220 | Accepts 0 or more changesets. |
|
221 | 221 | Will return empty list when passed no args. |
|
222 | 222 | Greatest common ancestor of a single changeset is that changeset. |
|
223 | 223 | """ |
|
224 | 224 | # i18n: "ancestor" is a keyword |
|
225 | 225 | l = getlist(x) |
|
226 | 226 | rl = fullreposet(repo) |
|
227 | 227 | anc = None |
|
228 | 228 | |
|
229 | 229 | # (getset(repo, rl, i) for i in l) generates a list of lists |
|
230 | 230 | for revs in (getset(repo, rl, i) for i in l): |
|
231 | 231 | for r in revs: |
|
232 | 232 | if anc is None: |
|
233 | 233 | anc = repo[r] |
|
234 | 234 | else: |
|
235 | 235 | anc = anc.ancestor(repo[r]) |
|
236 | 236 | |
|
237 | 237 | if anc is not None and anc.rev() in subset: |
|
238 | 238 | return baseset([anc.rev()]) |
|
239 | 239 | return baseset() |
|
240 | 240 | |
|
241 | 241 | def _ancestors(repo, subset, x, followfirst=False, startdepth=None, |
|
242 | 242 | stopdepth=None): |
|
243 | 243 | heads = getset(repo, fullreposet(repo), x) |
|
244 | 244 | if not heads: |
|
245 | 245 | return baseset() |
|
246 | 246 | s = dagop.revancestors(repo, heads, followfirst, startdepth, stopdepth) |
|
247 | 247 | return subset & s |
|
248 | 248 | |
|
249 | 249 | @predicate('ancestors(set[, depth])', safe=True) |
|
250 | 250 | def ancestors(repo, subset, x): |
|
251 | 251 | """Changesets that are ancestors of changesets in set, including the |
|
252 | 252 | given changesets themselves. |
|
253 | 253 | |
|
254 | 254 | If depth is specified, the result only includes changesets up to |
|
255 | 255 | the specified generation. |
|
256 | 256 | """ |
|
257 | 257 | # startdepth is for internal use only until we can decide the UI |
|
258 | 258 | args = getargsdict(x, 'ancestors', 'set depth startdepth') |
|
259 | 259 | if 'set' not in args: |
|
260 | 260 | # i18n: "ancestors" is a keyword |
|
261 | 261 | raise error.ParseError(_('ancestors takes at least 1 argument')) |
|
262 | 262 | startdepth = stopdepth = None |
|
263 | 263 | if 'startdepth' in args: |
|
264 | 264 | n = getinteger(args['startdepth'], |
|
265 | 265 | "ancestors expects an integer startdepth") |
|
266 | 266 | if n < 0: |
|
267 | 267 | raise error.ParseError("negative startdepth") |
|
268 | 268 | startdepth = n |
|
269 | 269 | if 'depth' in args: |
|
270 | 270 | # i18n: "ancestors" is a keyword |
|
271 | 271 | n = getinteger(args['depth'], _("ancestors expects an integer depth")) |
|
272 | 272 | if n < 0: |
|
273 | 273 | raise error.ParseError(_("negative depth")) |
|
274 | 274 | stopdepth = n + 1 |
|
275 | 275 | return _ancestors(repo, subset, args['set'], |
|
276 | 276 | startdepth=startdepth, stopdepth=stopdepth) |
|
277 | 277 | |
|
278 | 278 | @predicate('_firstancestors', safe=True) |
|
279 | 279 | def _firstancestors(repo, subset, x): |
|
280 | 280 | # ``_firstancestors(set)`` |
|
281 | 281 | # Like ``ancestors(set)`` but follows only the first parents. |
|
282 | 282 | return _ancestors(repo, subset, x, followfirst=True) |
|
283 | 283 | |
|
284 | 284 | def _childrenspec(repo, subset, x, n, order): |
|
285 | 285 | """Changesets that are the Nth child of a changeset |
|
286 | 286 | in set. |
|
287 | 287 | """ |
|
288 | 288 | cs = set() |
|
289 | 289 | for r in getset(repo, fullreposet(repo), x): |
|
290 | 290 | for i in range(n): |
|
291 | 291 | c = repo[r].children() |
|
292 | 292 | if len(c) == 0: |
|
293 | 293 | break |
|
294 | 294 | if len(c) > 1: |
|
295 | 295 | raise error.RepoLookupError( |
|
296 | 296 | _("revision in set has more than one child")) |
|
297 | 297 | r = c[0].rev() |
|
298 | 298 | else: |
|
299 | 299 | cs.add(r) |
|
300 | 300 | return subset & cs |
|
301 | 301 | |
|
302 | 302 | def ancestorspec(repo, subset, x, n, order): |
|
303 | 303 | """``set~n`` |
|
304 | 304 | Changesets that are the Nth ancestor (first parents only) of a changeset |
|
305 | 305 | in set. |
|
306 | 306 | """ |
|
307 | 307 | n = getinteger(n, _("~ expects a number")) |
|
308 | 308 | if n < 0: |
|
309 | 309 | # children lookup |
|
310 | 310 | return _childrenspec(repo, subset, x, -n, order) |
|
311 | 311 | ps = set() |
|
312 | 312 | cl = repo.changelog |
|
313 | 313 | for r in getset(repo, fullreposet(repo), x): |
|
314 | 314 | for i in range(n): |
|
315 | 315 | try: |
|
316 | 316 | r = cl.parentrevs(r)[0] |
|
317 | 317 | except error.WdirUnsupported: |
|
318 | 318 | r = repo[r].parents()[0].rev() |
|
319 | 319 | ps.add(r) |
|
320 | 320 | return subset & ps |
|
321 | 321 | |
|
322 | 322 | @predicate('author(string)', safe=True) |
|
323 | 323 | def author(repo, subset, x): |
|
324 | 324 | """Alias for ``user(string)``. |
|
325 | 325 | """ |
|
326 | 326 | # i18n: "author" is a keyword |
|
327 | 327 | n = getstring(x, _("author requires a string")) |
|
328 | 328 | kind, pattern, matcher = _substringmatcher(n, casesensitive=False) |
|
329 | 329 | return subset.filter(lambda x: matcher(repo[x].user()), |
|
330 | 330 | condrepr=('<user %r>', n)) |
|
331 | 331 | |
|
332 | 332 | @predicate('bisect(string)', safe=True) |
|
333 | 333 | def bisect(repo, subset, x): |
|
334 | 334 | """Changesets marked in the specified bisect status: |
|
335 | 335 | |
|
336 | 336 | - ``good``, ``bad``, ``skip``: csets explicitly marked as good/bad/skip |
|
337 | 337 | - ``goods``, ``bads`` : csets topologically good/bad |
|
338 | 338 | - ``range`` : csets taking part in the bisection |
|
339 | 339 | - ``pruned`` : csets that are goods, bads or skipped |
|
340 | 340 | - ``untested`` : csets whose fate is yet unknown |
|
341 | 341 | - ``ignored`` : csets ignored due to DAG topology |
|
342 | 342 | - ``current`` : the cset currently being bisected |
|
343 | 343 | """ |
|
344 | 344 | # i18n: "bisect" is a keyword |
|
345 | 345 | status = getstring(x, _("bisect requires a string")).lower() |
|
346 | 346 | state = set(hbisect.get(repo, status)) |
|
347 | 347 | return subset & state |
|
348 | 348 | |
|
349 | 349 | # Backward-compatibility |
|
350 | 350 | # - no help entry so that we do not advertise it any more |
|
351 | 351 | @predicate('bisected', safe=True) |
|
352 | 352 | def bisected(repo, subset, x): |
|
353 | 353 | return bisect(repo, subset, x) |
|
354 | 354 | |
|
355 | 355 | @predicate('bookmark([name])', safe=True) |
|
356 | 356 | def bookmark(repo, subset, x): |
|
357 | 357 | """The named bookmark or all bookmarks. |
|
358 | 358 | |
|
359 | 359 | Pattern matching is supported for `name`. See :hg:`help revisions.patterns`. |
|
360 | 360 | """ |
|
361 | 361 | # i18n: "bookmark" is a keyword |
|
362 | 362 | args = getargs(x, 0, 1, _('bookmark takes one or no arguments')) |
|
363 | 363 | if args: |
|
364 | 364 | bm = getstring(args[0], |
|
365 | 365 | # i18n: "bookmark" is a keyword |
|
366 | 366 | _('the argument to bookmark must be a string')) |
|
367 | 367 | kind, pattern, matcher = util.stringmatcher(bm) |
|
368 | 368 | bms = set() |
|
369 | 369 | if kind == 'literal': |
|
370 | 370 | bmrev = repo._bookmarks.get(pattern, None) |
|
371 | 371 | if not bmrev: |
|
372 | 372 | raise error.RepoLookupError(_("bookmark '%s' does not exist") |
|
373 | 373 | % pattern) |
|
374 | 374 | bms.add(repo[bmrev].rev()) |
|
375 | 375 | else: |
|
376 | 376 | matchrevs = set() |
|
377 | 377 | for name, bmrev in repo._bookmarks.iteritems(): |
|
378 | 378 | if matcher(name): |
|
379 | 379 | matchrevs.add(bmrev) |
|
380 | 380 | if not matchrevs: |
|
381 | 381 | raise error.RepoLookupError(_("no bookmarks exist" |
|
382 | 382 | " that match '%s'") % pattern) |
|
383 | 383 | for bmrev in matchrevs: |
|
384 | 384 | bms.add(repo[bmrev].rev()) |
|
385 | 385 | else: |
|
386 | 386 | bms = {repo[r].rev() for r in repo._bookmarks.values()} |
|
387 | 387 | bms -= {node.nullrev} |
|
388 | 388 | return subset & bms |
|
389 | 389 | |
|
390 | 390 | @predicate('branch(string or set)', safe=True) |
|
391 | 391 | def branch(repo, subset, x): |
|
392 | 392 | """ |
|
393 | 393 | All changesets belonging to the given branch or the branches of the given |
|
394 | 394 | changesets. |
|
395 | 395 | |
|
396 | 396 | Pattern matching is supported for `string`. See |
|
397 | 397 | :hg:`help revisions.patterns`. |
|
398 | 398 | """ |
|
399 | 399 | getbi = repo.revbranchcache().branchinfo |
|
400 | 400 | def getbranch(r): |
|
401 | 401 | try: |
|
402 | 402 | return getbi(r)[0] |
|
403 | 403 | except error.WdirUnsupported: |
|
404 | 404 | return repo[r].branch() |
|
405 | 405 | |
|
406 | 406 | try: |
|
407 | 407 | b = getstring(x, '') |
|
408 | 408 | except error.ParseError: |
|
409 | 409 | # not a string, but another revspec, e.g. tip() |
|
410 | 410 | pass |
|
411 | 411 | else: |
|
412 | 412 | kind, pattern, matcher = util.stringmatcher(b) |
|
413 | 413 | if kind == 'literal': |
|
414 | 414 | # note: falls through to the revspec case if no branch with |
|
415 | 415 | # this name exists and pattern kind is not specified explicitly |
|
416 | 416 | if pattern in repo.branchmap(): |
|
417 | 417 | return subset.filter(lambda r: matcher(getbranch(r)), |
|
418 | 418 | condrepr=('<branch %r>', b)) |
|
419 | 419 | if b.startswith('literal:'): |
|
420 | 420 | raise error.RepoLookupError(_("branch '%s' does not exist") |
|
421 | 421 | % pattern) |
|
422 | 422 | else: |
|
423 | 423 | return subset.filter(lambda r: matcher(getbranch(r)), |
|
424 | 424 | condrepr=('<branch %r>', b)) |
|
425 | 425 | |
|
426 | 426 | s = getset(repo, fullreposet(repo), x) |
|
427 | 427 | b = set() |
|
428 | 428 | for r in s: |
|
429 | 429 | b.add(getbranch(r)) |
|
430 | 430 | c = s.__contains__ |
|
431 | 431 | return subset.filter(lambda r: c(r) or getbranch(r) in b, |
|
432 | 432 | condrepr=lambda: '<branch %r>' % sorted(b)) |
|
433 | 433 | |
|
434 | 434 | @predicate('bumped()', safe=True) |
|
435 | 435 | def bumped(repo, subset, x): |
|
436 | 436 | """Mutable changesets marked as successors of public changesets. |
|
437 | 437 | |
|
438 | 438 | Only non-public and non-obsolete changesets can be `bumped`. |
|
439 | 439 | """ |
|
440 | 440 | # i18n: "bumped" is a keyword |
|
441 | 441 | getargs(x, 0, 0, _("bumped takes no arguments")) |
|
442 | 442 | bumped = obsmod.getrevs(repo, 'bumped') |
|
443 | 443 | return subset & bumped |
|
444 | 444 | |
|
445 | 445 | @predicate('bundle()', safe=True) |
|
446 | 446 | def bundle(repo, subset, x): |
|
447 | 447 | """Changesets in the bundle. |
|
448 | 448 | |
|
449 | 449 | Bundle must be specified by the -R option.""" |
|
450 | 450 | |
|
451 | 451 | try: |
|
452 | 452 | bundlerevs = repo.changelog.bundlerevs |
|
453 | 453 | except AttributeError: |
|
454 | 454 | raise error.Abort(_("no bundle provided - specify with -R")) |
|
455 | 455 | return subset & bundlerevs |
|
456 | 456 | |
|
457 | 457 | def checkstatus(repo, subset, pat, field): |
|
458 | 458 | hasset = matchmod.patkind(pat) == 'set' |
|
459 | 459 | |
|
460 | 460 | mcache = [None] |
|
461 | 461 | def matches(x): |
|
462 | 462 | c = repo[x] |
|
463 | 463 | if not mcache[0] or hasset: |
|
464 | 464 | mcache[0] = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
465 | 465 | m = mcache[0] |
|
466 | 466 | fname = None |
|
467 | 467 | if not m.anypats() and len(m.files()) == 1: |
|
468 | 468 | fname = m.files()[0] |
|
469 | 469 | if fname is not None: |
|
470 | 470 | if fname not in c.files(): |
|
471 | 471 | return False |
|
472 | 472 | else: |
|
473 | 473 | for f in c.files(): |
|
474 | 474 | if m(f): |
|
475 | 475 | break |
|
476 | 476 | else: |
|
477 | 477 | return False |
|
478 | 478 | files = repo.status(c.p1().node(), c.node())[field] |
|
479 | 479 | if fname is not None: |
|
480 | 480 | if fname in files: |
|
481 | 481 | return True |
|
482 | 482 | else: |
|
483 | 483 | for f in files: |
|
484 | 484 | if m(f): |
|
485 | 485 | return True |
|
486 | 486 | |
|
487 | 487 | return subset.filter(matches, condrepr=('<status[%r] %r>', field, pat)) |
|
488 | 488 | |
|
489 | 489 | def _children(repo, subset, parentset): |
|
490 | 490 | if not parentset: |
|
491 | 491 | return baseset() |
|
492 | 492 | cs = set() |
|
493 | 493 | pr = repo.changelog.parentrevs |
|
494 | 494 | minrev = parentset.min() |
|
495 | 495 | nullrev = node.nullrev |
|
496 | 496 | for r in subset: |
|
497 | 497 | if r <= minrev: |
|
498 | 498 | continue |
|
499 | 499 | p1, p2 = pr(r) |
|
500 | 500 | if p1 in parentset: |
|
501 | 501 | cs.add(r) |
|
502 | 502 | if p2 != nullrev and p2 in parentset: |
|
503 | 503 | cs.add(r) |
|
504 | 504 | return baseset(cs) |
|
505 | 505 | |
|
506 | 506 | @predicate('children(set)', safe=True) |
|
507 | 507 | def children(repo, subset, x): |
|
508 | 508 | """Child changesets of changesets in set. |
|
509 | 509 | """ |
|
510 | 510 | s = getset(repo, fullreposet(repo), x) |
|
511 | 511 | cs = _children(repo, subset, s) |
|
512 | 512 | return subset & cs |
|
513 | 513 | |
|
514 | 514 | @predicate('closed()', safe=True) |
|
515 | 515 | def closed(repo, subset, x): |
|
516 | 516 | """Changeset is closed. |
|
517 | 517 | """ |
|
518 | 518 | # i18n: "closed" is a keyword |
|
519 | 519 | getargs(x, 0, 0, _("closed takes no arguments")) |
|
520 | 520 | return subset.filter(lambda r: repo[r].closesbranch(), |
|
521 | 521 | condrepr='<branch closed>') |
|
522 | 522 | |
|
523 | 523 | @predicate('contains(pattern)') |
|
524 | 524 | def contains(repo, subset, x): |
|
525 | 525 | """The revision's manifest contains a file matching pattern (but might not |
|
526 | 526 | modify it). See :hg:`help patterns` for information about file patterns. |
|
527 | 527 | |
|
528 | 528 | The pattern without explicit kind like ``glob:`` is expected to be |
|
529 | 529 | relative to the current directory and match against a file exactly |
|
530 | 530 | for efficiency. |
|
531 | 531 | """ |
|
532 | 532 | # i18n: "contains" is a keyword |
|
533 | 533 | pat = getstring(x, _("contains requires a pattern")) |
|
534 | 534 | |
|
535 | 535 | def matches(x): |
|
536 | 536 | if not matchmod.patkind(pat): |
|
537 | 537 | pats = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
538 | 538 | if pats in repo[x]: |
|
539 | 539 | return True |
|
540 | 540 | else: |
|
541 | 541 | c = repo[x] |
|
542 | 542 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) |
|
543 | 543 | for f in c.manifest(): |
|
544 | 544 | if m(f): |
|
545 | 545 | return True |
|
546 | 546 | return False |
|
547 | 547 | |
|
548 | 548 | return subset.filter(matches, condrepr=('<contains %r>', pat)) |
|
549 | 549 | |
|
550 | 550 | @predicate('converted([id])', safe=True) |
|
551 | 551 | def converted(repo, subset, x): |
|
552 | 552 | """Changesets converted from the given identifier in the old repository if |
|
553 | 553 | present, or all converted changesets if no identifier is specified. |
|
554 | 554 | """ |
|
555 | 555 | |
|
556 | 556 | # There is exactly no chance of resolving the revision, so do a simple |
|
557 | 557 | # string compare and hope for the best |
|
558 | 558 | |
|
559 | 559 | rev = None |
|
560 | 560 | # i18n: "converted" is a keyword |
|
561 | 561 | l = getargs(x, 0, 1, _('converted takes one or no arguments')) |
|
562 | 562 | if l: |
|
563 | 563 | # i18n: "converted" is a keyword |
|
564 | 564 | rev = getstring(l[0], _('converted requires a revision')) |
|
565 | 565 | |
|
566 | 566 | def _matchvalue(r): |
|
567 | 567 | source = repo[r].extra().get('convert_revision', None) |
|
568 | 568 | return source is not None and (rev is None or source.startswith(rev)) |
|
569 | 569 | |
|
570 | 570 | return subset.filter(lambda r: _matchvalue(r), |
|
571 | 571 | condrepr=('<converted %r>', rev)) |
|
572 | 572 | |
|
573 | 573 | @predicate('date(interval)', safe=True) |
|
574 | 574 | def date(repo, subset, x): |
|
575 | 575 | """Changesets within the interval, see :hg:`help dates`. |
|
576 | 576 | """ |
|
577 | 577 | # i18n: "date" is a keyword |
|
578 | 578 | ds = getstring(x, _("date requires a string")) |
|
579 | 579 | dm = util.matchdate(ds) |
|
580 | 580 | return subset.filter(lambda x: dm(repo[x].date()[0]), |
|
581 | 581 | condrepr=('<date %r>', ds)) |
|
582 | 582 | |
|
583 | 583 | @predicate('desc(string)', safe=True) |
|
584 | 584 | def desc(repo, subset, x): |
|
585 | 585 | """Search commit message for string. The match is case-insensitive. |
|
586 | 586 | |
|
587 | 587 | Pattern matching is supported for `string`. See |
|
588 | 588 | :hg:`help revisions.patterns`. |
|
589 | 589 | """ |
|
590 | 590 | # i18n: "desc" is a keyword |
|
591 | 591 | ds = getstring(x, _("desc requires a string")) |
|
592 | 592 | |
|
593 | 593 | kind, pattern, matcher = _substringmatcher(ds, casesensitive=False) |
|
594 | 594 | |
|
595 | 595 | return subset.filter(lambda r: matcher(repo[r].description()), |
|
596 | 596 | condrepr=('<desc %r>', ds)) |
|
597 | 597 | |
|
598 | 598 | def _descendants(repo, subset, x, followfirst=False, startdepth=None, |
|
599 | 599 | stopdepth=None): |
|
600 | 600 | roots = getset(repo, fullreposet(repo), x) |
|
601 | 601 | if not roots: |
|
602 | 602 | return baseset() |
|
603 | 603 | s = dagop.revdescendants(repo, roots, followfirst, startdepth, stopdepth) |
|
604 | 604 | return subset & s |
|
605 | 605 | |
|
606 | 606 | @predicate('descendants(set[, depth])', safe=True) |
|
607 | 607 | def descendants(repo, subset, x): |
|
608 | 608 | """Changesets which are descendants of changesets in set, including the |
|
609 | 609 | given changesets themselves. |
|
610 | 610 | |
|
611 | 611 | If depth is specified, the result only includes changesets up to |
|
612 | 612 | the specified generation. |
|
613 | 613 | """ |
|
614 | 614 | # startdepth is for internal use only until we can decide the UI |
|
615 | 615 | args = getargsdict(x, 'descendants', 'set depth startdepth') |
|
616 | 616 | if 'set' not in args: |
|
617 | 617 | # i18n: "descendants" is a keyword |
|
618 | 618 | raise error.ParseError(_('descendants takes at least 1 argument')) |
|
619 | 619 | startdepth = stopdepth = None |
|
620 | 620 | if 'startdepth' in args: |
|
621 | 621 | n = getinteger(args['startdepth'], |
|
622 | 622 | "descendants expects an integer startdepth") |
|
623 | 623 | if n < 0: |
|
624 | 624 | raise error.ParseError("negative startdepth") |
|
625 | 625 | startdepth = n |
|
626 | 626 | if 'depth' in args: |
|
627 | 627 | # i18n: "descendants" is a keyword |
|
628 | 628 | n = getinteger(args['depth'], _("descendants expects an integer depth")) |
|
629 | 629 | if n < 0: |
|
630 | 630 | raise error.ParseError(_("negative depth")) |
|
631 | 631 | stopdepth = n + 1 |
|
632 | 632 | return _descendants(repo, subset, args['set'], |
|
633 | 633 | startdepth=startdepth, stopdepth=stopdepth) |
|
634 | 634 | |
|
635 | 635 | @predicate('_firstdescendants', safe=True) |
|
636 | 636 | def _firstdescendants(repo, subset, x): |
|
637 | 637 | # ``_firstdescendants(set)`` |
|
638 | 638 | # Like ``descendants(set)`` but follows only the first parents. |
|
639 | 639 | return _descendants(repo, subset, x, followfirst=True) |
|
640 | 640 | |
|
641 | 641 | @predicate('destination([set])', safe=True) |
|
642 | 642 | def destination(repo, subset, x): |
|
643 | 643 | """Changesets that were created by a graft, transplant or rebase operation, |
|
644 | 644 | with the given revisions specified as the source. Omitting the optional set |
|
645 | 645 | is the same as passing all(). |
|
646 | 646 | """ |
|
647 | 647 | if x is not None: |
|
648 | 648 | sources = getset(repo, fullreposet(repo), x) |
|
649 | 649 | else: |
|
650 | 650 | sources = fullreposet(repo) |
|
651 | 651 | |
|
652 | 652 | dests = set() |
|
653 | 653 | |
|
654 | 654 | # subset contains all of the possible destinations that can be returned, so |
|
655 | 655 | # iterate over them and see if their source(s) were provided in the arg set. |
|
656 | 656 | # Even if the immediate src of r is not in the arg set, src's source (or |
|
657 | 657 | # further back) may be. Scanning back further than the immediate src allows |
|
658 | 658 | # transitive transplants and rebases to yield the same results as transitive |
|
659 | 659 | # grafts. |
|
660 | 660 | for r in subset: |
|
661 | 661 | src = _getrevsource(repo, r) |
|
662 | 662 | lineage = None |
|
663 | 663 | |
|
664 | 664 | while src is not None: |
|
665 | 665 | if lineage is None: |
|
666 | 666 | lineage = list() |
|
667 | 667 | |
|
668 | 668 | lineage.append(r) |
|
669 | 669 | |
|
670 | 670 | # The visited lineage is a match if the current source is in the arg |
|
671 | 671 | # set. Since every candidate dest is visited by way of iterating |
|
672 | 672 | # subset, any dests further back in the lineage will be tested by a |
|
673 | 673 | # different iteration over subset. Likewise, if the src was already |
|
674 | 674 | # selected, the current lineage can be selected without going back |
|
675 | 675 | # further. |
|
676 | 676 | if src in sources or src in dests: |
|
677 | 677 | dests.update(lineage) |
|
678 | 678 | break |
|
679 | 679 | |
|
680 | 680 | r = src |
|
681 | 681 | src = _getrevsource(repo, r) |
|
682 | 682 | |
|
683 | 683 | return subset.filter(dests.__contains__, |
|
684 | 684 | condrepr=lambda: '<destination %r>' % sorted(dests)) |
|
685 | 685 | |
|
686 | 686 | @predicate('divergent()', safe=True) |
|
687 | 687 | def divergent(repo, subset, x): |
|
688 | 688 | """ |
|
689 | 689 | Final successors of changesets with an alternative set of final successors. |
|
690 | 690 | """ |
|
691 | 691 | # i18n: "divergent" is a keyword |
|
692 | 692 | getargs(x, 0, 0, _("divergent takes no arguments")) |
|
693 | 693 | divergent = obsmod.getrevs(repo, 'divergent') |
|
694 | 694 | return subset & divergent |
|
695 | 695 | |
|
696 | 696 | @predicate('extinct()', safe=True) |
|
697 | 697 | def extinct(repo, subset, x): |
|
698 | 698 | """Obsolete changesets with obsolete descendants only. |
|
699 | 699 | """ |
|
700 | 700 | # i18n: "extinct" is a keyword |
|
701 | 701 | getargs(x, 0, 0, _("extinct takes no arguments")) |
|
702 | 702 | extincts = obsmod.getrevs(repo, 'extinct') |
|
703 | 703 | return subset & extincts |
|
704 | 704 | |
|
705 | 705 | @predicate('extra(label, [value])', safe=True) |
|
706 | 706 | def extra(repo, subset, x): |
|
707 | 707 | """Changesets with the given label in the extra metadata, with the given |
|
708 | 708 | optional value. |
|
709 | 709 | |
|
710 | 710 | Pattern matching is supported for `value`. See |
|
711 | 711 | :hg:`help revisions.patterns`. |
|
712 | 712 | """ |
|
713 | 713 | args = getargsdict(x, 'extra', 'label value') |
|
714 | 714 | if 'label' not in args: |
|
715 | 715 | # i18n: "extra" is a keyword |
|
716 | 716 | raise error.ParseError(_('extra takes at least 1 argument')) |
|
717 | 717 | # i18n: "extra" is a keyword |
|
718 | 718 | label = getstring(args['label'], _('first argument to extra must be ' |
|
719 | 719 | 'a string')) |
|
720 | 720 | value = None |
|
721 | 721 | |
|
722 | 722 | if 'value' in args: |
|
723 | 723 | # i18n: "extra" is a keyword |
|
724 | 724 | value = getstring(args['value'], _('second argument to extra must be ' |
|
725 | 725 | 'a string')) |
|
726 | 726 | kind, value, matcher = util.stringmatcher(value) |
|
727 | 727 | |
|
728 | 728 | def _matchvalue(r): |
|
729 | 729 | extra = repo[r].extra() |
|
730 | 730 | return label in extra and (value is None or matcher(extra[label])) |
|
731 | 731 | |
|
732 | 732 | return subset.filter(lambda r: _matchvalue(r), |
|
733 | 733 | condrepr=('<extra[%r] %r>', label, value)) |
|
734 | 734 | |
|
735 | 735 | @predicate('filelog(pattern)', safe=True) |
|
736 | 736 | def filelog(repo, subset, x): |
|
737 | 737 | """Changesets connected to the specified filelog. |
|
738 | 738 | |
|
739 | 739 | For performance reasons, visits only revisions mentioned in the file-level |
|
740 | 740 | filelog, rather than filtering through all changesets (much faster, but |
|
741 | 741 | doesn't include deletes or duplicate changes). For a slower, more accurate |
|
742 | 742 | result, use ``file()``. |
|
743 | 743 | |
|
744 | 744 | The pattern without explicit kind like ``glob:`` is expected to be |
|
745 | 745 | relative to the current directory and match against a file exactly |
|
746 | 746 | for efficiency. |
|
747 | 747 | |
|
748 | 748 | If some linkrev points to revisions filtered by the current repoview, we'll |
|
749 | 749 | work around it to return a non-filtered value. |
|
750 | 750 | """ |
|
751 | 751 | |
|
752 | 752 | # i18n: "filelog" is a keyword |
|
753 | 753 | pat = getstring(x, _("filelog requires a pattern")) |
|
754 | 754 | s = set() |
|
755 | 755 | cl = repo.changelog |
|
756 | 756 | |
|
757 | 757 | if not matchmod.patkind(pat): |
|
758 | 758 | f = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
759 | 759 | files = [f] |
|
760 | 760 | else: |
|
761 | 761 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[None]) |
|
762 | 762 | files = (f for f in repo[None] if m(f)) |
|
763 | 763 | |
|
764 | 764 | for f in files: |
|
765 | 765 | fl = repo.file(f) |
|
766 | 766 | known = {} |
|
767 | 767 | scanpos = 0 |
|
768 | 768 | for fr in list(fl): |
|
769 | 769 | fn = fl.node(fr) |
|
770 | 770 | if fn in known: |
|
771 | 771 | s.add(known[fn]) |
|
772 | 772 | continue |
|
773 | 773 | |
|
774 | 774 | lr = fl.linkrev(fr) |
|
775 | 775 | if lr in cl: |
|
776 | 776 | s.add(lr) |
|
777 | 777 | elif scanpos is not None: |
|
778 | 778 | # lowest matching changeset is filtered, scan further |
|
779 | 779 | # ahead in changelog |
|
780 | 780 | start = max(lr, scanpos) + 1 |
|
781 | 781 | scanpos = None |
|
782 | 782 | for r in cl.revs(start): |
|
783 | 783 | # minimize parsing of non-matching entries |
|
784 | 784 | if f in cl.revision(r) and f in cl.readfiles(r): |
|
785 | 785 | try: |
|
786 | 786 | # try to use manifest delta fastpath |
|
787 | 787 | n = repo[r].filenode(f) |
|
788 | 788 | if n not in known: |
|
789 | 789 | if n == fn: |
|
790 | 790 | s.add(r) |
|
791 | 791 | scanpos = r |
|
792 | 792 | break |
|
793 | 793 | else: |
|
794 | 794 | known[n] = r |
|
795 | 795 | except error.ManifestLookupError: |
|
796 | 796 | # deletion in changelog |
|
797 | 797 | continue |
|
798 | 798 | |
|
799 | 799 | return subset & s |
|
800 | 800 | |
|
801 | 801 | @predicate('first(set, [n])', safe=True, takeorder=True) |
|
802 | 802 | def first(repo, subset, x, order): |
|
803 | 803 | """An alias for limit(). |
|
804 | 804 | """ |
|
805 | 805 | return limit(repo, subset, x, order) |
|
806 | 806 | |
|
807 | 807 | def _follow(repo, subset, x, name, followfirst=False): |
|
808 | 808 | l = getargs(x, 0, 2, _("%s takes no arguments or a pattern " |
|
809 | 809 | "and an optional revset") % name) |
|
810 | 810 | c = repo['.'] |
|
811 | 811 | if l: |
|
812 | 812 | x = getstring(l[0], _("%s expected a pattern") % name) |
|
813 | 813 | rev = None |
|
814 | 814 | if len(l) >= 2: |
|
815 | 815 | revs = getset(repo, fullreposet(repo), l[1]) |
|
816 | 816 | if len(revs) != 1: |
|
817 | 817 | raise error.RepoLookupError( |
|
818 | 818 | _("%s expected one starting revision") % name) |
|
819 | 819 | rev = revs.last() |
|
820 | 820 | c = repo[rev] |
|
821 | 821 | matcher = matchmod.match(repo.root, repo.getcwd(), [x], |
|
822 | 822 | ctx=repo[rev], default='path') |
|
823 | 823 | |
|
824 | 824 | files = c.manifest().walk(matcher) |
|
825 | 825 | |
|
826 | 826 | s = set() |
|
827 | 827 | for fname in files: |
|
828 | 828 | fctx = c[fname] |
|
829 | 829 | s = s.union(set(c.rev() for c in fctx.ancestors(followfirst))) |
|
830 | 830 | # include the revision responsible for the most recent version |
|
831 | 831 | s.add(fctx.introrev()) |
|
832 | 832 | else: |
|
833 | 833 | s = dagop.revancestors(repo, baseset([c.rev()]), followfirst) |
|
834 | 834 | |
|
835 | 835 | return subset & s |
|
836 | 836 | |
|
837 | 837 | @predicate('follow([pattern[, startrev]])', safe=True) |
|
838 | 838 | def follow(repo, subset, x): |
|
839 | 839 | """ |
|
840 | 840 | An alias for ``::.`` (ancestors of the working directory's first parent). |
|
841 | 841 | If pattern is specified, the histories of files matching given |
|
842 | 842 | pattern in the revision given by startrev are followed, including copies. |
|
843 | 843 | """ |
|
844 | 844 | return _follow(repo, subset, x, 'follow') |
|
845 | 845 | |
|
846 | 846 | @predicate('_followfirst', safe=True) |
|
847 | 847 | def _followfirst(repo, subset, x): |
|
848 | 848 | # ``followfirst([pattern[, startrev]])`` |
|
849 | 849 | # Like ``follow([pattern[, startrev]])`` but follows only the first parent |
|
850 | 850 | # of every revisions or files revisions. |
|
851 | 851 | return _follow(repo, subset, x, '_followfirst', followfirst=True) |
|
852 | 852 | |
|
853 | 853 | @predicate('followlines(file, fromline:toline[, startrev=., descend=False])', |
|
854 | 854 | safe=True) |
|
855 | 855 | def followlines(repo, subset, x): |
|
856 | 856 | """Changesets modifying `file` in line range ('fromline', 'toline'). |
|
857 | 857 | |
|
858 | 858 | Line range corresponds to 'file' content at 'startrev' and should hence be |
|
859 | 859 | consistent with file size. If startrev is not specified, working directory's |
|
860 | 860 | parent is used. |
|
861 | 861 | |
|
862 | 862 | By default, ancestors of 'startrev' are returned. If 'descend' is True, |
|
863 | 863 | descendants of 'startrev' are returned though renames are (currently) not |
|
864 | 864 | followed in this direction. |
|
865 | 865 | """ |
|
866 | 866 | args = getargsdict(x, 'followlines', 'file *lines startrev descend') |
|
867 | 867 | if len(args['lines']) != 1: |
|
868 | 868 | raise error.ParseError(_("followlines requires a line range")) |
|
869 | 869 | |
|
870 | 870 | rev = '.' |
|
871 | 871 | if 'startrev' in args: |
|
872 | 872 | revs = getset(repo, fullreposet(repo), args['startrev']) |
|
873 | 873 | if len(revs) != 1: |
|
874 | 874 | raise error.ParseError( |
|
875 | 875 | # i18n: "followlines" is a keyword |
|
876 | 876 | _("followlines expects exactly one revision")) |
|
877 | 877 | rev = revs.last() |
|
878 | 878 | |
|
879 | 879 | pat = getstring(args['file'], _("followlines requires a pattern")) |
|
880 | 880 | if not matchmod.patkind(pat): |
|
881 | 881 | fname = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
|
882 | 882 | else: |
|
883 | 883 | m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev]) |
|
884 | 884 | files = [f for f in repo[rev] if m(f)] |
|
885 | 885 | if len(files) != 1: |
|
886 | 886 | # i18n: "followlines" is a keyword |
|
887 | 887 | raise error.ParseError(_("followlines expects exactly one file")) |
|
888 | 888 | fname = files[0] |
|
889 | 889 | |
|
890 | 890 | # i18n: "followlines" is a keyword |
|
891 | 891 | lr = getrange(args['lines'][0], _("followlines expects a line range")) |
|
892 | 892 | fromline, toline = [getinteger(a, _("line range bounds must be integers")) |
|
893 | 893 | for a in lr] |
|
894 | 894 | fromline, toline = util.processlinerange(fromline, toline) |
|
895 | 895 | |
|
896 | 896 | fctx = repo[rev].filectx(fname) |
|
897 | 897 | descend = False |
|
898 | 898 | if 'descend' in args: |
|
899 | 899 | descend = getboolean(args['descend'], |
|
900 | 900 | # i18n: "descend" is a keyword |
|
901 | 901 | _("descend argument must be a boolean")) |
|
902 | 902 | if descend: |
|
903 | 903 | rs = generatorset( |
|
904 | 904 | (c.rev() for c, _linerange |
|
905 | 905 | in dagop.blockdescendants(fctx, fromline, toline)), |
|
906 | 906 | iterasc=True) |
|
907 | 907 | else: |
|
908 | 908 | rs = generatorset( |
|
909 | 909 | (c.rev() for c, _linerange |
|
910 | 910 | in dagop.blockancestors(fctx, fromline, toline)), |
|
911 | 911 | iterasc=False) |
|
912 | 912 | return subset & rs |
|
913 | 913 | |
|
914 | 914 | @predicate('all()', safe=True) |
|
915 | 915 | def getall(repo, subset, x): |
|
916 | 916 | """All changesets, the same as ``0:tip``. |
|
917 | 917 | """ |
|
918 | 918 | # i18n: "all" is a keyword |
|
919 | 919 | getargs(x, 0, 0, _("all takes no arguments")) |
|
920 | 920 | return subset & spanset(repo) # drop "null" if any |
|
921 | 921 | |
|
922 | 922 | @predicate('grep(regex)') |
|
923 | 923 | def grep(repo, subset, x): |
|
924 | 924 | """Like ``keyword(string)`` but accepts a regex. Use ``grep(r'...')`` |
|
925 | 925 | to ensure special escape characters are handled correctly. Unlike |
|
926 | 926 | ``keyword(string)``, the match is case-sensitive. |
|
927 | 927 | """ |
|
928 | 928 | try: |
|
929 | 929 | # i18n: "grep" is a keyword |
|
930 | 930 | gr = re.compile(getstring(x, _("grep requires a string"))) |
|
931 | 931 | except re.error as e: |
|
932 | 932 | raise error.ParseError(_('invalid match pattern: %s') % e) |
|
933 | 933 | |
|
934 | 934 | def matches(x): |
|
935 | 935 | c = repo[x] |
|
936 | 936 | for e in c.files() + [c.user(), c.description()]: |
|
937 | 937 | if gr.search(e): |
|
938 | 938 | return True |
|
939 | 939 | return False |
|
940 | 940 | |
|
941 | 941 | return subset.filter(matches, condrepr=('<grep %r>', gr.pattern)) |
|
942 | 942 | |
|
943 | 943 | @predicate('_matchfiles', safe=True) |
|
944 | 944 | def _matchfiles(repo, subset, x): |
|
945 | 945 | # _matchfiles takes a revset list of prefixed arguments: |
|
946 | 946 | # |
|
947 | 947 | # [p:foo, i:bar, x:baz] |
|
948 | 948 | # |
|
949 | 949 | # builds a match object from them and filters subset. Allowed |
|
950 | 950 | # prefixes are 'p:' for regular patterns, 'i:' for include |
|
951 | 951 | # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
952 | 952 | # a revision identifier, or the empty string to reference the |
|
953 | 953 | # working directory, from which the match object is |
|
954 | 954 | # initialized. Use 'd:' to set the default matching mode, default |
|
955 | 955 | # to 'glob'. At most one 'r:' and 'd:' argument can be passed. |
|
956 | 956 | |
|
957 | 957 | l = getargs(x, 1, -1, "_matchfiles requires at least one argument") |
|
958 | 958 | pats, inc, exc = [], [], [] |
|
959 | 959 | rev, default = None, None |
|
960 | 960 | for arg in l: |
|
961 | 961 | s = getstring(arg, "_matchfiles requires string arguments") |
|
962 | 962 | prefix, value = s[:2], s[2:] |
|
963 | 963 | if prefix == 'p:': |
|
964 | 964 | pats.append(value) |
|
965 | 965 | elif prefix == 'i:': |
|
966 | 966 | inc.append(value) |
|
967 | 967 | elif prefix == 'x:': |
|
968 | 968 | exc.append(value) |
|
969 | 969 | elif prefix == 'r:': |
|
970 | 970 | if rev is not None: |
|
971 | 971 | raise error.ParseError('_matchfiles expected at most one ' |
|
972 | 972 | 'revision') |
|
973 | 973 | if value != '': # empty means working directory; leave rev as None |
|
974 | 974 | rev = value |
|
975 | 975 | elif prefix == 'd:': |
|
976 | 976 | if default is not None: |
|
977 | 977 | raise error.ParseError('_matchfiles expected at most one ' |
|
978 | 978 | 'default mode') |
|
979 | 979 | default = value |
|
980 | 980 | else: |
|
981 | 981 | raise error.ParseError('invalid _matchfiles prefix: %s' % prefix) |
|
982 | 982 | if not default: |
|
983 | 983 | default = 'glob' |
|
984 | 984 | |
|
985 | 985 | m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
|
986 | 986 | exclude=exc, ctx=repo[rev], default=default) |
|
987 | 987 | |
|
988 | 988 | # This directly read the changelog data as creating changectx for all |
|
989 | 989 | # revisions is quite expensive. |
|
990 | 990 | getfiles = repo.changelog.readfiles |
|
991 | 991 | wdirrev = node.wdirrev |
|
992 | 992 | def matches(x): |
|
993 | 993 | if x == wdirrev: |
|
994 | 994 | files = repo[x].files() |
|
995 | 995 | else: |
|
996 | 996 | files = getfiles(x) |
|
997 | 997 | for f in files: |
|
998 | 998 | if m(f): |
|
999 | 999 | return True |
|
1000 | 1000 | return False |
|
1001 | 1001 | |
|
1002 | 1002 | return subset.filter(matches, |
|
1003 | 1003 | condrepr=('<matchfiles patterns=%r, include=%r ' |
|
1004 | 1004 | 'exclude=%r, default=%r, rev=%r>', |
|
1005 | 1005 | pats, inc, exc, default, rev)) |
|
1006 | 1006 | |
|
1007 | 1007 | @predicate('file(pattern)', safe=True) |
|
1008 | 1008 | def hasfile(repo, subset, x): |
|
1009 | 1009 | """Changesets affecting files matched by pattern. |
|
1010 | 1010 | |
|
1011 | 1011 | For a faster but less accurate result, consider using ``filelog()`` |
|
1012 | 1012 | instead. |
|
1013 | 1013 | |
|
1014 | 1014 | This predicate uses ``glob:`` as the default kind of pattern. |
|
1015 | 1015 | """ |
|
1016 | 1016 | # i18n: "file" is a keyword |
|
1017 | 1017 | pat = getstring(x, _("file requires a pattern")) |
|
1018 | 1018 | return _matchfiles(repo, subset, ('string', 'p:' + pat)) |
|
1019 | 1019 | |
|
1020 | 1020 | @predicate('head()', safe=True) |
|
1021 | 1021 | def head(repo, subset, x): |
|
1022 | 1022 | """Changeset is a named branch head. |
|
1023 | 1023 | """ |
|
1024 | 1024 | # i18n: "head" is a keyword |
|
1025 | 1025 | getargs(x, 0, 0, _("head takes no arguments")) |
|
1026 | 1026 | hs = set() |
|
1027 | 1027 | cl = repo.changelog |
|
1028 | 1028 | for ls in repo.branchmap().itervalues(): |
|
1029 | 1029 | hs.update(cl.rev(h) for h in ls) |
|
1030 | 1030 | return subset & baseset(hs) |
|
1031 | 1031 | |
|
1032 | 1032 | @predicate('heads(set)', safe=True) |
|
1033 | 1033 | def heads(repo, subset, x): |
|
1034 | 1034 | """Members of set with no children in set. |
|
1035 | 1035 | """ |
|
1036 | 1036 | s = getset(repo, subset, x) |
|
1037 | 1037 | ps = parents(repo, subset, x) |
|
1038 | 1038 | return s - ps |
|
1039 | 1039 | |
|
1040 | 1040 | @predicate('hidden()', safe=True) |
|
1041 | 1041 | def hidden(repo, subset, x): |
|
1042 | 1042 | """Hidden changesets. |
|
1043 | 1043 | """ |
|
1044 | 1044 | # i18n: "hidden" is a keyword |
|
1045 | 1045 | getargs(x, 0, 0, _("hidden takes no arguments")) |
|
1046 | 1046 | hiddenrevs = repoview.filterrevs(repo, 'visible') |
|
1047 | 1047 | return subset & hiddenrevs |
|
1048 | 1048 | |
|
1049 | 1049 | @predicate('keyword(string)', safe=True) |
|
1050 | 1050 | def keyword(repo, subset, x): |
|
1051 | 1051 | """Search commit message, user name, and names of changed files for |
|
1052 | 1052 | string. The match is case-insensitive. |
|
1053 | 1053 | |
|
1054 | 1054 | For a regular expression or case sensitive search of these fields, use |
|
1055 | 1055 | ``grep(regex)``. |
|
1056 | 1056 | """ |
|
1057 | 1057 | # i18n: "keyword" is a keyword |
|
1058 | 1058 | kw = encoding.lower(getstring(x, _("keyword requires a string"))) |
|
1059 | 1059 | |
|
1060 | 1060 | def matches(r): |
|
1061 | 1061 | c = repo[r] |
|
1062 | 1062 | return any(kw in encoding.lower(t) |
|
1063 | 1063 | for t in c.files() + [c.user(), c.description()]) |
|
1064 | 1064 | |
|
1065 | 1065 | return subset.filter(matches, condrepr=('<keyword %r>', kw)) |
|
1066 | 1066 | |
|
1067 | 1067 | @predicate('limit(set[, n[, offset]])', safe=True, takeorder=True) |
|
1068 | 1068 | def limit(repo, subset, x, order): |
|
1069 | 1069 | """First n members of set, defaulting to 1, starting from offset. |
|
1070 | 1070 | """ |
|
1071 | 1071 | args = getargsdict(x, 'limit', 'set n offset') |
|
1072 | 1072 | if 'set' not in args: |
|
1073 | 1073 | # i18n: "limit" is a keyword |
|
1074 | 1074 | raise error.ParseError(_("limit requires one to three arguments")) |
|
1075 | 1075 | # i18n: "limit" is a keyword |
|
1076 | 1076 | lim = getinteger(args.get('n'), _("limit expects a number"), default=1) |
|
1077 | 1077 | if lim < 0: |
|
1078 | 1078 | raise error.ParseError(_("negative number to select")) |
|
1079 | 1079 | # i18n: "limit" is a keyword |
|
1080 | 1080 | ofs = getinteger(args.get('offset'), _("limit expects a number"), default=0) |
|
1081 | 1081 | if ofs < 0: |
|
1082 | 1082 | raise error.ParseError(_("negative offset")) |
|
1083 | 1083 | os = getset(repo, fullreposet(repo), args['set']) |
|
1084 | 1084 | ls = os.slice(ofs, ofs + lim) |
|
1085 | 1085 | if order == followorder and lim > 1: |
|
1086 | 1086 | return subset & ls |
|
1087 | 1087 | return ls & subset |
|
1088 | 1088 | |
|
1089 | 1089 | @predicate('last(set, [n])', safe=True, takeorder=True) |
|
1090 | 1090 | def last(repo, subset, x, order): |
|
1091 | 1091 | """Last n members of set, defaulting to 1. |
|
1092 | 1092 | """ |
|
1093 | 1093 | # i18n: "last" is a keyword |
|
1094 | 1094 | l = getargs(x, 1, 2, _("last requires one or two arguments")) |
|
1095 | 1095 | lim = 1 |
|
1096 | 1096 | if len(l) == 2: |
|
1097 | 1097 | # i18n: "last" is a keyword |
|
1098 | 1098 | lim = getinteger(l[1], _("last expects a number")) |
|
1099 | 1099 | if lim < 0: |
|
1100 | 1100 | raise error.ParseError(_("negative number to select")) |
|
1101 | 1101 | os = getset(repo, fullreposet(repo), l[0]) |
|
1102 | 1102 | os.reverse() |
|
1103 | 1103 | ls = os.slice(0, lim) |
|
1104 | 1104 | if order == followorder and lim > 1: |
|
1105 | 1105 | return subset & ls |
|
1106 | 1106 | ls.reverse() |
|
1107 | 1107 | return ls & subset |
|
1108 | 1108 | |
|
1109 | 1109 | @predicate('max(set)', safe=True) |
|
1110 | 1110 | def maxrev(repo, subset, x): |
|
1111 | 1111 | """Changeset with highest revision number in set. |
|
1112 | 1112 | """ |
|
1113 | 1113 | os = getset(repo, fullreposet(repo), x) |
|
1114 | 1114 | try: |
|
1115 | 1115 | m = os.max() |
|
1116 | 1116 | if m in subset: |
|
1117 | 1117 | return baseset([m], datarepr=('<max %r, %r>', subset, os)) |
|
1118 | 1118 | except ValueError: |
|
1119 | 1119 | # os.max() throws a ValueError when the collection is empty. |
|
1120 | 1120 | # Same as python's max(). |
|
1121 | 1121 | pass |
|
1122 | 1122 | return baseset(datarepr=('<max %r, %r>', subset, os)) |
|
1123 | 1123 | |
|
1124 | 1124 | @predicate('merge()', safe=True) |
|
1125 | 1125 | def merge(repo, subset, x): |
|
1126 | 1126 | """Changeset is a merge changeset. |
|
1127 | 1127 | """ |
|
1128 | 1128 | # i18n: "merge" is a keyword |
|
1129 | 1129 | getargs(x, 0, 0, _("merge takes no arguments")) |
|
1130 | 1130 | cl = repo.changelog |
|
1131 | 1131 | return subset.filter(lambda r: cl.parentrevs(r)[1] != -1, |
|
1132 | 1132 | condrepr='<merge>') |
|
1133 | 1133 | |
|
1134 | 1134 | @predicate('branchpoint()', safe=True) |
|
1135 | 1135 | def branchpoint(repo, subset, x): |
|
1136 | 1136 | """Changesets with more than one child. |
|
1137 | 1137 | """ |
|
1138 | 1138 | # i18n: "branchpoint" is a keyword |
|
1139 | 1139 | getargs(x, 0, 0, _("branchpoint takes no arguments")) |
|
1140 | 1140 | cl = repo.changelog |
|
1141 | 1141 | if not subset: |
|
1142 | 1142 | return baseset() |
|
1143 | 1143 | # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset |
|
1144 | 1144 | # (and if it is not, it should.) |
|
1145 | 1145 | baserev = min(subset) |
|
1146 | 1146 | parentscount = [0]*(len(repo) - baserev) |
|
1147 | 1147 | for r in cl.revs(start=baserev + 1): |
|
1148 | 1148 | for p in cl.parentrevs(r): |
|
1149 | 1149 | if p >= baserev: |
|
1150 | 1150 | parentscount[p - baserev] += 1 |
|
1151 | 1151 | return subset.filter(lambda r: parentscount[r - baserev] > 1, |
|
1152 | 1152 | condrepr='<branchpoint>') |
|
1153 | 1153 | |
|
1154 | 1154 | @predicate('min(set)', safe=True) |
|
1155 | 1155 | def minrev(repo, subset, x): |
|
1156 | 1156 | """Changeset with lowest revision number in set. |
|
1157 | 1157 | """ |
|
1158 | 1158 | os = getset(repo, fullreposet(repo), x) |
|
1159 | 1159 | try: |
|
1160 | 1160 | m = os.min() |
|
1161 | 1161 | if m in subset: |
|
1162 | 1162 | return baseset([m], datarepr=('<min %r, %r>', subset, os)) |
|
1163 | 1163 | except ValueError: |
|
1164 | 1164 | # os.min() throws a ValueError when the collection is empty. |
|
1165 | 1165 | # Same as python's min(). |
|
1166 | 1166 | pass |
|
1167 | 1167 | return baseset(datarepr=('<min %r, %r>', subset, os)) |
|
1168 | 1168 | |
|
1169 | 1169 | @predicate('modifies(pattern)', safe=True) |
|
1170 | 1170 | def modifies(repo, subset, x): |
|
1171 | 1171 | """Changesets modifying files matched by pattern. |
|
1172 | 1172 | |
|
1173 | 1173 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1174 | 1174 | relative to the current directory and match against a file or a |
|
1175 | 1175 | directory. |
|
1176 | 1176 | """ |
|
1177 | 1177 | # i18n: "modifies" is a keyword |
|
1178 | 1178 | pat = getstring(x, _("modifies requires a pattern")) |
|
1179 | 1179 | return checkstatus(repo, subset, pat, 0) |
|
1180 | 1180 | |
|
1181 | 1181 | @predicate('named(namespace)') |
|
1182 | 1182 | def named(repo, subset, x): |
|
1183 | 1183 | """The changesets in a given namespace. |
|
1184 | 1184 | |
|
1185 | 1185 | Pattern matching is supported for `namespace`. See |
|
1186 | 1186 | :hg:`help revisions.patterns`. |
|
1187 | 1187 | """ |
|
1188 | 1188 | # i18n: "named" is a keyword |
|
1189 | 1189 | args = getargs(x, 1, 1, _('named requires a namespace argument')) |
|
1190 | 1190 | |
|
1191 | 1191 | ns = getstring(args[0], |
|
1192 | 1192 | # i18n: "named" is a keyword |
|
1193 | 1193 | _('the argument to named must be a string')) |
|
1194 | 1194 | kind, pattern, matcher = util.stringmatcher(ns) |
|
1195 | 1195 | namespaces = set() |
|
1196 | 1196 | if kind == 'literal': |
|
1197 | 1197 | if pattern not in repo.names: |
|
1198 | 1198 | raise error.RepoLookupError(_("namespace '%s' does not exist") |
|
1199 | 1199 | % ns) |
|
1200 | 1200 | namespaces.add(repo.names[pattern]) |
|
1201 | 1201 | else: |
|
1202 | 1202 | for name, ns in repo.names.iteritems(): |
|
1203 | 1203 | if matcher(name): |
|
1204 | 1204 | namespaces.add(ns) |
|
1205 | 1205 | if not namespaces: |
|
1206 | 1206 | raise error.RepoLookupError(_("no namespace exists" |
|
1207 | 1207 | " that match '%s'") % pattern) |
|
1208 | 1208 | |
|
1209 | 1209 | names = set() |
|
1210 | 1210 | for ns in namespaces: |
|
1211 | 1211 | for name in ns.listnames(repo): |
|
1212 | 1212 | if name not in ns.deprecated: |
|
1213 | 1213 | names.update(repo[n].rev() for n in ns.nodes(repo, name)) |
|
1214 | 1214 | |
|
1215 | 1215 | names -= {node.nullrev} |
|
1216 | 1216 | return subset & names |
|
1217 | 1217 | |
|
1218 | 1218 | @predicate('id(string)', safe=True) |
|
1219 | 1219 | def node_(repo, subset, x): |
|
1220 | 1220 | """Revision non-ambiguously specified by the given hex string prefix. |
|
1221 | 1221 | """ |
|
1222 | 1222 | # i18n: "id" is a keyword |
|
1223 | 1223 | l = getargs(x, 1, 1, _("id requires one argument")) |
|
1224 | 1224 | # i18n: "id" is a keyword |
|
1225 | 1225 | n = getstring(l[0], _("id requires a string")) |
|
1226 | 1226 | if len(n) == 40: |
|
1227 | 1227 | try: |
|
1228 | 1228 | rn = repo.changelog.rev(node.bin(n)) |
|
1229 | 1229 | except error.WdirUnsupported: |
|
1230 | 1230 | rn = node.wdirrev |
|
1231 | 1231 | except (LookupError, TypeError): |
|
1232 | 1232 | rn = None |
|
1233 | 1233 | else: |
|
1234 | 1234 | rn = None |
|
1235 | 1235 | try: |
|
1236 | 1236 | pm = repo.changelog._partialmatch(n) |
|
1237 | 1237 | if pm is not None: |
|
1238 | 1238 | rn = repo.changelog.rev(pm) |
|
1239 | 1239 | except error.WdirUnsupported: |
|
1240 | 1240 | rn = node.wdirrev |
|
1241 | 1241 | |
|
1242 | 1242 | if rn is None: |
|
1243 | 1243 | return baseset() |
|
1244 | 1244 | result = baseset([rn]) |
|
1245 | 1245 | return result & subset |
|
1246 | 1246 | |
|
1247 | 1247 | @predicate('obsolete()', safe=True) |
|
1248 | 1248 | def obsolete(repo, subset, x): |
|
1249 | 1249 | """Mutable changeset with a newer version.""" |
|
1250 | 1250 | # i18n: "obsolete" is a keyword |
|
1251 | 1251 | getargs(x, 0, 0, _("obsolete takes no arguments")) |
|
1252 | 1252 | obsoletes = obsmod.getrevs(repo, 'obsolete') |
|
1253 | 1253 | return subset & obsoletes |
|
1254 | 1254 | |
|
1255 | 1255 | @predicate('only(set, [set])', safe=True) |
|
1256 | 1256 | def only(repo, subset, x): |
|
1257 | 1257 | """Changesets that are ancestors of the first set that are not ancestors |
|
1258 | 1258 | of any other head in the repo. If a second set is specified, the result |
|
1259 | 1259 | is ancestors of the first set that are not ancestors of the second set |
|
1260 | 1260 | (i.e. ::<set1> - ::<set2>). |
|
1261 | 1261 | """ |
|
1262 | 1262 | cl = repo.changelog |
|
1263 | 1263 | # i18n: "only" is a keyword |
|
1264 | 1264 | args = getargs(x, 1, 2, _('only takes one or two arguments')) |
|
1265 | 1265 | include = getset(repo, fullreposet(repo), args[0]) |
|
1266 | 1266 | if len(args) == 1: |
|
1267 | 1267 | if not include: |
|
1268 | 1268 | return baseset() |
|
1269 | 1269 | |
|
1270 | 1270 | descendants = set(dagop.revdescendants(repo, include, False)) |
|
1271 | 1271 | exclude = [rev for rev in cl.headrevs() |
|
1272 | 1272 | if not rev in descendants and not rev in include] |
|
1273 | 1273 | else: |
|
1274 | 1274 | exclude = getset(repo, fullreposet(repo), args[1]) |
|
1275 | 1275 | |
|
1276 | 1276 | results = set(cl.findmissingrevs(common=exclude, heads=include)) |
|
1277 | 1277 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1278 | 1278 | # some optimizations from the fact this is a baseset. |
|
1279 | 1279 | return subset & results |
|
1280 | 1280 | |
|
1281 | 1281 | @predicate('origin([set])', safe=True) |
|
1282 | 1282 | def origin(repo, subset, x): |
|
1283 | 1283 | """ |
|
1284 | 1284 | Changesets that were specified as a source for the grafts, transplants or |
|
1285 | 1285 | rebases that created the given revisions. Omitting the optional set is the |
|
1286 | 1286 | same as passing all(). If a changeset created by these operations is itself |
|
1287 | 1287 | specified as a source for one of these operations, only the source changeset |
|
1288 | 1288 | for the first operation is selected. |
|
1289 | 1289 | """ |
|
1290 | 1290 | if x is not None: |
|
1291 | 1291 | dests = getset(repo, fullreposet(repo), x) |
|
1292 | 1292 | else: |
|
1293 | 1293 | dests = fullreposet(repo) |
|
1294 | 1294 | |
|
1295 | 1295 | def _firstsrc(rev): |
|
1296 | 1296 | src = _getrevsource(repo, rev) |
|
1297 | 1297 | if src is None: |
|
1298 | 1298 | return None |
|
1299 | 1299 | |
|
1300 | 1300 | while True: |
|
1301 | 1301 | prev = _getrevsource(repo, src) |
|
1302 | 1302 | |
|
1303 | 1303 | if prev is None: |
|
1304 | 1304 | return src |
|
1305 | 1305 | src = prev |
|
1306 | 1306 | |
|
1307 | 1307 | o = {_firstsrc(r) for r in dests} |
|
1308 | 1308 | o -= {None} |
|
1309 | 1309 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1310 | 1310 | # some optimizations from the fact this is a baseset. |
|
1311 | 1311 | return subset & o |
|
1312 | 1312 | |
|
1313 | 1313 | @predicate('outgoing([path])', safe=False) |
|
1314 | 1314 | def outgoing(repo, subset, x): |
|
1315 | 1315 | """Changesets not found in the specified destination repository, or the |
|
1316 | 1316 | default push location. |
|
1317 | 1317 | """ |
|
1318 | 1318 | # Avoid cycles. |
|
1319 | 1319 | from . import ( |
|
1320 | 1320 | discovery, |
|
1321 | 1321 | hg, |
|
1322 | 1322 | ) |
|
1323 | 1323 | # i18n: "outgoing" is a keyword |
|
1324 | 1324 | l = getargs(x, 0, 1, _("outgoing takes one or no arguments")) |
|
1325 | 1325 | # i18n: "outgoing" is a keyword |
|
1326 | 1326 | dest = l and getstring(l[0], _("outgoing requires a repository path")) or '' |
|
1327 | 1327 | dest = repo.ui.expandpath(dest or 'default-push', dest or 'default') |
|
1328 | 1328 | dest, branches = hg.parseurl(dest) |
|
1329 | 1329 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1330 | 1330 | if revs: |
|
1331 | 1331 | revs = [repo.lookup(rev) for rev in revs] |
|
1332 | 1332 | other = hg.peer(repo, {}, dest) |
|
1333 | 1333 | repo.ui.pushbuffer() |
|
1334 | 1334 | outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs) |
|
1335 | 1335 | repo.ui.popbuffer() |
|
1336 | 1336 | cl = repo.changelog |
|
1337 | 1337 | o = {cl.rev(r) for r in outgoing.missing} |
|
1338 | 1338 | return subset & o |
|
1339 | 1339 | |
|
1340 | 1340 | @predicate('p1([set])', safe=True) |
|
1341 | 1341 | def p1(repo, subset, x): |
|
1342 | 1342 | """First parent of changesets in set, or the working directory. |
|
1343 | 1343 | """ |
|
1344 | 1344 | if x is None: |
|
1345 | 1345 | p = repo[x].p1().rev() |
|
1346 | 1346 | if p >= 0: |
|
1347 | 1347 | return subset & baseset([p]) |
|
1348 | 1348 | return baseset() |
|
1349 | 1349 | |
|
1350 | 1350 | ps = set() |
|
1351 | 1351 | cl = repo.changelog |
|
1352 | 1352 | for r in getset(repo, fullreposet(repo), x): |
|
1353 | 1353 | try: |
|
1354 | 1354 | ps.add(cl.parentrevs(r)[0]) |
|
1355 | 1355 | except error.WdirUnsupported: |
|
1356 | 1356 | ps.add(repo[r].parents()[0].rev()) |
|
1357 | 1357 | ps -= {node.nullrev} |
|
1358 | 1358 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1359 | 1359 | # some optimizations from the fact this is a baseset. |
|
1360 | 1360 | return subset & ps |
|
1361 | 1361 | |
|
1362 | 1362 | @predicate('p2([set])', safe=True) |
|
1363 | 1363 | def p2(repo, subset, x): |
|
1364 | 1364 | """Second parent of changesets in set, or the working directory. |
|
1365 | 1365 | """ |
|
1366 | 1366 | if x is None: |
|
1367 | 1367 | ps = repo[x].parents() |
|
1368 | 1368 | try: |
|
1369 | 1369 | p = ps[1].rev() |
|
1370 | 1370 | if p >= 0: |
|
1371 | 1371 | return subset & baseset([p]) |
|
1372 | 1372 | return baseset() |
|
1373 | 1373 | except IndexError: |
|
1374 | 1374 | return baseset() |
|
1375 | 1375 | |
|
1376 | 1376 | ps = set() |
|
1377 | 1377 | cl = repo.changelog |
|
1378 | 1378 | for r in getset(repo, fullreposet(repo), x): |
|
1379 | 1379 | try: |
|
1380 | 1380 | ps.add(cl.parentrevs(r)[1]) |
|
1381 | 1381 | except error.WdirUnsupported: |
|
1382 | 1382 | parents = repo[r].parents() |
|
1383 | 1383 | if len(parents) == 2: |
|
1384 | 1384 | ps.add(parents[1]) |
|
1385 | 1385 | ps -= {node.nullrev} |
|
1386 | 1386 | # XXX we should turn this into a baseset instead of a set, smartset may do |
|
1387 | 1387 | # some optimizations from the fact this is a baseset. |
|
1388 | 1388 | return subset & ps |
|
1389 | 1389 | |
|
1390 | 1390 | def parentpost(repo, subset, x, order): |
|
1391 | 1391 | return p1(repo, subset, x) |
|
1392 | 1392 | |
|
1393 | 1393 | @predicate('parents([set])', safe=True) |
|
1394 | 1394 | def parents(repo, subset, x): |
|
1395 | 1395 | """ |
|
1396 | 1396 | The set of all parents for all changesets in set, or the working directory. |
|
1397 | 1397 | """ |
|
1398 | 1398 | if x is None: |
|
1399 | 1399 | ps = set(p.rev() for p in repo[x].parents()) |
|
1400 | 1400 | else: |
|
1401 | 1401 | ps = set() |
|
1402 | 1402 | cl = repo.changelog |
|
1403 | 1403 | up = ps.update |
|
1404 | 1404 | parentrevs = cl.parentrevs |
|
1405 | 1405 | for r in getset(repo, fullreposet(repo), x): |
|
1406 | 1406 | try: |
|
1407 | 1407 | up(parentrevs(r)) |
|
1408 | 1408 | except error.WdirUnsupported: |
|
1409 | 1409 | up(p.rev() for p in repo[r].parents()) |
|
1410 | 1410 | ps -= {node.nullrev} |
|
1411 | 1411 | return subset & ps |
|
1412 | 1412 | |
|
1413 | 1413 | def _phase(repo, subset, *targets): |
|
1414 | 1414 | """helper to select all rev in <targets> phases""" |
|
1415 | 1415 | s = repo._phasecache.getrevset(repo, targets) |
|
1416 | 1416 | return subset & s |
|
1417 | 1417 | |
|
1418 | 1418 | @predicate('draft()', safe=True) |
|
1419 | 1419 | def draft(repo, subset, x): |
|
1420 | 1420 | """Changeset in draft phase.""" |
|
1421 | 1421 | # i18n: "draft" is a keyword |
|
1422 | 1422 | getargs(x, 0, 0, _("draft takes no arguments")) |
|
1423 | 1423 | target = phases.draft |
|
1424 | 1424 | return _phase(repo, subset, target) |
|
1425 | 1425 | |
|
1426 | 1426 | @predicate('secret()', safe=True) |
|
1427 | 1427 | def secret(repo, subset, x): |
|
1428 | 1428 | """Changeset in secret phase.""" |
|
1429 | 1429 | # i18n: "secret" is a keyword |
|
1430 | 1430 | getargs(x, 0, 0, _("secret takes no arguments")) |
|
1431 | 1431 | target = phases.secret |
|
1432 | 1432 | return _phase(repo, subset, target) |
|
1433 | 1433 | |
|
1434 | 1434 | def parentspec(repo, subset, x, n, order): |
|
1435 | 1435 | """``set^0`` |
|
1436 | 1436 | The set. |
|
1437 | 1437 | ``set^1`` (or ``set^``), ``set^2`` |
|
1438 | 1438 | First or second parent, respectively, of all changesets in set. |
|
1439 | 1439 | """ |
|
1440 | 1440 | try: |
|
1441 | 1441 | n = int(n[1]) |
|
1442 | 1442 | if n not in (0, 1, 2): |
|
1443 | 1443 | raise ValueError |
|
1444 | 1444 | except (TypeError, ValueError): |
|
1445 | 1445 | raise error.ParseError(_("^ expects a number 0, 1, or 2")) |
|
1446 | 1446 | ps = set() |
|
1447 | 1447 | cl = repo.changelog |
|
1448 | 1448 | for r in getset(repo, fullreposet(repo), x): |
|
1449 | 1449 | if n == 0: |
|
1450 | 1450 | ps.add(r) |
|
1451 | 1451 | elif n == 1: |
|
1452 | 1452 | try: |
|
1453 | 1453 | ps.add(cl.parentrevs(r)[0]) |
|
1454 | 1454 | except error.WdirUnsupported: |
|
1455 | 1455 | ps.add(repo[r].parents()[0].rev()) |
|
1456 | 1456 | else: |
|
1457 | 1457 | try: |
|
1458 | 1458 | parents = cl.parentrevs(r) |
|
1459 | 1459 | if parents[1] != node.nullrev: |
|
1460 | 1460 | ps.add(parents[1]) |
|
1461 | 1461 | except error.WdirUnsupported: |
|
1462 | 1462 | parents = repo[r].parents() |
|
1463 | 1463 | if len(parents) == 2: |
|
1464 | 1464 | ps.add(parents[1].rev()) |
|
1465 | 1465 | return subset & ps |
|
1466 | 1466 | |
|
1467 | 1467 | @predicate('present(set)', safe=True) |
|
1468 | 1468 | def present(repo, subset, x): |
|
1469 | 1469 | """An empty set, if any revision in set isn't found; otherwise, |
|
1470 | 1470 | all revisions in set. |
|
1471 | 1471 | |
|
1472 | 1472 | If any of specified revisions is not present in the local repository, |
|
1473 | 1473 | the query is normally aborted. But this predicate allows the query |
|
1474 | 1474 | to continue even in such cases. |
|
1475 | 1475 | """ |
|
1476 | 1476 | try: |
|
1477 | 1477 | return getset(repo, subset, x) |
|
1478 | 1478 | except error.RepoLookupError: |
|
1479 | 1479 | return baseset() |
|
1480 | 1480 | |
|
1481 | 1481 | # for internal use |
|
1482 | 1482 | @predicate('_notpublic', safe=True) |
|
1483 | 1483 | def _notpublic(repo, subset, x): |
|
1484 | 1484 | getargs(x, 0, 0, "_notpublic takes no arguments") |
|
1485 | 1485 | return _phase(repo, subset, phases.draft, phases.secret) |
|
1486 | 1486 | |
|
1487 | 1487 | @predicate('public()', safe=True) |
|
1488 | 1488 | def public(repo, subset, x): |
|
1489 | 1489 | """Changeset in public phase.""" |
|
1490 | 1490 | # i18n: "public" is a keyword |
|
1491 | 1491 | getargs(x, 0, 0, _("public takes no arguments")) |
|
1492 | 1492 | phase = repo._phasecache.phase |
|
1493 | 1493 | target = phases.public |
|
1494 | 1494 | condition = lambda r: phase(repo, r) == target |
|
1495 | 1495 | return subset.filter(condition, condrepr=('<phase %r>', target), |
|
1496 | 1496 | cache=False) |
|
1497 | 1497 | |
|
1498 | 1498 | @predicate('remote([id [,path]])', safe=False) |
|
1499 | 1499 | def remote(repo, subset, x): |
|
1500 | 1500 | """Local revision that corresponds to the given identifier in a |
|
1501 | 1501 | remote repository, if present. Here, the '.' identifier is a |
|
1502 | 1502 | synonym for the current local branch. |
|
1503 | 1503 | """ |
|
1504 | 1504 | |
|
1505 | 1505 | from . import hg # avoid start-up nasties |
|
1506 | 1506 | # i18n: "remote" is a keyword |
|
1507 | 1507 | l = getargs(x, 0, 2, _("remote takes zero, one, or two arguments")) |
|
1508 | 1508 | |
|
1509 | 1509 | q = '.' |
|
1510 | 1510 | if len(l) > 0: |
|
1511 | 1511 | # i18n: "remote" is a keyword |
|
1512 | 1512 | q = getstring(l[0], _("remote requires a string id")) |
|
1513 | 1513 | if q == '.': |
|
1514 | 1514 | q = repo['.'].branch() |
|
1515 | 1515 | |
|
1516 | 1516 | dest = '' |
|
1517 | 1517 | if len(l) > 1: |
|
1518 | 1518 | # i18n: "remote" is a keyword |
|
1519 | 1519 | dest = getstring(l[1], _("remote requires a repository path")) |
|
1520 | 1520 | dest = repo.ui.expandpath(dest or 'default') |
|
1521 | 1521 | dest, branches = hg.parseurl(dest) |
|
1522 | 1522 | revs, checkout = hg.addbranchrevs(repo, repo, branches, []) |
|
1523 | 1523 | if revs: |
|
1524 | 1524 | revs = [repo.lookup(rev) for rev in revs] |
|
1525 | 1525 | other = hg.peer(repo, {}, dest) |
|
1526 | 1526 | n = other.lookup(q) |
|
1527 | 1527 | if n in repo: |
|
1528 | 1528 | r = repo[n].rev() |
|
1529 | 1529 | if r in subset: |
|
1530 | 1530 | return baseset([r]) |
|
1531 | 1531 | return baseset() |
|
1532 | 1532 | |
|
1533 | 1533 | @predicate('removes(pattern)', safe=True) |
|
1534 | 1534 | def removes(repo, subset, x): |
|
1535 | 1535 | """Changesets which remove files matching pattern. |
|
1536 | 1536 | |
|
1537 | 1537 | The pattern without explicit kind like ``glob:`` is expected to be |
|
1538 | 1538 | relative to the current directory and match against a file or a |
|
1539 | 1539 | directory. |
|
1540 | 1540 | """ |
|
1541 | 1541 | # i18n: "removes" is a keyword |
|
1542 | 1542 | pat = getstring(x, _("removes requires a pattern")) |
|
1543 | 1543 | return checkstatus(repo, subset, pat, 2) |
|
1544 | 1544 | |
|
1545 | 1545 | @predicate('rev(number)', safe=True) |
|
1546 | 1546 | def rev(repo, subset, x): |
|
1547 | 1547 | """Revision with the given numeric identifier. |
|
1548 | 1548 | """ |
|
1549 | 1549 | # i18n: "rev" is a keyword |
|
1550 | 1550 | l = getargs(x, 1, 1, _("rev requires one argument")) |
|
1551 | 1551 | try: |
|
1552 | 1552 | # i18n: "rev" is a keyword |
|
1553 | 1553 | l = int(getstring(l[0], _("rev requires a number"))) |
|
1554 | 1554 | except (TypeError, ValueError): |
|
1555 | 1555 | # i18n: "rev" is a keyword |
|
1556 | 1556 | raise error.ParseError(_("rev expects a number")) |
|
1557 | 1557 | if l not in repo.changelog and l not in (node.nullrev, node.wdirrev): |
|
1558 | 1558 | return baseset() |
|
1559 | 1559 | return subset & baseset([l]) |
|
1560 | 1560 | |
|
1561 | 1561 | @predicate('matching(revision [, field])', safe=True) |
|
1562 | 1562 | def matching(repo, subset, x): |
|
1563 | 1563 | """Changesets in which a given set of fields match the set of fields in the |
|
1564 | 1564 | selected revision or set. |
|
1565 | 1565 | |
|
1566 | 1566 | To match more than one field pass the list of fields to match separated |
|
1567 | 1567 | by spaces (e.g. ``author description``). |
|
1568 | 1568 | |
|
1569 | 1569 | Valid fields are most regular revision fields and some special fields. |
|
1570 | 1570 | |
|
1571 | 1571 | Regular revision fields are ``description``, ``author``, ``branch``, |
|
1572 | 1572 | ``date``, ``files``, ``phase``, ``parents``, ``substate``, ``user`` |
|
1573 | 1573 | and ``diff``. |
|
1574 | 1574 | Note that ``author`` and ``user`` are synonyms. ``diff`` refers to the |
|
1575 | 1575 | contents of the revision. Two revisions matching their ``diff`` will |
|
1576 | 1576 | also match their ``files``. |
|
1577 | 1577 | |
|
1578 | 1578 | Special fields are ``summary`` and ``metadata``: |
|
1579 | 1579 | ``summary`` matches the first line of the description. |
|
1580 | 1580 | ``metadata`` is equivalent to matching ``description user date`` |
|
1581 | 1581 | (i.e. it matches the main metadata fields). |
|
1582 | 1582 | |
|
1583 | 1583 | ``metadata`` is the default field which is used when no fields are |
|
1584 | 1584 | specified. You can match more than one field at a time. |
|
1585 | 1585 | """ |
|
1586 | 1586 | # i18n: "matching" is a keyword |
|
1587 | 1587 | l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments")) |
|
1588 | 1588 | |
|
1589 | 1589 | revs = getset(repo, fullreposet(repo), l[0]) |
|
1590 | 1590 | |
|
1591 | 1591 | fieldlist = ['metadata'] |
|
1592 | 1592 | if len(l) > 1: |
|
1593 | 1593 | fieldlist = getstring(l[1], |
|
1594 | 1594 | # i18n: "matching" is a keyword |
|
1595 | 1595 | _("matching requires a string " |
|
1596 | 1596 | "as its second argument")).split() |
|
1597 | 1597 | |
|
1598 | 1598 | # Make sure that there are no repeated fields, |
|
1599 | 1599 | # expand the 'special' 'metadata' field type |
|
1600 | 1600 | # and check the 'files' whenever we check the 'diff' |
|
1601 | 1601 | fields = [] |
|
1602 | 1602 | for field in fieldlist: |
|
1603 | 1603 | if field == 'metadata': |
|
1604 | 1604 | fields += ['user', 'description', 'date'] |
|
1605 | 1605 | elif field == 'diff': |
|
1606 | 1606 | # a revision matching the diff must also match the files |
|
1607 | 1607 | # since matching the diff is very costly, make sure to |
|
1608 | 1608 | # also match the files first |
|
1609 | 1609 | fields += ['files', 'diff'] |
|
1610 | 1610 | else: |
|
1611 | 1611 | if field == 'author': |
|
1612 | 1612 | field = 'user' |
|
1613 | 1613 | fields.append(field) |
|
1614 | 1614 | fields = set(fields) |
|
1615 | 1615 | if 'summary' in fields and 'description' in fields: |
|
1616 | 1616 | # If a revision matches its description it also matches its summary |
|
1617 | 1617 | fields.discard('summary') |
|
1618 | 1618 | |
|
1619 | 1619 | # We may want to match more than one field |
|
1620 | 1620 | # Not all fields take the same amount of time to be matched |
|
1621 | 1621 | # Sort the selected fields in order of increasing matching cost |
|
1622 | 1622 | fieldorder = ['phase', 'parents', 'user', 'date', 'branch', 'summary', |
|
1623 | 1623 | 'files', 'description', 'substate', 'diff'] |
|
1624 | 1624 | def fieldkeyfunc(f): |
|
1625 | 1625 | try: |
|
1626 | 1626 | return fieldorder.index(f) |
|
1627 | 1627 | except ValueError: |
|
1628 | 1628 | # assume an unknown field is very costly |
|
1629 | 1629 | return len(fieldorder) |
|
1630 | 1630 | fields = list(fields) |
|
1631 | 1631 | fields.sort(key=fieldkeyfunc) |
|
1632 | 1632 | |
|
1633 | 1633 | # Each field will be matched with its own "getfield" function |
|
1634 | 1634 | # which will be added to the getfieldfuncs array of functions |
|
1635 | 1635 | getfieldfuncs = [] |
|
1636 | 1636 | _funcs = { |
|
1637 | 1637 | 'user': lambda r: repo[r].user(), |
|
1638 | 1638 | 'branch': lambda r: repo[r].branch(), |
|
1639 | 1639 | 'date': lambda r: repo[r].date(), |
|
1640 | 1640 | 'description': lambda r: repo[r].description(), |
|
1641 | 1641 | 'files': lambda r: repo[r].files(), |
|
1642 | 1642 | 'parents': lambda r: repo[r].parents(), |
|
1643 | 1643 | 'phase': lambda r: repo[r].phase(), |
|
1644 | 1644 | 'substate': lambda r: repo[r].substate, |
|
1645 | 1645 | 'summary': lambda r: repo[r].description().splitlines()[0], |
|
1646 | 1646 | 'diff': lambda r: list(repo[r].diff(git=True),) |
|
1647 | 1647 | } |
|
1648 | 1648 | for info in fields: |
|
1649 | 1649 | getfield = _funcs.get(info, None) |
|
1650 | 1650 | if getfield is None: |
|
1651 | 1651 | raise error.ParseError( |
|
1652 | 1652 | # i18n: "matching" is a keyword |
|
1653 | 1653 | _("unexpected field name passed to matching: %s") % info) |
|
1654 | 1654 | getfieldfuncs.append(getfield) |
|
1655 | 1655 | # convert the getfield array of functions into a "getinfo" function |
|
1656 | 1656 | # which returns an array of field values (or a single value if there |
|
1657 | 1657 | # is only one field to match) |
|
1658 | 1658 | getinfo = lambda r: [f(r) for f in getfieldfuncs] |
|
1659 | 1659 | |
|
1660 | 1660 | def matches(x): |
|
1661 | 1661 | for rev in revs: |
|
1662 | 1662 | target = getinfo(rev) |
|
1663 | 1663 | match = True |
|
1664 | 1664 | for n, f in enumerate(getfieldfuncs): |
|
1665 | 1665 | if target[n] != f(x): |
|
1666 | 1666 | match = False |
|
1667 | 1667 | if match: |
|
1668 | 1668 | return True |
|
1669 | 1669 | return False |
|
1670 | 1670 | |
|
1671 | 1671 | return subset.filter(matches, condrepr=('<matching%r %r>', fields, revs)) |
|
1672 | 1672 | |
|
1673 | 1673 | @predicate('reverse(set)', safe=True, takeorder=True) |
|
1674 | 1674 | def reverse(repo, subset, x, order): |
|
1675 | 1675 | """Reverse order of set. |
|
1676 | 1676 | """ |
|
1677 | 1677 | l = getset(repo, subset, x) |
|
1678 | 1678 | if order == defineorder: |
|
1679 | 1679 | l.reverse() |
|
1680 | 1680 | return l |
|
1681 | 1681 | |
|
1682 | 1682 | @predicate('roots(set)', safe=True) |
|
1683 | 1683 | def roots(repo, subset, x): |
|
1684 | 1684 | """Changesets in set with no parent changeset in set. |
|
1685 | 1685 | """ |
|
1686 | 1686 | s = getset(repo, fullreposet(repo), x) |
|
1687 | 1687 | parents = repo.changelog.parentrevs |
|
1688 | 1688 | def filter(r): |
|
1689 | 1689 | for p in parents(r): |
|
1690 | 1690 | if 0 <= p and p in s: |
|
1691 | 1691 | return False |
|
1692 | 1692 | return True |
|
1693 | 1693 | return subset & s.filter(filter, condrepr='<roots>') |
|
1694 | 1694 | |
|
1695 | 1695 | _sortkeyfuncs = { |
|
1696 | 1696 | 'rev': lambda c: c.rev(), |
|
1697 | 1697 | 'branch': lambda c: c.branch(), |
|
1698 | 1698 | 'desc': lambda c: c.description(), |
|
1699 | 1699 | 'user': lambda c: c.user(), |
|
1700 | 1700 | 'author': lambda c: c.user(), |
|
1701 | 1701 | 'date': lambda c: c.date()[0], |
|
1702 | 1702 | } |
|
1703 | 1703 | |
|
1704 | 1704 | def _getsortargs(x): |
|
1705 | 1705 | """Parse sort options into (set, [(key, reverse)], opts)""" |
|
1706 | 1706 | args = getargsdict(x, 'sort', 'set keys topo.firstbranch') |
|
1707 | 1707 | if 'set' not in args: |
|
1708 | 1708 | # i18n: "sort" is a keyword |
|
1709 | 1709 | raise error.ParseError(_('sort requires one or two arguments')) |
|
1710 | 1710 | keys = "rev" |
|
1711 | 1711 | if 'keys' in args: |
|
1712 | 1712 | # i18n: "sort" is a keyword |
|
1713 | 1713 | keys = getstring(args['keys'], _("sort spec must be a string")) |
|
1714 | 1714 | |
|
1715 | 1715 | keyflags = [] |
|
1716 | 1716 | for k in keys.split(): |
|
1717 | 1717 | fk = k |
|
1718 | 1718 | reverse = (k[0] == '-') |
|
1719 | 1719 | if reverse: |
|
1720 | 1720 | k = k[1:] |
|
1721 | 1721 | if k not in _sortkeyfuncs and k != 'topo': |
|
1722 | 1722 | raise error.ParseError(_("unknown sort key %r") % fk) |
|
1723 | 1723 | keyflags.append((k, reverse)) |
|
1724 | 1724 | |
|
1725 | 1725 | if len(keyflags) > 1 and any(k == 'topo' for k, reverse in keyflags): |
|
1726 | 1726 | # i18n: "topo" is a keyword |
|
1727 | 1727 | raise error.ParseError(_('topo sort order cannot be combined ' |
|
1728 | 1728 | 'with other sort keys')) |
|
1729 | 1729 | |
|
1730 | 1730 | opts = {} |
|
1731 | 1731 | if 'topo.firstbranch' in args: |
|
1732 | 1732 | if any(k == 'topo' for k, reverse in keyflags): |
|
1733 | 1733 | opts['topo.firstbranch'] = args['topo.firstbranch'] |
|
1734 | 1734 | else: |
|
1735 | 1735 | # i18n: "topo" and "topo.firstbranch" are keywords |
|
1736 | 1736 | raise error.ParseError(_('topo.firstbranch can only be used ' |
|
1737 | 1737 | 'when using the topo sort key')) |
|
1738 | 1738 | |
|
1739 | 1739 | return args['set'], keyflags, opts |
|
1740 | 1740 | |
|
1741 | 1741 | @predicate('sort(set[, [-]key... [, ...]])', safe=True, takeorder=True) |
|
1742 | 1742 | def sort(repo, subset, x, order): |
|
1743 | 1743 | """Sort set by keys. The default sort order is ascending, specify a key |
|
1744 | 1744 | as ``-key`` to sort in descending order. |
|
1745 | 1745 | |
|
1746 | 1746 | The keys can be: |
|
1747 | 1747 | |
|
1748 | 1748 | - ``rev`` for the revision number, |
|
1749 | 1749 | - ``branch`` for the branch name, |
|
1750 | 1750 | - ``desc`` for the commit message (description), |
|
1751 | 1751 | - ``user`` for user name (``author`` can be used as an alias), |
|
1752 | 1752 | - ``date`` for the commit date |
|
1753 | 1753 | - ``topo`` for a reverse topographical sort |
|
1754 | 1754 | |
|
1755 | 1755 | The ``topo`` sort order cannot be combined with other sort keys. This sort |
|
1756 | 1756 | takes one optional argument, ``topo.firstbranch``, which takes a revset that |
|
1757 | 1757 | specifies what topographical branches to prioritize in the sort. |
|
1758 | 1758 | |
|
1759 | 1759 | """ |
|
1760 | 1760 | s, keyflags, opts = _getsortargs(x) |
|
1761 | 1761 | revs = getset(repo, subset, s) |
|
1762 | 1762 | |
|
1763 | 1763 | if not keyflags or order != defineorder: |
|
1764 | 1764 | return revs |
|
1765 | 1765 | if len(keyflags) == 1 and keyflags[0][0] == "rev": |
|
1766 | 1766 | revs.sort(reverse=keyflags[0][1]) |
|
1767 | 1767 | return revs |
|
1768 | 1768 | elif keyflags[0][0] == "topo": |
|
1769 | 1769 | firstbranch = () |
|
1770 | 1770 | if 'topo.firstbranch' in opts: |
|
1771 | 1771 | firstbranch = getset(repo, subset, opts['topo.firstbranch']) |
|
1772 | 1772 | revs = baseset(dagop.toposort(revs, repo.changelog.parentrevs, |
|
1773 | 1773 | firstbranch), |
|
1774 | 1774 | istopo=True) |
|
1775 | 1775 | if keyflags[0][1]: |
|
1776 | 1776 | revs.reverse() |
|
1777 | 1777 | return revs |
|
1778 | 1778 | |
|
1779 | 1779 | # sort() is guaranteed to be stable |
|
1780 | 1780 | ctxs = [repo[r] for r in revs] |
|
1781 | 1781 | for k, reverse in reversed(keyflags): |
|
1782 | 1782 | ctxs.sort(key=_sortkeyfuncs[k], reverse=reverse) |
|
1783 | 1783 | return baseset([c.rev() for c in ctxs]) |
|
1784 | 1784 | |
|
1785 | 1785 | @predicate('subrepo([pattern])') |
|
1786 | 1786 | def subrepo(repo, subset, x): |
|
1787 | 1787 | """Changesets that add, modify or remove the given subrepo. If no subrepo |
|
1788 | 1788 | pattern is named, any subrepo changes are returned. |
|
1789 | 1789 | """ |
|
1790 | 1790 | # i18n: "subrepo" is a keyword |
|
1791 | 1791 | args = getargs(x, 0, 1, _('subrepo takes at most one argument')) |
|
1792 | 1792 | pat = None |
|
1793 | 1793 | if len(args) != 0: |
|
1794 | 1794 | pat = getstring(args[0], _("subrepo requires a pattern")) |
|
1795 | 1795 | |
|
1796 | 1796 | m = matchmod.exact(repo.root, repo.root, ['.hgsubstate']) |
|
1797 | 1797 | |
|
1798 | 1798 | def submatches(names): |
|
1799 | 1799 | k, p, m = util.stringmatcher(pat) |
|
1800 | 1800 | for name in names: |
|
1801 | 1801 | if m(name): |
|
1802 | 1802 | yield name |
|
1803 | 1803 | |
|
1804 | 1804 | def matches(x): |
|
1805 | 1805 | c = repo[x] |
|
1806 | 1806 | s = repo.status(c.p1().node(), c.node(), match=m) |
|
1807 | 1807 | |
|
1808 | 1808 | if pat is None: |
|
1809 | 1809 | return s.added or s.modified or s.removed |
|
1810 | 1810 | |
|
1811 | 1811 | if s.added: |
|
1812 | 1812 | return any(submatches(c.substate.keys())) |
|
1813 | 1813 | |
|
1814 | 1814 | if s.modified: |
|
1815 | 1815 | subs = set(c.p1().substate.keys()) |
|
1816 | 1816 | subs.update(c.substate.keys()) |
|
1817 | 1817 | |
|
1818 | 1818 | for path in submatches(subs): |
|
1819 | 1819 | if c.p1().substate.get(path) != c.substate.get(path): |
|
1820 | 1820 | return True |
|
1821 | 1821 | |
|
1822 | 1822 | if s.removed: |
|
1823 | 1823 | return any(submatches(c.p1().substate.keys())) |
|
1824 | 1824 | |
|
1825 | 1825 | return False |
|
1826 | 1826 | |
|
1827 | 1827 | return subset.filter(matches, condrepr=('<subrepo %r>', pat)) |
|
1828 | 1828 | |
|
1829 | 1829 | def _substringmatcher(pattern, casesensitive=True): |
|
1830 | 1830 | kind, pattern, matcher = util.stringmatcher(pattern, |
|
1831 | 1831 | casesensitive=casesensitive) |
|
1832 | 1832 | if kind == 'literal': |
|
1833 | 1833 | if not casesensitive: |
|
1834 | 1834 | pattern = encoding.lower(pattern) |
|
1835 | 1835 | matcher = lambda s: pattern in encoding.lower(s) |
|
1836 | 1836 | else: |
|
1837 | 1837 | matcher = lambda s: pattern in s |
|
1838 | 1838 | return kind, pattern, matcher |
|
1839 | 1839 | |
|
1840 | 1840 | @predicate('tag([name])', safe=True) |
|
1841 | 1841 | def tag(repo, subset, x): |
|
1842 | 1842 | """The specified tag by name, or all tagged revisions if no name is given. |
|
1843 | 1843 | |
|
1844 | 1844 | Pattern matching is supported for `name`. See |
|
1845 | 1845 | :hg:`help revisions.patterns`. |
|
1846 | 1846 | """ |
|
1847 | 1847 | # i18n: "tag" is a keyword |
|
1848 | 1848 | args = getargs(x, 0, 1, _("tag takes one or no arguments")) |
|
1849 | 1849 | cl = repo.changelog |
|
1850 | 1850 | if args: |
|
1851 | 1851 | pattern = getstring(args[0], |
|
1852 | 1852 | # i18n: "tag" is a keyword |
|
1853 | 1853 | _('the argument to tag must be a string')) |
|
1854 | 1854 | kind, pattern, matcher = util.stringmatcher(pattern) |
|
1855 | 1855 | if kind == 'literal': |
|
1856 | 1856 | # avoid resolving all tags |
|
1857 | 1857 | tn = repo._tagscache.tags.get(pattern, None) |
|
1858 | 1858 | if tn is None: |
|
1859 | 1859 | raise error.RepoLookupError(_("tag '%s' does not exist") |
|
1860 | 1860 | % pattern) |
|
1861 | 1861 | s = {repo[tn].rev()} |
|
1862 | 1862 | else: |
|
1863 | 1863 | s = {cl.rev(n) for t, n in repo.tagslist() if matcher(t)} |
|
1864 | 1864 | else: |
|
1865 | 1865 | s = {cl.rev(n) for t, n in repo.tagslist() if t != 'tip'} |
|
1866 | 1866 | return subset & s |
|
1867 | 1867 | |
|
1868 | 1868 | @predicate('tagged', safe=True) |
|
1869 | 1869 | def tagged(repo, subset, x): |
|
1870 | 1870 | return tag(repo, subset, x) |
|
1871 | 1871 | |
|
1872 | 1872 | @predicate('unstable()', safe=True) |
|
1873 | 1873 | def unstable(repo, subset, x): |
|
1874 | 1874 | """Non-obsolete changesets with obsolete ancestors. |
|
1875 | 1875 | """ |
|
1876 | 1876 | # i18n: "unstable" is a keyword |
|
1877 | 1877 | getargs(x, 0, 0, _("unstable takes no arguments")) |
|
1878 | 1878 | unstables = obsmod.getrevs(repo, 'unstable') |
|
1879 | 1879 | return subset & unstables |
|
1880 | 1880 | |
|
1881 | 1881 | |
|
1882 | 1882 | @predicate('user(string)', safe=True) |
|
1883 | 1883 | def user(repo, subset, x): |
|
1884 | 1884 | """User name contains string. The match is case-insensitive. |
|
1885 | 1885 | |
|
1886 | 1886 | Pattern matching is supported for `string`. See |
|
1887 | 1887 | :hg:`help revisions.patterns`. |
|
1888 | 1888 | """ |
|
1889 | 1889 | return author(repo, subset, x) |
|
1890 | 1890 | |
|
1891 | 1891 | @predicate('wdir()', safe=True) |
|
1892 | 1892 | def wdir(repo, subset, x): |
|
1893 | 1893 | """Working directory. (EXPERIMENTAL)""" |
|
1894 | 1894 | # i18n: "wdir" is a keyword |
|
1895 | 1895 | getargs(x, 0, 0, _("wdir takes no arguments")) |
|
1896 | 1896 | if node.wdirrev in subset or isinstance(subset, fullreposet): |
|
1897 | 1897 | return baseset([node.wdirrev]) |
|
1898 | 1898 | return baseset() |
|
1899 | 1899 | |
|
1900 | 1900 | def _orderedlist(repo, subset, x): |
|
1901 | 1901 | s = getstring(x, "internal error") |
|
1902 | 1902 | if not s: |
|
1903 | 1903 | return baseset() |
|
1904 | 1904 | # remove duplicates here. it's difficult for caller to deduplicate sets |
|
1905 | 1905 | # because different symbols can point to the same rev. |
|
1906 | 1906 | cl = repo.changelog |
|
1907 | 1907 | ls = [] |
|
1908 | 1908 | seen = set() |
|
1909 | 1909 | for t in s.split('\0'): |
|
1910 | 1910 | try: |
|
1911 | 1911 | # fast path for integer revision |
|
1912 | 1912 | r = int(t) |
|
1913 | 1913 | if str(r) != t or r not in cl: |
|
1914 | 1914 | raise ValueError |
|
1915 | 1915 | revs = [r] |
|
1916 | 1916 | except ValueError: |
|
1917 | 1917 | revs = stringset(repo, subset, t) |
|
1918 | 1918 | |
|
1919 | 1919 | for r in revs: |
|
1920 | 1920 | if r in seen: |
|
1921 | 1921 | continue |
|
1922 | 1922 | if (r in subset |
|
1923 | 1923 | or r == node.nullrev and isinstance(subset, fullreposet)): |
|
1924 | 1924 | ls.append(r) |
|
1925 | 1925 | seen.add(r) |
|
1926 | 1926 | return baseset(ls) |
|
1927 | 1927 | |
|
1928 | 1928 | # for internal use |
|
1929 | 1929 | @predicate('_list', safe=True, takeorder=True) |
|
1930 | 1930 | def _list(repo, subset, x, order): |
|
1931 | 1931 | if order == followorder: |
|
1932 | 1932 | # slow path to take the subset order |
|
1933 | 1933 | return subset & _orderedlist(repo, fullreposet(repo), x) |
|
1934 | 1934 | else: |
|
1935 | 1935 | return _orderedlist(repo, subset, x) |
|
1936 | 1936 | |
|
1937 | 1937 | def _orderedintlist(repo, subset, x): |
|
1938 | 1938 | s = getstring(x, "internal error") |
|
1939 | 1939 | if not s: |
|
1940 | 1940 | return baseset() |
|
1941 | 1941 | ls = [int(r) for r in s.split('\0')] |
|
1942 | 1942 | s = subset |
|
1943 | 1943 | return baseset([r for r in ls if r in s]) |
|
1944 | 1944 | |
|
1945 | 1945 | # for internal use |
|
1946 | 1946 | @predicate('_intlist', safe=True, takeorder=True) |
|
1947 | 1947 | def _intlist(repo, subset, x, order): |
|
1948 | 1948 | if order == followorder: |
|
1949 | 1949 | # slow path to take the subset order |
|
1950 | 1950 | return subset & _orderedintlist(repo, fullreposet(repo), x) |
|
1951 | 1951 | else: |
|
1952 | 1952 | return _orderedintlist(repo, subset, x) |
|
1953 | 1953 | |
|
1954 | 1954 | def _orderedhexlist(repo, subset, x): |
|
1955 | 1955 | s = getstring(x, "internal error") |
|
1956 | 1956 | if not s: |
|
1957 | 1957 | return baseset() |
|
1958 | 1958 | cl = repo.changelog |
|
1959 | 1959 | ls = [cl.rev(node.bin(r)) for r in s.split('\0')] |
|
1960 | 1960 | s = subset |
|
1961 | 1961 | return baseset([r for r in ls if r in s]) |
|
1962 | 1962 | |
|
1963 | 1963 | # for internal use |
|
1964 | 1964 | @predicate('_hexlist', safe=True, takeorder=True) |
|
1965 | 1965 | def _hexlist(repo, subset, x, order): |
|
1966 | 1966 | if order == followorder: |
|
1967 | 1967 | # slow path to take the subset order |
|
1968 | 1968 | return subset & _orderedhexlist(repo, fullreposet(repo), x) |
|
1969 | 1969 | else: |
|
1970 | 1970 | return _orderedhexlist(repo, subset, x) |
|
1971 | 1971 | |
|
1972 | 1972 | methods = { |
|
1973 | 1973 | "range": rangeset, |
|
1974 | 1974 | "rangeall": rangeall, |
|
1975 | 1975 | "rangepre": rangepre, |
|
1976 | 1976 | "rangepost": rangepost, |
|
1977 | 1977 | "dagrange": dagrange, |
|
1978 | 1978 | "string": stringset, |
|
1979 | 1979 | "symbol": stringset, |
|
1980 | 1980 | "and": andset, |
|
1981 | 1981 | "or": orset, |
|
1982 | 1982 | "not": notset, |
|
1983 | 1983 | "difference": differenceset, |
|
1984 | 1984 | "list": listset, |
|
1985 | 1985 | "keyvalue": keyvaluepair, |
|
1986 | 1986 | "func": func, |
|
1987 | 1987 | "ancestor": ancestorspec, |
|
1988 | 1988 | "parent": parentspec, |
|
1989 | 1989 | "parentpost": parentpost, |
|
1990 | 1990 | } |
|
1991 | 1991 | |
|
1992 | 1992 | def posttreebuilthook(tree, repo): |
|
1993 | 1993 | # hook for extensions to execute code on the optimized tree |
|
1994 | 1994 | pass |
|
1995 | 1995 | |
|
1996 | 1996 | def match(ui, spec, repo=None, order=defineorder): |
|
1997 | 1997 | """Create a matcher for a single revision spec |
|
1998 | 1998 | |
|
1999 | 1999 | If order=followorder, a matcher takes the ordering specified by the input |
|
2000 | 2000 | set. |
|
2001 | 2001 | """ |
|
2002 | 2002 | return matchany(ui, [spec], repo=repo, order=order) |
|
2003 | 2003 | |
|
2004 | def matchany(ui, specs, repo=None, order=defineorder): | |
|
2004 | def matchany(ui, specs, repo=None, order=defineorder, localalias=None): | |
|
2005 | 2005 | """Create a matcher that will include any revisions matching one of the |
|
2006 | 2006 | given specs |
|
2007 | 2007 | |
|
2008 | 2008 | If order=followorder, a matcher takes the ordering specified by the input |
|
2009 | 2009 | set. |
|
2010 | ||
|
2011 | If localalias is not None, it is a dict {name: definitionstring}. It takes | |
|
2012 | precedence over [revsetalias] config section. | |
|
2010 | 2013 | """ |
|
2011 | 2014 | if not specs: |
|
2012 | 2015 | def mfunc(repo, subset=None): |
|
2013 | 2016 | return baseset() |
|
2014 | 2017 | return mfunc |
|
2015 | 2018 | if not all(specs): |
|
2016 | 2019 | raise error.ParseError(_("empty query")) |
|
2017 | 2020 | lookup = None |
|
2018 | 2021 | if repo: |
|
2019 | 2022 | lookup = repo.__contains__ |
|
2020 | 2023 | if len(specs) == 1: |
|
2021 | 2024 | tree = revsetlang.parse(specs[0], lookup) |
|
2022 | 2025 | else: |
|
2023 | 2026 | tree = ('or', |
|
2024 | 2027 | ('list',) + tuple(revsetlang.parse(s, lookup) for s in specs)) |
|
2025 | 2028 | |
|
2029 | aliases = [] | |
|
2030 | warn = None | |
|
2026 | 2031 | if ui: |
|
2027 | tree = revsetlang.expandaliases(ui, tree) | |
|
2032 | aliases.extend(ui.configitems('revsetalias')) | |
|
2033 | warn = ui.warn | |
|
2034 | if localalias: | |
|
2035 | aliases.extend(localalias.items()) | |
|
2036 | if aliases: | |
|
2037 | tree = revsetlang.expandaliases(tree, aliases, warn=warn) | |
|
2028 | 2038 | tree = revsetlang.foldconcat(tree) |
|
2029 | 2039 | tree = revsetlang.analyze(tree, order) |
|
2030 | 2040 | tree = revsetlang.optimize(tree) |
|
2031 | 2041 | posttreebuilthook(tree, repo) |
|
2032 | 2042 | return makematcher(tree) |
|
2033 | 2043 | |
|
2034 | 2044 | def makematcher(tree): |
|
2035 | 2045 | """Create a matcher from an evaluatable tree""" |
|
2036 | 2046 | def mfunc(repo, subset=None): |
|
2037 | 2047 | if subset is None: |
|
2038 | 2048 | subset = fullreposet(repo) |
|
2039 | 2049 | return getset(repo, subset, tree) |
|
2040 | 2050 | return mfunc |
|
2041 | 2051 | |
|
2042 | 2052 | def loadpredicate(ui, extname, registrarobj): |
|
2043 | 2053 | """Load revset predicates from specified registrarobj |
|
2044 | 2054 | """ |
|
2045 | 2055 | for name, func in registrarobj._table.iteritems(): |
|
2046 | 2056 | symbols[name] = func |
|
2047 | 2057 | if func._safe: |
|
2048 | 2058 | safesymbols.add(name) |
|
2049 | 2059 | |
|
2050 | 2060 | # load built-in predicates explicitly to setup safesymbols |
|
2051 | 2061 | loadpredicate(None, None, predicate) |
|
2052 | 2062 | |
|
2053 | 2063 | # tell hggettext to extract docstrings from these functions: |
|
2054 | 2064 | i18nfunctions = symbols.values() |
@@ -1,723 +1,725 b'' | |||
|
1 | 1 | # revsetlang.py - parser, tokenizer and utility for revision set language |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2010 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import string |
|
11 | 11 | |
|
12 | 12 | from .i18n import _ |
|
13 | 13 | from . import ( |
|
14 | 14 | error, |
|
15 | 15 | node, |
|
16 | 16 | parser, |
|
17 | 17 | pycompat, |
|
18 | 18 | util, |
|
19 | 19 | ) |
|
20 | 20 | |
|
21 | 21 | elements = { |
|
22 | 22 | # token-type: binding-strength, primary, prefix, infix, suffix |
|
23 | 23 | "(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None), |
|
24 | 24 | "##": (20, None, None, ("_concat", 20), None), |
|
25 | 25 | "~": (18, None, None, ("ancestor", 18), None), |
|
26 | 26 | "^": (18, None, None, ("parent", 18), "parentpost"), |
|
27 | 27 | "-": (5, None, ("negate", 19), ("minus", 5), None), |
|
28 | 28 | "::": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"), |
|
29 | 29 | "..": (17, None, ("dagrangepre", 17), ("dagrange", 17), "dagrangepost"), |
|
30 | 30 | ":": (15, "rangeall", ("rangepre", 15), ("range", 15), "rangepost"), |
|
31 | 31 | "not": (10, None, ("not", 10), None, None), |
|
32 | 32 | "!": (10, None, ("not", 10), None, None), |
|
33 | 33 | "and": (5, None, None, ("and", 5), None), |
|
34 | 34 | "&": (5, None, None, ("and", 5), None), |
|
35 | 35 | "%": (5, None, None, ("only", 5), "onlypost"), |
|
36 | 36 | "or": (4, None, None, ("or", 4), None), |
|
37 | 37 | "|": (4, None, None, ("or", 4), None), |
|
38 | 38 | "+": (4, None, None, ("or", 4), None), |
|
39 | 39 | "=": (3, None, None, ("keyvalue", 3), None), |
|
40 | 40 | ",": (2, None, None, ("list", 2), None), |
|
41 | 41 | ")": (0, None, None, None, None), |
|
42 | 42 | "symbol": (0, "symbol", None, None, None), |
|
43 | 43 | "string": (0, "string", None, None, None), |
|
44 | 44 | "end": (0, None, None, None, None), |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | keywords = {'and', 'or', 'not'} |
|
48 | 48 | |
|
49 | 49 | _quoteletters = {'"', "'"} |
|
50 | 50 | _simpleopletters = set(pycompat.iterbytestr("():=,-|&+!~^%")) |
|
51 | 51 | |
|
52 | 52 | # default set of valid characters for the initial letter of symbols |
|
53 | 53 | _syminitletters = set(pycompat.iterbytestr( |
|
54 | 54 | string.ascii_letters.encode('ascii') + |
|
55 | 55 | string.digits.encode('ascii') + |
|
56 | 56 | '._@')) | set(map(pycompat.bytechr, xrange(128, 256))) |
|
57 | 57 | |
|
58 | 58 | # default set of valid characters for non-initial letters of symbols |
|
59 | 59 | _symletters = _syminitletters | set(pycompat.iterbytestr('-/')) |
|
60 | 60 | |
|
61 | 61 | def tokenize(program, lookup=None, syminitletters=None, symletters=None): |
|
62 | 62 | ''' |
|
63 | 63 | Parse a revset statement into a stream of tokens |
|
64 | 64 | |
|
65 | 65 | ``syminitletters`` is the set of valid characters for the initial |
|
66 | 66 | letter of symbols. |
|
67 | 67 | |
|
68 | 68 | By default, character ``c`` is recognized as valid for initial |
|
69 | 69 | letter of symbols, if ``c.isalnum() or c in '._@' or ord(c) > 127``. |
|
70 | 70 | |
|
71 | 71 | ``symletters`` is the set of valid characters for non-initial |
|
72 | 72 | letters of symbols. |
|
73 | 73 | |
|
74 | 74 | By default, character ``c`` is recognized as valid for non-initial |
|
75 | 75 | letters of symbols, if ``c.isalnum() or c in '-._/@' or ord(c) > 127``. |
|
76 | 76 | |
|
77 | 77 | Check that @ is a valid unquoted token character (issue3686): |
|
78 | 78 | >>> list(tokenize("@::")) |
|
79 | 79 | [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)] |
|
80 | 80 | |
|
81 | 81 | ''' |
|
82 | 82 | program = pycompat.bytestr(program) |
|
83 | 83 | if syminitletters is None: |
|
84 | 84 | syminitletters = _syminitletters |
|
85 | 85 | if symletters is None: |
|
86 | 86 | symletters = _symletters |
|
87 | 87 | |
|
88 | 88 | if program and lookup: |
|
89 | 89 | # attempt to parse old-style ranges first to deal with |
|
90 | 90 | # things like old-tag which contain query metacharacters |
|
91 | 91 | parts = program.split(':', 1) |
|
92 | 92 | if all(lookup(sym) for sym in parts if sym): |
|
93 | 93 | if parts[0]: |
|
94 | 94 | yield ('symbol', parts[0], 0) |
|
95 | 95 | if len(parts) > 1: |
|
96 | 96 | s = len(parts[0]) |
|
97 | 97 | yield (':', None, s) |
|
98 | 98 | if parts[1]: |
|
99 | 99 | yield ('symbol', parts[1], s + 1) |
|
100 | 100 | yield ('end', None, len(program)) |
|
101 | 101 | return |
|
102 | 102 | |
|
103 | 103 | pos, l = 0, len(program) |
|
104 | 104 | while pos < l: |
|
105 | 105 | c = program[pos] |
|
106 | 106 | if c.isspace(): # skip inter-token whitespace |
|
107 | 107 | pass |
|
108 | 108 | elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully |
|
109 | 109 | yield ('::', None, pos) |
|
110 | 110 | pos += 1 # skip ahead |
|
111 | 111 | elif c == '.' and program[pos:pos + 2] == '..': # look ahead carefully |
|
112 | 112 | yield ('..', None, pos) |
|
113 | 113 | pos += 1 # skip ahead |
|
114 | 114 | elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully |
|
115 | 115 | yield ('##', None, pos) |
|
116 | 116 | pos += 1 # skip ahead |
|
117 | 117 | elif c in _simpleopletters: # handle simple operators |
|
118 | 118 | yield (c, None, pos) |
|
119 | 119 | elif (c in _quoteletters or c == 'r' and |
|
120 | 120 | program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings |
|
121 | 121 | if c == 'r': |
|
122 | 122 | pos += 1 |
|
123 | 123 | c = program[pos] |
|
124 | 124 | decode = lambda x: x |
|
125 | 125 | else: |
|
126 | 126 | decode = parser.unescapestr |
|
127 | 127 | pos += 1 |
|
128 | 128 | s = pos |
|
129 | 129 | while pos < l: # find closing quote |
|
130 | 130 | d = program[pos] |
|
131 | 131 | if d == '\\': # skip over escaped characters |
|
132 | 132 | pos += 2 |
|
133 | 133 | continue |
|
134 | 134 | if d == c: |
|
135 | 135 | yield ('string', decode(program[s:pos]), s) |
|
136 | 136 | break |
|
137 | 137 | pos += 1 |
|
138 | 138 | else: |
|
139 | 139 | raise error.ParseError(_("unterminated string"), s) |
|
140 | 140 | # gather up a symbol/keyword |
|
141 | 141 | elif c in syminitletters: |
|
142 | 142 | s = pos |
|
143 | 143 | pos += 1 |
|
144 | 144 | while pos < l: # find end of symbol |
|
145 | 145 | d = program[pos] |
|
146 | 146 | if d not in symletters: |
|
147 | 147 | break |
|
148 | 148 | if d == '.' and program[pos - 1] == '.': # special case for .. |
|
149 | 149 | pos -= 1 |
|
150 | 150 | break |
|
151 | 151 | pos += 1 |
|
152 | 152 | sym = program[s:pos] |
|
153 | 153 | if sym in keywords: # operator keywords |
|
154 | 154 | yield (sym, None, s) |
|
155 | 155 | elif '-' in sym: |
|
156 | 156 | # some jerk gave us foo-bar-baz, try to check if it's a symbol |
|
157 | 157 | if lookup and lookup(sym): |
|
158 | 158 | # looks like a real symbol |
|
159 | 159 | yield ('symbol', sym, s) |
|
160 | 160 | else: |
|
161 | 161 | # looks like an expression |
|
162 | 162 | parts = sym.split('-') |
|
163 | 163 | for p in parts[:-1]: |
|
164 | 164 | if p: # possible consecutive - |
|
165 | 165 | yield ('symbol', p, s) |
|
166 | 166 | s += len(p) |
|
167 | 167 | yield ('-', None, pos) |
|
168 | 168 | s += 1 |
|
169 | 169 | if parts[-1]: # possible trailing - |
|
170 | 170 | yield ('symbol', parts[-1], s) |
|
171 | 171 | else: |
|
172 | 172 | yield ('symbol', sym, s) |
|
173 | 173 | pos -= 1 |
|
174 | 174 | else: |
|
175 | 175 | raise error.ParseError(_("syntax error in revset '%s'") % |
|
176 | 176 | program, pos) |
|
177 | 177 | pos += 1 |
|
178 | 178 | yield ('end', None, pos) |
|
179 | 179 | |
|
180 | 180 | # helpers |
|
181 | 181 | |
|
182 | 182 | _notset = object() |
|
183 | 183 | |
|
184 | 184 | def getsymbol(x): |
|
185 | 185 | if x and x[0] == 'symbol': |
|
186 | 186 | return x[1] |
|
187 | 187 | raise error.ParseError(_('not a symbol')) |
|
188 | 188 | |
|
189 | 189 | def getstring(x, err): |
|
190 | 190 | if x and (x[0] == 'string' or x[0] == 'symbol'): |
|
191 | 191 | return x[1] |
|
192 | 192 | raise error.ParseError(err) |
|
193 | 193 | |
|
194 | 194 | def getinteger(x, err, default=_notset): |
|
195 | 195 | if not x and default is not _notset: |
|
196 | 196 | return default |
|
197 | 197 | try: |
|
198 | 198 | return int(getstring(x, err)) |
|
199 | 199 | except ValueError: |
|
200 | 200 | raise error.ParseError(err) |
|
201 | 201 | |
|
202 | 202 | def getboolean(x, err): |
|
203 | 203 | value = util.parsebool(getsymbol(x)) |
|
204 | 204 | if value is not None: |
|
205 | 205 | return value |
|
206 | 206 | raise error.ParseError(err) |
|
207 | 207 | |
|
208 | 208 | def getlist(x): |
|
209 | 209 | if not x: |
|
210 | 210 | return [] |
|
211 | 211 | if x[0] == 'list': |
|
212 | 212 | return list(x[1:]) |
|
213 | 213 | return [x] |
|
214 | 214 | |
|
215 | 215 | def getrange(x, err): |
|
216 | 216 | if not x: |
|
217 | 217 | raise error.ParseError(err) |
|
218 | 218 | op = x[0] |
|
219 | 219 | if op == 'range': |
|
220 | 220 | return x[1], x[2] |
|
221 | 221 | elif op == 'rangepre': |
|
222 | 222 | return None, x[1] |
|
223 | 223 | elif op == 'rangepost': |
|
224 | 224 | return x[1], None |
|
225 | 225 | elif op == 'rangeall': |
|
226 | 226 | return None, None |
|
227 | 227 | raise error.ParseError(err) |
|
228 | 228 | |
|
229 | 229 | def getargs(x, min, max, err): |
|
230 | 230 | l = getlist(x) |
|
231 | 231 | if len(l) < min or (max >= 0 and len(l) > max): |
|
232 | 232 | raise error.ParseError(err) |
|
233 | 233 | return l |
|
234 | 234 | |
|
235 | 235 | def getargsdict(x, funcname, keys): |
|
236 | 236 | return parser.buildargsdict(getlist(x), funcname, parser.splitargspec(keys), |
|
237 | 237 | keyvaluenode='keyvalue', keynode='symbol') |
|
238 | 238 | |
|
239 | 239 | def _isnamedfunc(x, funcname): |
|
240 | 240 | """Check if given tree matches named function""" |
|
241 | 241 | return x and x[0] == 'func' and getsymbol(x[1]) == funcname |
|
242 | 242 | |
|
243 | 243 | def _isposargs(x, n): |
|
244 | 244 | """Check if given tree is n-length list of positional arguments""" |
|
245 | 245 | l = getlist(x) |
|
246 | 246 | return len(l) == n and all(y and y[0] != 'keyvalue' for y in l) |
|
247 | 247 | |
|
248 | 248 | def _matchnamedfunc(x, funcname): |
|
249 | 249 | """Return args tree if given tree matches named function; otherwise None |
|
250 | 250 | |
|
251 | 251 | This can't be used for testing a nullary function since its args tree |
|
252 | 252 | is also None. Use _isnamedfunc() instead. |
|
253 | 253 | """ |
|
254 | 254 | if not _isnamedfunc(x, funcname): |
|
255 | 255 | return |
|
256 | 256 | return x[2] |
|
257 | 257 | |
|
258 | 258 | # Constants for ordering requirement, used in _analyze(): |
|
259 | 259 | # |
|
260 | 260 | # If 'define', any nested functions and operations can change the ordering of |
|
261 | 261 | # the entries in the set. If 'follow', any nested functions and operations |
|
262 | 262 | # should take the ordering specified by the first operand to the '&' operator. |
|
263 | 263 | # |
|
264 | 264 | # For instance, |
|
265 | 265 | # |
|
266 | 266 | # X & (Y | Z) |
|
267 | 267 | # ^ ^^^^^^^ |
|
268 | 268 | # | follow |
|
269 | 269 | # define |
|
270 | 270 | # |
|
271 | 271 | # will be evaluated as 'or(y(x()), z(x()))', where 'x()' can change the order |
|
272 | 272 | # of the entries in the set, but 'y()', 'z()' and 'or()' shouldn't. |
|
273 | 273 | # |
|
274 | 274 | # 'any' means the order doesn't matter. For instance, |
|
275 | 275 | # |
|
276 | 276 | # X & !Y |
|
277 | 277 | # ^ |
|
278 | 278 | # any |
|
279 | 279 | # |
|
280 | 280 | # 'y()' can either enforce its ordering requirement or take the ordering |
|
281 | 281 | # specified by 'x()' because 'not()' doesn't care the order. |
|
282 | 282 | # |
|
283 | 283 | # Transition of ordering requirement: |
|
284 | 284 | # |
|
285 | 285 | # 1. starts with 'define' |
|
286 | 286 | # 2. shifts to 'follow' by 'x & y' |
|
287 | 287 | # 3. changes back to 'define' on function call 'f(x)' or function-like |
|
288 | 288 | # operation 'x (f) y' because 'f' may have its own ordering requirement |
|
289 | 289 | # for 'x' and 'y' (e.g. 'first(x)') |
|
290 | 290 | # |
|
291 | 291 | anyorder = 'any' # don't care the order |
|
292 | 292 | defineorder = 'define' # should define the order |
|
293 | 293 | followorder = 'follow' # must follow the current order |
|
294 | 294 | |
|
295 | 295 | # transition table for 'x & y', from the current expression 'x' to 'y' |
|
296 | 296 | _tofolloworder = { |
|
297 | 297 | anyorder: anyorder, |
|
298 | 298 | defineorder: followorder, |
|
299 | 299 | followorder: followorder, |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | def _matchonly(revs, bases): |
|
303 | 303 | """ |
|
304 | 304 | >>> f = lambda *args: _matchonly(*map(parse, args)) |
|
305 | 305 | >>> f('ancestors(A)', 'not ancestors(B)') |
|
306 | 306 | ('list', ('symbol', 'A'), ('symbol', 'B')) |
|
307 | 307 | """ |
|
308 | 308 | ta = _matchnamedfunc(revs, 'ancestors') |
|
309 | 309 | tb = bases and bases[0] == 'not' and _matchnamedfunc(bases[1], 'ancestors') |
|
310 | 310 | if _isposargs(ta, 1) and _isposargs(tb, 1): |
|
311 | 311 | return ('list', ta, tb) |
|
312 | 312 | |
|
313 | 313 | def _fixops(x): |
|
314 | 314 | """Rewrite raw parsed tree to resolve ambiguous syntax which cannot be |
|
315 | 315 | handled well by our simple top-down parser""" |
|
316 | 316 | if not isinstance(x, tuple): |
|
317 | 317 | return x |
|
318 | 318 | |
|
319 | 319 | op = x[0] |
|
320 | 320 | if op == 'parent': |
|
321 | 321 | # x^:y means (x^) : y, not x ^ (:y) |
|
322 | 322 | # x^: means (x^) :, not x ^ (:) |
|
323 | 323 | post = ('parentpost', x[1]) |
|
324 | 324 | if x[2][0] == 'dagrangepre': |
|
325 | 325 | return _fixops(('dagrange', post, x[2][1])) |
|
326 | 326 | elif x[2][0] == 'rangepre': |
|
327 | 327 | return _fixops(('range', post, x[2][1])) |
|
328 | 328 | elif x[2][0] == 'rangeall': |
|
329 | 329 | return _fixops(('rangepost', post)) |
|
330 | 330 | elif op == 'or': |
|
331 | 331 | # make number of arguments deterministic: |
|
332 | 332 | # x + y + z -> (or x y z) -> (or (list x y z)) |
|
333 | 333 | return (op, _fixops(('list',) + x[1:])) |
|
334 | 334 | |
|
335 | 335 | return (op,) + tuple(_fixops(y) for y in x[1:]) |
|
336 | 336 | |
|
337 | 337 | def _analyze(x, order): |
|
338 | 338 | if x is None: |
|
339 | 339 | return x |
|
340 | 340 | |
|
341 | 341 | op = x[0] |
|
342 | 342 | if op == 'minus': |
|
343 | 343 | return _analyze(('and', x[1], ('not', x[2])), order) |
|
344 | 344 | elif op == 'only': |
|
345 | 345 | t = ('func', ('symbol', 'only'), ('list', x[1], x[2])) |
|
346 | 346 | return _analyze(t, order) |
|
347 | 347 | elif op == 'onlypost': |
|
348 | 348 | return _analyze(('func', ('symbol', 'only'), x[1]), order) |
|
349 | 349 | elif op == 'dagrangepre': |
|
350 | 350 | return _analyze(('func', ('symbol', 'ancestors'), x[1]), order) |
|
351 | 351 | elif op == 'dagrangepost': |
|
352 | 352 | return _analyze(('func', ('symbol', 'descendants'), x[1]), order) |
|
353 | 353 | elif op == 'negate': |
|
354 | 354 | s = getstring(x[1], _("can't negate that")) |
|
355 | 355 | return _analyze(('string', '-' + s), order) |
|
356 | 356 | elif op in ('string', 'symbol'): |
|
357 | 357 | return x |
|
358 | 358 | elif op == 'and': |
|
359 | 359 | ta = _analyze(x[1], order) |
|
360 | 360 | tb = _analyze(x[2], _tofolloworder[order]) |
|
361 | 361 | return (op, ta, tb, order) |
|
362 | 362 | elif op == 'or': |
|
363 | 363 | return (op, _analyze(x[1], order), order) |
|
364 | 364 | elif op == 'not': |
|
365 | 365 | return (op, _analyze(x[1], anyorder), order) |
|
366 | 366 | elif op == 'rangeall': |
|
367 | 367 | return (op, None, order) |
|
368 | 368 | elif op in ('rangepre', 'rangepost', 'parentpost'): |
|
369 | 369 | return (op, _analyze(x[1], defineorder), order) |
|
370 | 370 | elif op == 'group': |
|
371 | 371 | return _analyze(x[1], order) |
|
372 | 372 | elif op in ('dagrange', 'range', 'parent', 'ancestor'): |
|
373 | 373 | ta = _analyze(x[1], defineorder) |
|
374 | 374 | tb = _analyze(x[2], defineorder) |
|
375 | 375 | return (op, ta, tb, order) |
|
376 | 376 | elif op == 'list': |
|
377 | 377 | return (op,) + tuple(_analyze(y, order) for y in x[1:]) |
|
378 | 378 | elif op == 'keyvalue': |
|
379 | 379 | return (op, x[1], _analyze(x[2], order)) |
|
380 | 380 | elif op == 'func': |
|
381 | 381 | f = getsymbol(x[1]) |
|
382 | 382 | d = defineorder |
|
383 | 383 | if f == 'present': |
|
384 | 384 | # 'present(set)' is known to return the argument set with no |
|
385 | 385 | # modification, so forward the current order to its argument |
|
386 | 386 | d = order |
|
387 | 387 | return (op, x[1], _analyze(x[2], d), order) |
|
388 | 388 | raise ValueError('invalid operator %r' % op) |
|
389 | 389 | |
|
390 | 390 | def analyze(x, order=defineorder): |
|
391 | 391 | """Transform raw parsed tree to evaluatable tree which can be fed to |
|
392 | 392 | optimize() or getset() |
|
393 | 393 | |
|
394 | 394 | All pseudo operations should be mapped to real operations or functions |
|
395 | 395 | defined in methods or symbols table respectively. |
|
396 | 396 | |
|
397 | 397 | 'order' specifies how the current expression 'x' is ordered (see the |
|
398 | 398 | constants defined above.) |
|
399 | 399 | """ |
|
400 | 400 | return _analyze(x, order) |
|
401 | 401 | |
|
402 | 402 | def _optimize(x, small): |
|
403 | 403 | if x is None: |
|
404 | 404 | return 0, x |
|
405 | 405 | |
|
406 | 406 | smallbonus = 1 |
|
407 | 407 | if small: |
|
408 | 408 | smallbonus = .5 |
|
409 | 409 | |
|
410 | 410 | op = x[0] |
|
411 | 411 | if op in ('string', 'symbol'): |
|
412 | 412 | return smallbonus, x # single revisions are small |
|
413 | 413 | elif op == 'and': |
|
414 | 414 | wa, ta = _optimize(x[1], True) |
|
415 | 415 | wb, tb = _optimize(x[2], True) |
|
416 | 416 | order = x[3] |
|
417 | 417 | w = min(wa, wb) |
|
418 | 418 | |
|
419 | 419 | # (::x and not ::y)/(not ::y and ::x) have a fast path |
|
420 | 420 | tm = _matchonly(ta, tb) or _matchonly(tb, ta) |
|
421 | 421 | if tm: |
|
422 | 422 | return w, ('func', ('symbol', 'only'), tm, order) |
|
423 | 423 | |
|
424 | 424 | if tb is not None and tb[0] == 'not': |
|
425 | 425 | return wa, ('difference', ta, tb[1], order) |
|
426 | 426 | |
|
427 | 427 | if wa > wb: |
|
428 | 428 | return w, (op, tb, ta, order) |
|
429 | 429 | return w, (op, ta, tb, order) |
|
430 | 430 | elif op == 'or': |
|
431 | 431 | # fast path for machine-generated expression, that is likely to have |
|
432 | 432 | # lots of trivial revisions: 'a + b + c()' to '_list(a b) + c()' |
|
433 | 433 | order = x[2] |
|
434 | 434 | ws, ts, ss = [], [], [] |
|
435 | 435 | def flushss(): |
|
436 | 436 | if not ss: |
|
437 | 437 | return |
|
438 | 438 | if len(ss) == 1: |
|
439 | 439 | w, t = ss[0] |
|
440 | 440 | else: |
|
441 | 441 | s = '\0'.join(t[1] for w, t in ss) |
|
442 | 442 | y = ('func', ('symbol', '_list'), ('string', s), order) |
|
443 | 443 | w, t = _optimize(y, False) |
|
444 | 444 | ws.append(w) |
|
445 | 445 | ts.append(t) |
|
446 | 446 | del ss[:] |
|
447 | 447 | for y in getlist(x[1]): |
|
448 | 448 | w, t = _optimize(y, False) |
|
449 | 449 | if t is not None and (t[0] == 'string' or t[0] == 'symbol'): |
|
450 | 450 | ss.append((w, t)) |
|
451 | 451 | continue |
|
452 | 452 | flushss() |
|
453 | 453 | ws.append(w) |
|
454 | 454 | ts.append(t) |
|
455 | 455 | flushss() |
|
456 | 456 | if len(ts) == 1: |
|
457 | 457 | return ws[0], ts[0] # 'or' operation is fully optimized out |
|
458 | 458 | if order != defineorder: |
|
459 | 459 | # reorder by weight only when f(a + b) == f(b + a) |
|
460 | 460 | ts = [wt[1] for wt in sorted(zip(ws, ts), key=lambda wt: wt[0])] |
|
461 | 461 | return max(ws), (op, ('list',) + tuple(ts), order) |
|
462 | 462 | elif op == 'not': |
|
463 | 463 | # Optimize not public() to _notpublic() because we have a fast version |
|
464 | 464 | if x[1][:3] == ('func', ('symbol', 'public'), None): |
|
465 | 465 | order = x[1][3] |
|
466 | 466 | newsym = ('func', ('symbol', '_notpublic'), None, order) |
|
467 | 467 | o = _optimize(newsym, not small) |
|
468 | 468 | return o[0], o[1] |
|
469 | 469 | else: |
|
470 | 470 | o = _optimize(x[1], not small) |
|
471 | 471 | order = x[2] |
|
472 | 472 | return o[0], (op, o[1], order) |
|
473 | 473 | elif op == 'rangeall': |
|
474 | 474 | return smallbonus, x |
|
475 | 475 | elif op in ('rangepre', 'rangepost', 'parentpost'): |
|
476 | 476 | o = _optimize(x[1], small) |
|
477 | 477 | order = x[2] |
|
478 | 478 | return o[0], (op, o[1], order) |
|
479 | 479 | elif op in ('dagrange', 'range', 'parent', 'ancestor'): |
|
480 | 480 | wa, ta = _optimize(x[1], small) |
|
481 | 481 | wb, tb = _optimize(x[2], small) |
|
482 | 482 | order = x[3] |
|
483 | 483 | return wa + wb, (op, ta, tb, order) |
|
484 | 484 | elif op == 'list': |
|
485 | 485 | ws, ts = zip(*(_optimize(y, small) for y in x[1:])) |
|
486 | 486 | return sum(ws), (op,) + ts |
|
487 | 487 | elif op == 'keyvalue': |
|
488 | 488 | w, t = _optimize(x[2], small) |
|
489 | 489 | return w, (op, x[1], t) |
|
490 | 490 | elif op == 'func': |
|
491 | 491 | f = getsymbol(x[1]) |
|
492 | 492 | wa, ta = _optimize(x[2], small) |
|
493 | 493 | if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep', |
|
494 | 494 | 'keyword', 'outgoing', 'user', 'destination'): |
|
495 | 495 | w = 10 # slow |
|
496 | 496 | elif f in ('modifies', 'adds', 'removes'): |
|
497 | 497 | w = 30 # slower |
|
498 | 498 | elif f == "contains": |
|
499 | 499 | w = 100 # very slow |
|
500 | 500 | elif f == "ancestor": |
|
501 | 501 | w = 1 * smallbonus |
|
502 | 502 | elif f in ('reverse', 'limit', 'first', 'wdir', '_intlist'): |
|
503 | 503 | w = 0 |
|
504 | 504 | elif f == "sort": |
|
505 | 505 | w = 10 # assume most sorts look at changelog |
|
506 | 506 | else: |
|
507 | 507 | w = 1 |
|
508 | 508 | order = x[3] |
|
509 | 509 | return w + wa, (op, x[1], ta, order) |
|
510 | 510 | raise ValueError('invalid operator %r' % op) |
|
511 | 511 | |
|
512 | 512 | def optimize(tree): |
|
513 | 513 | """Optimize evaluatable tree |
|
514 | 514 | |
|
515 | 515 | All pseudo operations should be transformed beforehand. |
|
516 | 516 | """ |
|
517 | 517 | _weight, newtree = _optimize(tree, small=True) |
|
518 | 518 | return newtree |
|
519 | 519 | |
|
520 | 520 | # the set of valid characters for the initial letter of symbols in |
|
521 | 521 | # alias declarations and definitions |
|
522 | 522 | _aliassyminitletters = _syminitletters | set(pycompat.sysstr('$')) |
|
523 | 523 | |
|
524 | 524 | def _parsewith(spec, lookup=None, syminitletters=None): |
|
525 | 525 | """Generate a parse tree of given spec with given tokenizing options |
|
526 | 526 | |
|
527 | 527 | >>> _parsewith('foo($1)', syminitletters=_aliassyminitletters) |
|
528 | 528 | ('func', ('symbol', 'foo'), ('symbol', '$1')) |
|
529 | 529 | >>> _parsewith('$1') |
|
530 | 530 | Traceback (most recent call last): |
|
531 | 531 | ... |
|
532 | 532 | ParseError: ("syntax error in revset '$1'", 0) |
|
533 | 533 | >>> _parsewith('foo bar') |
|
534 | 534 | Traceback (most recent call last): |
|
535 | 535 | ... |
|
536 | 536 | ParseError: ('invalid token', 4) |
|
537 | 537 | """ |
|
538 | 538 | p = parser.parser(elements) |
|
539 | 539 | tree, pos = p.parse(tokenize(spec, lookup=lookup, |
|
540 | 540 | syminitletters=syminitletters)) |
|
541 | 541 | if pos != len(spec): |
|
542 | 542 | raise error.ParseError(_('invalid token'), pos) |
|
543 | 543 | return _fixops(parser.simplifyinfixops(tree, ('list', 'or'))) |
|
544 | 544 | |
|
545 | 545 | class _aliasrules(parser.basealiasrules): |
|
546 | 546 | """Parsing and expansion rule set of revset aliases""" |
|
547 | 547 | _section = _('revset alias') |
|
548 | 548 | |
|
549 | 549 | @staticmethod |
|
550 | 550 | def _parse(spec): |
|
551 | 551 | """Parse alias declaration/definition ``spec`` |
|
552 | 552 | |
|
553 | 553 | This allows symbol names to use also ``$`` as an initial letter |
|
554 | 554 | (for backward compatibility), and callers of this function should |
|
555 | 555 | examine whether ``$`` is used also for unexpected symbols or not. |
|
556 | 556 | """ |
|
557 | 557 | return _parsewith(spec, syminitletters=_aliassyminitletters) |
|
558 | 558 | |
|
559 | 559 | @staticmethod |
|
560 | 560 | def _trygetfunc(tree): |
|
561 | 561 | if tree[0] == 'func' and tree[1][0] == 'symbol': |
|
562 | 562 | return tree[1][1], getlist(tree[2]) |
|
563 | 563 | |
|
564 |
def expandaliases( |
|
|
565 | aliases = _aliasrules.buildmap(ui.configitems('revsetalias')) | |
|
564 | def expandaliases(tree, aliases, warn=None): | |
|
565 | """Expand aliases in a tree, aliases is a list of (name, value) tuples""" | |
|
566 | aliases = _aliasrules.buildmap(aliases) | |
|
566 | 567 | tree = _aliasrules.expand(aliases, tree) |
|
567 | 568 | # warn about problematic (but not referred) aliases |
|
569 | if warn is not None: | |
|
568 | 570 | for name, alias in sorted(aliases.iteritems()): |
|
569 | 571 | if alias.error and not alias.warned: |
|
570 |
|
|
|
572 | warn(_('warning: %s\n') % (alias.error)) | |
|
571 | 573 | alias.warned = True |
|
572 | 574 | return tree |
|
573 | 575 | |
|
574 | 576 | def foldconcat(tree): |
|
575 | 577 | """Fold elements to be concatenated by `##` |
|
576 | 578 | """ |
|
577 | 579 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
578 | 580 | return tree |
|
579 | 581 | if tree[0] == '_concat': |
|
580 | 582 | pending = [tree] |
|
581 | 583 | l = [] |
|
582 | 584 | while pending: |
|
583 | 585 | e = pending.pop() |
|
584 | 586 | if e[0] == '_concat': |
|
585 | 587 | pending.extend(reversed(e[1:])) |
|
586 | 588 | elif e[0] in ('string', 'symbol'): |
|
587 | 589 | l.append(e[1]) |
|
588 | 590 | else: |
|
589 | 591 | msg = _("\"##\" can't concatenate \"%s\" element") % (e[0]) |
|
590 | 592 | raise error.ParseError(msg) |
|
591 | 593 | return ('string', ''.join(l)) |
|
592 | 594 | else: |
|
593 | 595 | return tuple(foldconcat(t) for t in tree) |
|
594 | 596 | |
|
595 | 597 | def parse(spec, lookup=None): |
|
596 | 598 | return _parsewith(spec, lookup=lookup) |
|
597 | 599 | |
|
598 | 600 | def _quote(s): |
|
599 | 601 | r"""Quote a value in order to make it safe for the revset engine. |
|
600 | 602 | |
|
601 | 603 | >>> _quote('asdf') |
|
602 | 604 | "'asdf'" |
|
603 | 605 | >>> _quote("asdf'\"") |
|
604 | 606 | '\'asdf\\\'"\'' |
|
605 | 607 | >>> _quote('asdf\'') |
|
606 | 608 | "'asdf\\''" |
|
607 | 609 | >>> _quote(1) |
|
608 | 610 | "'1'" |
|
609 | 611 | """ |
|
610 | 612 | return "'%s'" % util.escapestr(pycompat.bytestr(s)) |
|
611 | 613 | |
|
612 | 614 | def formatspec(expr, *args): |
|
613 | 615 | ''' |
|
614 | 616 | This is a convenience function for using revsets internally, and |
|
615 | 617 | escapes arguments appropriately. Aliases are intentionally ignored |
|
616 | 618 | so that intended expression behavior isn't accidentally subverted. |
|
617 | 619 | |
|
618 | 620 | Supported arguments: |
|
619 | 621 | |
|
620 | 622 | %r = revset expression, parenthesized |
|
621 | 623 | %d = int(arg), no quoting |
|
622 | 624 | %s = string(arg), escaped and single-quoted |
|
623 | 625 | %b = arg.branch(), escaped and single-quoted |
|
624 | 626 | %n = hex(arg), single-quoted |
|
625 | 627 | %% = a literal '%' |
|
626 | 628 | |
|
627 | 629 | Prefixing the type with 'l' specifies a parenthesized list of that type. |
|
628 | 630 | |
|
629 | 631 | >>> formatspec('%r:: and %lr', '10 or 11', ("this()", "that()")) |
|
630 | 632 | '(10 or 11):: and ((this()) or (that()))' |
|
631 | 633 | >>> formatspec('%d:: and not %d::', 10, 20) |
|
632 | 634 | '10:: and not 20::' |
|
633 | 635 | >>> formatspec('%ld or %ld', [], [1]) |
|
634 | 636 | "_list('') or 1" |
|
635 | 637 | >>> formatspec('keyword(%s)', 'foo\\xe9') |
|
636 | 638 | "keyword('foo\\\\xe9')" |
|
637 | 639 | >>> b = lambda: 'default' |
|
638 | 640 | >>> b.branch = b |
|
639 | 641 | >>> formatspec('branch(%b)', b) |
|
640 | 642 | "branch('default')" |
|
641 | 643 | >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) |
|
642 | 644 | "root(_list('a\\x00b\\x00c\\x00d'))" |
|
643 | 645 | ''' |
|
644 | 646 | |
|
645 | 647 | def argtype(c, arg): |
|
646 | 648 | if c == 'd': |
|
647 | 649 | return '%d' % int(arg) |
|
648 | 650 | elif c == 's': |
|
649 | 651 | return _quote(arg) |
|
650 | 652 | elif c == 'r': |
|
651 | 653 | parse(arg) # make sure syntax errors are confined |
|
652 | 654 | return '(%s)' % arg |
|
653 | 655 | elif c == 'n': |
|
654 | 656 | return _quote(node.hex(arg)) |
|
655 | 657 | elif c == 'b': |
|
656 | 658 | return _quote(arg.branch()) |
|
657 | 659 | |
|
658 | 660 | def listexp(s, t): |
|
659 | 661 | l = len(s) |
|
660 | 662 | if l == 0: |
|
661 | 663 | return "_list('')" |
|
662 | 664 | elif l == 1: |
|
663 | 665 | return argtype(t, s[0]) |
|
664 | 666 | elif t == 'd': |
|
665 | 667 | return "_intlist('%s')" % "\0".join('%d' % int(a) for a in s) |
|
666 | 668 | elif t == 's': |
|
667 | 669 | return "_list('%s')" % "\0".join(s) |
|
668 | 670 | elif t == 'n': |
|
669 | 671 | return "_hexlist('%s')" % "\0".join(node.hex(a) for a in s) |
|
670 | 672 | elif t == 'b': |
|
671 | 673 | return "_list('%s')" % "\0".join(a.branch() for a in s) |
|
672 | 674 | |
|
673 | 675 | m = l // 2 |
|
674 | 676 | return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t)) |
|
675 | 677 | |
|
676 | 678 | expr = pycompat.bytestr(expr) |
|
677 | 679 | ret = '' |
|
678 | 680 | pos = 0 |
|
679 | 681 | arg = 0 |
|
680 | 682 | while pos < len(expr): |
|
681 | 683 | c = expr[pos] |
|
682 | 684 | if c == '%': |
|
683 | 685 | pos += 1 |
|
684 | 686 | d = expr[pos] |
|
685 | 687 | if d == '%': |
|
686 | 688 | ret += d |
|
687 | 689 | elif d in 'dsnbr': |
|
688 | 690 | ret += argtype(d, args[arg]) |
|
689 | 691 | arg += 1 |
|
690 | 692 | elif d == 'l': |
|
691 | 693 | # a list of some type |
|
692 | 694 | pos += 1 |
|
693 | 695 | d = expr[pos] |
|
694 | 696 | ret += listexp(list(args[arg]), d) |
|
695 | 697 | arg += 1 |
|
696 | 698 | else: |
|
697 | 699 | raise error.Abort(_('unexpected revspec format character %s') |
|
698 | 700 | % d) |
|
699 | 701 | else: |
|
700 | 702 | ret += c |
|
701 | 703 | pos += 1 |
|
702 | 704 | |
|
703 | 705 | return ret |
|
704 | 706 | |
|
705 | 707 | def prettyformat(tree): |
|
706 | 708 | return parser.prettyformat(tree, ('string', 'symbol')) |
|
707 | 709 | |
|
708 | 710 | def depth(tree): |
|
709 | 711 | if isinstance(tree, tuple): |
|
710 | 712 | return max(map(depth, tree)) + 1 |
|
711 | 713 | else: |
|
712 | 714 | return 0 |
|
713 | 715 | |
|
714 | 716 | def funcsused(tree): |
|
715 | 717 | if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): |
|
716 | 718 | return set() |
|
717 | 719 | else: |
|
718 | 720 | funcs = set() |
|
719 | 721 | for s in tree[1:]: |
|
720 | 722 | funcs |= funcsused(s) |
|
721 | 723 | if tree[0] == 'func': |
|
722 | 724 | funcs.add(tree[1][1]) |
|
723 | 725 | return funcs |
@@ -1,4262 +1,4285 b'' | |||
|
1 | 1 | $ HGENCODING=utf-8 |
|
2 | 2 | $ export HGENCODING |
|
3 | 3 | $ cat > testrevset.py << EOF |
|
4 | 4 | > import mercurial.revset |
|
5 | 5 | > |
|
6 | 6 | > baseset = mercurial.revset.baseset |
|
7 | 7 | > |
|
8 | 8 | > def r3232(repo, subset, x): |
|
9 | 9 | > """"simple revset that return [3,2,3,2] |
|
10 | 10 | > |
|
11 | 11 | > revisions duplicated on purpose. |
|
12 | 12 | > """ |
|
13 | 13 | > if 3 not in subset: |
|
14 | 14 | > if 2 in subset: |
|
15 | 15 | > return baseset([2,2]) |
|
16 | 16 | > return baseset() |
|
17 | 17 | > return baseset([3,3,2,2]) |
|
18 | 18 | > |
|
19 | 19 | > mercurial.revset.symbols['r3232'] = r3232 |
|
20 | 20 | > EOF |
|
21 | 21 | $ cat >> $HGRCPATH << EOF |
|
22 | 22 | > [extensions] |
|
23 | 23 | > testrevset=$TESTTMP/testrevset.py |
|
24 | 24 | > EOF |
|
25 | 25 | |
|
26 | 26 | $ try() { |
|
27 | 27 | > hg debugrevspec --debug "$@" |
|
28 | 28 | > } |
|
29 | 29 | |
|
30 | 30 | $ log() { |
|
31 | 31 | > hg log --template '{rev}\n' -r "$1" |
|
32 | 32 | > } |
|
33 | 33 | |
|
34 | 34 | extension to build '_intlist()' and '_hexlist()', which is necessary because |
|
35 | 35 | these predicates use '\0' as a separator: |
|
36 | 36 | |
|
37 | 37 | $ cat <<EOF > debugrevlistspec.py |
|
38 | 38 | > from __future__ import absolute_import |
|
39 | 39 | > from mercurial import ( |
|
40 | 40 | > node as nodemod, |
|
41 | 41 | > registrar, |
|
42 | 42 | > revset, |
|
43 | 43 | > revsetlang, |
|
44 | 44 | > smartset, |
|
45 | 45 | > ) |
|
46 | 46 | > cmdtable = {} |
|
47 | 47 | > command = registrar.command(cmdtable) |
|
48 | 48 | > @command(b'debugrevlistspec', |
|
49 | 49 | > [('', 'optimize', None, 'print parsed tree after optimizing'), |
|
50 | 50 | > ('', 'bin', None, 'unhexlify arguments')]) |
|
51 | 51 | > def debugrevlistspec(ui, repo, fmt, *args, **opts): |
|
52 | 52 | > if opts['bin']: |
|
53 | 53 | > args = map(nodemod.bin, args) |
|
54 | 54 | > expr = revsetlang.formatspec(fmt, list(args)) |
|
55 | 55 | > if ui.verbose: |
|
56 | 56 | > tree = revsetlang.parse(expr, lookup=repo.__contains__) |
|
57 | 57 | > ui.note(revsetlang.prettyformat(tree), "\n") |
|
58 | 58 | > if opts["optimize"]: |
|
59 | 59 | > opttree = revsetlang.optimize(revsetlang.analyze(tree)) |
|
60 | 60 | > ui.note("* optimized:\n", revsetlang.prettyformat(opttree), |
|
61 | 61 | > "\n") |
|
62 | 62 | > func = revset.match(ui, expr, repo) |
|
63 | 63 | > revs = func(repo) |
|
64 | 64 | > if ui.verbose: |
|
65 | 65 | > ui.note("* set:\n", smartset.prettyformat(revs), "\n") |
|
66 | 66 | > for c in revs: |
|
67 | 67 | > ui.write("%s\n" % c) |
|
68 | 68 | > EOF |
|
69 | 69 | $ cat <<EOF >> $HGRCPATH |
|
70 | 70 | > [extensions] |
|
71 | 71 | > debugrevlistspec = $TESTTMP/debugrevlistspec.py |
|
72 | 72 | > EOF |
|
73 | 73 | $ trylist() { |
|
74 | 74 | > hg debugrevlistspec --debug "$@" |
|
75 | 75 | > } |
|
76 | 76 | |
|
77 | 77 | $ hg init repo |
|
78 | 78 | $ cd repo |
|
79 | 79 | |
|
80 | 80 | $ echo a > a |
|
81 | 81 | $ hg branch a |
|
82 | 82 | marked working directory as branch a |
|
83 | 83 | (branches are permanent and global, did you want a bookmark?) |
|
84 | 84 | $ hg ci -Aqm0 |
|
85 | 85 | |
|
86 | 86 | $ echo b > b |
|
87 | 87 | $ hg branch b |
|
88 | 88 | marked working directory as branch b |
|
89 | 89 | $ hg ci -Aqm1 |
|
90 | 90 | |
|
91 | 91 | $ rm a |
|
92 | 92 | $ hg branch a-b-c- |
|
93 | 93 | marked working directory as branch a-b-c- |
|
94 | 94 | $ hg ci -Aqm2 -u Bob |
|
95 | 95 | |
|
96 | 96 | $ hg log -r "extra('branch', 'a-b-c-')" --template '{rev}\n' |
|
97 | 97 | 2 |
|
98 | 98 | $ hg log -r "extra('branch')" --template '{rev}\n' |
|
99 | 99 | 0 |
|
100 | 100 | 1 |
|
101 | 101 | 2 |
|
102 | 102 | $ hg log -r "extra('branch', 're:a')" --template '{rev} {branch}\n' |
|
103 | 103 | 0 a |
|
104 | 104 | 2 a-b-c- |
|
105 | 105 | |
|
106 | 106 | $ hg co 1 |
|
107 | 107 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
108 | 108 | $ hg branch +a+b+c+ |
|
109 | 109 | marked working directory as branch +a+b+c+ |
|
110 | 110 | $ hg ci -Aqm3 |
|
111 | 111 | |
|
112 | 112 | $ hg co 2 # interleave |
|
113 | 113 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
114 | 114 | $ echo bb > b |
|
115 | 115 | $ hg branch -- -a-b-c- |
|
116 | 116 | marked working directory as branch -a-b-c- |
|
117 | 117 | $ hg ci -Aqm4 -d "May 12 2005" |
|
118 | 118 | |
|
119 | 119 | $ hg co 3 |
|
120 | 120 | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
121 | 121 | $ hg branch !a/b/c/ |
|
122 | 122 | marked working directory as branch !a/b/c/ |
|
123 | 123 | $ hg ci -Aqm"5 bug" |
|
124 | 124 | |
|
125 | 125 | $ hg merge 4 |
|
126 | 126 | 1 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
127 | 127 | (branch merge, don't forget to commit) |
|
128 | 128 | $ hg branch _a_b_c_ |
|
129 | 129 | marked working directory as branch _a_b_c_ |
|
130 | 130 | $ hg ci -Aqm"6 issue619" |
|
131 | 131 | |
|
132 | 132 | $ hg branch .a.b.c. |
|
133 | 133 | marked working directory as branch .a.b.c. |
|
134 | 134 | $ hg ci -Aqm7 |
|
135 | 135 | |
|
136 | 136 | $ hg branch all |
|
137 | 137 | marked working directory as branch all |
|
138 | 138 | |
|
139 | 139 | $ hg co 4 |
|
140 | 140 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
141 | 141 | $ hg branch Γ© |
|
142 | 142 | marked working directory as branch \xc3\xa9 (esc) |
|
143 | 143 | $ hg ci -Aqm9 |
|
144 | 144 | |
|
145 | 145 | $ hg tag -r6 1.0 |
|
146 | 146 | $ hg bookmark -r6 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
|
147 | 147 | |
|
148 | 148 | $ hg clone --quiet -U -r 7 . ../remote1 |
|
149 | 149 | $ hg clone --quiet -U -r 8 . ../remote2 |
|
150 | 150 | $ echo "[paths]" >> .hg/hgrc |
|
151 | 151 | $ echo "default = ../remote1" >> .hg/hgrc |
|
152 | 152 | |
|
153 | 153 | trivial |
|
154 | 154 | |
|
155 | 155 | $ try 0:1 |
|
156 | 156 | (range |
|
157 | 157 | ('symbol', '0') |
|
158 | 158 | ('symbol', '1')) |
|
159 | 159 | * set: |
|
160 | 160 | <spanset+ 0:2> |
|
161 | 161 | 0 |
|
162 | 162 | 1 |
|
163 | 163 | $ try --optimize : |
|
164 | 164 | (rangeall |
|
165 | 165 | None) |
|
166 | 166 | * optimized: |
|
167 | 167 | (rangeall |
|
168 | 168 | None |
|
169 | 169 | define) |
|
170 | 170 | * set: |
|
171 | 171 | <spanset+ 0:10> |
|
172 | 172 | 0 |
|
173 | 173 | 1 |
|
174 | 174 | 2 |
|
175 | 175 | 3 |
|
176 | 176 | 4 |
|
177 | 177 | 5 |
|
178 | 178 | 6 |
|
179 | 179 | 7 |
|
180 | 180 | 8 |
|
181 | 181 | 9 |
|
182 | 182 | $ try 3::6 |
|
183 | 183 | (dagrange |
|
184 | 184 | ('symbol', '3') |
|
185 | 185 | ('symbol', '6')) |
|
186 | 186 | * set: |
|
187 | 187 | <baseset+ [3, 5, 6]> |
|
188 | 188 | 3 |
|
189 | 189 | 5 |
|
190 | 190 | 6 |
|
191 | 191 | $ try '0|1|2' |
|
192 | 192 | (or |
|
193 | 193 | (list |
|
194 | 194 | ('symbol', '0') |
|
195 | 195 | ('symbol', '1') |
|
196 | 196 | ('symbol', '2'))) |
|
197 | 197 | * set: |
|
198 | 198 | <baseset [0, 1, 2]> |
|
199 | 199 | 0 |
|
200 | 200 | 1 |
|
201 | 201 | 2 |
|
202 | 202 | |
|
203 | 203 | names that should work without quoting |
|
204 | 204 | |
|
205 | 205 | $ try a |
|
206 | 206 | ('symbol', 'a') |
|
207 | 207 | * set: |
|
208 | 208 | <baseset [0]> |
|
209 | 209 | 0 |
|
210 | 210 | $ try b-a |
|
211 | 211 | (minus |
|
212 | 212 | ('symbol', 'b') |
|
213 | 213 | ('symbol', 'a')) |
|
214 | 214 | * set: |
|
215 | 215 | <filteredset |
|
216 | 216 | <baseset [1]>, |
|
217 | 217 | <not |
|
218 | 218 | <baseset [0]>>> |
|
219 | 219 | 1 |
|
220 | 220 | $ try _a_b_c_ |
|
221 | 221 | ('symbol', '_a_b_c_') |
|
222 | 222 | * set: |
|
223 | 223 | <baseset [6]> |
|
224 | 224 | 6 |
|
225 | 225 | $ try _a_b_c_-a |
|
226 | 226 | (minus |
|
227 | 227 | ('symbol', '_a_b_c_') |
|
228 | 228 | ('symbol', 'a')) |
|
229 | 229 | * set: |
|
230 | 230 | <filteredset |
|
231 | 231 | <baseset [6]>, |
|
232 | 232 | <not |
|
233 | 233 | <baseset [0]>>> |
|
234 | 234 | 6 |
|
235 | 235 | $ try .a.b.c. |
|
236 | 236 | ('symbol', '.a.b.c.') |
|
237 | 237 | * set: |
|
238 | 238 | <baseset [7]> |
|
239 | 239 | 7 |
|
240 | 240 | $ try .a.b.c.-a |
|
241 | 241 | (minus |
|
242 | 242 | ('symbol', '.a.b.c.') |
|
243 | 243 | ('symbol', 'a')) |
|
244 | 244 | * set: |
|
245 | 245 | <filteredset |
|
246 | 246 | <baseset [7]>, |
|
247 | 247 | <not |
|
248 | 248 | <baseset [0]>>> |
|
249 | 249 | 7 |
|
250 | 250 | |
|
251 | 251 | names that should be caught by fallback mechanism |
|
252 | 252 | |
|
253 | 253 | $ try -- '-a-b-c-' |
|
254 | 254 | ('symbol', '-a-b-c-') |
|
255 | 255 | * set: |
|
256 | 256 | <baseset [4]> |
|
257 | 257 | 4 |
|
258 | 258 | $ log -a-b-c- |
|
259 | 259 | 4 |
|
260 | 260 | $ try '+a+b+c+' |
|
261 | 261 | ('symbol', '+a+b+c+') |
|
262 | 262 | * set: |
|
263 | 263 | <baseset [3]> |
|
264 | 264 | 3 |
|
265 | 265 | $ try '+a+b+c+:' |
|
266 | 266 | (rangepost |
|
267 | 267 | ('symbol', '+a+b+c+')) |
|
268 | 268 | * set: |
|
269 | 269 | <spanset+ 3:10> |
|
270 | 270 | 3 |
|
271 | 271 | 4 |
|
272 | 272 | 5 |
|
273 | 273 | 6 |
|
274 | 274 | 7 |
|
275 | 275 | 8 |
|
276 | 276 | 9 |
|
277 | 277 | $ try ':+a+b+c+' |
|
278 | 278 | (rangepre |
|
279 | 279 | ('symbol', '+a+b+c+')) |
|
280 | 280 | * set: |
|
281 | 281 | <spanset+ 0:4> |
|
282 | 282 | 0 |
|
283 | 283 | 1 |
|
284 | 284 | 2 |
|
285 | 285 | 3 |
|
286 | 286 | $ try -- '-a-b-c-:+a+b+c+' |
|
287 | 287 | (range |
|
288 | 288 | ('symbol', '-a-b-c-') |
|
289 | 289 | ('symbol', '+a+b+c+')) |
|
290 | 290 | * set: |
|
291 | 291 | <spanset- 3:5> |
|
292 | 292 | 4 |
|
293 | 293 | 3 |
|
294 | 294 | $ log '-a-b-c-:+a+b+c+' |
|
295 | 295 | 4 |
|
296 | 296 | 3 |
|
297 | 297 | |
|
298 | 298 | $ try -- -a-b-c--a # complains |
|
299 | 299 | (minus |
|
300 | 300 | (minus |
|
301 | 301 | (minus |
|
302 | 302 | (negate |
|
303 | 303 | ('symbol', 'a')) |
|
304 | 304 | ('symbol', 'b')) |
|
305 | 305 | ('symbol', 'c')) |
|
306 | 306 | (negate |
|
307 | 307 | ('symbol', 'a'))) |
|
308 | 308 | abort: unknown revision '-a'! |
|
309 | 309 | [255] |
|
310 | 310 | $ try Γ© |
|
311 | 311 | ('symbol', '\xc3\xa9') |
|
312 | 312 | * set: |
|
313 | 313 | <baseset [9]> |
|
314 | 314 | 9 |
|
315 | 315 | |
|
316 | 316 | no quoting needed |
|
317 | 317 | |
|
318 | 318 | $ log ::a-b-c- |
|
319 | 319 | 0 |
|
320 | 320 | 1 |
|
321 | 321 | 2 |
|
322 | 322 | |
|
323 | 323 | quoting needed |
|
324 | 324 | |
|
325 | 325 | $ try '"-a-b-c-"-a' |
|
326 | 326 | (minus |
|
327 | 327 | ('string', '-a-b-c-') |
|
328 | 328 | ('symbol', 'a')) |
|
329 | 329 | * set: |
|
330 | 330 | <filteredset |
|
331 | 331 | <baseset [4]>, |
|
332 | 332 | <not |
|
333 | 333 | <baseset [0]>>> |
|
334 | 334 | 4 |
|
335 | 335 | |
|
336 | 336 | $ log '1 or 2' |
|
337 | 337 | 1 |
|
338 | 338 | 2 |
|
339 | 339 | $ log '1|2' |
|
340 | 340 | 1 |
|
341 | 341 | 2 |
|
342 | 342 | $ log '1 and 2' |
|
343 | 343 | $ log '1&2' |
|
344 | 344 | $ try '1&2|3' # precedence - and is higher |
|
345 | 345 | (or |
|
346 | 346 | (list |
|
347 | 347 | (and |
|
348 | 348 | ('symbol', '1') |
|
349 | 349 | ('symbol', '2')) |
|
350 | 350 | ('symbol', '3'))) |
|
351 | 351 | * set: |
|
352 | 352 | <addset |
|
353 | 353 | <baseset []>, |
|
354 | 354 | <baseset [3]>> |
|
355 | 355 | 3 |
|
356 | 356 | $ try '1|2&3' |
|
357 | 357 | (or |
|
358 | 358 | (list |
|
359 | 359 | ('symbol', '1') |
|
360 | 360 | (and |
|
361 | 361 | ('symbol', '2') |
|
362 | 362 | ('symbol', '3')))) |
|
363 | 363 | * set: |
|
364 | 364 | <addset |
|
365 | 365 | <baseset [1]>, |
|
366 | 366 | <baseset []>> |
|
367 | 367 | 1 |
|
368 | 368 | $ try '1&2&3' # associativity |
|
369 | 369 | (and |
|
370 | 370 | (and |
|
371 | 371 | ('symbol', '1') |
|
372 | 372 | ('symbol', '2')) |
|
373 | 373 | ('symbol', '3')) |
|
374 | 374 | * set: |
|
375 | 375 | <baseset []> |
|
376 | 376 | $ try '1|(2|3)' |
|
377 | 377 | (or |
|
378 | 378 | (list |
|
379 | 379 | ('symbol', '1') |
|
380 | 380 | (group |
|
381 | 381 | (or |
|
382 | 382 | (list |
|
383 | 383 | ('symbol', '2') |
|
384 | 384 | ('symbol', '3')))))) |
|
385 | 385 | * set: |
|
386 | 386 | <addset |
|
387 | 387 | <baseset [1]>, |
|
388 | 388 | <baseset [2, 3]>> |
|
389 | 389 | 1 |
|
390 | 390 | 2 |
|
391 | 391 | 3 |
|
392 | 392 | $ log '1.0' # tag |
|
393 | 393 | 6 |
|
394 | 394 | $ log 'a' # branch |
|
395 | 395 | 0 |
|
396 | 396 | $ log '2785f51ee' |
|
397 | 397 | 0 |
|
398 | 398 | $ log 'date(2005)' |
|
399 | 399 | 4 |
|
400 | 400 | $ log 'date(this is a test)' |
|
401 | 401 | hg: parse error at 10: unexpected token: symbol |
|
402 | 402 | [255] |
|
403 | 403 | $ log 'date()' |
|
404 | 404 | hg: parse error: date requires a string |
|
405 | 405 | [255] |
|
406 | 406 | $ log 'date' |
|
407 | 407 | abort: unknown revision 'date'! |
|
408 | 408 | [255] |
|
409 | 409 | $ log 'date(' |
|
410 | 410 | hg: parse error at 5: not a prefix: end |
|
411 | 411 | [255] |
|
412 | 412 | $ log 'date("\xy")' |
|
413 | 413 | hg: parse error: invalid \x escape |
|
414 | 414 | [255] |
|
415 | 415 | $ log 'date(tip)' |
|
416 | 416 | hg: parse error: invalid date: 'tip' |
|
417 | 417 | [255] |
|
418 | 418 | $ log '0:date' |
|
419 | 419 | abort: unknown revision 'date'! |
|
420 | 420 | [255] |
|
421 | 421 | $ log '::"date"' |
|
422 | 422 | abort: unknown revision 'date'! |
|
423 | 423 | [255] |
|
424 | 424 | $ hg book date -r 4 |
|
425 | 425 | $ log '0:date' |
|
426 | 426 | 0 |
|
427 | 427 | 1 |
|
428 | 428 | 2 |
|
429 | 429 | 3 |
|
430 | 430 | 4 |
|
431 | 431 | $ log '::date' |
|
432 | 432 | 0 |
|
433 | 433 | 1 |
|
434 | 434 | 2 |
|
435 | 435 | 4 |
|
436 | 436 | $ log '::"date"' |
|
437 | 437 | 0 |
|
438 | 438 | 1 |
|
439 | 439 | 2 |
|
440 | 440 | 4 |
|
441 | 441 | $ log 'date(2005) and 1::' |
|
442 | 442 | 4 |
|
443 | 443 | $ hg book -d date |
|
444 | 444 | |
|
445 | 445 | function name should be a symbol |
|
446 | 446 | |
|
447 | 447 | $ log '"date"(2005)' |
|
448 | 448 | hg: parse error: not a symbol |
|
449 | 449 | [255] |
|
450 | 450 | |
|
451 | 451 | keyword arguments |
|
452 | 452 | |
|
453 | 453 | $ log 'extra(branch, value=a)' |
|
454 | 454 | 0 |
|
455 | 455 | |
|
456 | 456 | $ log 'extra(branch, a, b)' |
|
457 | 457 | hg: parse error: extra takes at most 2 positional arguments |
|
458 | 458 | [255] |
|
459 | 459 | $ log 'extra(a, label=b)' |
|
460 | 460 | hg: parse error: extra got multiple values for keyword argument 'label' |
|
461 | 461 | [255] |
|
462 | 462 | $ log 'extra(label=branch, default)' |
|
463 | 463 | hg: parse error: extra got an invalid argument |
|
464 | 464 | [255] |
|
465 | 465 | $ log 'extra(branch, foo+bar=baz)' |
|
466 | 466 | hg: parse error: extra got an invalid argument |
|
467 | 467 | [255] |
|
468 | 468 | $ log 'extra(unknown=branch)' |
|
469 | 469 | hg: parse error: extra got an unexpected keyword argument 'unknown' |
|
470 | 470 | [255] |
|
471 | 471 | |
|
472 | 472 | $ try 'foo=bar|baz' |
|
473 | 473 | (keyvalue |
|
474 | 474 | ('symbol', 'foo') |
|
475 | 475 | (or |
|
476 | 476 | (list |
|
477 | 477 | ('symbol', 'bar') |
|
478 | 478 | ('symbol', 'baz')))) |
|
479 | 479 | hg: parse error: can't use a key-value pair in this context |
|
480 | 480 | [255] |
|
481 | 481 | |
|
482 | 482 | right-hand side should be optimized recursively |
|
483 | 483 | |
|
484 | 484 | $ try --optimize 'foo=(not public())' |
|
485 | 485 | (keyvalue |
|
486 | 486 | ('symbol', 'foo') |
|
487 | 487 | (group |
|
488 | 488 | (not |
|
489 | 489 | (func |
|
490 | 490 | ('symbol', 'public') |
|
491 | 491 | None)))) |
|
492 | 492 | * optimized: |
|
493 | 493 | (keyvalue |
|
494 | 494 | ('symbol', 'foo') |
|
495 | 495 | (func |
|
496 | 496 | ('symbol', '_notpublic') |
|
497 | 497 | None |
|
498 | 498 | any)) |
|
499 | 499 | hg: parse error: can't use a key-value pair in this context |
|
500 | 500 | [255] |
|
501 | 501 | |
|
502 | 502 | parsed tree at stages: |
|
503 | 503 | |
|
504 | 504 | $ hg debugrevspec -p all '()' |
|
505 | 505 | * parsed: |
|
506 | 506 | (group |
|
507 | 507 | None) |
|
508 | 508 | * expanded: |
|
509 | 509 | (group |
|
510 | 510 | None) |
|
511 | 511 | * concatenated: |
|
512 | 512 | (group |
|
513 | 513 | None) |
|
514 | 514 | * analyzed: |
|
515 | 515 | None |
|
516 | 516 | * optimized: |
|
517 | 517 | None |
|
518 | 518 | hg: parse error: missing argument |
|
519 | 519 | [255] |
|
520 | 520 | |
|
521 | 521 | $ hg debugrevspec --no-optimized -p all '()' |
|
522 | 522 | * parsed: |
|
523 | 523 | (group |
|
524 | 524 | None) |
|
525 | 525 | * expanded: |
|
526 | 526 | (group |
|
527 | 527 | None) |
|
528 | 528 | * concatenated: |
|
529 | 529 | (group |
|
530 | 530 | None) |
|
531 | 531 | * analyzed: |
|
532 | 532 | None |
|
533 | 533 | hg: parse error: missing argument |
|
534 | 534 | [255] |
|
535 | 535 | |
|
536 | 536 | $ hg debugrevspec -p parsed -p analyzed -p optimized '(0|1)-1' |
|
537 | 537 | * parsed: |
|
538 | 538 | (minus |
|
539 | 539 | (group |
|
540 | 540 | (or |
|
541 | 541 | (list |
|
542 | 542 | ('symbol', '0') |
|
543 | 543 | ('symbol', '1')))) |
|
544 | 544 | ('symbol', '1')) |
|
545 | 545 | * analyzed: |
|
546 | 546 | (and |
|
547 | 547 | (or |
|
548 | 548 | (list |
|
549 | 549 | ('symbol', '0') |
|
550 | 550 | ('symbol', '1')) |
|
551 | 551 | define) |
|
552 | 552 | (not |
|
553 | 553 | ('symbol', '1') |
|
554 | 554 | follow) |
|
555 | 555 | define) |
|
556 | 556 | * optimized: |
|
557 | 557 | (difference |
|
558 | 558 | (func |
|
559 | 559 | ('symbol', '_list') |
|
560 | 560 | ('string', '0\x001') |
|
561 | 561 | define) |
|
562 | 562 | ('symbol', '1') |
|
563 | 563 | define) |
|
564 | 564 | 0 |
|
565 | 565 | |
|
566 | 566 | $ hg debugrevspec -p unknown '0' |
|
567 | 567 | abort: invalid stage name: unknown |
|
568 | 568 | [255] |
|
569 | 569 | |
|
570 | 570 | $ hg debugrevspec -p all --optimize '0' |
|
571 | 571 | abort: cannot use --optimize with --show-stage |
|
572 | 572 | [255] |
|
573 | 573 | |
|
574 | 574 | verify optimized tree: |
|
575 | 575 | |
|
576 | 576 | $ hg debugrevspec --verify '0|1' |
|
577 | 577 | |
|
578 | 578 | $ hg debugrevspec --verify -v -p analyzed -p optimized 'r3232() & 2' |
|
579 | 579 | * analyzed: |
|
580 | 580 | (and |
|
581 | 581 | (func |
|
582 | 582 | ('symbol', 'r3232') |
|
583 | 583 | None |
|
584 | 584 | define) |
|
585 | 585 | ('symbol', '2') |
|
586 | 586 | define) |
|
587 | 587 | * optimized: |
|
588 | 588 | (and |
|
589 | 589 | ('symbol', '2') |
|
590 | 590 | (func |
|
591 | 591 | ('symbol', 'r3232') |
|
592 | 592 | None |
|
593 | 593 | define) |
|
594 | 594 | define) |
|
595 | 595 | * analyzed set: |
|
596 | 596 | <baseset [2]> |
|
597 | 597 | * optimized set: |
|
598 | 598 | <baseset [2, 2]> |
|
599 | 599 | --- analyzed |
|
600 | 600 | +++ optimized |
|
601 | 601 | 2 |
|
602 | 602 | +2 |
|
603 | 603 | [1] |
|
604 | 604 | |
|
605 | 605 | $ hg debugrevspec --no-optimized --verify-optimized '0' |
|
606 | 606 | abort: cannot use --verify-optimized with --no-optimized |
|
607 | 607 | [255] |
|
608 | 608 | |
|
609 | 609 | Test that symbols only get parsed as functions if there's an opening |
|
610 | 610 | parenthesis. |
|
611 | 611 | |
|
612 | 612 | $ hg book only -r 9 |
|
613 | 613 | $ log 'only(only)' # Outer "only" is a function, inner "only" is the bookmark |
|
614 | 614 | 8 |
|
615 | 615 | 9 |
|
616 | 616 | |
|
617 | 617 | ':y' behaves like '0:y', but can't be rewritten as such since the revision '0' |
|
618 | 618 | may be hidden (issue5385) |
|
619 | 619 | |
|
620 | 620 | $ try -p parsed -p analyzed ':' |
|
621 | 621 | * parsed: |
|
622 | 622 | (rangeall |
|
623 | 623 | None) |
|
624 | 624 | * analyzed: |
|
625 | 625 | (rangeall |
|
626 | 626 | None |
|
627 | 627 | define) |
|
628 | 628 | * set: |
|
629 | 629 | <spanset+ 0:10> |
|
630 | 630 | 0 |
|
631 | 631 | 1 |
|
632 | 632 | 2 |
|
633 | 633 | 3 |
|
634 | 634 | 4 |
|
635 | 635 | 5 |
|
636 | 636 | 6 |
|
637 | 637 | 7 |
|
638 | 638 | 8 |
|
639 | 639 | 9 |
|
640 | 640 | $ try -p analyzed ':1' |
|
641 | 641 | * analyzed: |
|
642 | 642 | (rangepre |
|
643 | 643 | ('symbol', '1') |
|
644 | 644 | define) |
|
645 | 645 | * set: |
|
646 | 646 | <spanset+ 0:2> |
|
647 | 647 | 0 |
|
648 | 648 | 1 |
|
649 | 649 | $ try -p analyzed ':(1|2)' |
|
650 | 650 | * analyzed: |
|
651 | 651 | (rangepre |
|
652 | 652 | (or |
|
653 | 653 | (list |
|
654 | 654 | ('symbol', '1') |
|
655 | 655 | ('symbol', '2')) |
|
656 | 656 | define) |
|
657 | 657 | define) |
|
658 | 658 | * set: |
|
659 | 659 | <spanset+ 0:3> |
|
660 | 660 | 0 |
|
661 | 661 | 1 |
|
662 | 662 | 2 |
|
663 | 663 | $ try -p analyzed ':(1&2)' |
|
664 | 664 | * analyzed: |
|
665 | 665 | (rangepre |
|
666 | 666 | (and |
|
667 | 667 | ('symbol', '1') |
|
668 | 668 | ('symbol', '2') |
|
669 | 669 | define) |
|
670 | 670 | define) |
|
671 | 671 | * set: |
|
672 | 672 | <baseset []> |
|
673 | 673 | |
|
674 | 674 | infix/suffix resolution of ^ operator (issue2884): |
|
675 | 675 | |
|
676 | 676 | x^:y means (x^):y |
|
677 | 677 | |
|
678 | 678 | $ try '1^:2' |
|
679 | 679 | (range |
|
680 | 680 | (parentpost |
|
681 | 681 | ('symbol', '1')) |
|
682 | 682 | ('symbol', '2')) |
|
683 | 683 | * set: |
|
684 | 684 | <spanset+ 0:3> |
|
685 | 685 | 0 |
|
686 | 686 | 1 |
|
687 | 687 | 2 |
|
688 | 688 | |
|
689 | 689 | $ try '1^::2' |
|
690 | 690 | (dagrange |
|
691 | 691 | (parentpost |
|
692 | 692 | ('symbol', '1')) |
|
693 | 693 | ('symbol', '2')) |
|
694 | 694 | * set: |
|
695 | 695 | <baseset+ [0, 1, 2]> |
|
696 | 696 | 0 |
|
697 | 697 | 1 |
|
698 | 698 | 2 |
|
699 | 699 | |
|
700 | 700 | $ try '9^:' |
|
701 | 701 | (rangepost |
|
702 | 702 | (parentpost |
|
703 | 703 | ('symbol', '9'))) |
|
704 | 704 | * set: |
|
705 | 705 | <spanset+ 8:10> |
|
706 | 706 | 8 |
|
707 | 707 | 9 |
|
708 | 708 | |
|
709 | 709 | x^:y should be resolved before omitting group operators |
|
710 | 710 | |
|
711 | 711 | $ try '1^(:2)' |
|
712 | 712 | (parent |
|
713 | 713 | ('symbol', '1') |
|
714 | 714 | (group |
|
715 | 715 | (rangepre |
|
716 | 716 | ('symbol', '2')))) |
|
717 | 717 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
718 | 718 | [255] |
|
719 | 719 | |
|
720 | 720 | x^:y should be resolved recursively |
|
721 | 721 | |
|
722 | 722 | $ try 'sort(1^:2)' |
|
723 | 723 | (func |
|
724 | 724 | ('symbol', 'sort') |
|
725 | 725 | (range |
|
726 | 726 | (parentpost |
|
727 | 727 | ('symbol', '1')) |
|
728 | 728 | ('symbol', '2'))) |
|
729 | 729 | * set: |
|
730 | 730 | <spanset+ 0:3> |
|
731 | 731 | 0 |
|
732 | 732 | 1 |
|
733 | 733 | 2 |
|
734 | 734 | |
|
735 | 735 | $ try '(3^:4)^:2' |
|
736 | 736 | (range |
|
737 | 737 | (parentpost |
|
738 | 738 | (group |
|
739 | 739 | (range |
|
740 | 740 | (parentpost |
|
741 | 741 | ('symbol', '3')) |
|
742 | 742 | ('symbol', '4')))) |
|
743 | 743 | ('symbol', '2')) |
|
744 | 744 | * set: |
|
745 | 745 | <spanset+ 0:3> |
|
746 | 746 | 0 |
|
747 | 747 | 1 |
|
748 | 748 | 2 |
|
749 | 749 | |
|
750 | 750 | $ try '(3^::4)^::2' |
|
751 | 751 | (dagrange |
|
752 | 752 | (parentpost |
|
753 | 753 | (group |
|
754 | 754 | (dagrange |
|
755 | 755 | (parentpost |
|
756 | 756 | ('symbol', '3')) |
|
757 | 757 | ('symbol', '4')))) |
|
758 | 758 | ('symbol', '2')) |
|
759 | 759 | * set: |
|
760 | 760 | <baseset+ [0, 1, 2]> |
|
761 | 761 | 0 |
|
762 | 762 | 1 |
|
763 | 763 | 2 |
|
764 | 764 | |
|
765 | 765 | $ try '(9^:)^:' |
|
766 | 766 | (rangepost |
|
767 | 767 | (parentpost |
|
768 | 768 | (group |
|
769 | 769 | (rangepost |
|
770 | 770 | (parentpost |
|
771 | 771 | ('symbol', '9')))))) |
|
772 | 772 | * set: |
|
773 | 773 | <spanset+ 4:10> |
|
774 | 774 | 4 |
|
775 | 775 | 5 |
|
776 | 776 | 6 |
|
777 | 777 | 7 |
|
778 | 778 | 8 |
|
779 | 779 | 9 |
|
780 | 780 | |
|
781 | 781 | x^ in alias should also be resolved |
|
782 | 782 | |
|
783 | 783 | $ try 'A' --config 'revsetalias.A=1^:2' |
|
784 | 784 | ('symbol', 'A') |
|
785 | 785 | * expanded: |
|
786 | 786 | (range |
|
787 | 787 | (parentpost |
|
788 | 788 | ('symbol', '1')) |
|
789 | 789 | ('symbol', '2')) |
|
790 | 790 | * set: |
|
791 | 791 | <spanset+ 0:3> |
|
792 | 792 | 0 |
|
793 | 793 | 1 |
|
794 | 794 | 2 |
|
795 | 795 | |
|
796 | 796 | $ try 'A:2' --config 'revsetalias.A=1^' |
|
797 | 797 | (range |
|
798 | 798 | ('symbol', 'A') |
|
799 | 799 | ('symbol', '2')) |
|
800 | 800 | * expanded: |
|
801 | 801 | (range |
|
802 | 802 | (parentpost |
|
803 | 803 | ('symbol', '1')) |
|
804 | 804 | ('symbol', '2')) |
|
805 | 805 | * set: |
|
806 | 806 | <spanset+ 0:3> |
|
807 | 807 | 0 |
|
808 | 808 | 1 |
|
809 | 809 | 2 |
|
810 | 810 | |
|
811 | 811 | but not beyond the boundary of alias expansion, because the resolution should |
|
812 | 812 | be made at the parsing stage |
|
813 | 813 | |
|
814 | 814 | $ try '1^A' --config 'revsetalias.A=:2' |
|
815 | 815 | (parent |
|
816 | 816 | ('symbol', '1') |
|
817 | 817 | ('symbol', 'A')) |
|
818 | 818 | * expanded: |
|
819 | 819 | (parent |
|
820 | 820 | ('symbol', '1') |
|
821 | 821 | (rangepre |
|
822 | 822 | ('symbol', '2'))) |
|
823 | 823 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
824 | 824 | [255] |
|
825 | 825 | |
|
826 | 826 | ancestor can accept 0 or more arguments |
|
827 | 827 | |
|
828 | 828 | $ log 'ancestor()' |
|
829 | 829 | $ log 'ancestor(1)' |
|
830 | 830 | 1 |
|
831 | 831 | $ log 'ancestor(4,5)' |
|
832 | 832 | 1 |
|
833 | 833 | $ log 'ancestor(4,5) and 4' |
|
834 | 834 | $ log 'ancestor(0,0,1,3)' |
|
835 | 835 | 0 |
|
836 | 836 | $ log 'ancestor(3,1,5,3,5,1)' |
|
837 | 837 | 1 |
|
838 | 838 | $ log 'ancestor(0,1,3,5)' |
|
839 | 839 | 0 |
|
840 | 840 | $ log 'ancestor(1,2,3,4,5)' |
|
841 | 841 | 1 |
|
842 | 842 | |
|
843 | 843 | test ancestors |
|
844 | 844 | |
|
845 | 845 | $ hg log -G -T '{rev}\n' --config experimental.graphshorten=True |
|
846 | 846 | @ 9 |
|
847 | 847 | o 8 |
|
848 | 848 | | o 7 |
|
849 | 849 | | o 6 |
|
850 | 850 | |/| |
|
851 | 851 | | o 5 |
|
852 | 852 | o | 4 |
|
853 | 853 | | o 3 |
|
854 | 854 | o | 2 |
|
855 | 855 | |/ |
|
856 | 856 | o 1 |
|
857 | 857 | o 0 |
|
858 | 858 | |
|
859 | 859 | $ log 'ancestors(5)' |
|
860 | 860 | 0 |
|
861 | 861 | 1 |
|
862 | 862 | 3 |
|
863 | 863 | 5 |
|
864 | 864 | $ log 'ancestor(ancestors(5))' |
|
865 | 865 | 0 |
|
866 | 866 | $ log '::r3232()' |
|
867 | 867 | 0 |
|
868 | 868 | 1 |
|
869 | 869 | 2 |
|
870 | 870 | 3 |
|
871 | 871 | |
|
872 | 872 | test ancestors with depth limit |
|
873 | 873 | |
|
874 | 874 | (depth=0 selects the node itself) |
|
875 | 875 | |
|
876 | 876 | $ log 'reverse(ancestors(9, depth=0))' |
|
877 | 877 | 9 |
|
878 | 878 | |
|
879 | 879 | (interleaved: '4' would be missing if heap queue were higher depth first) |
|
880 | 880 | |
|
881 | 881 | $ log 'reverse(ancestors(8:9, depth=1))' |
|
882 | 882 | 9 |
|
883 | 883 | 8 |
|
884 | 884 | 4 |
|
885 | 885 | |
|
886 | 886 | (interleaved: '2' would be missing if heap queue were higher depth first) |
|
887 | 887 | |
|
888 | 888 | $ log 'reverse(ancestors(7+8, depth=2))' |
|
889 | 889 | 8 |
|
890 | 890 | 7 |
|
891 | 891 | 6 |
|
892 | 892 | 5 |
|
893 | 893 | 4 |
|
894 | 894 | 2 |
|
895 | 895 | |
|
896 | 896 | (walk example above by separate queries) |
|
897 | 897 | |
|
898 | 898 | $ log 'reverse(ancestors(8, depth=2)) + reverse(ancestors(7, depth=2))' |
|
899 | 899 | 8 |
|
900 | 900 | 4 |
|
901 | 901 | 2 |
|
902 | 902 | 7 |
|
903 | 903 | 6 |
|
904 | 904 | 5 |
|
905 | 905 | |
|
906 | 906 | (walk 2nd and 3rd ancestors) |
|
907 | 907 | |
|
908 | 908 | $ log 'reverse(ancestors(7, depth=3, startdepth=2))' |
|
909 | 909 | 5 |
|
910 | 910 | 4 |
|
911 | 911 | 3 |
|
912 | 912 | 2 |
|
913 | 913 | |
|
914 | 914 | (interleaved: '4' would be missing if higher-depth ancestors weren't scanned) |
|
915 | 915 | |
|
916 | 916 | $ log 'reverse(ancestors(7+8, depth=2, startdepth=2))' |
|
917 | 917 | 5 |
|
918 | 918 | 4 |
|
919 | 919 | 2 |
|
920 | 920 | |
|
921 | 921 | (note that 'ancestors(x, depth=y, startdepth=z)' does not identical to |
|
922 | 922 | 'ancestors(x, depth=y) - ancestors(x, depth=z-1)' because a node may have |
|
923 | 923 | multiple depths) |
|
924 | 924 | |
|
925 | 925 | $ log 'reverse(ancestors(7+8, depth=2) - ancestors(7+8, depth=1))' |
|
926 | 926 | 5 |
|
927 | 927 | 2 |
|
928 | 928 | |
|
929 | 929 | test bad arguments passed to ancestors() |
|
930 | 930 | |
|
931 | 931 | $ log 'ancestors(., depth=-1)' |
|
932 | 932 | hg: parse error: negative depth |
|
933 | 933 | [255] |
|
934 | 934 | $ log 'ancestors(., depth=foo)' |
|
935 | 935 | hg: parse error: ancestors expects an integer depth |
|
936 | 936 | [255] |
|
937 | 937 | |
|
938 | 938 | test descendants |
|
939 | 939 | |
|
940 | 940 | $ hg log -G -T '{rev}\n' --config experimental.graphshorten=True |
|
941 | 941 | @ 9 |
|
942 | 942 | o 8 |
|
943 | 943 | | o 7 |
|
944 | 944 | | o 6 |
|
945 | 945 | |/| |
|
946 | 946 | | o 5 |
|
947 | 947 | o | 4 |
|
948 | 948 | | o 3 |
|
949 | 949 | o | 2 |
|
950 | 950 | |/ |
|
951 | 951 | o 1 |
|
952 | 952 | o 0 |
|
953 | 953 | |
|
954 | 954 | (null is ultimate root and has optimized path) |
|
955 | 955 | |
|
956 | 956 | $ log 'null:4 & descendants(null)' |
|
957 | 957 | -1 |
|
958 | 958 | 0 |
|
959 | 959 | 1 |
|
960 | 960 | 2 |
|
961 | 961 | 3 |
|
962 | 962 | 4 |
|
963 | 963 | |
|
964 | 964 | (including merge) |
|
965 | 965 | |
|
966 | 966 | $ log ':8 & descendants(2)' |
|
967 | 967 | 2 |
|
968 | 968 | 4 |
|
969 | 969 | 6 |
|
970 | 970 | 7 |
|
971 | 971 | 8 |
|
972 | 972 | |
|
973 | 973 | (multiple roots) |
|
974 | 974 | |
|
975 | 975 | $ log ':8 & descendants(2+5)' |
|
976 | 976 | 2 |
|
977 | 977 | 4 |
|
978 | 978 | 5 |
|
979 | 979 | 6 |
|
980 | 980 | 7 |
|
981 | 981 | 8 |
|
982 | 982 | |
|
983 | 983 | test descendants with depth limit |
|
984 | 984 | |
|
985 | 985 | (depth=0 selects the node itself) |
|
986 | 986 | |
|
987 | 987 | $ log 'descendants(0, depth=0)' |
|
988 | 988 | 0 |
|
989 | 989 | $ log 'null: & descendants(null, depth=0)' |
|
990 | 990 | -1 |
|
991 | 991 | |
|
992 | 992 | (p2 = null should be ignored) |
|
993 | 993 | |
|
994 | 994 | $ log 'null: & descendants(null, depth=2)' |
|
995 | 995 | -1 |
|
996 | 996 | 0 |
|
997 | 997 | 1 |
|
998 | 998 | |
|
999 | 999 | (multiple paths: depth(6) = (2, 3)) |
|
1000 | 1000 | |
|
1001 | 1001 | $ log 'descendants(1+3, depth=2)' |
|
1002 | 1002 | 1 |
|
1003 | 1003 | 2 |
|
1004 | 1004 | 3 |
|
1005 | 1005 | 4 |
|
1006 | 1006 | 5 |
|
1007 | 1007 | 6 |
|
1008 | 1008 | |
|
1009 | 1009 | (multiple paths: depth(5) = (1, 2), depth(6) = (2, 3)) |
|
1010 | 1010 | |
|
1011 | 1011 | $ log 'descendants(3+1, depth=2, startdepth=2)' |
|
1012 | 1012 | 4 |
|
1013 | 1013 | 5 |
|
1014 | 1014 | 6 |
|
1015 | 1015 | |
|
1016 | 1016 | (multiple depths: depth(6) = (0, 2, 4), search for depth=2) |
|
1017 | 1017 | |
|
1018 | 1018 | $ log 'descendants(0+3+6, depth=3, startdepth=1)' |
|
1019 | 1019 | 1 |
|
1020 | 1020 | 2 |
|
1021 | 1021 | 3 |
|
1022 | 1022 | 4 |
|
1023 | 1023 | 5 |
|
1024 | 1024 | 6 |
|
1025 | 1025 | 7 |
|
1026 | 1026 | |
|
1027 | 1027 | (multiple depths: depth(6) = (0, 4), no match) |
|
1028 | 1028 | |
|
1029 | 1029 | $ log 'descendants(0+6, depth=3, startdepth=1)' |
|
1030 | 1030 | 1 |
|
1031 | 1031 | 2 |
|
1032 | 1032 | 3 |
|
1033 | 1033 | 4 |
|
1034 | 1034 | 5 |
|
1035 | 1035 | 7 |
|
1036 | 1036 | |
|
1037 | 1037 | test author |
|
1038 | 1038 | |
|
1039 | 1039 | $ log 'author(bob)' |
|
1040 | 1040 | 2 |
|
1041 | 1041 | $ log 'author("re:bob|test")' |
|
1042 | 1042 | 0 |
|
1043 | 1043 | 1 |
|
1044 | 1044 | 2 |
|
1045 | 1045 | 3 |
|
1046 | 1046 | 4 |
|
1047 | 1047 | 5 |
|
1048 | 1048 | 6 |
|
1049 | 1049 | 7 |
|
1050 | 1050 | 8 |
|
1051 | 1051 | 9 |
|
1052 | 1052 | $ log 'author(r"re:\S")' |
|
1053 | 1053 | 0 |
|
1054 | 1054 | 1 |
|
1055 | 1055 | 2 |
|
1056 | 1056 | 3 |
|
1057 | 1057 | 4 |
|
1058 | 1058 | 5 |
|
1059 | 1059 | 6 |
|
1060 | 1060 | 7 |
|
1061 | 1061 | 8 |
|
1062 | 1062 | 9 |
|
1063 | 1063 | $ log 'branch(Γ©)' |
|
1064 | 1064 | 8 |
|
1065 | 1065 | 9 |
|
1066 | 1066 | $ log 'branch(a)' |
|
1067 | 1067 | 0 |
|
1068 | 1068 | $ hg log -r 'branch("re:a")' --template '{rev} {branch}\n' |
|
1069 | 1069 | 0 a |
|
1070 | 1070 | 2 a-b-c- |
|
1071 | 1071 | 3 +a+b+c+ |
|
1072 | 1072 | 4 -a-b-c- |
|
1073 | 1073 | 5 !a/b/c/ |
|
1074 | 1074 | 6 _a_b_c_ |
|
1075 | 1075 | 7 .a.b.c. |
|
1076 | 1076 | $ log 'children(ancestor(4,5))' |
|
1077 | 1077 | 2 |
|
1078 | 1078 | 3 |
|
1079 | 1079 | |
|
1080 | 1080 | $ log 'children(4)' |
|
1081 | 1081 | 6 |
|
1082 | 1082 | 8 |
|
1083 | 1083 | $ log 'children(null)' |
|
1084 | 1084 | 0 |
|
1085 | 1085 | |
|
1086 | 1086 | $ log 'closed()' |
|
1087 | 1087 | $ log 'contains(a)' |
|
1088 | 1088 | 0 |
|
1089 | 1089 | 1 |
|
1090 | 1090 | 3 |
|
1091 | 1091 | 5 |
|
1092 | 1092 | $ log 'contains("../repo/a")' |
|
1093 | 1093 | 0 |
|
1094 | 1094 | 1 |
|
1095 | 1095 | 3 |
|
1096 | 1096 | 5 |
|
1097 | 1097 | $ log 'desc(B)' |
|
1098 | 1098 | 5 |
|
1099 | 1099 | $ hg log -r 'desc(r"re:S?u")' --template "{rev} {desc|firstline}\n" |
|
1100 | 1100 | 5 5 bug |
|
1101 | 1101 | 6 6 issue619 |
|
1102 | 1102 | $ log 'descendants(2 or 3)' |
|
1103 | 1103 | 2 |
|
1104 | 1104 | 3 |
|
1105 | 1105 | 4 |
|
1106 | 1106 | 5 |
|
1107 | 1107 | 6 |
|
1108 | 1108 | 7 |
|
1109 | 1109 | 8 |
|
1110 | 1110 | 9 |
|
1111 | 1111 | $ log 'file("b*")' |
|
1112 | 1112 | 1 |
|
1113 | 1113 | 4 |
|
1114 | 1114 | $ log 'filelog("b")' |
|
1115 | 1115 | 1 |
|
1116 | 1116 | 4 |
|
1117 | 1117 | $ log 'filelog("../repo/b")' |
|
1118 | 1118 | 1 |
|
1119 | 1119 | 4 |
|
1120 | 1120 | $ log 'follow()' |
|
1121 | 1121 | 0 |
|
1122 | 1122 | 1 |
|
1123 | 1123 | 2 |
|
1124 | 1124 | 4 |
|
1125 | 1125 | 8 |
|
1126 | 1126 | 9 |
|
1127 | 1127 | $ log 'grep("issue\d+")' |
|
1128 | 1128 | 6 |
|
1129 | 1129 | $ try 'grep("(")' # invalid regular expression |
|
1130 | 1130 | (func |
|
1131 | 1131 | ('symbol', 'grep') |
|
1132 | 1132 | ('string', '(')) |
|
1133 | 1133 | hg: parse error: invalid match pattern: unbalanced parenthesis |
|
1134 | 1134 | [255] |
|
1135 | 1135 | $ try 'grep("\bissue\d+")' |
|
1136 | 1136 | (func |
|
1137 | 1137 | ('symbol', 'grep') |
|
1138 | 1138 | ('string', '\x08issue\\d+')) |
|
1139 | 1139 | * set: |
|
1140 | 1140 | <filteredset |
|
1141 | 1141 | <fullreposet+ 0:10>, |
|
1142 | 1142 | <grep '\x08issue\\d+'>> |
|
1143 | 1143 | $ try 'grep(r"\bissue\d+")' |
|
1144 | 1144 | (func |
|
1145 | 1145 | ('symbol', 'grep') |
|
1146 | 1146 | ('string', '\\bissue\\d+')) |
|
1147 | 1147 | * set: |
|
1148 | 1148 | <filteredset |
|
1149 | 1149 | <fullreposet+ 0:10>, |
|
1150 | 1150 | <grep '\\bissue\\d+'>> |
|
1151 | 1151 | 6 |
|
1152 | 1152 | $ try 'grep(r"\")' |
|
1153 | 1153 | hg: parse error at 7: unterminated string |
|
1154 | 1154 | [255] |
|
1155 | 1155 | $ log 'head()' |
|
1156 | 1156 | 0 |
|
1157 | 1157 | 1 |
|
1158 | 1158 | 2 |
|
1159 | 1159 | 3 |
|
1160 | 1160 | 4 |
|
1161 | 1161 | 5 |
|
1162 | 1162 | 6 |
|
1163 | 1163 | 7 |
|
1164 | 1164 | 9 |
|
1165 | 1165 | $ log 'heads(6::)' |
|
1166 | 1166 | 7 |
|
1167 | 1167 | $ log 'keyword(issue)' |
|
1168 | 1168 | 6 |
|
1169 | 1169 | $ log 'keyword("test a")' |
|
1170 | 1170 | |
|
1171 | 1171 | Test first (=limit) and last |
|
1172 | 1172 | |
|
1173 | 1173 | $ log 'limit(head(), 1)' |
|
1174 | 1174 | 0 |
|
1175 | 1175 | $ log 'limit(author("re:bob|test"), 3, 5)' |
|
1176 | 1176 | 5 |
|
1177 | 1177 | 6 |
|
1178 | 1178 | 7 |
|
1179 | 1179 | $ log 'limit(author("re:bob|test"), offset=6)' |
|
1180 | 1180 | 6 |
|
1181 | 1181 | $ log 'limit(author("re:bob|test"), offset=10)' |
|
1182 | 1182 | $ log 'limit(all(), 1, -1)' |
|
1183 | 1183 | hg: parse error: negative offset |
|
1184 | 1184 | [255] |
|
1185 | 1185 | $ log 'limit(all(), -1)' |
|
1186 | 1186 | hg: parse error: negative number to select |
|
1187 | 1187 | [255] |
|
1188 | 1188 | $ log 'limit(all(), 0)' |
|
1189 | 1189 | |
|
1190 | 1190 | $ log 'last(all(), -1)' |
|
1191 | 1191 | hg: parse error: negative number to select |
|
1192 | 1192 | [255] |
|
1193 | 1193 | $ log 'last(all(), 0)' |
|
1194 | 1194 | $ log 'last(all(), 1)' |
|
1195 | 1195 | 9 |
|
1196 | 1196 | $ log 'last(all(), 2)' |
|
1197 | 1197 | 8 |
|
1198 | 1198 | 9 |
|
1199 | 1199 | |
|
1200 | 1200 | Test smartset.slice() by first/last() |
|
1201 | 1201 | |
|
1202 | 1202 | (using unoptimized set, filteredset as example) |
|
1203 | 1203 | |
|
1204 | 1204 | $ hg debugrevspec --no-show-revs -s '0:7 & branch("re:")' |
|
1205 | 1205 | * set: |
|
1206 | 1206 | <filteredset |
|
1207 | 1207 | <spanset+ 0:8>, |
|
1208 | 1208 | <branch 're:'>> |
|
1209 | 1209 | $ log 'limit(0:7 & branch("re:"), 3, 4)' |
|
1210 | 1210 | 4 |
|
1211 | 1211 | 5 |
|
1212 | 1212 | 6 |
|
1213 | 1213 | $ log 'limit(7:0 & branch("re:"), 3, 4)' |
|
1214 | 1214 | 3 |
|
1215 | 1215 | 2 |
|
1216 | 1216 | 1 |
|
1217 | 1217 | $ log 'last(0:7 & branch("re:"), 2)' |
|
1218 | 1218 | 6 |
|
1219 | 1219 | 7 |
|
1220 | 1220 | |
|
1221 | 1221 | (using baseset) |
|
1222 | 1222 | |
|
1223 | 1223 | $ hg debugrevspec --no-show-revs -s 0+1+2+3+4+5+6+7 |
|
1224 | 1224 | * set: |
|
1225 | 1225 | <baseset [0, 1, 2, 3, 4, 5, 6, 7]> |
|
1226 | 1226 | $ hg debugrevspec --no-show-revs -s 0::7 |
|
1227 | 1227 | * set: |
|
1228 | 1228 | <baseset+ [0, 1, 2, 3, 4, 5, 6, 7]> |
|
1229 | 1229 | $ log 'limit(0+1+2+3+4+5+6+7, 3, 4)' |
|
1230 | 1230 | 4 |
|
1231 | 1231 | 5 |
|
1232 | 1232 | 6 |
|
1233 | 1233 | $ log 'limit(sort(0::7, rev), 3, 4)' |
|
1234 | 1234 | 4 |
|
1235 | 1235 | 5 |
|
1236 | 1236 | 6 |
|
1237 | 1237 | $ log 'limit(sort(0::7, -rev), 3, 4)' |
|
1238 | 1238 | 3 |
|
1239 | 1239 | 2 |
|
1240 | 1240 | 1 |
|
1241 | 1241 | $ log 'last(sort(0::7, rev), 2)' |
|
1242 | 1242 | 6 |
|
1243 | 1243 | 7 |
|
1244 | 1244 | $ hg debugrevspec -s 'limit(sort(0::7, rev), 3, 6)' |
|
1245 | 1245 | * set: |
|
1246 | 1246 | <baseset+ [6, 7]> |
|
1247 | 1247 | 6 |
|
1248 | 1248 | 7 |
|
1249 | 1249 | $ hg debugrevspec -s 'limit(sort(0::7, rev), 3, 9)' |
|
1250 | 1250 | * set: |
|
1251 | 1251 | <baseset+ []> |
|
1252 | 1252 | $ hg debugrevspec -s 'limit(sort(0::7, -rev), 3, 6)' |
|
1253 | 1253 | * set: |
|
1254 | 1254 | <baseset- [0, 1]> |
|
1255 | 1255 | 1 |
|
1256 | 1256 | 0 |
|
1257 | 1257 | $ hg debugrevspec -s 'limit(sort(0::7, -rev), 3, 9)' |
|
1258 | 1258 | * set: |
|
1259 | 1259 | <baseset- []> |
|
1260 | 1260 | $ hg debugrevspec -s 'limit(0::7, 0)' |
|
1261 | 1261 | * set: |
|
1262 | 1262 | <baseset+ []> |
|
1263 | 1263 | |
|
1264 | 1264 | (using spanset) |
|
1265 | 1265 | |
|
1266 | 1266 | $ hg debugrevspec --no-show-revs -s 0:7 |
|
1267 | 1267 | * set: |
|
1268 | 1268 | <spanset+ 0:8> |
|
1269 | 1269 | $ log 'limit(0:7, 3, 4)' |
|
1270 | 1270 | 4 |
|
1271 | 1271 | 5 |
|
1272 | 1272 | 6 |
|
1273 | 1273 | $ log 'limit(7:0, 3, 4)' |
|
1274 | 1274 | 3 |
|
1275 | 1275 | 2 |
|
1276 | 1276 | 1 |
|
1277 | 1277 | $ log 'limit(0:7, 3, 6)' |
|
1278 | 1278 | 6 |
|
1279 | 1279 | 7 |
|
1280 | 1280 | $ log 'limit(7:0, 3, 6)' |
|
1281 | 1281 | 1 |
|
1282 | 1282 | 0 |
|
1283 | 1283 | $ log 'last(0:7, 2)' |
|
1284 | 1284 | 6 |
|
1285 | 1285 | 7 |
|
1286 | 1286 | $ hg debugrevspec -s 'limit(0:7, 3, 6)' |
|
1287 | 1287 | * set: |
|
1288 | 1288 | <spanset+ 6:8> |
|
1289 | 1289 | 6 |
|
1290 | 1290 | 7 |
|
1291 | 1291 | $ hg debugrevspec -s 'limit(0:7, 3, 9)' |
|
1292 | 1292 | * set: |
|
1293 | 1293 | <spanset+ 8:8> |
|
1294 | 1294 | $ hg debugrevspec -s 'limit(7:0, 3, 6)' |
|
1295 | 1295 | * set: |
|
1296 | 1296 | <spanset- 0:2> |
|
1297 | 1297 | 1 |
|
1298 | 1298 | 0 |
|
1299 | 1299 | $ hg debugrevspec -s 'limit(7:0, 3, 9)' |
|
1300 | 1300 | * set: |
|
1301 | 1301 | <spanset- 0:0> |
|
1302 | 1302 | $ hg debugrevspec -s 'limit(0:7, 0)' |
|
1303 | 1303 | * set: |
|
1304 | 1304 | <spanset+ 0:0> |
|
1305 | 1305 | |
|
1306 | 1306 | Test order of first/last revisions |
|
1307 | 1307 | |
|
1308 | 1308 | $ hg debugrevspec -s 'first(4:0, 3) & 3:' |
|
1309 | 1309 | * set: |
|
1310 | 1310 | <filteredset |
|
1311 | 1311 | <spanset- 2:5>, |
|
1312 | 1312 | <spanset+ 3:10>> |
|
1313 | 1313 | 4 |
|
1314 | 1314 | 3 |
|
1315 | 1315 | |
|
1316 | 1316 | $ hg debugrevspec -s '3: & first(4:0, 3)' |
|
1317 | 1317 | * set: |
|
1318 | 1318 | <filteredset |
|
1319 | 1319 | <spanset+ 3:10>, |
|
1320 | 1320 | <spanset- 2:5>> |
|
1321 | 1321 | 3 |
|
1322 | 1322 | 4 |
|
1323 | 1323 | |
|
1324 | 1324 | $ hg debugrevspec -s 'last(4:0, 3) & :1' |
|
1325 | 1325 | * set: |
|
1326 | 1326 | <filteredset |
|
1327 | 1327 | <spanset- 0:3>, |
|
1328 | 1328 | <spanset+ 0:2>> |
|
1329 | 1329 | 1 |
|
1330 | 1330 | 0 |
|
1331 | 1331 | |
|
1332 | 1332 | $ hg debugrevspec -s ':1 & last(4:0, 3)' |
|
1333 | 1333 | * set: |
|
1334 | 1334 | <filteredset |
|
1335 | 1335 | <spanset+ 0:2>, |
|
1336 | 1336 | <spanset+ 0:3>> |
|
1337 | 1337 | 0 |
|
1338 | 1338 | 1 |
|
1339 | 1339 | |
|
1340 | 1340 | Test scmutil.revsingle() should return the last revision |
|
1341 | 1341 | |
|
1342 | 1342 | $ hg debugrevspec -s 'last(0::)' |
|
1343 | 1343 | * set: |
|
1344 | 1344 | <baseset slice=0:1 |
|
1345 | 1345 | <generatorset->> |
|
1346 | 1346 | 9 |
|
1347 | 1347 | $ hg identify -r '0::' --num |
|
1348 | 1348 | 9 |
|
1349 | 1349 | |
|
1350 | 1350 | Test matching |
|
1351 | 1351 | |
|
1352 | 1352 | $ log 'matching(6)' |
|
1353 | 1353 | 6 |
|
1354 | 1354 | $ log 'matching(6:7, "phase parents user date branch summary files description substate")' |
|
1355 | 1355 | 6 |
|
1356 | 1356 | 7 |
|
1357 | 1357 | |
|
1358 | 1358 | Testing min and max |
|
1359 | 1359 | |
|
1360 | 1360 | max: simple |
|
1361 | 1361 | |
|
1362 | 1362 | $ log 'max(contains(a))' |
|
1363 | 1363 | 5 |
|
1364 | 1364 | |
|
1365 | 1365 | max: simple on unordered set) |
|
1366 | 1366 | |
|
1367 | 1367 | $ log 'max((4+0+2+5+7) and contains(a))' |
|
1368 | 1368 | 5 |
|
1369 | 1369 | |
|
1370 | 1370 | max: no result |
|
1371 | 1371 | |
|
1372 | 1372 | $ log 'max(contains(stringthatdoesnotappearanywhere))' |
|
1373 | 1373 | |
|
1374 | 1374 | max: no result on unordered set |
|
1375 | 1375 | |
|
1376 | 1376 | $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
1377 | 1377 | |
|
1378 | 1378 | min: simple |
|
1379 | 1379 | |
|
1380 | 1380 | $ log 'min(contains(a))' |
|
1381 | 1381 | 0 |
|
1382 | 1382 | |
|
1383 | 1383 | min: simple on unordered set |
|
1384 | 1384 | |
|
1385 | 1385 | $ log 'min((4+0+2+5+7) and contains(a))' |
|
1386 | 1386 | 0 |
|
1387 | 1387 | |
|
1388 | 1388 | min: empty |
|
1389 | 1389 | |
|
1390 | 1390 | $ log 'min(contains(stringthatdoesnotappearanywhere))' |
|
1391 | 1391 | |
|
1392 | 1392 | min: empty on unordered set |
|
1393 | 1393 | |
|
1394 | 1394 | $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))' |
|
1395 | 1395 | |
|
1396 | 1396 | |
|
1397 | 1397 | $ log 'merge()' |
|
1398 | 1398 | 6 |
|
1399 | 1399 | $ log 'branchpoint()' |
|
1400 | 1400 | 1 |
|
1401 | 1401 | 4 |
|
1402 | 1402 | $ log 'modifies(b)' |
|
1403 | 1403 | 4 |
|
1404 | 1404 | $ log 'modifies("path:b")' |
|
1405 | 1405 | 4 |
|
1406 | 1406 | $ log 'modifies("*")' |
|
1407 | 1407 | 4 |
|
1408 | 1408 | 6 |
|
1409 | 1409 | $ log 'modifies("set:modified()")' |
|
1410 | 1410 | 4 |
|
1411 | 1411 | $ log 'id(5)' |
|
1412 | 1412 | 2 |
|
1413 | 1413 | $ log 'only(9)' |
|
1414 | 1414 | 8 |
|
1415 | 1415 | 9 |
|
1416 | 1416 | $ log 'only(8)' |
|
1417 | 1417 | 8 |
|
1418 | 1418 | $ log 'only(9, 5)' |
|
1419 | 1419 | 2 |
|
1420 | 1420 | 4 |
|
1421 | 1421 | 8 |
|
1422 | 1422 | 9 |
|
1423 | 1423 | $ log 'only(7 + 9, 5 + 2)' |
|
1424 | 1424 | 4 |
|
1425 | 1425 | 6 |
|
1426 | 1426 | 7 |
|
1427 | 1427 | 8 |
|
1428 | 1428 | 9 |
|
1429 | 1429 | |
|
1430 | 1430 | Test empty set input |
|
1431 | 1431 | $ log 'only(p2())' |
|
1432 | 1432 | $ log 'only(p1(), p2())' |
|
1433 | 1433 | 0 |
|
1434 | 1434 | 1 |
|
1435 | 1435 | 2 |
|
1436 | 1436 | 4 |
|
1437 | 1437 | 8 |
|
1438 | 1438 | 9 |
|
1439 | 1439 | |
|
1440 | 1440 | Test '%' operator |
|
1441 | 1441 | |
|
1442 | 1442 | $ log '9%' |
|
1443 | 1443 | 8 |
|
1444 | 1444 | 9 |
|
1445 | 1445 | $ log '9%5' |
|
1446 | 1446 | 2 |
|
1447 | 1447 | 4 |
|
1448 | 1448 | 8 |
|
1449 | 1449 | 9 |
|
1450 | 1450 | $ log '(7 + 9)%(5 + 2)' |
|
1451 | 1451 | 4 |
|
1452 | 1452 | 6 |
|
1453 | 1453 | 7 |
|
1454 | 1454 | 8 |
|
1455 | 1455 | 9 |
|
1456 | 1456 | |
|
1457 | 1457 | Test operand of '%' is optimized recursively (issue4670) |
|
1458 | 1458 | |
|
1459 | 1459 | $ try --optimize '8:9-8%' |
|
1460 | 1460 | (onlypost |
|
1461 | 1461 | (minus |
|
1462 | 1462 | (range |
|
1463 | 1463 | ('symbol', '8') |
|
1464 | 1464 | ('symbol', '9')) |
|
1465 | 1465 | ('symbol', '8'))) |
|
1466 | 1466 | * optimized: |
|
1467 | 1467 | (func |
|
1468 | 1468 | ('symbol', 'only') |
|
1469 | 1469 | (difference |
|
1470 | 1470 | (range |
|
1471 | 1471 | ('symbol', '8') |
|
1472 | 1472 | ('symbol', '9') |
|
1473 | 1473 | define) |
|
1474 | 1474 | ('symbol', '8') |
|
1475 | 1475 | define) |
|
1476 | 1476 | define) |
|
1477 | 1477 | * set: |
|
1478 | 1478 | <baseset+ [8, 9]> |
|
1479 | 1479 | 8 |
|
1480 | 1480 | 9 |
|
1481 | 1481 | $ try --optimize '(9)%(5)' |
|
1482 | 1482 | (only |
|
1483 | 1483 | (group |
|
1484 | 1484 | ('symbol', '9')) |
|
1485 | 1485 | (group |
|
1486 | 1486 | ('symbol', '5'))) |
|
1487 | 1487 | * optimized: |
|
1488 | 1488 | (func |
|
1489 | 1489 | ('symbol', 'only') |
|
1490 | 1490 | (list |
|
1491 | 1491 | ('symbol', '9') |
|
1492 | 1492 | ('symbol', '5')) |
|
1493 | 1493 | define) |
|
1494 | 1494 | * set: |
|
1495 | 1495 | <baseset+ [2, 4, 8, 9]> |
|
1496 | 1496 | 2 |
|
1497 | 1497 | 4 |
|
1498 | 1498 | 8 |
|
1499 | 1499 | 9 |
|
1500 | 1500 | |
|
1501 | 1501 | Test the order of operations |
|
1502 | 1502 | |
|
1503 | 1503 | $ log '7 + 9%5 + 2' |
|
1504 | 1504 | 7 |
|
1505 | 1505 | 2 |
|
1506 | 1506 | 4 |
|
1507 | 1507 | 8 |
|
1508 | 1508 | 9 |
|
1509 | 1509 | |
|
1510 | 1510 | Test explicit numeric revision |
|
1511 | 1511 | $ log 'rev(-2)' |
|
1512 | 1512 | $ log 'rev(-1)' |
|
1513 | 1513 | -1 |
|
1514 | 1514 | $ log 'rev(0)' |
|
1515 | 1515 | 0 |
|
1516 | 1516 | $ log 'rev(9)' |
|
1517 | 1517 | 9 |
|
1518 | 1518 | $ log 'rev(10)' |
|
1519 | 1519 | $ log 'rev(tip)' |
|
1520 | 1520 | hg: parse error: rev expects a number |
|
1521 | 1521 | [255] |
|
1522 | 1522 | |
|
1523 | 1523 | Test hexadecimal revision |
|
1524 | 1524 | $ log 'id(2)' |
|
1525 | 1525 | abort: 00changelog.i@2: ambiguous identifier! |
|
1526 | 1526 | [255] |
|
1527 | 1527 | $ log 'id(23268)' |
|
1528 | 1528 | 4 |
|
1529 | 1529 | $ log 'id(2785f51eece)' |
|
1530 | 1530 | 0 |
|
1531 | 1531 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532c)' |
|
1532 | 1532 | 8 |
|
1533 | 1533 | $ log 'id(d5d0dcbdc4a)' |
|
1534 | 1534 | $ log 'id(d5d0dcbdc4w)' |
|
1535 | 1535 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532d)' |
|
1536 | 1536 | $ log 'id(d5d0dcbdc4d9ff5dbb2d336f32f0bb561c1a532q)' |
|
1537 | 1537 | $ log 'id(1.0)' |
|
1538 | 1538 | $ log 'id(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)' |
|
1539 | 1539 | |
|
1540 | 1540 | Test null revision |
|
1541 | 1541 | $ log '(null)' |
|
1542 | 1542 | -1 |
|
1543 | 1543 | $ log '(null:0)' |
|
1544 | 1544 | -1 |
|
1545 | 1545 | 0 |
|
1546 | 1546 | $ log '(0:null)' |
|
1547 | 1547 | 0 |
|
1548 | 1548 | -1 |
|
1549 | 1549 | $ log 'null::0' |
|
1550 | 1550 | -1 |
|
1551 | 1551 | 0 |
|
1552 | 1552 | $ log 'null:tip - 0:' |
|
1553 | 1553 | -1 |
|
1554 | 1554 | $ log 'null: and null::' | head -1 |
|
1555 | 1555 | -1 |
|
1556 | 1556 | $ log 'null: or 0:' | head -2 |
|
1557 | 1557 | -1 |
|
1558 | 1558 | 0 |
|
1559 | 1559 | $ log 'ancestors(null)' |
|
1560 | 1560 | -1 |
|
1561 | 1561 | $ log 'reverse(null:)' | tail -2 |
|
1562 | 1562 | 0 |
|
1563 | 1563 | -1 |
|
1564 | 1564 | $ log 'first(null:)' |
|
1565 | 1565 | -1 |
|
1566 | 1566 | $ log 'min(null:)' |
|
1567 | 1567 | BROKEN: should be '-1' |
|
1568 | 1568 | $ log 'tip:null and all()' | tail -2 |
|
1569 | 1569 | 1 |
|
1570 | 1570 | 0 |
|
1571 | 1571 | |
|
1572 | 1572 | Test working-directory revision |
|
1573 | 1573 | $ hg debugrevspec 'wdir()' |
|
1574 | 1574 | 2147483647 |
|
1575 | 1575 | $ hg debugrevspec 'wdir()^' |
|
1576 | 1576 | 9 |
|
1577 | 1577 | $ hg up 7 |
|
1578 | 1578 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
1579 | 1579 | $ hg debugrevspec 'wdir()^' |
|
1580 | 1580 | 7 |
|
1581 | 1581 | $ hg debugrevspec 'wdir()^0' |
|
1582 | 1582 | 2147483647 |
|
1583 | 1583 | $ hg debugrevspec 'wdir()~3' |
|
1584 | 1584 | 5 |
|
1585 | 1585 | $ hg debugrevspec 'ancestors(wdir())' |
|
1586 | 1586 | 0 |
|
1587 | 1587 | 1 |
|
1588 | 1588 | 2 |
|
1589 | 1589 | 3 |
|
1590 | 1590 | 4 |
|
1591 | 1591 | 5 |
|
1592 | 1592 | 6 |
|
1593 | 1593 | 7 |
|
1594 | 1594 | 2147483647 |
|
1595 | 1595 | $ hg debugrevspec 'wdir()~0' |
|
1596 | 1596 | 2147483647 |
|
1597 | 1597 | $ hg debugrevspec 'p1(wdir())' |
|
1598 | 1598 | 7 |
|
1599 | 1599 | $ hg debugrevspec 'p2(wdir())' |
|
1600 | 1600 | $ hg debugrevspec 'parents(wdir())' |
|
1601 | 1601 | 7 |
|
1602 | 1602 | $ hg debugrevspec 'wdir()^1' |
|
1603 | 1603 | 7 |
|
1604 | 1604 | $ hg debugrevspec 'wdir()^2' |
|
1605 | 1605 | $ hg debugrevspec 'wdir()^3' |
|
1606 | 1606 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
1607 | 1607 | [255] |
|
1608 | 1608 | For tests consistency |
|
1609 | 1609 | $ hg up 9 |
|
1610 | 1610 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
1611 | 1611 | $ hg debugrevspec 'tip or wdir()' |
|
1612 | 1612 | 9 |
|
1613 | 1613 | 2147483647 |
|
1614 | 1614 | $ hg debugrevspec '0:tip and wdir()' |
|
1615 | 1615 | $ log '0:wdir()' | tail -3 |
|
1616 | 1616 | 8 |
|
1617 | 1617 | 9 |
|
1618 | 1618 | 2147483647 |
|
1619 | 1619 | $ log 'wdir():0' | head -3 |
|
1620 | 1620 | 2147483647 |
|
1621 | 1621 | 9 |
|
1622 | 1622 | 8 |
|
1623 | 1623 | $ log 'wdir():wdir()' |
|
1624 | 1624 | 2147483647 |
|
1625 | 1625 | $ log '(all() + wdir()) & min(. + wdir())' |
|
1626 | 1626 | 9 |
|
1627 | 1627 | $ log '(all() + wdir()) & max(. + wdir())' |
|
1628 | 1628 | 2147483647 |
|
1629 | 1629 | $ log 'first(wdir() + .)' |
|
1630 | 1630 | 2147483647 |
|
1631 | 1631 | $ log 'last(. + wdir())' |
|
1632 | 1632 | 2147483647 |
|
1633 | 1633 | |
|
1634 | 1634 | Test working-directory integer revision and node id |
|
1635 | 1635 | (BUG: '0:wdir()' is still needed to populate wdir revision) |
|
1636 | 1636 | |
|
1637 | 1637 | $ hg debugrevspec '0:wdir() & 2147483647' |
|
1638 | 1638 | 2147483647 |
|
1639 | 1639 | $ hg debugrevspec '0:wdir() & rev(2147483647)' |
|
1640 | 1640 | 2147483647 |
|
1641 | 1641 | $ hg debugrevspec '0:wdir() & ffffffffffffffffffffffffffffffffffffffff' |
|
1642 | 1642 | 2147483647 |
|
1643 | 1643 | $ hg debugrevspec '0:wdir() & ffffffffffff' |
|
1644 | 1644 | 2147483647 |
|
1645 | 1645 | $ hg debugrevspec '0:wdir() & id(ffffffffffffffffffffffffffffffffffffffff)' |
|
1646 | 1646 | 2147483647 |
|
1647 | 1647 | $ hg debugrevspec '0:wdir() & id(ffffffffffff)' |
|
1648 | 1648 | 2147483647 |
|
1649 | 1649 | |
|
1650 | 1650 | $ cd .. |
|
1651 | 1651 | |
|
1652 | 1652 | Test short 'ff...' hash collision |
|
1653 | 1653 | (BUG: '0:wdir()' is still needed to populate wdir revision) |
|
1654 | 1654 | |
|
1655 | 1655 | $ hg init wdir-hashcollision |
|
1656 | 1656 | $ cd wdir-hashcollision |
|
1657 | 1657 | $ cat <<EOF >> .hg/hgrc |
|
1658 | 1658 | > [experimental] |
|
1659 | 1659 | > evolution = createmarkers |
|
1660 | 1660 | > EOF |
|
1661 | 1661 | $ echo 0 > a |
|
1662 | 1662 | $ hg ci -qAm 0 |
|
1663 | 1663 | $ for i in 2463 2961 6726 78127; do |
|
1664 | 1664 | > hg up -q 0 |
|
1665 | 1665 | > echo $i > a |
|
1666 | 1666 | > hg ci -qm $i |
|
1667 | 1667 | > done |
|
1668 | 1668 | $ hg up -q null |
|
1669 | 1669 | $ hg log -r '0:wdir()' -T '{rev}:{node} {shortest(node, 3)}\n' |
|
1670 | 1670 | 0:b4e73ffab476aa0ee32ed81ca51e07169844bc6a b4e |
|
1671 | 1671 | 1:fffbae3886c8fbb2114296380d276fd37715d571 fffba |
|
1672 | 1672 | 2:fffb6093b00943f91034b9bdad069402c834e572 fffb6 |
|
1673 | 1673 | 3:fff48a9b9de34a4d64120c29548214c67980ade3 fff4 |
|
1674 | 1674 | 4:ffff85cff0ff78504fcdc3c0bc10de0c65379249 ffff8 |
|
1675 | 1675 | 2147483647:ffffffffffffffffffffffffffffffffffffffff fffff |
|
1676 | 1676 | $ hg debugobsolete fffbae3886c8fbb2114296380d276fd37715d571 |
|
1677 | 1677 | |
|
1678 | 1678 | $ hg debugrevspec '0:wdir() & fff' |
|
1679 | 1679 | abort: 00changelog.i@fff: ambiguous identifier! |
|
1680 | 1680 | [255] |
|
1681 | 1681 | $ hg debugrevspec '0:wdir() & ffff' |
|
1682 | 1682 | abort: 00changelog.i@ffff: ambiguous identifier! |
|
1683 | 1683 | [255] |
|
1684 | 1684 | $ hg debugrevspec '0:wdir() & fffb' |
|
1685 | 1685 | abort: 00changelog.i@fffb: ambiguous identifier! |
|
1686 | 1686 | [255] |
|
1687 | 1687 | BROKEN should be '2' (node lookup uses unfiltered repo since dc25ed84bee8) |
|
1688 | 1688 | $ hg debugrevspec '0:wdir() & id(fffb)' |
|
1689 | 1689 | 2 |
|
1690 | 1690 | $ hg debugrevspec '0:wdir() & ffff8' |
|
1691 | 1691 | 4 |
|
1692 | 1692 | $ hg debugrevspec '0:wdir() & fffff' |
|
1693 | 1693 | 2147483647 |
|
1694 | 1694 | |
|
1695 | 1695 | $ cd .. |
|
1696 | 1696 | |
|
1697 | 1697 | Test branch() with wdir() |
|
1698 | 1698 | |
|
1699 | 1699 | $ cd repo |
|
1700 | 1700 | |
|
1701 | 1701 | $ log '0:wdir() & branch("literal:Γ©")' |
|
1702 | 1702 | 8 |
|
1703 | 1703 | 9 |
|
1704 | 1704 | 2147483647 |
|
1705 | 1705 | $ log '0:wdir() & branch("re:Γ©")' |
|
1706 | 1706 | 8 |
|
1707 | 1707 | 9 |
|
1708 | 1708 | 2147483647 |
|
1709 | 1709 | $ log '0:wdir() & branch("re:^a")' |
|
1710 | 1710 | 0 |
|
1711 | 1711 | 2 |
|
1712 | 1712 | $ log '0:wdir() & branch(8)' |
|
1713 | 1713 | 8 |
|
1714 | 1714 | 9 |
|
1715 | 1715 | 2147483647 |
|
1716 | 1716 | |
|
1717 | 1717 | branch(wdir()) returns all revisions belonging to the working branch. The wdir |
|
1718 | 1718 | itself isn't returned unless it is explicitly populated. |
|
1719 | 1719 | |
|
1720 | 1720 | $ log 'branch(wdir())' |
|
1721 | 1721 | 8 |
|
1722 | 1722 | 9 |
|
1723 | 1723 | $ log '0:wdir() & branch(wdir())' |
|
1724 | 1724 | 8 |
|
1725 | 1725 | 9 |
|
1726 | 1726 | 2147483647 |
|
1727 | 1727 | |
|
1728 | 1728 | $ log 'outgoing()' |
|
1729 | 1729 | 8 |
|
1730 | 1730 | 9 |
|
1731 | 1731 | $ log 'outgoing("../remote1")' |
|
1732 | 1732 | 8 |
|
1733 | 1733 | 9 |
|
1734 | 1734 | $ log 'outgoing("../remote2")' |
|
1735 | 1735 | 3 |
|
1736 | 1736 | 5 |
|
1737 | 1737 | 6 |
|
1738 | 1738 | 7 |
|
1739 | 1739 | 9 |
|
1740 | 1740 | $ log 'p1(merge())' |
|
1741 | 1741 | 5 |
|
1742 | 1742 | $ log 'p2(merge())' |
|
1743 | 1743 | 4 |
|
1744 | 1744 | $ log 'parents(merge())' |
|
1745 | 1745 | 4 |
|
1746 | 1746 | 5 |
|
1747 | 1747 | $ log 'p1(branchpoint())' |
|
1748 | 1748 | 0 |
|
1749 | 1749 | 2 |
|
1750 | 1750 | $ log 'p2(branchpoint())' |
|
1751 | 1751 | $ log 'parents(branchpoint())' |
|
1752 | 1752 | 0 |
|
1753 | 1753 | 2 |
|
1754 | 1754 | $ log 'removes(a)' |
|
1755 | 1755 | 2 |
|
1756 | 1756 | 6 |
|
1757 | 1757 | $ log 'roots(all())' |
|
1758 | 1758 | 0 |
|
1759 | 1759 | $ log 'reverse(2 or 3 or 4 or 5)' |
|
1760 | 1760 | 5 |
|
1761 | 1761 | 4 |
|
1762 | 1762 | 3 |
|
1763 | 1763 | 2 |
|
1764 | 1764 | $ log 'reverse(all())' |
|
1765 | 1765 | 9 |
|
1766 | 1766 | 8 |
|
1767 | 1767 | 7 |
|
1768 | 1768 | 6 |
|
1769 | 1769 | 5 |
|
1770 | 1770 | 4 |
|
1771 | 1771 | 3 |
|
1772 | 1772 | 2 |
|
1773 | 1773 | 1 |
|
1774 | 1774 | 0 |
|
1775 | 1775 | $ log 'reverse(all()) & filelog(b)' |
|
1776 | 1776 | 4 |
|
1777 | 1777 | 1 |
|
1778 | 1778 | $ log 'rev(5)' |
|
1779 | 1779 | 5 |
|
1780 | 1780 | $ log 'sort(limit(reverse(all()), 3))' |
|
1781 | 1781 | 7 |
|
1782 | 1782 | 8 |
|
1783 | 1783 | 9 |
|
1784 | 1784 | $ log 'sort(2 or 3 or 4 or 5, date)' |
|
1785 | 1785 | 2 |
|
1786 | 1786 | 3 |
|
1787 | 1787 | 5 |
|
1788 | 1788 | 4 |
|
1789 | 1789 | $ log 'tagged()' |
|
1790 | 1790 | 6 |
|
1791 | 1791 | $ log 'tag()' |
|
1792 | 1792 | 6 |
|
1793 | 1793 | $ log 'tag(1.0)' |
|
1794 | 1794 | 6 |
|
1795 | 1795 | $ log 'tag(tip)' |
|
1796 | 1796 | 9 |
|
1797 | 1797 | |
|
1798 | 1798 | Test order of revisions in compound expression |
|
1799 | 1799 | ---------------------------------------------- |
|
1800 | 1800 | |
|
1801 | 1801 | The general rule is that only the outermost (= leftmost) predicate can |
|
1802 | 1802 | enforce its ordering requirement. The other predicates should take the |
|
1803 | 1803 | ordering defined by it. |
|
1804 | 1804 | |
|
1805 | 1805 | 'A & B' should follow the order of 'A': |
|
1806 | 1806 | |
|
1807 | 1807 | $ log '2:0 & 0::2' |
|
1808 | 1808 | 2 |
|
1809 | 1809 | 1 |
|
1810 | 1810 | 0 |
|
1811 | 1811 | |
|
1812 | 1812 | 'head()' combines sets in right order: |
|
1813 | 1813 | |
|
1814 | 1814 | $ log '2:0 & head()' |
|
1815 | 1815 | 2 |
|
1816 | 1816 | 1 |
|
1817 | 1817 | 0 |
|
1818 | 1818 | |
|
1819 | 1819 | 'x:y' takes ordering parameter into account: |
|
1820 | 1820 | |
|
1821 | 1821 | $ try -p optimized '3:0 & 0:3 & not 2:1' |
|
1822 | 1822 | * optimized: |
|
1823 | 1823 | (difference |
|
1824 | 1824 | (and |
|
1825 | 1825 | (range |
|
1826 | 1826 | ('symbol', '3') |
|
1827 | 1827 | ('symbol', '0') |
|
1828 | 1828 | define) |
|
1829 | 1829 | (range |
|
1830 | 1830 | ('symbol', '0') |
|
1831 | 1831 | ('symbol', '3') |
|
1832 | 1832 | follow) |
|
1833 | 1833 | define) |
|
1834 | 1834 | (range |
|
1835 | 1835 | ('symbol', '2') |
|
1836 | 1836 | ('symbol', '1') |
|
1837 | 1837 | any) |
|
1838 | 1838 | define) |
|
1839 | 1839 | * set: |
|
1840 | 1840 | <filteredset |
|
1841 | 1841 | <filteredset |
|
1842 | 1842 | <spanset- 0:4>, |
|
1843 | 1843 | <spanset+ 0:4>>, |
|
1844 | 1844 | <not |
|
1845 | 1845 | <spanset+ 1:3>>> |
|
1846 | 1846 | 3 |
|
1847 | 1847 | 0 |
|
1848 | 1848 | |
|
1849 | 1849 | 'a + b', which is optimized to '_list(a b)', should take the ordering of |
|
1850 | 1850 | the left expression: |
|
1851 | 1851 | |
|
1852 | 1852 | $ try --optimize '2:0 & (0 + 1 + 2)' |
|
1853 | 1853 | (and |
|
1854 | 1854 | (range |
|
1855 | 1855 | ('symbol', '2') |
|
1856 | 1856 | ('symbol', '0')) |
|
1857 | 1857 | (group |
|
1858 | 1858 | (or |
|
1859 | 1859 | (list |
|
1860 | 1860 | ('symbol', '0') |
|
1861 | 1861 | ('symbol', '1') |
|
1862 | 1862 | ('symbol', '2'))))) |
|
1863 | 1863 | * optimized: |
|
1864 | 1864 | (and |
|
1865 | 1865 | (range |
|
1866 | 1866 | ('symbol', '2') |
|
1867 | 1867 | ('symbol', '0') |
|
1868 | 1868 | define) |
|
1869 | 1869 | (func |
|
1870 | 1870 | ('symbol', '_list') |
|
1871 | 1871 | ('string', '0\x001\x002') |
|
1872 | 1872 | follow) |
|
1873 | 1873 | define) |
|
1874 | 1874 | * set: |
|
1875 | 1875 | <filteredset |
|
1876 | 1876 | <spanset- 0:3>, |
|
1877 | 1877 | <baseset [0, 1, 2]>> |
|
1878 | 1878 | 2 |
|
1879 | 1879 | 1 |
|
1880 | 1880 | 0 |
|
1881 | 1881 | |
|
1882 | 1882 | 'A + B' should take the ordering of the left expression: |
|
1883 | 1883 | |
|
1884 | 1884 | $ try --optimize '2:0 & (0:1 + 2)' |
|
1885 | 1885 | (and |
|
1886 | 1886 | (range |
|
1887 | 1887 | ('symbol', '2') |
|
1888 | 1888 | ('symbol', '0')) |
|
1889 | 1889 | (group |
|
1890 | 1890 | (or |
|
1891 | 1891 | (list |
|
1892 | 1892 | (range |
|
1893 | 1893 | ('symbol', '0') |
|
1894 | 1894 | ('symbol', '1')) |
|
1895 | 1895 | ('symbol', '2'))))) |
|
1896 | 1896 | * optimized: |
|
1897 | 1897 | (and |
|
1898 | 1898 | (range |
|
1899 | 1899 | ('symbol', '2') |
|
1900 | 1900 | ('symbol', '0') |
|
1901 | 1901 | define) |
|
1902 | 1902 | (or |
|
1903 | 1903 | (list |
|
1904 | 1904 | ('symbol', '2') |
|
1905 | 1905 | (range |
|
1906 | 1906 | ('symbol', '0') |
|
1907 | 1907 | ('symbol', '1') |
|
1908 | 1908 | follow)) |
|
1909 | 1909 | follow) |
|
1910 | 1910 | define) |
|
1911 | 1911 | * set: |
|
1912 | 1912 | <filteredset |
|
1913 | 1913 | <spanset- 0:3>, |
|
1914 | 1914 | <addset |
|
1915 | 1915 | <baseset [2]>, |
|
1916 | 1916 | <spanset+ 0:2>>> |
|
1917 | 1917 | 2 |
|
1918 | 1918 | 1 |
|
1919 | 1919 | 0 |
|
1920 | 1920 | |
|
1921 | 1921 | '_intlist(a b)' should behave like 'a + b': |
|
1922 | 1922 | |
|
1923 | 1923 | $ trylist --optimize '2:0 & %ld' 0 1 2 |
|
1924 | 1924 | (and |
|
1925 | 1925 | (range |
|
1926 | 1926 | ('symbol', '2') |
|
1927 | 1927 | ('symbol', '0')) |
|
1928 | 1928 | (func |
|
1929 | 1929 | ('symbol', '_intlist') |
|
1930 | 1930 | ('string', '0\x001\x002'))) |
|
1931 | 1931 | * optimized: |
|
1932 | 1932 | (and |
|
1933 | 1933 | (func |
|
1934 | 1934 | ('symbol', '_intlist') |
|
1935 | 1935 | ('string', '0\x001\x002') |
|
1936 | 1936 | follow) |
|
1937 | 1937 | (range |
|
1938 | 1938 | ('symbol', '2') |
|
1939 | 1939 | ('symbol', '0') |
|
1940 | 1940 | define) |
|
1941 | 1941 | define) |
|
1942 | 1942 | * set: |
|
1943 | 1943 | <filteredset |
|
1944 | 1944 | <spanset- 0:3>, |
|
1945 | 1945 | <baseset+ [0, 1, 2]>> |
|
1946 | 1946 | 2 |
|
1947 | 1947 | 1 |
|
1948 | 1948 | 0 |
|
1949 | 1949 | |
|
1950 | 1950 | $ trylist --optimize '%ld & 2:0' 0 2 1 |
|
1951 | 1951 | (and |
|
1952 | 1952 | (func |
|
1953 | 1953 | ('symbol', '_intlist') |
|
1954 | 1954 | ('string', '0\x002\x001')) |
|
1955 | 1955 | (range |
|
1956 | 1956 | ('symbol', '2') |
|
1957 | 1957 | ('symbol', '0'))) |
|
1958 | 1958 | * optimized: |
|
1959 | 1959 | (and |
|
1960 | 1960 | (func |
|
1961 | 1961 | ('symbol', '_intlist') |
|
1962 | 1962 | ('string', '0\x002\x001') |
|
1963 | 1963 | define) |
|
1964 | 1964 | (range |
|
1965 | 1965 | ('symbol', '2') |
|
1966 | 1966 | ('symbol', '0') |
|
1967 | 1967 | follow) |
|
1968 | 1968 | define) |
|
1969 | 1969 | * set: |
|
1970 | 1970 | <filteredset |
|
1971 | 1971 | <baseset [0, 2, 1]>, |
|
1972 | 1972 | <spanset- 0:3>> |
|
1973 | 1973 | 0 |
|
1974 | 1974 | 2 |
|
1975 | 1975 | 1 |
|
1976 | 1976 | |
|
1977 | 1977 | '_hexlist(a b)' should behave like 'a + b': |
|
1978 | 1978 | |
|
1979 | 1979 | $ trylist --optimize --bin '2:0 & %ln' `hg log -T '{node} ' -r0:2` |
|
1980 | 1980 | (and |
|
1981 | 1981 | (range |
|
1982 | 1982 | ('symbol', '2') |
|
1983 | 1983 | ('symbol', '0')) |
|
1984 | 1984 | (func |
|
1985 | 1985 | ('symbol', '_hexlist') |
|
1986 | 1986 | ('string', '*'))) (glob) |
|
1987 | 1987 | * optimized: |
|
1988 | 1988 | (and |
|
1989 | 1989 | (range |
|
1990 | 1990 | ('symbol', '2') |
|
1991 | 1991 | ('symbol', '0') |
|
1992 | 1992 | define) |
|
1993 | 1993 | (func |
|
1994 | 1994 | ('symbol', '_hexlist') |
|
1995 | 1995 | ('string', '*') (glob) |
|
1996 | 1996 | follow) |
|
1997 | 1997 | define) |
|
1998 | 1998 | * set: |
|
1999 | 1999 | <filteredset |
|
2000 | 2000 | <spanset- 0:3>, |
|
2001 | 2001 | <baseset [0, 1, 2]>> |
|
2002 | 2002 | 2 |
|
2003 | 2003 | 1 |
|
2004 | 2004 | 0 |
|
2005 | 2005 | |
|
2006 | 2006 | $ trylist --optimize --bin '%ln & 2:0' `hg log -T '{node} ' -r0+2+1` |
|
2007 | 2007 | (and |
|
2008 | 2008 | (func |
|
2009 | 2009 | ('symbol', '_hexlist') |
|
2010 | 2010 | ('string', '*')) (glob) |
|
2011 | 2011 | (range |
|
2012 | 2012 | ('symbol', '2') |
|
2013 | 2013 | ('symbol', '0'))) |
|
2014 | 2014 | * optimized: |
|
2015 | 2015 | (and |
|
2016 | 2016 | (range |
|
2017 | 2017 | ('symbol', '2') |
|
2018 | 2018 | ('symbol', '0') |
|
2019 | 2019 | follow) |
|
2020 | 2020 | (func |
|
2021 | 2021 | ('symbol', '_hexlist') |
|
2022 | 2022 | ('string', '*') (glob) |
|
2023 | 2023 | define) |
|
2024 | 2024 | define) |
|
2025 | 2025 | * set: |
|
2026 | 2026 | <baseset [0, 2, 1]> |
|
2027 | 2027 | 0 |
|
2028 | 2028 | 2 |
|
2029 | 2029 | 1 |
|
2030 | 2030 | |
|
2031 | 2031 | '_list' should not go through the slow follow-order path if order doesn't |
|
2032 | 2032 | matter: |
|
2033 | 2033 | |
|
2034 | 2034 | $ try -p optimized '2:0 & not (0 + 1)' |
|
2035 | 2035 | * optimized: |
|
2036 | 2036 | (difference |
|
2037 | 2037 | (range |
|
2038 | 2038 | ('symbol', '2') |
|
2039 | 2039 | ('symbol', '0') |
|
2040 | 2040 | define) |
|
2041 | 2041 | (func |
|
2042 | 2042 | ('symbol', '_list') |
|
2043 | 2043 | ('string', '0\x001') |
|
2044 | 2044 | any) |
|
2045 | 2045 | define) |
|
2046 | 2046 | * set: |
|
2047 | 2047 | <filteredset |
|
2048 | 2048 | <spanset- 0:3>, |
|
2049 | 2049 | <not |
|
2050 | 2050 | <baseset [0, 1]>>> |
|
2051 | 2051 | 2 |
|
2052 | 2052 | |
|
2053 | 2053 | $ try -p optimized '2:0 & not (0:2 & (0 + 1))' |
|
2054 | 2054 | * optimized: |
|
2055 | 2055 | (difference |
|
2056 | 2056 | (range |
|
2057 | 2057 | ('symbol', '2') |
|
2058 | 2058 | ('symbol', '0') |
|
2059 | 2059 | define) |
|
2060 | 2060 | (and |
|
2061 | 2061 | (range |
|
2062 | 2062 | ('symbol', '0') |
|
2063 | 2063 | ('symbol', '2') |
|
2064 | 2064 | any) |
|
2065 | 2065 | (func |
|
2066 | 2066 | ('symbol', '_list') |
|
2067 | 2067 | ('string', '0\x001') |
|
2068 | 2068 | any) |
|
2069 | 2069 | any) |
|
2070 | 2070 | define) |
|
2071 | 2071 | * set: |
|
2072 | 2072 | <filteredset |
|
2073 | 2073 | <spanset- 0:3>, |
|
2074 | 2074 | <not |
|
2075 | 2075 | <baseset [0, 1]>>> |
|
2076 | 2076 | 2 |
|
2077 | 2077 | |
|
2078 | 2078 | because 'present()' does nothing other than suppressing an error, the |
|
2079 | 2079 | ordering requirement should be forwarded to the nested expression |
|
2080 | 2080 | |
|
2081 | 2081 | $ try -p optimized 'present(2 + 0 + 1)' |
|
2082 | 2082 | * optimized: |
|
2083 | 2083 | (func |
|
2084 | 2084 | ('symbol', 'present') |
|
2085 | 2085 | (func |
|
2086 | 2086 | ('symbol', '_list') |
|
2087 | 2087 | ('string', '2\x000\x001') |
|
2088 | 2088 | define) |
|
2089 | 2089 | define) |
|
2090 | 2090 | * set: |
|
2091 | 2091 | <baseset [2, 0, 1]> |
|
2092 | 2092 | 2 |
|
2093 | 2093 | 0 |
|
2094 | 2094 | 1 |
|
2095 | 2095 | |
|
2096 | 2096 | $ try --optimize '2:0 & present(0 + 1 + 2)' |
|
2097 | 2097 | (and |
|
2098 | 2098 | (range |
|
2099 | 2099 | ('symbol', '2') |
|
2100 | 2100 | ('symbol', '0')) |
|
2101 | 2101 | (func |
|
2102 | 2102 | ('symbol', 'present') |
|
2103 | 2103 | (or |
|
2104 | 2104 | (list |
|
2105 | 2105 | ('symbol', '0') |
|
2106 | 2106 | ('symbol', '1') |
|
2107 | 2107 | ('symbol', '2'))))) |
|
2108 | 2108 | * optimized: |
|
2109 | 2109 | (and |
|
2110 | 2110 | (range |
|
2111 | 2111 | ('symbol', '2') |
|
2112 | 2112 | ('symbol', '0') |
|
2113 | 2113 | define) |
|
2114 | 2114 | (func |
|
2115 | 2115 | ('symbol', 'present') |
|
2116 | 2116 | (func |
|
2117 | 2117 | ('symbol', '_list') |
|
2118 | 2118 | ('string', '0\x001\x002') |
|
2119 | 2119 | follow) |
|
2120 | 2120 | follow) |
|
2121 | 2121 | define) |
|
2122 | 2122 | * set: |
|
2123 | 2123 | <filteredset |
|
2124 | 2124 | <spanset- 0:3>, |
|
2125 | 2125 | <baseset [0, 1, 2]>> |
|
2126 | 2126 | 2 |
|
2127 | 2127 | 1 |
|
2128 | 2128 | 0 |
|
2129 | 2129 | |
|
2130 | 2130 | 'reverse()' should take effect only if it is the outermost expression: |
|
2131 | 2131 | |
|
2132 | 2132 | $ try --optimize '0:2 & reverse(all())' |
|
2133 | 2133 | (and |
|
2134 | 2134 | (range |
|
2135 | 2135 | ('symbol', '0') |
|
2136 | 2136 | ('symbol', '2')) |
|
2137 | 2137 | (func |
|
2138 | 2138 | ('symbol', 'reverse') |
|
2139 | 2139 | (func |
|
2140 | 2140 | ('symbol', 'all') |
|
2141 | 2141 | None))) |
|
2142 | 2142 | * optimized: |
|
2143 | 2143 | (and |
|
2144 | 2144 | (range |
|
2145 | 2145 | ('symbol', '0') |
|
2146 | 2146 | ('symbol', '2') |
|
2147 | 2147 | define) |
|
2148 | 2148 | (func |
|
2149 | 2149 | ('symbol', 'reverse') |
|
2150 | 2150 | (func |
|
2151 | 2151 | ('symbol', 'all') |
|
2152 | 2152 | None |
|
2153 | 2153 | define) |
|
2154 | 2154 | follow) |
|
2155 | 2155 | define) |
|
2156 | 2156 | * set: |
|
2157 | 2157 | <filteredset |
|
2158 | 2158 | <spanset+ 0:3>, |
|
2159 | 2159 | <spanset+ 0:10>> |
|
2160 | 2160 | 0 |
|
2161 | 2161 | 1 |
|
2162 | 2162 | 2 |
|
2163 | 2163 | |
|
2164 | 2164 | 'sort()' should take effect only if it is the outermost expression: |
|
2165 | 2165 | |
|
2166 | 2166 | $ try --optimize '0:2 & sort(all(), -rev)' |
|
2167 | 2167 | (and |
|
2168 | 2168 | (range |
|
2169 | 2169 | ('symbol', '0') |
|
2170 | 2170 | ('symbol', '2')) |
|
2171 | 2171 | (func |
|
2172 | 2172 | ('symbol', 'sort') |
|
2173 | 2173 | (list |
|
2174 | 2174 | (func |
|
2175 | 2175 | ('symbol', 'all') |
|
2176 | 2176 | None) |
|
2177 | 2177 | (negate |
|
2178 | 2178 | ('symbol', 'rev'))))) |
|
2179 | 2179 | * optimized: |
|
2180 | 2180 | (and |
|
2181 | 2181 | (range |
|
2182 | 2182 | ('symbol', '0') |
|
2183 | 2183 | ('symbol', '2') |
|
2184 | 2184 | define) |
|
2185 | 2185 | (func |
|
2186 | 2186 | ('symbol', 'sort') |
|
2187 | 2187 | (list |
|
2188 | 2188 | (func |
|
2189 | 2189 | ('symbol', 'all') |
|
2190 | 2190 | None |
|
2191 | 2191 | define) |
|
2192 | 2192 | ('string', '-rev')) |
|
2193 | 2193 | follow) |
|
2194 | 2194 | define) |
|
2195 | 2195 | * set: |
|
2196 | 2196 | <filteredset |
|
2197 | 2197 | <spanset+ 0:3>, |
|
2198 | 2198 | <spanset+ 0:10>> |
|
2199 | 2199 | 0 |
|
2200 | 2200 | 1 |
|
2201 | 2201 | 2 |
|
2202 | 2202 | |
|
2203 | 2203 | invalid argument passed to noop sort(): |
|
2204 | 2204 | |
|
2205 | 2205 | $ log '0:2 & sort()' |
|
2206 | 2206 | hg: parse error: sort requires one or two arguments |
|
2207 | 2207 | [255] |
|
2208 | 2208 | $ log '0:2 & sort(all(), -invalid)' |
|
2209 | 2209 | hg: parse error: unknown sort key '-invalid' |
|
2210 | 2210 | [255] |
|
2211 | 2211 | |
|
2212 | 2212 | for 'A & f(B)', 'B' should not be affected by the order of 'A': |
|
2213 | 2213 | |
|
2214 | 2214 | $ try --optimize '2:0 & first(1 + 0 + 2)' |
|
2215 | 2215 | (and |
|
2216 | 2216 | (range |
|
2217 | 2217 | ('symbol', '2') |
|
2218 | 2218 | ('symbol', '0')) |
|
2219 | 2219 | (func |
|
2220 | 2220 | ('symbol', 'first') |
|
2221 | 2221 | (or |
|
2222 | 2222 | (list |
|
2223 | 2223 | ('symbol', '1') |
|
2224 | 2224 | ('symbol', '0') |
|
2225 | 2225 | ('symbol', '2'))))) |
|
2226 | 2226 | * optimized: |
|
2227 | 2227 | (and |
|
2228 | 2228 | (range |
|
2229 | 2229 | ('symbol', '2') |
|
2230 | 2230 | ('symbol', '0') |
|
2231 | 2231 | define) |
|
2232 | 2232 | (func |
|
2233 | 2233 | ('symbol', 'first') |
|
2234 | 2234 | (func |
|
2235 | 2235 | ('symbol', '_list') |
|
2236 | 2236 | ('string', '1\x000\x002') |
|
2237 | 2237 | define) |
|
2238 | 2238 | follow) |
|
2239 | 2239 | define) |
|
2240 | 2240 | * set: |
|
2241 | 2241 | <filteredset |
|
2242 | 2242 | <baseset [1]>, |
|
2243 | 2243 | <spanset- 0:3>> |
|
2244 | 2244 | 1 |
|
2245 | 2245 | |
|
2246 | 2246 | $ try --optimize '2:0 & not last(0 + 2 + 1)' |
|
2247 | 2247 | (and |
|
2248 | 2248 | (range |
|
2249 | 2249 | ('symbol', '2') |
|
2250 | 2250 | ('symbol', '0')) |
|
2251 | 2251 | (not |
|
2252 | 2252 | (func |
|
2253 | 2253 | ('symbol', 'last') |
|
2254 | 2254 | (or |
|
2255 | 2255 | (list |
|
2256 | 2256 | ('symbol', '0') |
|
2257 | 2257 | ('symbol', '2') |
|
2258 | 2258 | ('symbol', '1')))))) |
|
2259 | 2259 | * optimized: |
|
2260 | 2260 | (difference |
|
2261 | 2261 | (range |
|
2262 | 2262 | ('symbol', '2') |
|
2263 | 2263 | ('symbol', '0') |
|
2264 | 2264 | define) |
|
2265 | 2265 | (func |
|
2266 | 2266 | ('symbol', 'last') |
|
2267 | 2267 | (func |
|
2268 | 2268 | ('symbol', '_list') |
|
2269 | 2269 | ('string', '0\x002\x001') |
|
2270 | 2270 | define) |
|
2271 | 2271 | any) |
|
2272 | 2272 | define) |
|
2273 | 2273 | * set: |
|
2274 | 2274 | <filteredset |
|
2275 | 2275 | <spanset- 0:3>, |
|
2276 | 2276 | <not |
|
2277 | 2277 | <baseset [1]>>> |
|
2278 | 2278 | 2 |
|
2279 | 2279 | 0 |
|
2280 | 2280 | |
|
2281 | 2281 | for 'A & (op)(B)', 'B' should not be affected by the order of 'A': |
|
2282 | 2282 | |
|
2283 | 2283 | $ try --optimize '2:0 & (1 + 0 + 2):(0 + 2 + 1)' |
|
2284 | 2284 | (and |
|
2285 | 2285 | (range |
|
2286 | 2286 | ('symbol', '2') |
|
2287 | 2287 | ('symbol', '0')) |
|
2288 | 2288 | (range |
|
2289 | 2289 | (group |
|
2290 | 2290 | (or |
|
2291 | 2291 | (list |
|
2292 | 2292 | ('symbol', '1') |
|
2293 | 2293 | ('symbol', '0') |
|
2294 | 2294 | ('symbol', '2')))) |
|
2295 | 2295 | (group |
|
2296 | 2296 | (or |
|
2297 | 2297 | (list |
|
2298 | 2298 | ('symbol', '0') |
|
2299 | 2299 | ('symbol', '2') |
|
2300 | 2300 | ('symbol', '1')))))) |
|
2301 | 2301 | * optimized: |
|
2302 | 2302 | (and |
|
2303 | 2303 | (range |
|
2304 | 2304 | ('symbol', '2') |
|
2305 | 2305 | ('symbol', '0') |
|
2306 | 2306 | define) |
|
2307 | 2307 | (range |
|
2308 | 2308 | (func |
|
2309 | 2309 | ('symbol', '_list') |
|
2310 | 2310 | ('string', '1\x000\x002') |
|
2311 | 2311 | define) |
|
2312 | 2312 | (func |
|
2313 | 2313 | ('symbol', '_list') |
|
2314 | 2314 | ('string', '0\x002\x001') |
|
2315 | 2315 | define) |
|
2316 | 2316 | follow) |
|
2317 | 2317 | define) |
|
2318 | 2318 | * set: |
|
2319 | 2319 | <filteredset |
|
2320 | 2320 | <spanset- 0:3>, |
|
2321 | 2321 | <baseset [1]>> |
|
2322 | 2322 | 1 |
|
2323 | 2323 | |
|
2324 | 2324 | 'A & B' can be rewritten as 'B & A' by weight, but that's fine as long as |
|
2325 | 2325 | the ordering rule is determined before the rewrite; in this example, |
|
2326 | 2326 | 'B' follows the order of the initial set, which is the same order as 'A' |
|
2327 | 2327 | since 'A' also follows the order: |
|
2328 | 2328 | |
|
2329 | 2329 | $ try --optimize 'contains("glob:*") & (2 + 0 + 1)' |
|
2330 | 2330 | (and |
|
2331 | 2331 | (func |
|
2332 | 2332 | ('symbol', 'contains') |
|
2333 | 2333 | ('string', 'glob:*')) |
|
2334 | 2334 | (group |
|
2335 | 2335 | (or |
|
2336 | 2336 | (list |
|
2337 | 2337 | ('symbol', '2') |
|
2338 | 2338 | ('symbol', '0') |
|
2339 | 2339 | ('symbol', '1'))))) |
|
2340 | 2340 | * optimized: |
|
2341 | 2341 | (and |
|
2342 | 2342 | (func |
|
2343 | 2343 | ('symbol', '_list') |
|
2344 | 2344 | ('string', '2\x000\x001') |
|
2345 | 2345 | follow) |
|
2346 | 2346 | (func |
|
2347 | 2347 | ('symbol', 'contains') |
|
2348 | 2348 | ('string', 'glob:*') |
|
2349 | 2349 | define) |
|
2350 | 2350 | define) |
|
2351 | 2351 | * set: |
|
2352 | 2352 | <filteredset |
|
2353 | 2353 | <baseset+ [0, 1, 2]>, |
|
2354 | 2354 | <contains 'glob:*'>> |
|
2355 | 2355 | 0 |
|
2356 | 2356 | 1 |
|
2357 | 2357 | 2 |
|
2358 | 2358 | |
|
2359 | 2359 | and in this example, 'A & B' is rewritten as 'B & A', but 'A' overrides |
|
2360 | 2360 | the order appropriately: |
|
2361 | 2361 | |
|
2362 | 2362 | $ try --optimize 'reverse(contains("glob:*")) & (0 + 2 + 1)' |
|
2363 | 2363 | (and |
|
2364 | 2364 | (func |
|
2365 | 2365 | ('symbol', 'reverse') |
|
2366 | 2366 | (func |
|
2367 | 2367 | ('symbol', 'contains') |
|
2368 | 2368 | ('string', 'glob:*'))) |
|
2369 | 2369 | (group |
|
2370 | 2370 | (or |
|
2371 | 2371 | (list |
|
2372 | 2372 | ('symbol', '0') |
|
2373 | 2373 | ('symbol', '2') |
|
2374 | 2374 | ('symbol', '1'))))) |
|
2375 | 2375 | * optimized: |
|
2376 | 2376 | (and |
|
2377 | 2377 | (func |
|
2378 | 2378 | ('symbol', '_list') |
|
2379 | 2379 | ('string', '0\x002\x001') |
|
2380 | 2380 | follow) |
|
2381 | 2381 | (func |
|
2382 | 2382 | ('symbol', 'reverse') |
|
2383 | 2383 | (func |
|
2384 | 2384 | ('symbol', 'contains') |
|
2385 | 2385 | ('string', 'glob:*') |
|
2386 | 2386 | define) |
|
2387 | 2387 | define) |
|
2388 | 2388 | define) |
|
2389 | 2389 | * set: |
|
2390 | 2390 | <filteredset |
|
2391 | 2391 | <baseset- [0, 1, 2]>, |
|
2392 | 2392 | <contains 'glob:*'>> |
|
2393 | 2393 | 2 |
|
2394 | 2394 | 1 |
|
2395 | 2395 | 0 |
|
2396 | 2396 | |
|
2397 | 2397 | 'A + B' can be rewritten to 'B + A' by weight only when the order doesn't |
|
2398 | 2398 | matter (e.g. 'X & (A + B)' can be 'X & (B + A)', but '(A + B) & X' can't): |
|
2399 | 2399 | |
|
2400 | 2400 | $ try -p optimized '0:2 & (reverse(contains("a")) + 2)' |
|
2401 | 2401 | * optimized: |
|
2402 | 2402 | (and |
|
2403 | 2403 | (range |
|
2404 | 2404 | ('symbol', '0') |
|
2405 | 2405 | ('symbol', '2') |
|
2406 | 2406 | define) |
|
2407 | 2407 | (or |
|
2408 | 2408 | (list |
|
2409 | 2409 | ('symbol', '2') |
|
2410 | 2410 | (func |
|
2411 | 2411 | ('symbol', 'reverse') |
|
2412 | 2412 | (func |
|
2413 | 2413 | ('symbol', 'contains') |
|
2414 | 2414 | ('string', 'a') |
|
2415 | 2415 | define) |
|
2416 | 2416 | follow)) |
|
2417 | 2417 | follow) |
|
2418 | 2418 | define) |
|
2419 | 2419 | * set: |
|
2420 | 2420 | <filteredset |
|
2421 | 2421 | <spanset+ 0:3>, |
|
2422 | 2422 | <addset |
|
2423 | 2423 | <baseset [2]>, |
|
2424 | 2424 | <filteredset |
|
2425 | 2425 | <fullreposet+ 0:10>, |
|
2426 | 2426 | <contains 'a'>>>> |
|
2427 | 2427 | 0 |
|
2428 | 2428 | 1 |
|
2429 | 2429 | 2 |
|
2430 | 2430 | |
|
2431 | 2431 | $ try -p optimized '(reverse(contains("a")) + 2) & 0:2' |
|
2432 | 2432 | * optimized: |
|
2433 | 2433 | (and |
|
2434 | 2434 | (range |
|
2435 | 2435 | ('symbol', '0') |
|
2436 | 2436 | ('symbol', '2') |
|
2437 | 2437 | follow) |
|
2438 | 2438 | (or |
|
2439 | 2439 | (list |
|
2440 | 2440 | (func |
|
2441 | 2441 | ('symbol', 'reverse') |
|
2442 | 2442 | (func |
|
2443 | 2443 | ('symbol', 'contains') |
|
2444 | 2444 | ('string', 'a') |
|
2445 | 2445 | define) |
|
2446 | 2446 | define) |
|
2447 | 2447 | ('symbol', '2')) |
|
2448 | 2448 | define) |
|
2449 | 2449 | define) |
|
2450 | 2450 | * set: |
|
2451 | 2451 | <addset |
|
2452 | 2452 | <filteredset |
|
2453 | 2453 | <spanset- 0:3>, |
|
2454 | 2454 | <contains 'a'>>, |
|
2455 | 2455 | <baseset [2]>> |
|
2456 | 2456 | 1 |
|
2457 | 2457 | 0 |
|
2458 | 2458 | 2 |
|
2459 | 2459 | |
|
2460 | 2460 | test sort revset |
|
2461 | 2461 | -------------------------------------------- |
|
2462 | 2462 | |
|
2463 | 2463 | test when adding two unordered revsets |
|
2464 | 2464 | |
|
2465 | 2465 | $ log 'sort(keyword(issue) or modifies(b))' |
|
2466 | 2466 | 4 |
|
2467 | 2467 | 6 |
|
2468 | 2468 | |
|
2469 | 2469 | test when sorting a reversed collection in the same way it is |
|
2470 | 2470 | |
|
2471 | 2471 | $ log 'sort(reverse(all()), -rev)' |
|
2472 | 2472 | 9 |
|
2473 | 2473 | 8 |
|
2474 | 2474 | 7 |
|
2475 | 2475 | 6 |
|
2476 | 2476 | 5 |
|
2477 | 2477 | 4 |
|
2478 | 2478 | 3 |
|
2479 | 2479 | 2 |
|
2480 | 2480 | 1 |
|
2481 | 2481 | 0 |
|
2482 | 2482 | |
|
2483 | 2483 | test when sorting a reversed collection |
|
2484 | 2484 | |
|
2485 | 2485 | $ log 'sort(reverse(all()), rev)' |
|
2486 | 2486 | 0 |
|
2487 | 2487 | 1 |
|
2488 | 2488 | 2 |
|
2489 | 2489 | 3 |
|
2490 | 2490 | 4 |
|
2491 | 2491 | 5 |
|
2492 | 2492 | 6 |
|
2493 | 2493 | 7 |
|
2494 | 2494 | 8 |
|
2495 | 2495 | 9 |
|
2496 | 2496 | |
|
2497 | 2497 | |
|
2498 | 2498 | test sorting two sorted collections in different orders |
|
2499 | 2499 | |
|
2500 | 2500 | $ log 'sort(outgoing() or reverse(removes(a)), rev)' |
|
2501 | 2501 | 2 |
|
2502 | 2502 | 6 |
|
2503 | 2503 | 8 |
|
2504 | 2504 | 9 |
|
2505 | 2505 | |
|
2506 | 2506 | test sorting two sorted collections in different orders backwards |
|
2507 | 2507 | |
|
2508 | 2508 | $ log 'sort(outgoing() or reverse(removes(a)), -rev)' |
|
2509 | 2509 | 9 |
|
2510 | 2510 | 8 |
|
2511 | 2511 | 6 |
|
2512 | 2512 | 2 |
|
2513 | 2513 | |
|
2514 | 2514 | test empty sort key which is noop |
|
2515 | 2515 | |
|
2516 | 2516 | $ log 'sort(0 + 2 + 1, "")' |
|
2517 | 2517 | 0 |
|
2518 | 2518 | 2 |
|
2519 | 2519 | 1 |
|
2520 | 2520 | |
|
2521 | 2521 | test invalid sort keys |
|
2522 | 2522 | |
|
2523 | 2523 | $ log 'sort(all(), -invalid)' |
|
2524 | 2524 | hg: parse error: unknown sort key '-invalid' |
|
2525 | 2525 | [255] |
|
2526 | 2526 | |
|
2527 | 2527 | $ cd .. |
|
2528 | 2528 | |
|
2529 | 2529 | test sorting by multiple keys including variable-length strings |
|
2530 | 2530 | |
|
2531 | 2531 | $ hg init sorting |
|
2532 | 2532 | $ cd sorting |
|
2533 | 2533 | $ cat <<EOF >> .hg/hgrc |
|
2534 | 2534 | > [ui] |
|
2535 | 2535 | > logtemplate = '{rev} {branch|p5}{desc|p5}{author|p5}{date|hgdate}\n' |
|
2536 | 2536 | > [templatealias] |
|
2537 | 2537 | > p5(s) = pad(s, 5) |
|
2538 | 2538 | > EOF |
|
2539 | 2539 | $ hg branch -qf b12 |
|
2540 | 2540 | $ hg ci -m m111 -u u112 -d '111 10800' |
|
2541 | 2541 | $ hg branch -qf b11 |
|
2542 | 2542 | $ hg ci -m m12 -u u111 -d '112 7200' |
|
2543 | 2543 | $ hg branch -qf b111 |
|
2544 | 2544 | $ hg ci -m m11 -u u12 -d '111 3600' |
|
2545 | 2545 | $ hg branch -qf b112 |
|
2546 | 2546 | $ hg ci -m m111 -u u11 -d '120 0' |
|
2547 | 2547 | $ hg branch -qf b111 |
|
2548 | 2548 | $ hg ci -m m112 -u u111 -d '110 14400' |
|
2549 | 2549 | created new head |
|
2550 | 2550 | |
|
2551 | 2551 | compare revisions (has fast path): |
|
2552 | 2552 | |
|
2553 | 2553 | $ hg log -r 'sort(all(), rev)' |
|
2554 | 2554 | 0 b12 m111 u112 111 10800 |
|
2555 | 2555 | 1 b11 m12 u111 112 7200 |
|
2556 | 2556 | 2 b111 m11 u12 111 3600 |
|
2557 | 2557 | 3 b112 m111 u11 120 0 |
|
2558 | 2558 | 4 b111 m112 u111 110 14400 |
|
2559 | 2559 | |
|
2560 | 2560 | $ hg log -r 'sort(all(), -rev)' |
|
2561 | 2561 | 4 b111 m112 u111 110 14400 |
|
2562 | 2562 | 3 b112 m111 u11 120 0 |
|
2563 | 2563 | 2 b111 m11 u12 111 3600 |
|
2564 | 2564 | 1 b11 m12 u111 112 7200 |
|
2565 | 2565 | 0 b12 m111 u112 111 10800 |
|
2566 | 2566 | |
|
2567 | 2567 | compare variable-length strings (issue5218): |
|
2568 | 2568 | |
|
2569 | 2569 | $ hg log -r 'sort(all(), branch)' |
|
2570 | 2570 | 1 b11 m12 u111 112 7200 |
|
2571 | 2571 | 2 b111 m11 u12 111 3600 |
|
2572 | 2572 | 4 b111 m112 u111 110 14400 |
|
2573 | 2573 | 3 b112 m111 u11 120 0 |
|
2574 | 2574 | 0 b12 m111 u112 111 10800 |
|
2575 | 2575 | |
|
2576 | 2576 | $ hg log -r 'sort(all(), -branch)' |
|
2577 | 2577 | 0 b12 m111 u112 111 10800 |
|
2578 | 2578 | 3 b112 m111 u11 120 0 |
|
2579 | 2579 | 2 b111 m11 u12 111 3600 |
|
2580 | 2580 | 4 b111 m112 u111 110 14400 |
|
2581 | 2581 | 1 b11 m12 u111 112 7200 |
|
2582 | 2582 | |
|
2583 | 2583 | $ hg log -r 'sort(all(), desc)' |
|
2584 | 2584 | 2 b111 m11 u12 111 3600 |
|
2585 | 2585 | 0 b12 m111 u112 111 10800 |
|
2586 | 2586 | 3 b112 m111 u11 120 0 |
|
2587 | 2587 | 4 b111 m112 u111 110 14400 |
|
2588 | 2588 | 1 b11 m12 u111 112 7200 |
|
2589 | 2589 | |
|
2590 | 2590 | $ hg log -r 'sort(all(), -desc)' |
|
2591 | 2591 | 1 b11 m12 u111 112 7200 |
|
2592 | 2592 | 4 b111 m112 u111 110 14400 |
|
2593 | 2593 | 0 b12 m111 u112 111 10800 |
|
2594 | 2594 | 3 b112 m111 u11 120 0 |
|
2595 | 2595 | 2 b111 m11 u12 111 3600 |
|
2596 | 2596 | |
|
2597 | 2597 | $ hg log -r 'sort(all(), user)' |
|
2598 | 2598 | 3 b112 m111 u11 120 0 |
|
2599 | 2599 | 1 b11 m12 u111 112 7200 |
|
2600 | 2600 | 4 b111 m112 u111 110 14400 |
|
2601 | 2601 | 0 b12 m111 u112 111 10800 |
|
2602 | 2602 | 2 b111 m11 u12 111 3600 |
|
2603 | 2603 | |
|
2604 | 2604 | $ hg log -r 'sort(all(), -user)' |
|
2605 | 2605 | 2 b111 m11 u12 111 3600 |
|
2606 | 2606 | 0 b12 m111 u112 111 10800 |
|
2607 | 2607 | 1 b11 m12 u111 112 7200 |
|
2608 | 2608 | 4 b111 m112 u111 110 14400 |
|
2609 | 2609 | 3 b112 m111 u11 120 0 |
|
2610 | 2610 | |
|
2611 | 2611 | compare dates (tz offset should have no effect): |
|
2612 | 2612 | |
|
2613 | 2613 | $ hg log -r 'sort(all(), date)' |
|
2614 | 2614 | 4 b111 m112 u111 110 14400 |
|
2615 | 2615 | 0 b12 m111 u112 111 10800 |
|
2616 | 2616 | 2 b111 m11 u12 111 3600 |
|
2617 | 2617 | 1 b11 m12 u111 112 7200 |
|
2618 | 2618 | 3 b112 m111 u11 120 0 |
|
2619 | 2619 | |
|
2620 | 2620 | $ hg log -r 'sort(all(), -date)' |
|
2621 | 2621 | 3 b112 m111 u11 120 0 |
|
2622 | 2622 | 1 b11 m12 u111 112 7200 |
|
2623 | 2623 | 0 b12 m111 u112 111 10800 |
|
2624 | 2624 | 2 b111 m11 u12 111 3600 |
|
2625 | 2625 | 4 b111 m112 u111 110 14400 |
|
2626 | 2626 | |
|
2627 | 2627 | be aware that 'sort(x, -k)' is not exactly the same as 'reverse(sort(x, k))' |
|
2628 | 2628 | because '-k' reverses the comparison, not the list itself: |
|
2629 | 2629 | |
|
2630 | 2630 | $ hg log -r 'sort(0 + 2, date)' |
|
2631 | 2631 | 0 b12 m111 u112 111 10800 |
|
2632 | 2632 | 2 b111 m11 u12 111 3600 |
|
2633 | 2633 | |
|
2634 | 2634 | $ hg log -r 'sort(0 + 2, -date)' |
|
2635 | 2635 | 0 b12 m111 u112 111 10800 |
|
2636 | 2636 | 2 b111 m11 u12 111 3600 |
|
2637 | 2637 | |
|
2638 | 2638 | $ hg log -r 'reverse(sort(0 + 2, date))' |
|
2639 | 2639 | 2 b111 m11 u12 111 3600 |
|
2640 | 2640 | 0 b12 m111 u112 111 10800 |
|
2641 | 2641 | |
|
2642 | 2642 | sort by multiple keys: |
|
2643 | 2643 | |
|
2644 | 2644 | $ hg log -r 'sort(all(), "branch -rev")' |
|
2645 | 2645 | 1 b11 m12 u111 112 7200 |
|
2646 | 2646 | 4 b111 m112 u111 110 14400 |
|
2647 | 2647 | 2 b111 m11 u12 111 3600 |
|
2648 | 2648 | 3 b112 m111 u11 120 0 |
|
2649 | 2649 | 0 b12 m111 u112 111 10800 |
|
2650 | 2650 | |
|
2651 | 2651 | $ hg log -r 'sort(all(), "-desc -date")' |
|
2652 | 2652 | 1 b11 m12 u111 112 7200 |
|
2653 | 2653 | 4 b111 m112 u111 110 14400 |
|
2654 | 2654 | 3 b112 m111 u11 120 0 |
|
2655 | 2655 | 0 b12 m111 u112 111 10800 |
|
2656 | 2656 | 2 b111 m11 u12 111 3600 |
|
2657 | 2657 | |
|
2658 | 2658 | $ hg log -r 'sort(all(), "user -branch date rev")' |
|
2659 | 2659 | 3 b112 m111 u11 120 0 |
|
2660 | 2660 | 4 b111 m112 u111 110 14400 |
|
2661 | 2661 | 1 b11 m12 u111 112 7200 |
|
2662 | 2662 | 0 b12 m111 u112 111 10800 |
|
2663 | 2663 | 2 b111 m11 u12 111 3600 |
|
2664 | 2664 | |
|
2665 | 2665 | toposort prioritises graph branches |
|
2666 | 2666 | |
|
2667 | 2667 | $ hg up 2 |
|
2668 | 2668 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
2669 | 2669 | $ touch a |
|
2670 | 2670 | $ hg addremove |
|
2671 | 2671 | adding a |
|
2672 | 2672 | $ hg ci -m 't1' -u 'tu' -d '130 0' |
|
2673 | 2673 | created new head |
|
2674 | 2674 | $ echo 'a' >> a |
|
2675 | 2675 | $ hg ci -m 't2' -u 'tu' -d '130 0' |
|
2676 | 2676 | $ hg book book1 |
|
2677 | 2677 | $ hg up 4 |
|
2678 | 2678 | 0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
|
2679 | 2679 | (leaving bookmark book1) |
|
2680 | 2680 | $ touch a |
|
2681 | 2681 | $ hg addremove |
|
2682 | 2682 | adding a |
|
2683 | 2683 | $ hg ci -m 't3' -u 'tu' -d '130 0' |
|
2684 | 2684 | |
|
2685 | 2685 | $ hg log -r 'sort(all(), topo)' |
|
2686 | 2686 | 7 b111 t3 tu 130 0 |
|
2687 | 2687 | 4 b111 m112 u111 110 14400 |
|
2688 | 2688 | 3 b112 m111 u11 120 0 |
|
2689 | 2689 | 6 b111 t2 tu 130 0 |
|
2690 | 2690 | 5 b111 t1 tu 130 0 |
|
2691 | 2691 | 2 b111 m11 u12 111 3600 |
|
2692 | 2692 | 1 b11 m12 u111 112 7200 |
|
2693 | 2693 | 0 b12 m111 u112 111 10800 |
|
2694 | 2694 | |
|
2695 | 2695 | $ hg log -r 'sort(all(), -topo)' |
|
2696 | 2696 | 0 b12 m111 u112 111 10800 |
|
2697 | 2697 | 1 b11 m12 u111 112 7200 |
|
2698 | 2698 | 2 b111 m11 u12 111 3600 |
|
2699 | 2699 | 5 b111 t1 tu 130 0 |
|
2700 | 2700 | 6 b111 t2 tu 130 0 |
|
2701 | 2701 | 3 b112 m111 u11 120 0 |
|
2702 | 2702 | 4 b111 m112 u111 110 14400 |
|
2703 | 2703 | 7 b111 t3 tu 130 0 |
|
2704 | 2704 | |
|
2705 | 2705 | $ hg log -r 'sort(all(), topo, topo.firstbranch=book1)' |
|
2706 | 2706 | 6 b111 t2 tu 130 0 |
|
2707 | 2707 | 5 b111 t1 tu 130 0 |
|
2708 | 2708 | 7 b111 t3 tu 130 0 |
|
2709 | 2709 | 4 b111 m112 u111 110 14400 |
|
2710 | 2710 | 3 b112 m111 u11 120 0 |
|
2711 | 2711 | 2 b111 m11 u12 111 3600 |
|
2712 | 2712 | 1 b11 m12 u111 112 7200 |
|
2713 | 2713 | 0 b12 m111 u112 111 10800 |
|
2714 | 2714 | |
|
2715 | 2715 | topographical sorting can't be combined with other sort keys, and you can't |
|
2716 | 2716 | use the topo.firstbranch option when topo sort is not active: |
|
2717 | 2717 | |
|
2718 | 2718 | $ hg log -r 'sort(all(), "topo user")' |
|
2719 | 2719 | hg: parse error: topo sort order cannot be combined with other sort keys |
|
2720 | 2720 | [255] |
|
2721 | 2721 | |
|
2722 | 2722 | $ hg log -r 'sort(all(), user, topo.firstbranch=book1)' |
|
2723 | 2723 | hg: parse error: topo.firstbranch can only be used when using the topo sort key |
|
2724 | 2724 | [255] |
|
2725 | 2725 | |
|
2726 | 2726 | topo.firstbranch should accept any kind of expressions: |
|
2727 | 2727 | |
|
2728 | 2728 | $ hg log -r 'sort(0, topo, topo.firstbranch=(book1))' |
|
2729 | 2729 | 0 b12 m111 u112 111 10800 |
|
2730 | 2730 | |
|
2731 | 2731 | $ cd .. |
|
2732 | 2732 | $ cd repo |
|
2733 | 2733 | |
|
2734 | 2734 | test subtracting something from an addset |
|
2735 | 2735 | |
|
2736 | 2736 | $ log '(outgoing() or removes(a)) - removes(a)' |
|
2737 | 2737 | 8 |
|
2738 | 2738 | 9 |
|
2739 | 2739 | |
|
2740 | 2740 | test intersecting something with an addset |
|
2741 | 2741 | |
|
2742 | 2742 | $ log 'parents(outgoing() or removes(a))' |
|
2743 | 2743 | 1 |
|
2744 | 2744 | 4 |
|
2745 | 2745 | 5 |
|
2746 | 2746 | 8 |
|
2747 | 2747 | |
|
2748 | 2748 | test that `or` operation combines elements in the right order: |
|
2749 | 2749 | |
|
2750 | 2750 | $ log '3:4 or 2:5' |
|
2751 | 2751 | 3 |
|
2752 | 2752 | 4 |
|
2753 | 2753 | 2 |
|
2754 | 2754 | 5 |
|
2755 | 2755 | $ log '3:4 or 5:2' |
|
2756 | 2756 | 3 |
|
2757 | 2757 | 4 |
|
2758 | 2758 | 5 |
|
2759 | 2759 | 2 |
|
2760 | 2760 | $ log 'sort(3:4 or 2:5)' |
|
2761 | 2761 | 2 |
|
2762 | 2762 | 3 |
|
2763 | 2763 | 4 |
|
2764 | 2764 | 5 |
|
2765 | 2765 | $ log 'sort(3:4 or 5:2)' |
|
2766 | 2766 | 2 |
|
2767 | 2767 | 3 |
|
2768 | 2768 | 4 |
|
2769 | 2769 | 5 |
|
2770 | 2770 | |
|
2771 | 2771 | test that more than one `-r`s are combined in the right order and deduplicated: |
|
2772 | 2772 | |
|
2773 | 2773 | $ hg log -T '{rev}\n' -r 3 -r 3 -r 4 -r 5:2 -r 'ancestors(4)' |
|
2774 | 2774 | 3 |
|
2775 | 2775 | 4 |
|
2776 | 2776 | 5 |
|
2777 | 2777 | 2 |
|
2778 | 2778 | 0 |
|
2779 | 2779 | 1 |
|
2780 | 2780 | |
|
2781 | 2781 | test that `or` operation skips duplicated revisions from right-hand side |
|
2782 | 2782 | |
|
2783 | 2783 | $ try 'reverse(1::5) or ancestors(4)' |
|
2784 | 2784 | (or |
|
2785 | 2785 | (list |
|
2786 | 2786 | (func |
|
2787 | 2787 | ('symbol', 'reverse') |
|
2788 | 2788 | (dagrange |
|
2789 | 2789 | ('symbol', '1') |
|
2790 | 2790 | ('symbol', '5'))) |
|
2791 | 2791 | (func |
|
2792 | 2792 | ('symbol', 'ancestors') |
|
2793 | 2793 | ('symbol', '4')))) |
|
2794 | 2794 | * set: |
|
2795 | 2795 | <addset |
|
2796 | 2796 | <baseset- [1, 3, 5]>, |
|
2797 | 2797 | <generatorset+>> |
|
2798 | 2798 | 5 |
|
2799 | 2799 | 3 |
|
2800 | 2800 | 1 |
|
2801 | 2801 | 0 |
|
2802 | 2802 | 2 |
|
2803 | 2803 | 4 |
|
2804 | 2804 | $ try 'sort(ancestors(4) or reverse(1::5))' |
|
2805 | 2805 | (func |
|
2806 | 2806 | ('symbol', 'sort') |
|
2807 | 2807 | (or |
|
2808 | 2808 | (list |
|
2809 | 2809 | (func |
|
2810 | 2810 | ('symbol', 'ancestors') |
|
2811 | 2811 | ('symbol', '4')) |
|
2812 | 2812 | (func |
|
2813 | 2813 | ('symbol', 'reverse') |
|
2814 | 2814 | (dagrange |
|
2815 | 2815 | ('symbol', '1') |
|
2816 | 2816 | ('symbol', '5')))))) |
|
2817 | 2817 | * set: |
|
2818 | 2818 | <addset+ |
|
2819 | 2819 | <generatorset+>, |
|
2820 | 2820 | <baseset- [1, 3, 5]>> |
|
2821 | 2821 | 0 |
|
2822 | 2822 | 1 |
|
2823 | 2823 | 2 |
|
2824 | 2824 | 3 |
|
2825 | 2825 | 4 |
|
2826 | 2826 | 5 |
|
2827 | 2827 | |
|
2828 | 2828 | test optimization of trivial `or` operation |
|
2829 | 2829 | |
|
2830 | 2830 | $ try --optimize '0|(1)|"2"|-2|tip|null' |
|
2831 | 2831 | (or |
|
2832 | 2832 | (list |
|
2833 | 2833 | ('symbol', '0') |
|
2834 | 2834 | (group |
|
2835 | 2835 | ('symbol', '1')) |
|
2836 | 2836 | ('string', '2') |
|
2837 | 2837 | (negate |
|
2838 | 2838 | ('symbol', '2')) |
|
2839 | 2839 | ('symbol', 'tip') |
|
2840 | 2840 | ('symbol', 'null'))) |
|
2841 | 2841 | * optimized: |
|
2842 | 2842 | (func |
|
2843 | 2843 | ('symbol', '_list') |
|
2844 | 2844 | ('string', '0\x001\x002\x00-2\x00tip\x00null') |
|
2845 | 2845 | define) |
|
2846 | 2846 | * set: |
|
2847 | 2847 | <baseset [0, 1, 2, 8, 9, -1]> |
|
2848 | 2848 | 0 |
|
2849 | 2849 | 1 |
|
2850 | 2850 | 2 |
|
2851 | 2851 | 8 |
|
2852 | 2852 | 9 |
|
2853 | 2853 | -1 |
|
2854 | 2854 | |
|
2855 | 2855 | $ try --optimize '0|1|2:3' |
|
2856 | 2856 | (or |
|
2857 | 2857 | (list |
|
2858 | 2858 | ('symbol', '0') |
|
2859 | 2859 | ('symbol', '1') |
|
2860 | 2860 | (range |
|
2861 | 2861 | ('symbol', '2') |
|
2862 | 2862 | ('symbol', '3')))) |
|
2863 | 2863 | * optimized: |
|
2864 | 2864 | (or |
|
2865 | 2865 | (list |
|
2866 | 2866 | (func |
|
2867 | 2867 | ('symbol', '_list') |
|
2868 | 2868 | ('string', '0\x001') |
|
2869 | 2869 | define) |
|
2870 | 2870 | (range |
|
2871 | 2871 | ('symbol', '2') |
|
2872 | 2872 | ('symbol', '3') |
|
2873 | 2873 | define)) |
|
2874 | 2874 | define) |
|
2875 | 2875 | * set: |
|
2876 | 2876 | <addset |
|
2877 | 2877 | <baseset [0, 1]>, |
|
2878 | 2878 | <spanset+ 2:4>> |
|
2879 | 2879 | 0 |
|
2880 | 2880 | 1 |
|
2881 | 2881 | 2 |
|
2882 | 2882 | 3 |
|
2883 | 2883 | |
|
2884 | 2884 | $ try --optimize '0:1|2|3:4|5|6' |
|
2885 | 2885 | (or |
|
2886 | 2886 | (list |
|
2887 | 2887 | (range |
|
2888 | 2888 | ('symbol', '0') |
|
2889 | 2889 | ('symbol', '1')) |
|
2890 | 2890 | ('symbol', '2') |
|
2891 | 2891 | (range |
|
2892 | 2892 | ('symbol', '3') |
|
2893 | 2893 | ('symbol', '4')) |
|
2894 | 2894 | ('symbol', '5') |
|
2895 | 2895 | ('symbol', '6'))) |
|
2896 | 2896 | * optimized: |
|
2897 | 2897 | (or |
|
2898 | 2898 | (list |
|
2899 | 2899 | (range |
|
2900 | 2900 | ('symbol', '0') |
|
2901 | 2901 | ('symbol', '1') |
|
2902 | 2902 | define) |
|
2903 | 2903 | ('symbol', '2') |
|
2904 | 2904 | (range |
|
2905 | 2905 | ('symbol', '3') |
|
2906 | 2906 | ('symbol', '4') |
|
2907 | 2907 | define) |
|
2908 | 2908 | (func |
|
2909 | 2909 | ('symbol', '_list') |
|
2910 | 2910 | ('string', '5\x006') |
|
2911 | 2911 | define)) |
|
2912 | 2912 | define) |
|
2913 | 2913 | * set: |
|
2914 | 2914 | <addset |
|
2915 | 2915 | <addset |
|
2916 | 2916 | <spanset+ 0:2>, |
|
2917 | 2917 | <baseset [2]>>, |
|
2918 | 2918 | <addset |
|
2919 | 2919 | <spanset+ 3:5>, |
|
2920 | 2920 | <baseset [5, 6]>>> |
|
2921 | 2921 | 0 |
|
2922 | 2922 | 1 |
|
2923 | 2923 | 2 |
|
2924 | 2924 | 3 |
|
2925 | 2925 | 4 |
|
2926 | 2926 | 5 |
|
2927 | 2927 | 6 |
|
2928 | 2928 | |
|
2929 | 2929 | unoptimized `or` looks like this |
|
2930 | 2930 | |
|
2931 | 2931 | $ try --no-optimized -p analyzed '0|1|2|3|4' |
|
2932 | 2932 | * analyzed: |
|
2933 | 2933 | (or |
|
2934 | 2934 | (list |
|
2935 | 2935 | ('symbol', '0') |
|
2936 | 2936 | ('symbol', '1') |
|
2937 | 2937 | ('symbol', '2') |
|
2938 | 2938 | ('symbol', '3') |
|
2939 | 2939 | ('symbol', '4')) |
|
2940 | 2940 | define) |
|
2941 | 2941 | * set: |
|
2942 | 2942 | <addset |
|
2943 | 2943 | <addset |
|
2944 | 2944 | <baseset [0]>, |
|
2945 | 2945 | <baseset [1]>>, |
|
2946 | 2946 | <addset |
|
2947 | 2947 | <baseset [2]>, |
|
2948 | 2948 | <addset |
|
2949 | 2949 | <baseset [3]>, |
|
2950 | 2950 | <baseset [4]>>>> |
|
2951 | 2951 | 0 |
|
2952 | 2952 | 1 |
|
2953 | 2953 | 2 |
|
2954 | 2954 | 3 |
|
2955 | 2955 | 4 |
|
2956 | 2956 | |
|
2957 | 2957 | test that `_list` should be narrowed by provided `subset` |
|
2958 | 2958 | |
|
2959 | 2959 | $ log '0:2 and (null|1|2|3)' |
|
2960 | 2960 | 1 |
|
2961 | 2961 | 2 |
|
2962 | 2962 | |
|
2963 | 2963 | test that `_list` should remove duplicates |
|
2964 | 2964 | |
|
2965 | 2965 | $ log '0|1|2|1|2|-1|tip' |
|
2966 | 2966 | 0 |
|
2967 | 2967 | 1 |
|
2968 | 2968 | 2 |
|
2969 | 2969 | 9 |
|
2970 | 2970 | |
|
2971 | 2971 | test unknown revision in `_list` |
|
2972 | 2972 | |
|
2973 | 2973 | $ log '0|unknown' |
|
2974 | 2974 | abort: unknown revision 'unknown'! |
|
2975 | 2975 | [255] |
|
2976 | 2976 | |
|
2977 | 2977 | test integer range in `_list` |
|
2978 | 2978 | |
|
2979 | 2979 | $ log '-1|-10' |
|
2980 | 2980 | 9 |
|
2981 | 2981 | 0 |
|
2982 | 2982 | |
|
2983 | 2983 | $ log '-10|-11' |
|
2984 | 2984 | abort: unknown revision '-11'! |
|
2985 | 2985 | [255] |
|
2986 | 2986 | |
|
2987 | 2987 | $ log '9|10' |
|
2988 | 2988 | abort: unknown revision '10'! |
|
2989 | 2989 | [255] |
|
2990 | 2990 | |
|
2991 | 2991 | test '0000' != '0' in `_list` |
|
2992 | 2992 | |
|
2993 | 2993 | $ log '0|0000' |
|
2994 | 2994 | 0 |
|
2995 | 2995 | -1 |
|
2996 | 2996 | |
|
2997 | 2997 | test ',' in `_list` |
|
2998 | 2998 | $ log '0,1' |
|
2999 | 2999 | hg: parse error: can't use a list in this context |
|
3000 | 3000 | (see hg help "revsets.x or y") |
|
3001 | 3001 | [255] |
|
3002 | 3002 | $ try '0,1,2' |
|
3003 | 3003 | (list |
|
3004 | 3004 | ('symbol', '0') |
|
3005 | 3005 | ('symbol', '1') |
|
3006 | 3006 | ('symbol', '2')) |
|
3007 | 3007 | hg: parse error: can't use a list in this context |
|
3008 | 3008 | (see hg help "revsets.x or y") |
|
3009 | 3009 | [255] |
|
3010 | 3010 | |
|
3011 | 3011 | test that chained `or` operations make balanced addsets |
|
3012 | 3012 | |
|
3013 | 3013 | $ try '0:1|1:2|2:3|3:4|4:5' |
|
3014 | 3014 | (or |
|
3015 | 3015 | (list |
|
3016 | 3016 | (range |
|
3017 | 3017 | ('symbol', '0') |
|
3018 | 3018 | ('symbol', '1')) |
|
3019 | 3019 | (range |
|
3020 | 3020 | ('symbol', '1') |
|
3021 | 3021 | ('symbol', '2')) |
|
3022 | 3022 | (range |
|
3023 | 3023 | ('symbol', '2') |
|
3024 | 3024 | ('symbol', '3')) |
|
3025 | 3025 | (range |
|
3026 | 3026 | ('symbol', '3') |
|
3027 | 3027 | ('symbol', '4')) |
|
3028 | 3028 | (range |
|
3029 | 3029 | ('symbol', '4') |
|
3030 | 3030 | ('symbol', '5')))) |
|
3031 | 3031 | * set: |
|
3032 | 3032 | <addset |
|
3033 | 3033 | <addset |
|
3034 | 3034 | <spanset+ 0:2>, |
|
3035 | 3035 | <spanset+ 1:3>>, |
|
3036 | 3036 | <addset |
|
3037 | 3037 | <spanset+ 2:4>, |
|
3038 | 3038 | <addset |
|
3039 | 3039 | <spanset+ 3:5>, |
|
3040 | 3040 | <spanset+ 4:6>>>> |
|
3041 | 3041 | 0 |
|
3042 | 3042 | 1 |
|
3043 | 3043 | 2 |
|
3044 | 3044 | 3 |
|
3045 | 3045 | 4 |
|
3046 | 3046 | 5 |
|
3047 | 3047 | |
|
3048 | 3048 | no crash by empty group "()" while optimizing `or` operations |
|
3049 | 3049 | |
|
3050 | 3050 | $ try --optimize '0|()' |
|
3051 | 3051 | (or |
|
3052 | 3052 | (list |
|
3053 | 3053 | ('symbol', '0') |
|
3054 | 3054 | (group |
|
3055 | 3055 | None))) |
|
3056 | 3056 | * optimized: |
|
3057 | 3057 | (or |
|
3058 | 3058 | (list |
|
3059 | 3059 | ('symbol', '0') |
|
3060 | 3060 | None) |
|
3061 | 3061 | define) |
|
3062 | 3062 | hg: parse error: missing argument |
|
3063 | 3063 | [255] |
|
3064 | 3064 | |
|
3065 | 3065 | test that chained `or` operations never eat up stack (issue4624) |
|
3066 | 3066 | (uses `0:1` instead of `0` to avoid future optimization of trivial revisions) |
|
3067 | 3067 | |
|
3068 | 3068 | $ hg log -T '{rev}\n' -r `$PYTHON -c "print '+'.join(['0:1'] * 500)"` |
|
3069 | 3069 | 0 |
|
3070 | 3070 | 1 |
|
3071 | 3071 | |
|
3072 | 3072 | test that repeated `-r` options never eat up stack (issue4565) |
|
3073 | 3073 | (uses `-r 0::1` to avoid possible optimization at old-style parser) |
|
3074 | 3074 | |
|
3075 | 3075 | $ hg log -T '{rev}\n' `$PYTHON -c "for i in xrange(500): print '-r 0::1 ',"` |
|
3076 | 3076 | 0 |
|
3077 | 3077 | 1 |
|
3078 | 3078 | |
|
3079 | 3079 | check that conversion to only works |
|
3080 | 3080 | $ try --optimize '::3 - ::1' |
|
3081 | 3081 | (minus |
|
3082 | 3082 | (dagrangepre |
|
3083 | 3083 | ('symbol', '3')) |
|
3084 | 3084 | (dagrangepre |
|
3085 | 3085 | ('symbol', '1'))) |
|
3086 | 3086 | * optimized: |
|
3087 | 3087 | (func |
|
3088 | 3088 | ('symbol', 'only') |
|
3089 | 3089 | (list |
|
3090 | 3090 | ('symbol', '3') |
|
3091 | 3091 | ('symbol', '1')) |
|
3092 | 3092 | define) |
|
3093 | 3093 | * set: |
|
3094 | 3094 | <baseset+ [3]> |
|
3095 | 3095 | 3 |
|
3096 | 3096 | $ try --optimize 'ancestors(1) - ancestors(3)' |
|
3097 | 3097 | (minus |
|
3098 | 3098 | (func |
|
3099 | 3099 | ('symbol', 'ancestors') |
|
3100 | 3100 | ('symbol', '1')) |
|
3101 | 3101 | (func |
|
3102 | 3102 | ('symbol', 'ancestors') |
|
3103 | 3103 | ('symbol', '3'))) |
|
3104 | 3104 | * optimized: |
|
3105 | 3105 | (func |
|
3106 | 3106 | ('symbol', 'only') |
|
3107 | 3107 | (list |
|
3108 | 3108 | ('symbol', '1') |
|
3109 | 3109 | ('symbol', '3')) |
|
3110 | 3110 | define) |
|
3111 | 3111 | * set: |
|
3112 | 3112 | <baseset+ []> |
|
3113 | 3113 | $ try --optimize 'not ::2 and ::6' |
|
3114 | 3114 | (and |
|
3115 | 3115 | (not |
|
3116 | 3116 | (dagrangepre |
|
3117 | 3117 | ('symbol', '2'))) |
|
3118 | 3118 | (dagrangepre |
|
3119 | 3119 | ('symbol', '6'))) |
|
3120 | 3120 | * optimized: |
|
3121 | 3121 | (func |
|
3122 | 3122 | ('symbol', 'only') |
|
3123 | 3123 | (list |
|
3124 | 3124 | ('symbol', '6') |
|
3125 | 3125 | ('symbol', '2')) |
|
3126 | 3126 | define) |
|
3127 | 3127 | * set: |
|
3128 | 3128 | <baseset+ [3, 4, 5, 6]> |
|
3129 | 3129 | 3 |
|
3130 | 3130 | 4 |
|
3131 | 3131 | 5 |
|
3132 | 3132 | 6 |
|
3133 | 3133 | $ try --optimize 'ancestors(6) and not ancestors(4)' |
|
3134 | 3134 | (and |
|
3135 | 3135 | (func |
|
3136 | 3136 | ('symbol', 'ancestors') |
|
3137 | 3137 | ('symbol', '6')) |
|
3138 | 3138 | (not |
|
3139 | 3139 | (func |
|
3140 | 3140 | ('symbol', 'ancestors') |
|
3141 | 3141 | ('symbol', '4')))) |
|
3142 | 3142 | * optimized: |
|
3143 | 3143 | (func |
|
3144 | 3144 | ('symbol', 'only') |
|
3145 | 3145 | (list |
|
3146 | 3146 | ('symbol', '6') |
|
3147 | 3147 | ('symbol', '4')) |
|
3148 | 3148 | define) |
|
3149 | 3149 | * set: |
|
3150 | 3150 | <baseset+ [3, 5, 6]> |
|
3151 | 3151 | 3 |
|
3152 | 3152 | 5 |
|
3153 | 3153 | 6 |
|
3154 | 3154 | |
|
3155 | 3155 | no crash by empty group "()" while optimizing to "only()" |
|
3156 | 3156 | |
|
3157 | 3157 | $ try --optimize '::1 and ()' |
|
3158 | 3158 | (and |
|
3159 | 3159 | (dagrangepre |
|
3160 | 3160 | ('symbol', '1')) |
|
3161 | 3161 | (group |
|
3162 | 3162 | None)) |
|
3163 | 3163 | * optimized: |
|
3164 | 3164 | (and |
|
3165 | 3165 | None |
|
3166 | 3166 | (func |
|
3167 | 3167 | ('symbol', 'ancestors') |
|
3168 | 3168 | ('symbol', '1') |
|
3169 | 3169 | define) |
|
3170 | 3170 | define) |
|
3171 | 3171 | hg: parse error: missing argument |
|
3172 | 3172 | [255] |
|
3173 | 3173 | |
|
3174 | 3174 | optimization to only() works only if ancestors() takes only one argument |
|
3175 | 3175 | |
|
3176 | 3176 | $ hg debugrevspec -p optimized 'ancestors(6) - ancestors(4, 1)' |
|
3177 | 3177 | * optimized: |
|
3178 | 3178 | (difference |
|
3179 | 3179 | (func |
|
3180 | 3180 | ('symbol', 'ancestors') |
|
3181 | 3181 | ('symbol', '6') |
|
3182 | 3182 | define) |
|
3183 | 3183 | (func |
|
3184 | 3184 | ('symbol', 'ancestors') |
|
3185 | 3185 | (list |
|
3186 | 3186 | ('symbol', '4') |
|
3187 | 3187 | ('symbol', '1')) |
|
3188 | 3188 | any) |
|
3189 | 3189 | define) |
|
3190 | 3190 | 0 |
|
3191 | 3191 | 1 |
|
3192 | 3192 | 3 |
|
3193 | 3193 | 5 |
|
3194 | 3194 | 6 |
|
3195 | 3195 | $ hg debugrevspec -p optimized 'ancestors(6, 1) - ancestors(4)' |
|
3196 | 3196 | * optimized: |
|
3197 | 3197 | (difference |
|
3198 | 3198 | (func |
|
3199 | 3199 | ('symbol', 'ancestors') |
|
3200 | 3200 | (list |
|
3201 | 3201 | ('symbol', '6') |
|
3202 | 3202 | ('symbol', '1')) |
|
3203 | 3203 | define) |
|
3204 | 3204 | (func |
|
3205 | 3205 | ('symbol', 'ancestors') |
|
3206 | 3206 | ('symbol', '4') |
|
3207 | 3207 | any) |
|
3208 | 3208 | define) |
|
3209 | 3209 | 5 |
|
3210 | 3210 | 6 |
|
3211 | 3211 | |
|
3212 | 3212 | optimization disabled if keyword arguments passed (because we're too lazy |
|
3213 | 3213 | to support it) |
|
3214 | 3214 | |
|
3215 | 3215 | $ hg debugrevspec -p optimized 'ancestors(set=6) - ancestors(set=4)' |
|
3216 | 3216 | * optimized: |
|
3217 | 3217 | (difference |
|
3218 | 3218 | (func |
|
3219 | 3219 | ('symbol', 'ancestors') |
|
3220 | 3220 | (keyvalue |
|
3221 | 3221 | ('symbol', 'set') |
|
3222 | 3222 | ('symbol', '6')) |
|
3223 | 3223 | define) |
|
3224 | 3224 | (func |
|
3225 | 3225 | ('symbol', 'ancestors') |
|
3226 | 3226 | (keyvalue |
|
3227 | 3227 | ('symbol', 'set') |
|
3228 | 3228 | ('symbol', '4')) |
|
3229 | 3229 | any) |
|
3230 | 3230 | define) |
|
3231 | 3231 | 3 |
|
3232 | 3232 | 5 |
|
3233 | 3233 | 6 |
|
3234 | 3234 | |
|
3235 | 3235 | invalid function call should not be optimized to only() |
|
3236 | 3236 | |
|
3237 | 3237 | $ log '"ancestors"(6) and not ancestors(4)' |
|
3238 | 3238 | hg: parse error: not a symbol |
|
3239 | 3239 | [255] |
|
3240 | 3240 | |
|
3241 | 3241 | $ log 'ancestors(6) and not "ancestors"(4)' |
|
3242 | 3242 | hg: parse error: not a symbol |
|
3243 | 3243 | [255] |
|
3244 | 3244 | |
|
3245 | 3245 | we can use patterns when searching for tags |
|
3246 | 3246 | |
|
3247 | 3247 | $ log 'tag("1..*")' |
|
3248 | 3248 | abort: tag '1..*' does not exist! |
|
3249 | 3249 | [255] |
|
3250 | 3250 | $ log 'tag("re:1..*")' |
|
3251 | 3251 | 6 |
|
3252 | 3252 | $ log 'tag("re:[0-9].[0-9]")' |
|
3253 | 3253 | 6 |
|
3254 | 3254 | $ log 'tag("literal:1.0")' |
|
3255 | 3255 | 6 |
|
3256 | 3256 | $ log 'tag("re:0..*")' |
|
3257 | 3257 | |
|
3258 | 3258 | $ log 'tag(unknown)' |
|
3259 | 3259 | abort: tag 'unknown' does not exist! |
|
3260 | 3260 | [255] |
|
3261 | 3261 | $ log 'tag("re:unknown")' |
|
3262 | 3262 | $ log 'present(tag("unknown"))' |
|
3263 | 3263 | $ log 'present(tag("re:unknown"))' |
|
3264 | 3264 | $ log 'branch(unknown)' |
|
3265 | 3265 | abort: unknown revision 'unknown'! |
|
3266 | 3266 | [255] |
|
3267 | 3267 | $ log 'branch("literal:unknown")' |
|
3268 | 3268 | abort: branch 'unknown' does not exist! |
|
3269 | 3269 | [255] |
|
3270 | 3270 | $ log 'branch("re:unknown")' |
|
3271 | 3271 | $ log 'present(branch("unknown"))' |
|
3272 | 3272 | $ log 'present(branch("re:unknown"))' |
|
3273 | 3273 | $ log 'user(bob)' |
|
3274 | 3274 | 2 |
|
3275 | 3275 | |
|
3276 | 3276 | $ log '4::8' |
|
3277 | 3277 | 4 |
|
3278 | 3278 | 8 |
|
3279 | 3279 | $ log '4:8' |
|
3280 | 3280 | 4 |
|
3281 | 3281 | 5 |
|
3282 | 3282 | 6 |
|
3283 | 3283 | 7 |
|
3284 | 3284 | 8 |
|
3285 | 3285 | |
|
3286 | 3286 | $ log 'sort(!merge() & (modifies(b) | user(bob) | keyword(bug) | keyword(issue) & 1::9), "-date")' |
|
3287 | 3287 | 4 |
|
3288 | 3288 | 2 |
|
3289 | 3289 | 5 |
|
3290 | 3290 | |
|
3291 | 3291 | $ log 'not 0 and 0:2' |
|
3292 | 3292 | 1 |
|
3293 | 3293 | 2 |
|
3294 | 3294 | $ log 'not 1 and 0:2' |
|
3295 | 3295 | 0 |
|
3296 | 3296 | 2 |
|
3297 | 3297 | $ log 'not 2 and 0:2' |
|
3298 | 3298 | 0 |
|
3299 | 3299 | 1 |
|
3300 | 3300 | $ log '(1 and 2)::' |
|
3301 | 3301 | $ log '(1 and 2):' |
|
3302 | 3302 | $ log '(1 and 2):3' |
|
3303 | 3303 | $ log 'sort(head(), -rev)' |
|
3304 | 3304 | 9 |
|
3305 | 3305 | 7 |
|
3306 | 3306 | 6 |
|
3307 | 3307 | 5 |
|
3308 | 3308 | 4 |
|
3309 | 3309 | 3 |
|
3310 | 3310 | 2 |
|
3311 | 3311 | 1 |
|
3312 | 3312 | 0 |
|
3313 | 3313 | $ log '4::8 - 8' |
|
3314 | 3314 | 4 |
|
3315 | 3315 | |
|
3316 | 3316 | matching() should preserve the order of the input set: |
|
3317 | 3317 | |
|
3318 | 3318 | $ log '(2 or 3 or 1) and matching(1 or 2 or 3)' |
|
3319 | 3319 | 2 |
|
3320 | 3320 | 3 |
|
3321 | 3321 | 1 |
|
3322 | 3322 | |
|
3323 | 3323 | $ log 'named("unknown")' |
|
3324 | 3324 | abort: namespace 'unknown' does not exist! |
|
3325 | 3325 | [255] |
|
3326 | 3326 | $ log 'named("re:unknown")' |
|
3327 | 3327 | abort: no namespace exists that match 'unknown'! |
|
3328 | 3328 | [255] |
|
3329 | 3329 | $ log 'present(named("unknown"))' |
|
3330 | 3330 | $ log 'present(named("re:unknown"))' |
|
3331 | 3331 | |
|
3332 | 3332 | $ log 'tag()' |
|
3333 | 3333 | 6 |
|
3334 | 3334 | $ log 'named("tags")' |
|
3335 | 3335 | 6 |
|
3336 | 3336 | |
|
3337 | 3337 | issue2437 |
|
3338 | 3338 | |
|
3339 | 3339 | $ log '3 and p1(5)' |
|
3340 | 3340 | 3 |
|
3341 | 3341 | $ log '4 and p2(6)' |
|
3342 | 3342 | 4 |
|
3343 | 3343 | $ log '1 and parents(:2)' |
|
3344 | 3344 | 1 |
|
3345 | 3345 | $ log '2 and children(1:)' |
|
3346 | 3346 | 2 |
|
3347 | 3347 | $ log 'roots(all()) or roots(all())' |
|
3348 | 3348 | 0 |
|
3349 | 3349 | $ hg debugrevspec 'roots(all()) or roots(all())' |
|
3350 | 3350 | 0 |
|
3351 | 3351 | $ log 'heads(branch(Γ©)) or heads(branch(Γ©))' |
|
3352 | 3352 | 9 |
|
3353 | 3353 | $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(Γ©)))' |
|
3354 | 3354 | 4 |
|
3355 | 3355 | |
|
3356 | 3356 | issue2654: report a parse error if the revset was not completely parsed |
|
3357 | 3357 | |
|
3358 | 3358 | $ log '1 OR 2' |
|
3359 | 3359 | hg: parse error at 2: invalid token |
|
3360 | 3360 | [255] |
|
3361 | 3361 | |
|
3362 | 3362 | or operator should preserve ordering: |
|
3363 | 3363 | $ log 'reverse(2::4) or tip' |
|
3364 | 3364 | 4 |
|
3365 | 3365 | 2 |
|
3366 | 3366 | 9 |
|
3367 | 3367 | |
|
3368 | 3368 | parentrevspec |
|
3369 | 3369 | |
|
3370 | 3370 | $ log 'merge()^0' |
|
3371 | 3371 | 6 |
|
3372 | 3372 | $ log 'merge()^' |
|
3373 | 3373 | 5 |
|
3374 | 3374 | $ log 'merge()^1' |
|
3375 | 3375 | 5 |
|
3376 | 3376 | $ log 'merge()^2' |
|
3377 | 3377 | 4 |
|
3378 | 3378 | $ log '(not merge())^2' |
|
3379 | 3379 | $ log 'merge()^^' |
|
3380 | 3380 | 3 |
|
3381 | 3381 | $ log 'merge()^1^' |
|
3382 | 3382 | 3 |
|
3383 | 3383 | $ log 'merge()^^^' |
|
3384 | 3384 | 1 |
|
3385 | 3385 | |
|
3386 | 3386 | $ hg debugrevspec -s '(merge() | 0)~-1' |
|
3387 | 3387 | * set: |
|
3388 | 3388 | <baseset+ [1, 7]> |
|
3389 | 3389 | 1 |
|
3390 | 3390 | 7 |
|
3391 | 3391 | $ log 'merge()~-1' |
|
3392 | 3392 | 7 |
|
3393 | 3393 | $ log 'tip~-1' |
|
3394 | 3394 | $ log '(tip | merge())~-1' |
|
3395 | 3395 | 7 |
|
3396 | 3396 | $ log 'merge()~0' |
|
3397 | 3397 | 6 |
|
3398 | 3398 | $ log 'merge()~1' |
|
3399 | 3399 | 5 |
|
3400 | 3400 | $ log 'merge()~2' |
|
3401 | 3401 | 3 |
|
3402 | 3402 | $ log 'merge()~2^1' |
|
3403 | 3403 | 1 |
|
3404 | 3404 | $ log 'merge()~3' |
|
3405 | 3405 | 1 |
|
3406 | 3406 | |
|
3407 | 3407 | $ log '(-3:tip)^' |
|
3408 | 3408 | 4 |
|
3409 | 3409 | 6 |
|
3410 | 3410 | 8 |
|
3411 | 3411 | |
|
3412 | 3412 | $ log 'tip^foo' |
|
3413 | 3413 | hg: parse error: ^ expects a number 0, 1, or 2 |
|
3414 | 3414 | [255] |
|
3415 | 3415 | |
|
3416 | 3416 | $ log 'branchpoint()~-1' |
|
3417 | 3417 | abort: revision in set has more than one child! |
|
3418 | 3418 | [255] |
|
3419 | 3419 | |
|
3420 | 3420 | Bogus function gets suggestions |
|
3421 | 3421 | $ log 'add()' |
|
3422 | 3422 | hg: parse error: unknown identifier: add |
|
3423 | 3423 | (did you mean adds?) |
|
3424 | 3424 | [255] |
|
3425 | 3425 | $ log 'added()' |
|
3426 | 3426 | hg: parse error: unknown identifier: added |
|
3427 | 3427 | (did you mean adds?) |
|
3428 | 3428 | [255] |
|
3429 | 3429 | $ log 'remo()' |
|
3430 | 3430 | hg: parse error: unknown identifier: remo |
|
3431 | 3431 | (did you mean one of remote, removes?) |
|
3432 | 3432 | [255] |
|
3433 | 3433 | $ log 'babar()' |
|
3434 | 3434 | hg: parse error: unknown identifier: babar |
|
3435 | 3435 | [255] |
|
3436 | 3436 | |
|
3437 | 3437 | Bogus function with a similar internal name doesn't suggest the internal name |
|
3438 | 3438 | $ log 'matches()' |
|
3439 | 3439 | hg: parse error: unknown identifier: matches |
|
3440 | 3440 | (did you mean matching?) |
|
3441 | 3441 | [255] |
|
3442 | 3442 | |
|
3443 | 3443 | Undocumented functions aren't suggested as similar either |
|
3444 | 3444 | $ log 'tagged2()' |
|
3445 | 3445 | hg: parse error: unknown identifier: tagged2 |
|
3446 | 3446 | [255] |
|
3447 | 3447 | |
|
3448 | 3448 | multiple revspecs |
|
3449 | 3449 | |
|
3450 | 3450 | $ hg log -r 'tip~1:tip' -r 'tip~2:tip~1' --template '{rev}\n' |
|
3451 | 3451 | 8 |
|
3452 | 3452 | 9 |
|
3453 | 3453 | 4 |
|
3454 | 3454 | 5 |
|
3455 | 3455 | 6 |
|
3456 | 3456 | 7 |
|
3457 | 3457 | |
|
3458 | 3458 | test usage in revpair (with "+") |
|
3459 | 3459 | |
|
3460 | 3460 | (real pair) |
|
3461 | 3461 | |
|
3462 | 3462 | $ hg diff -r 'tip^^' -r 'tip' |
|
3463 | 3463 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
3464 | 3464 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
3465 | 3465 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
3466 | 3466 | @@ -0,0 +1,1 @@ |
|
3467 | 3467 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
3468 | 3468 | $ hg diff -r 'tip^^::tip' |
|
3469 | 3469 | diff -r 2326846efdab -r 24286f4ae135 .hgtags |
|
3470 | 3470 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
3471 | 3471 | +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000 |
|
3472 | 3472 | @@ -0,0 +1,1 @@ |
|
3473 | 3473 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
3474 | 3474 | |
|
3475 | 3475 | (single rev) |
|
3476 | 3476 | |
|
3477 | 3477 | $ hg diff -r 'tip^' -r 'tip^' |
|
3478 | 3478 | $ hg diff -r 'tip^:tip^' |
|
3479 | 3479 | |
|
3480 | 3480 | (single rev that does not looks like a range) |
|
3481 | 3481 | |
|
3482 | 3482 | $ hg diff -r 'tip^::tip^ or tip^' |
|
3483 | 3483 | diff -r d5d0dcbdc4d9 .hgtags |
|
3484 | 3484 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
3485 | 3485 | +++ b/.hgtags * (glob) |
|
3486 | 3486 | @@ -0,0 +1,1 @@ |
|
3487 | 3487 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
3488 | 3488 | $ hg diff -r 'tip^ or tip^' |
|
3489 | 3489 | diff -r d5d0dcbdc4d9 .hgtags |
|
3490 | 3490 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
|
3491 | 3491 | +++ b/.hgtags * (glob) |
|
3492 | 3492 | @@ -0,0 +1,1 @@ |
|
3493 | 3493 | +e0cc66ef77e8b6f711815af4e001a6594fde3ba5 1.0 |
|
3494 | 3494 | |
|
3495 | 3495 | (no rev) |
|
3496 | 3496 | |
|
3497 | 3497 | $ hg diff -r 'author("babar") or author("celeste")' |
|
3498 | 3498 | abort: empty revision range |
|
3499 | 3499 | [255] |
|
3500 | 3500 | |
|
3501 | 3501 | aliases: |
|
3502 | 3502 | |
|
3503 | 3503 | $ echo '[revsetalias]' >> .hg/hgrc |
|
3504 | 3504 | $ echo 'm = merge()' >> .hg/hgrc |
|
3505 | 3505 | (revset aliases can override builtin revsets) |
|
3506 | 3506 | $ echo 'p2($1) = p1($1)' >> .hg/hgrc |
|
3507 | 3507 | $ echo 'sincem = descendants(m)' >> .hg/hgrc |
|
3508 | 3508 | $ echo 'd($1) = reverse(sort($1, date))' >> .hg/hgrc |
|
3509 | 3509 | $ echo 'rs(ARG1, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
3510 | 3510 | $ echo 'rs4(ARG1, ARGA, ARGB, ARG2) = reverse(sort(ARG1, ARG2))' >> .hg/hgrc |
|
3511 | 3511 | |
|
3512 | 3512 | $ try m |
|
3513 | 3513 | ('symbol', 'm') |
|
3514 | 3514 | * expanded: |
|
3515 | 3515 | (func |
|
3516 | 3516 | ('symbol', 'merge') |
|
3517 | 3517 | None) |
|
3518 | 3518 | * set: |
|
3519 | 3519 | <filteredset |
|
3520 | 3520 | <fullreposet+ 0:10>, |
|
3521 | 3521 | <merge>> |
|
3522 | 3522 | 6 |
|
3523 | 3523 | |
|
3524 | 3524 | $ HGPLAIN=1 |
|
3525 | 3525 | $ export HGPLAIN |
|
3526 | 3526 | $ try m |
|
3527 | 3527 | ('symbol', 'm') |
|
3528 | 3528 | abort: unknown revision 'm'! |
|
3529 | 3529 | [255] |
|
3530 | 3530 | |
|
3531 | 3531 | $ HGPLAINEXCEPT=revsetalias |
|
3532 | 3532 | $ export HGPLAINEXCEPT |
|
3533 | 3533 | $ try m |
|
3534 | 3534 | ('symbol', 'm') |
|
3535 | 3535 | * expanded: |
|
3536 | 3536 | (func |
|
3537 | 3537 | ('symbol', 'merge') |
|
3538 | 3538 | None) |
|
3539 | 3539 | * set: |
|
3540 | 3540 | <filteredset |
|
3541 | 3541 | <fullreposet+ 0:10>, |
|
3542 | 3542 | <merge>> |
|
3543 | 3543 | 6 |
|
3544 | 3544 | |
|
3545 | 3545 | $ unset HGPLAIN |
|
3546 | 3546 | $ unset HGPLAINEXCEPT |
|
3547 | 3547 | |
|
3548 | 3548 | $ try 'p2(.)' |
|
3549 | 3549 | (func |
|
3550 | 3550 | ('symbol', 'p2') |
|
3551 | 3551 | ('symbol', '.')) |
|
3552 | 3552 | * expanded: |
|
3553 | 3553 | (func |
|
3554 | 3554 | ('symbol', 'p1') |
|
3555 | 3555 | ('symbol', '.')) |
|
3556 | 3556 | * set: |
|
3557 | 3557 | <baseset+ [8]> |
|
3558 | 3558 | 8 |
|
3559 | 3559 | |
|
3560 | 3560 | $ HGPLAIN=1 |
|
3561 | 3561 | $ export HGPLAIN |
|
3562 | 3562 | $ try 'p2(.)' |
|
3563 | 3563 | (func |
|
3564 | 3564 | ('symbol', 'p2') |
|
3565 | 3565 | ('symbol', '.')) |
|
3566 | 3566 | * set: |
|
3567 | 3567 | <baseset+ []> |
|
3568 | 3568 | |
|
3569 | 3569 | $ HGPLAINEXCEPT=revsetalias |
|
3570 | 3570 | $ export HGPLAINEXCEPT |
|
3571 | 3571 | $ try 'p2(.)' |
|
3572 | 3572 | (func |
|
3573 | 3573 | ('symbol', 'p2') |
|
3574 | 3574 | ('symbol', '.')) |
|
3575 | 3575 | * expanded: |
|
3576 | 3576 | (func |
|
3577 | 3577 | ('symbol', 'p1') |
|
3578 | 3578 | ('symbol', '.')) |
|
3579 | 3579 | * set: |
|
3580 | 3580 | <baseset+ [8]> |
|
3581 | 3581 | 8 |
|
3582 | 3582 | |
|
3583 | 3583 | $ unset HGPLAIN |
|
3584 | 3584 | $ unset HGPLAINEXCEPT |
|
3585 | 3585 | |
|
3586 | 3586 | test alias recursion |
|
3587 | 3587 | |
|
3588 | 3588 | $ try sincem |
|
3589 | 3589 | ('symbol', 'sincem') |
|
3590 | 3590 | * expanded: |
|
3591 | 3591 | (func |
|
3592 | 3592 | ('symbol', 'descendants') |
|
3593 | 3593 | (func |
|
3594 | 3594 | ('symbol', 'merge') |
|
3595 | 3595 | None)) |
|
3596 | 3596 | * set: |
|
3597 | 3597 | <generatorset+> |
|
3598 | 3598 | 6 |
|
3599 | 3599 | 7 |
|
3600 | 3600 | |
|
3601 | 3601 | test infinite recursion |
|
3602 | 3602 | |
|
3603 | 3603 | $ echo 'recurse1 = recurse2' >> .hg/hgrc |
|
3604 | 3604 | $ echo 'recurse2 = recurse1' >> .hg/hgrc |
|
3605 | 3605 | $ try recurse1 |
|
3606 | 3606 | ('symbol', 'recurse1') |
|
3607 | 3607 | hg: parse error: infinite expansion of revset alias "recurse1" detected |
|
3608 | 3608 | [255] |
|
3609 | 3609 | |
|
3610 | 3610 | $ echo 'level1($1, $2) = $1 or $2' >> .hg/hgrc |
|
3611 | 3611 | $ echo 'level2($1, $2) = level1($2, $1)' >> .hg/hgrc |
|
3612 | 3612 | $ try "level2(level1(1, 2), 3)" |
|
3613 | 3613 | (func |
|
3614 | 3614 | ('symbol', 'level2') |
|
3615 | 3615 | (list |
|
3616 | 3616 | (func |
|
3617 | 3617 | ('symbol', 'level1') |
|
3618 | 3618 | (list |
|
3619 | 3619 | ('symbol', '1') |
|
3620 | 3620 | ('symbol', '2'))) |
|
3621 | 3621 | ('symbol', '3'))) |
|
3622 | 3622 | * expanded: |
|
3623 | 3623 | (or |
|
3624 | 3624 | (list |
|
3625 | 3625 | ('symbol', '3') |
|
3626 | 3626 | (or |
|
3627 | 3627 | (list |
|
3628 | 3628 | ('symbol', '1') |
|
3629 | 3629 | ('symbol', '2'))))) |
|
3630 | 3630 | * set: |
|
3631 | 3631 | <addset |
|
3632 | 3632 | <baseset [3]>, |
|
3633 | 3633 | <baseset [1, 2]>> |
|
3634 | 3634 | 3 |
|
3635 | 3635 | 1 |
|
3636 | 3636 | 2 |
|
3637 | 3637 | |
|
3638 | 3638 | test nesting and variable passing |
|
3639 | 3639 | |
|
3640 | 3640 | $ echo 'nested($1) = nested2($1)' >> .hg/hgrc |
|
3641 | 3641 | $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc |
|
3642 | 3642 | $ echo 'nested3($1) = max($1)' >> .hg/hgrc |
|
3643 | 3643 | $ try 'nested(2:5)' |
|
3644 | 3644 | (func |
|
3645 | 3645 | ('symbol', 'nested') |
|
3646 | 3646 | (range |
|
3647 | 3647 | ('symbol', '2') |
|
3648 | 3648 | ('symbol', '5'))) |
|
3649 | 3649 | * expanded: |
|
3650 | 3650 | (func |
|
3651 | 3651 | ('symbol', 'max') |
|
3652 | 3652 | (range |
|
3653 | 3653 | ('symbol', '2') |
|
3654 | 3654 | ('symbol', '5'))) |
|
3655 | 3655 | * set: |
|
3656 | 3656 | <baseset |
|
3657 | 3657 | <max |
|
3658 | 3658 | <fullreposet+ 0:10>, |
|
3659 | 3659 | <spanset+ 2:6>>> |
|
3660 | 3660 | 5 |
|
3661 | 3661 | |
|
3662 | 3662 | test chained `or` operations are flattened at parsing phase |
|
3663 | 3663 | |
|
3664 | 3664 | $ echo 'chainedorops($1, $2, $3) = $1|$2|$3' >> .hg/hgrc |
|
3665 | 3665 | $ try 'chainedorops(0:1, 1:2, 2:3)' |
|
3666 | 3666 | (func |
|
3667 | 3667 | ('symbol', 'chainedorops') |
|
3668 | 3668 | (list |
|
3669 | 3669 | (range |
|
3670 | 3670 | ('symbol', '0') |
|
3671 | 3671 | ('symbol', '1')) |
|
3672 | 3672 | (range |
|
3673 | 3673 | ('symbol', '1') |
|
3674 | 3674 | ('symbol', '2')) |
|
3675 | 3675 | (range |
|
3676 | 3676 | ('symbol', '2') |
|
3677 | 3677 | ('symbol', '3')))) |
|
3678 | 3678 | * expanded: |
|
3679 | 3679 | (or |
|
3680 | 3680 | (list |
|
3681 | 3681 | (range |
|
3682 | 3682 | ('symbol', '0') |
|
3683 | 3683 | ('symbol', '1')) |
|
3684 | 3684 | (range |
|
3685 | 3685 | ('symbol', '1') |
|
3686 | 3686 | ('symbol', '2')) |
|
3687 | 3687 | (range |
|
3688 | 3688 | ('symbol', '2') |
|
3689 | 3689 | ('symbol', '3')))) |
|
3690 | 3690 | * set: |
|
3691 | 3691 | <addset |
|
3692 | 3692 | <spanset+ 0:2>, |
|
3693 | 3693 | <addset |
|
3694 | 3694 | <spanset+ 1:3>, |
|
3695 | 3695 | <spanset+ 2:4>>> |
|
3696 | 3696 | 0 |
|
3697 | 3697 | 1 |
|
3698 | 3698 | 2 |
|
3699 | 3699 | 3 |
|
3700 | 3700 | |
|
3701 | 3701 | test variable isolation, variable placeholders are rewritten as string |
|
3702 | 3702 | then parsed and matched again as string. Check they do not leak too |
|
3703 | 3703 | far away. |
|
3704 | 3704 | |
|
3705 | 3705 | $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc |
|
3706 | 3706 | $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc |
|
3707 | 3707 | $ try 'callinjection(2:5)' |
|
3708 | 3708 | (func |
|
3709 | 3709 | ('symbol', 'callinjection') |
|
3710 | 3710 | (range |
|
3711 | 3711 | ('symbol', '2') |
|
3712 | 3712 | ('symbol', '5'))) |
|
3713 | 3713 | * expanded: |
|
3714 | 3714 | (func |
|
3715 | 3715 | ('symbol', 'descendants') |
|
3716 | 3716 | (func |
|
3717 | 3717 | ('symbol', 'max') |
|
3718 | 3718 | ('string', '$1'))) |
|
3719 | 3719 | abort: unknown revision '$1'! |
|
3720 | 3720 | [255] |
|
3721 | 3721 | |
|
3722 | 3722 | test scope of alias expansion: 'universe' is expanded prior to 'shadowall(0)', |
|
3723 | 3723 | but 'all()' should never be substituted to '0()'. |
|
3724 | 3724 | |
|
3725 | 3725 | $ echo 'universe = all()' >> .hg/hgrc |
|
3726 | 3726 | $ echo 'shadowall(all) = all and universe' >> .hg/hgrc |
|
3727 | 3727 | $ try 'shadowall(0)' |
|
3728 | 3728 | (func |
|
3729 | 3729 | ('symbol', 'shadowall') |
|
3730 | 3730 | ('symbol', '0')) |
|
3731 | 3731 | * expanded: |
|
3732 | 3732 | (and |
|
3733 | 3733 | ('symbol', '0') |
|
3734 | 3734 | (func |
|
3735 | 3735 | ('symbol', 'all') |
|
3736 | 3736 | None)) |
|
3737 | 3737 | * set: |
|
3738 | 3738 | <filteredset |
|
3739 | 3739 | <baseset [0]>, |
|
3740 | 3740 | <spanset+ 0:10>> |
|
3741 | 3741 | 0 |
|
3742 | 3742 | |
|
3743 | 3743 | test unknown reference: |
|
3744 | 3744 | |
|
3745 | 3745 | $ try "unknownref(0)" --config 'revsetalias.unknownref($1)=$1:$2' |
|
3746 | 3746 | (func |
|
3747 | 3747 | ('symbol', 'unknownref') |
|
3748 | 3748 | ('symbol', '0')) |
|
3749 | 3749 | abort: bad definition of revset alias "unknownref": invalid symbol '$2' |
|
3750 | 3750 | [255] |
|
3751 | 3751 | |
|
3752 | 3752 | $ hg debugrevspec --debug --config revsetalias.anotherbadone='branch(' "tip" |
|
3753 | 3753 | ('symbol', 'tip') |
|
3754 | 3754 | warning: bad definition of revset alias "anotherbadone": at 7: not a prefix: end |
|
3755 | 3755 | * set: |
|
3756 | 3756 | <baseset [9]> |
|
3757 | 3757 | 9 |
|
3758 | 3758 | |
|
3759 | 3759 | $ try 'tip' |
|
3760 | 3760 | ('symbol', 'tip') |
|
3761 | 3761 | * set: |
|
3762 | 3762 | <baseset [9]> |
|
3763 | 3763 | 9 |
|
3764 | 3764 | |
|
3765 | 3765 | $ hg debugrevspec --debug --config revsetalias.'bad name'='tip' "tip" |
|
3766 | 3766 | ('symbol', 'tip') |
|
3767 | 3767 | warning: bad declaration of revset alias "bad name": at 4: invalid token |
|
3768 | 3768 | * set: |
|
3769 | 3769 | <baseset [9]> |
|
3770 | 3770 | 9 |
|
3771 | 3771 | $ echo 'strictreplacing($1, $10) = $10 or desc("$1")' >> .hg/hgrc |
|
3772 | 3772 | $ try 'strictreplacing("foo", tip)' |
|
3773 | 3773 | (func |
|
3774 | 3774 | ('symbol', 'strictreplacing') |
|
3775 | 3775 | (list |
|
3776 | 3776 | ('string', 'foo') |
|
3777 | 3777 | ('symbol', 'tip'))) |
|
3778 | 3778 | * expanded: |
|
3779 | 3779 | (or |
|
3780 | 3780 | (list |
|
3781 | 3781 | ('symbol', 'tip') |
|
3782 | 3782 | (func |
|
3783 | 3783 | ('symbol', 'desc') |
|
3784 | 3784 | ('string', '$1')))) |
|
3785 | 3785 | * set: |
|
3786 | 3786 | <addset |
|
3787 | 3787 | <baseset [9]>, |
|
3788 | 3788 | <filteredset |
|
3789 | 3789 | <fullreposet+ 0:10>, |
|
3790 | 3790 | <desc '$1'>>> |
|
3791 | 3791 | 9 |
|
3792 | 3792 | |
|
3793 | 3793 | $ try 'd(2:5)' |
|
3794 | 3794 | (func |
|
3795 | 3795 | ('symbol', 'd') |
|
3796 | 3796 | (range |
|
3797 | 3797 | ('symbol', '2') |
|
3798 | 3798 | ('symbol', '5'))) |
|
3799 | 3799 | * expanded: |
|
3800 | 3800 | (func |
|
3801 | 3801 | ('symbol', 'reverse') |
|
3802 | 3802 | (func |
|
3803 | 3803 | ('symbol', 'sort') |
|
3804 | 3804 | (list |
|
3805 | 3805 | (range |
|
3806 | 3806 | ('symbol', '2') |
|
3807 | 3807 | ('symbol', '5')) |
|
3808 | 3808 | ('symbol', 'date')))) |
|
3809 | 3809 | * set: |
|
3810 | 3810 | <baseset [4, 5, 3, 2]> |
|
3811 | 3811 | 4 |
|
3812 | 3812 | 5 |
|
3813 | 3813 | 3 |
|
3814 | 3814 | 2 |
|
3815 | 3815 | $ try 'rs(2 or 3, date)' |
|
3816 | 3816 | (func |
|
3817 | 3817 | ('symbol', 'rs') |
|
3818 | 3818 | (list |
|
3819 | 3819 | (or |
|
3820 | 3820 | (list |
|
3821 | 3821 | ('symbol', '2') |
|
3822 | 3822 | ('symbol', '3'))) |
|
3823 | 3823 | ('symbol', 'date'))) |
|
3824 | 3824 | * expanded: |
|
3825 | 3825 | (func |
|
3826 | 3826 | ('symbol', 'reverse') |
|
3827 | 3827 | (func |
|
3828 | 3828 | ('symbol', 'sort') |
|
3829 | 3829 | (list |
|
3830 | 3830 | (or |
|
3831 | 3831 | (list |
|
3832 | 3832 | ('symbol', '2') |
|
3833 | 3833 | ('symbol', '3'))) |
|
3834 | 3834 | ('symbol', 'date')))) |
|
3835 | 3835 | * set: |
|
3836 | 3836 | <baseset [3, 2]> |
|
3837 | 3837 | 3 |
|
3838 | 3838 | 2 |
|
3839 | 3839 | $ try 'rs()' |
|
3840 | 3840 | (func |
|
3841 | 3841 | ('symbol', 'rs') |
|
3842 | 3842 | None) |
|
3843 | 3843 | hg: parse error: invalid number of arguments: 0 |
|
3844 | 3844 | [255] |
|
3845 | 3845 | $ try 'rs(2)' |
|
3846 | 3846 | (func |
|
3847 | 3847 | ('symbol', 'rs') |
|
3848 | 3848 | ('symbol', '2')) |
|
3849 | 3849 | hg: parse error: invalid number of arguments: 1 |
|
3850 | 3850 | [255] |
|
3851 | 3851 | $ try 'rs(2, data, 7)' |
|
3852 | 3852 | (func |
|
3853 | 3853 | ('symbol', 'rs') |
|
3854 | 3854 | (list |
|
3855 | 3855 | ('symbol', '2') |
|
3856 | 3856 | ('symbol', 'data') |
|
3857 | 3857 | ('symbol', '7'))) |
|
3858 | 3858 | hg: parse error: invalid number of arguments: 3 |
|
3859 | 3859 | [255] |
|
3860 | 3860 | $ try 'rs4(2 or 3, x, x, date)' |
|
3861 | 3861 | (func |
|
3862 | 3862 | ('symbol', 'rs4') |
|
3863 | 3863 | (list |
|
3864 | 3864 | (or |
|
3865 | 3865 | (list |
|
3866 | 3866 | ('symbol', '2') |
|
3867 | 3867 | ('symbol', '3'))) |
|
3868 | 3868 | ('symbol', 'x') |
|
3869 | 3869 | ('symbol', 'x') |
|
3870 | 3870 | ('symbol', 'date'))) |
|
3871 | 3871 | * expanded: |
|
3872 | 3872 | (func |
|
3873 | 3873 | ('symbol', 'reverse') |
|
3874 | 3874 | (func |
|
3875 | 3875 | ('symbol', 'sort') |
|
3876 | 3876 | (list |
|
3877 | 3877 | (or |
|
3878 | 3878 | (list |
|
3879 | 3879 | ('symbol', '2') |
|
3880 | 3880 | ('symbol', '3'))) |
|
3881 | 3881 | ('symbol', 'date')))) |
|
3882 | 3882 | * set: |
|
3883 | 3883 | <baseset [3, 2]> |
|
3884 | 3884 | 3 |
|
3885 | 3885 | 2 |
|
3886 | 3886 | |
|
3887 | 3887 | issue4553: check that revset aliases override existing hash prefix |
|
3888 | 3888 | |
|
3889 | 3889 | $ hg log -qr e |
|
3890 | 3890 | 6:e0cc66ef77e8 |
|
3891 | 3891 | |
|
3892 | 3892 | $ hg log -qr e --config revsetalias.e="all()" |
|
3893 | 3893 | 0:2785f51eece5 |
|
3894 | 3894 | 1:d75937da8da0 |
|
3895 | 3895 | 2:5ed5505e9f1c |
|
3896 | 3896 | 3:8528aa5637f2 |
|
3897 | 3897 | 4:2326846efdab |
|
3898 | 3898 | 5:904fa392b941 |
|
3899 | 3899 | 6:e0cc66ef77e8 |
|
3900 | 3900 | 7:013af1973af4 |
|
3901 | 3901 | 8:d5d0dcbdc4d9 |
|
3902 | 3902 | 9:24286f4ae135 |
|
3903 | 3903 | |
|
3904 | 3904 | $ hg log -qr e: --config revsetalias.e="0" |
|
3905 | 3905 | 0:2785f51eece5 |
|
3906 | 3906 | 1:d75937da8da0 |
|
3907 | 3907 | 2:5ed5505e9f1c |
|
3908 | 3908 | 3:8528aa5637f2 |
|
3909 | 3909 | 4:2326846efdab |
|
3910 | 3910 | 5:904fa392b941 |
|
3911 | 3911 | 6:e0cc66ef77e8 |
|
3912 | 3912 | 7:013af1973af4 |
|
3913 | 3913 | 8:d5d0dcbdc4d9 |
|
3914 | 3914 | 9:24286f4ae135 |
|
3915 | 3915 | |
|
3916 | 3916 | $ hg log -qr :e --config revsetalias.e="9" |
|
3917 | 3917 | 0:2785f51eece5 |
|
3918 | 3918 | 1:d75937da8da0 |
|
3919 | 3919 | 2:5ed5505e9f1c |
|
3920 | 3920 | 3:8528aa5637f2 |
|
3921 | 3921 | 4:2326846efdab |
|
3922 | 3922 | 5:904fa392b941 |
|
3923 | 3923 | 6:e0cc66ef77e8 |
|
3924 | 3924 | 7:013af1973af4 |
|
3925 | 3925 | 8:d5d0dcbdc4d9 |
|
3926 | 3926 | 9:24286f4ae135 |
|
3927 | 3927 | |
|
3928 | 3928 | $ hg log -qr e: |
|
3929 | 3929 | 6:e0cc66ef77e8 |
|
3930 | 3930 | 7:013af1973af4 |
|
3931 | 3931 | 8:d5d0dcbdc4d9 |
|
3932 | 3932 | 9:24286f4ae135 |
|
3933 | 3933 | |
|
3934 | 3934 | $ hg log -qr :e |
|
3935 | 3935 | 0:2785f51eece5 |
|
3936 | 3936 | 1:d75937da8da0 |
|
3937 | 3937 | 2:5ed5505e9f1c |
|
3938 | 3938 | 3:8528aa5637f2 |
|
3939 | 3939 | 4:2326846efdab |
|
3940 | 3940 | 5:904fa392b941 |
|
3941 | 3941 | 6:e0cc66ef77e8 |
|
3942 | 3942 | |
|
3943 | 3943 | issue2549 - correct optimizations |
|
3944 | 3944 | |
|
3945 | 3945 | $ try 'limit(1 or 2 or 3, 2) and not 2' |
|
3946 | 3946 | (and |
|
3947 | 3947 | (func |
|
3948 | 3948 | ('symbol', 'limit') |
|
3949 | 3949 | (list |
|
3950 | 3950 | (or |
|
3951 | 3951 | (list |
|
3952 | 3952 | ('symbol', '1') |
|
3953 | 3953 | ('symbol', '2') |
|
3954 | 3954 | ('symbol', '3'))) |
|
3955 | 3955 | ('symbol', '2'))) |
|
3956 | 3956 | (not |
|
3957 | 3957 | ('symbol', '2'))) |
|
3958 | 3958 | * set: |
|
3959 | 3959 | <filteredset |
|
3960 | 3960 | <baseset [1, 2]>, |
|
3961 | 3961 | <not |
|
3962 | 3962 | <baseset [2]>>> |
|
3963 | 3963 | 1 |
|
3964 | 3964 | $ try 'max(1 or 2) and not 2' |
|
3965 | 3965 | (and |
|
3966 | 3966 | (func |
|
3967 | 3967 | ('symbol', 'max') |
|
3968 | 3968 | (or |
|
3969 | 3969 | (list |
|
3970 | 3970 | ('symbol', '1') |
|
3971 | 3971 | ('symbol', '2')))) |
|
3972 | 3972 | (not |
|
3973 | 3973 | ('symbol', '2'))) |
|
3974 | 3974 | * set: |
|
3975 | 3975 | <filteredset |
|
3976 | 3976 | <baseset |
|
3977 | 3977 | <max |
|
3978 | 3978 | <fullreposet+ 0:10>, |
|
3979 | 3979 | <baseset [1, 2]>>>, |
|
3980 | 3980 | <not |
|
3981 | 3981 | <baseset [2]>>> |
|
3982 | 3982 | $ try 'min(1 or 2) and not 1' |
|
3983 | 3983 | (and |
|
3984 | 3984 | (func |
|
3985 | 3985 | ('symbol', 'min') |
|
3986 | 3986 | (or |
|
3987 | 3987 | (list |
|
3988 | 3988 | ('symbol', '1') |
|
3989 | 3989 | ('symbol', '2')))) |
|
3990 | 3990 | (not |
|
3991 | 3991 | ('symbol', '1'))) |
|
3992 | 3992 | * set: |
|
3993 | 3993 | <filteredset |
|
3994 | 3994 | <baseset |
|
3995 | 3995 | <min |
|
3996 | 3996 | <fullreposet+ 0:10>, |
|
3997 | 3997 | <baseset [1, 2]>>>, |
|
3998 | 3998 | <not |
|
3999 | 3999 | <baseset [1]>>> |
|
4000 | 4000 | $ try 'last(1 or 2, 1) and not 2' |
|
4001 | 4001 | (and |
|
4002 | 4002 | (func |
|
4003 | 4003 | ('symbol', 'last') |
|
4004 | 4004 | (list |
|
4005 | 4005 | (or |
|
4006 | 4006 | (list |
|
4007 | 4007 | ('symbol', '1') |
|
4008 | 4008 | ('symbol', '2'))) |
|
4009 | 4009 | ('symbol', '1'))) |
|
4010 | 4010 | (not |
|
4011 | 4011 | ('symbol', '2'))) |
|
4012 | 4012 | * set: |
|
4013 | 4013 | <filteredset |
|
4014 | 4014 | <baseset [2]>, |
|
4015 | 4015 | <not |
|
4016 | 4016 | <baseset [2]>>> |
|
4017 | 4017 | |
|
4018 | 4018 | issue4289 - ordering of built-ins |
|
4019 | 4019 | $ hg log -M -q -r 3:2 |
|
4020 | 4020 | 3:8528aa5637f2 |
|
4021 | 4021 | 2:5ed5505e9f1c |
|
4022 | 4022 | |
|
4023 | 4023 | test revsets started with 40-chars hash (issue3669) |
|
4024 | 4024 | |
|
4025 | 4025 | $ ISSUE3669_TIP=`hg tip --template '{node}'` |
|
4026 | 4026 | $ hg log -r "${ISSUE3669_TIP}" --template '{rev}\n' |
|
4027 | 4027 | 9 |
|
4028 | 4028 | $ hg log -r "${ISSUE3669_TIP}^" --template '{rev}\n' |
|
4029 | 4029 | 8 |
|
4030 | 4030 | |
|
4031 | 4031 | test or-ed indirect predicates (issue3775) |
|
4032 | 4032 | |
|
4033 | 4033 | $ log '6 or 6^1' | sort |
|
4034 | 4034 | 5 |
|
4035 | 4035 | 6 |
|
4036 | 4036 | $ log '6^1 or 6' | sort |
|
4037 | 4037 | 5 |
|
4038 | 4038 | 6 |
|
4039 | 4039 | $ log '4 or 4~1' | sort |
|
4040 | 4040 | 2 |
|
4041 | 4041 | 4 |
|
4042 | 4042 | $ log '4~1 or 4' | sort |
|
4043 | 4043 | 2 |
|
4044 | 4044 | 4 |
|
4045 | 4045 | $ log '(0 or 2):(4 or 6) or 0 or 6' | sort |
|
4046 | 4046 | 0 |
|
4047 | 4047 | 1 |
|
4048 | 4048 | 2 |
|
4049 | 4049 | 3 |
|
4050 | 4050 | 4 |
|
4051 | 4051 | 5 |
|
4052 | 4052 | 6 |
|
4053 | 4053 | $ log '0 or 6 or (0 or 2):(4 or 6)' | sort |
|
4054 | 4054 | 0 |
|
4055 | 4055 | 1 |
|
4056 | 4056 | 2 |
|
4057 | 4057 | 3 |
|
4058 | 4058 | 4 |
|
4059 | 4059 | 5 |
|
4060 | 4060 | 6 |
|
4061 | 4061 | |
|
4062 | 4062 | tests for 'remote()' predicate: |
|
4063 | 4063 | #. (csets in remote) (id) (remote) |
|
4064 | 4064 | 1. less than local current branch "default" |
|
4065 | 4065 | 2. same with local specified "default" |
|
4066 | 4066 | 3. more than local specified specified |
|
4067 | 4067 | |
|
4068 | 4068 | $ hg clone --quiet -U . ../remote3 |
|
4069 | 4069 | $ cd ../remote3 |
|
4070 | 4070 | $ hg update -q 7 |
|
4071 | 4071 | $ echo r > r |
|
4072 | 4072 | $ hg ci -Aqm 10 |
|
4073 | 4073 | $ log 'remote()' |
|
4074 | 4074 | 7 |
|
4075 | 4075 | $ log 'remote("a-b-c-")' |
|
4076 | 4076 | 2 |
|
4077 | 4077 | $ cd ../repo |
|
4078 | 4078 | $ log 'remote(".a.b.c.", "../remote3")' |
|
4079 | 4079 | |
|
4080 | 4080 | tests for concatenation of strings/symbols by "##" |
|
4081 | 4081 | |
|
4082 | 4082 | $ try "278 ## '5f5' ## 1ee ## 'ce5'" |
|
4083 | 4083 | (_concat |
|
4084 | 4084 | (_concat |
|
4085 | 4085 | (_concat |
|
4086 | 4086 | ('symbol', '278') |
|
4087 | 4087 | ('string', '5f5')) |
|
4088 | 4088 | ('symbol', '1ee')) |
|
4089 | 4089 | ('string', 'ce5')) |
|
4090 | 4090 | * concatenated: |
|
4091 | 4091 | ('string', '2785f51eece5') |
|
4092 | 4092 | * set: |
|
4093 | 4093 | <baseset [0]> |
|
4094 | 4094 | 0 |
|
4095 | 4095 | |
|
4096 | 4096 | $ echo 'cat4($1, $2, $3, $4) = $1 ## $2 ## $3 ## $4' >> .hg/hgrc |
|
4097 | 4097 | $ try "cat4(278, '5f5', 1ee, 'ce5')" |
|
4098 | 4098 | (func |
|
4099 | 4099 | ('symbol', 'cat4') |
|
4100 | 4100 | (list |
|
4101 | 4101 | ('symbol', '278') |
|
4102 | 4102 | ('string', '5f5') |
|
4103 | 4103 | ('symbol', '1ee') |
|
4104 | 4104 | ('string', 'ce5'))) |
|
4105 | 4105 | * expanded: |
|
4106 | 4106 | (_concat |
|
4107 | 4107 | (_concat |
|
4108 | 4108 | (_concat |
|
4109 | 4109 | ('symbol', '278') |
|
4110 | 4110 | ('string', '5f5')) |
|
4111 | 4111 | ('symbol', '1ee')) |
|
4112 | 4112 | ('string', 'ce5')) |
|
4113 | 4113 | * concatenated: |
|
4114 | 4114 | ('string', '2785f51eece5') |
|
4115 | 4115 | * set: |
|
4116 | 4116 | <baseset [0]> |
|
4117 | 4117 | 0 |
|
4118 | 4118 | |
|
4119 | 4119 | (check concatenation in alias nesting) |
|
4120 | 4120 | |
|
4121 | 4121 | $ echo 'cat2($1, $2) = $1 ## $2' >> .hg/hgrc |
|
4122 | 4122 | $ echo 'cat2x2($1, $2, $3, $4) = cat2($1 ## $2, $3 ## $4)' >> .hg/hgrc |
|
4123 | 4123 | $ log "cat2x2(278, '5f5', 1ee, 'ce5')" |
|
4124 | 4124 | 0 |
|
4125 | 4125 | |
|
4126 | 4126 | (check operator priority) |
|
4127 | 4127 | |
|
4128 | 4128 | $ echo 'cat2n2($1, $2, $3, $4) = $1 ## $2 or $3 ## $4~2' >> .hg/hgrc |
|
4129 | 4129 | $ log "cat2n2(2785f5, 1eece5, 24286f, 4ae135)" |
|
4130 | 4130 | 0 |
|
4131 | 4131 | 4 |
|
4132 | 4132 | |
|
4133 | 4133 | $ cd .. |
|
4134 | 4134 | |
|
4135 | 4135 | prepare repository that has "default" branches of multiple roots |
|
4136 | 4136 | |
|
4137 | 4137 | $ hg init namedbranch |
|
4138 | 4138 | $ cd namedbranch |
|
4139 | 4139 | |
|
4140 | 4140 | $ echo default0 >> a |
|
4141 | 4141 | $ hg ci -Aqm0 |
|
4142 | 4142 | $ echo default1 >> a |
|
4143 | 4143 | $ hg ci -m1 |
|
4144 | 4144 | |
|
4145 | 4145 | $ hg branch -q stable |
|
4146 | 4146 | $ echo stable2 >> a |
|
4147 | 4147 | $ hg ci -m2 |
|
4148 | 4148 | $ echo stable3 >> a |
|
4149 | 4149 | $ hg ci -m3 |
|
4150 | 4150 | |
|
4151 | 4151 | $ hg update -q null |
|
4152 | 4152 | $ echo default4 >> a |
|
4153 | 4153 | $ hg ci -Aqm4 |
|
4154 | 4154 | $ echo default5 >> a |
|
4155 | 4155 | $ hg ci -m5 |
|
4156 | 4156 | |
|
4157 | 4157 | "null" revision belongs to "default" branch (issue4683) |
|
4158 | 4158 | |
|
4159 | 4159 | $ log 'branch(null)' |
|
4160 | 4160 | 0 |
|
4161 | 4161 | 1 |
|
4162 | 4162 | 4 |
|
4163 | 4163 | 5 |
|
4164 | 4164 | |
|
4165 | 4165 | "null" revision belongs to "default" branch, but it shouldn't appear in set |
|
4166 | 4166 | unless explicitly specified (issue4682) |
|
4167 | 4167 | |
|
4168 | 4168 | $ log 'children(branch(default))' |
|
4169 | 4169 | 1 |
|
4170 | 4170 | 2 |
|
4171 | 4171 | 5 |
|
4172 | 4172 | |
|
4173 | 4173 | $ cd .. |
|
4174 | 4174 | |
|
4175 | 4175 | test author/desc/keyword in problematic encoding |
|
4176 | 4176 | # unicode: cp932: |
|
4177 | 4177 | # u30A2 0x83 0x41(= 'A') |
|
4178 | 4178 | # u30C2 0x83 0x61(= 'a') |
|
4179 | 4179 | |
|
4180 | 4180 | $ hg init problematicencoding |
|
4181 | 4181 | $ cd problematicencoding |
|
4182 | 4182 | |
|
4183 | 4183 | $ $PYTHON > setup.sh <<EOF |
|
4184 | 4184 | > print u''' |
|
4185 | 4185 | > echo a > text |
|
4186 | 4186 | > hg add text |
|
4187 | 4187 | > hg --encoding utf-8 commit -u '\u30A2' -m none |
|
4188 | 4188 | > echo b > text |
|
4189 | 4189 | > hg --encoding utf-8 commit -u '\u30C2' -m none |
|
4190 | 4190 | > echo c > text |
|
4191 | 4191 | > hg --encoding utf-8 commit -u none -m '\u30A2' |
|
4192 | 4192 | > echo d > text |
|
4193 | 4193 | > hg --encoding utf-8 commit -u none -m '\u30C2' |
|
4194 | 4194 | > '''.encode('utf-8') |
|
4195 | 4195 | > EOF |
|
4196 | 4196 | $ sh < setup.sh |
|
4197 | 4197 | |
|
4198 | 4198 | test in problematic encoding |
|
4199 | 4199 | $ $PYTHON > test.sh <<EOF |
|
4200 | 4200 | > print u''' |
|
4201 | 4201 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30A2)' |
|
4202 | 4202 | > echo ==== |
|
4203 | 4203 | > hg --encoding cp932 log --template '{rev}\\n' -r 'author(\u30C2)' |
|
4204 | 4204 | > echo ==== |
|
4205 | 4205 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30A2)' |
|
4206 | 4206 | > echo ==== |
|
4207 | 4207 | > hg --encoding cp932 log --template '{rev}\\n' -r 'desc(\u30C2)' |
|
4208 | 4208 | > echo ==== |
|
4209 | 4209 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30A2)' |
|
4210 | 4210 | > echo ==== |
|
4211 | 4211 | > hg --encoding cp932 log --template '{rev}\\n' -r 'keyword(\u30C2)' |
|
4212 | 4212 | > '''.encode('cp932') |
|
4213 | 4213 | > EOF |
|
4214 | 4214 | $ sh < test.sh |
|
4215 | 4215 | 0 |
|
4216 | 4216 | ==== |
|
4217 | 4217 | 1 |
|
4218 | 4218 | ==== |
|
4219 | 4219 | 2 |
|
4220 | 4220 | ==== |
|
4221 | 4221 | 3 |
|
4222 | 4222 | ==== |
|
4223 | 4223 | 0 |
|
4224 | 4224 | 2 |
|
4225 | 4225 | ==== |
|
4226 | 4226 | 1 |
|
4227 | 4227 | 3 |
|
4228 | 4228 | |
|
4229 | 4229 | test error message of bad revset |
|
4230 | 4230 | $ hg log -r 'foo\\' |
|
4231 | 4231 | hg: parse error at 3: syntax error in revset 'foo\\' |
|
4232 | 4232 | [255] |
|
4233 | 4233 | |
|
4234 | 4234 | $ cd .. |
|
4235 | 4235 | |
|
4236 | 4236 | Test that revset predicate of extension isn't loaded at failure of |
|
4237 | 4237 | loading it |
|
4238 | 4238 | |
|
4239 | 4239 | $ cd repo |
|
4240 | 4240 | |
|
4241 | 4241 | $ cat <<EOF > $TESTTMP/custompredicate.py |
|
4242 | 4242 | > from mercurial import error, registrar, revset |
|
4243 | 4243 | > |
|
4244 | 4244 | > revsetpredicate = registrar.revsetpredicate() |
|
4245 | 4245 | > |
|
4246 | 4246 | > @revsetpredicate('custom1()') |
|
4247 | 4247 | > def custom1(repo, subset, x): |
|
4248 | 4248 | > return revset.baseset([1]) |
|
4249 | 4249 | > |
|
4250 | 4250 | > raise error.Abort('intentional failure of loading extension') |
|
4251 | 4251 | > EOF |
|
4252 | 4252 | $ cat <<EOF > .hg/hgrc |
|
4253 | 4253 | > [extensions] |
|
4254 | 4254 | > custompredicate = $TESTTMP/custompredicate.py |
|
4255 | 4255 | > EOF |
|
4256 | 4256 | |
|
4257 | 4257 | $ hg debugrevspec "custom1()" |
|
4258 | 4258 | *** failed to import extension custompredicate from $TESTTMP/custompredicate.py: intentional failure of loading extension |
|
4259 | 4259 | hg: parse error: unknown identifier: custom1 |
|
4260 | 4260 | [255] |
|
4261 | 4261 | |
|
4262 | Test repo.anyrevs with customized revset overrides | |
|
4263 | ||
|
4264 | $ cat > $TESTTMP/printprevset.py <<EOF | |
|
4265 | > from mercurial import encoding | |
|
4266 | > def reposetup(ui, repo): | |
|
4267 | > alias = {} | |
|
4268 | > p = encoding.environ.get('P') | |
|
4269 | > if p: | |
|
4270 | > alias['P'] = p | |
|
4271 | > revs = repo.anyrevs(['P'], user=True, localalias=alias) | |
|
4272 | > ui.write('P=%r' % list(revs)) | |
|
4273 | > EOF | |
|
4274 | ||
|
4275 | $ cat >> .hg/hgrc <<EOF | |
|
4276 | > custompredicate = ! | |
|
4277 | > printprevset = $TESTTMP/printprevset.py | |
|
4278 | > EOF | |
|
4279 | ||
|
4280 | $ hg --config revsetalias.P=1 log -r . -T '\n' | |
|
4281 | P=[1] | |
|
4282 | $ P=3 hg --config revsetalias.P=2 log -r . -T '\n' | |
|
4283 | P=[3] | |
|
4284 | ||
|
4262 | 4285 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now