##// END OF EJS Templates
debugignore: respect ui.relative-paths...
Martin von Zweigbergk -
r41785:be8741d4 default
parent child Browse files
Show More
@@ -1,3397 +1,3398 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 codecs
11 11 import collections
12 12 import difflib
13 13 import errno
14 14 import operator
15 15 import os
16 16 import random
17 17 import re
18 18 import socket
19 19 import ssl
20 20 import stat
21 21 import string
22 22 import subprocess
23 23 import sys
24 24 import time
25 25
26 26 from .i18n import _
27 27 from .node import (
28 28 bin,
29 29 hex,
30 30 nullhex,
31 31 nullid,
32 32 nullrev,
33 33 short,
34 34 )
35 35 from . import (
36 36 bundle2,
37 37 changegroup,
38 38 cmdutil,
39 39 color,
40 40 context,
41 41 copies,
42 42 dagparser,
43 43 encoding,
44 44 error,
45 45 exchange,
46 46 extensions,
47 47 filemerge,
48 48 filesetlang,
49 49 formatter,
50 50 hg,
51 51 httppeer,
52 52 localrepo,
53 53 lock as lockmod,
54 54 logcmdutil,
55 55 merge as mergemod,
56 56 obsolete,
57 57 obsutil,
58 58 phases,
59 59 policy,
60 60 pvec,
61 61 pycompat,
62 62 registrar,
63 63 repair,
64 64 revlog,
65 65 revset,
66 66 revsetlang,
67 67 scmutil,
68 68 setdiscovery,
69 69 simplemerge,
70 70 sshpeer,
71 71 sslutil,
72 72 streamclone,
73 73 templater,
74 74 treediscovery,
75 75 upgrade,
76 76 url as urlmod,
77 77 util,
78 78 vfs as vfsmod,
79 79 wireprotoframing,
80 80 wireprotoserver,
81 81 wireprotov2peer,
82 82 )
83 83 from .utils import (
84 84 cborutil,
85 85 dateutil,
86 86 procutil,
87 87 stringutil,
88 88 )
89 89
90 90 from .revlogutils import (
91 91 deltas as deltautil
92 92 )
93 93
94 94 release = lockmod.release
95 95
96 96 command = registrar.command()
97 97
98 98 @command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True)
99 99 def debugancestor(ui, repo, *args):
100 100 """find the ancestor revision of two revisions in a given index"""
101 101 if len(args) == 3:
102 102 index, rev1, rev2 = args
103 103 r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), index)
104 104 lookup = r.lookup
105 105 elif len(args) == 2:
106 106 if not repo:
107 107 raise error.Abort(_('there is no Mercurial repository here '
108 108 '(.hg not found)'))
109 109 rev1, rev2 = args
110 110 r = repo.changelog
111 111 lookup = repo.lookup
112 112 else:
113 113 raise error.Abort(_('either two or three arguments required'))
114 114 a = r.ancestor(lookup(rev1), lookup(rev2))
115 115 ui.write('%d:%s\n' % (r.rev(a), hex(a)))
116 116
117 117 @command('debugapplystreamclonebundle', [], 'FILE')
118 118 def debugapplystreamclonebundle(ui, repo, fname):
119 119 """apply a stream clone bundle file"""
120 120 f = hg.openpath(ui, fname)
121 121 gen = exchange.readbundle(ui, f, fname)
122 122 gen.apply(repo)
123 123
124 124 @command('debugbuilddag',
125 125 [('m', 'mergeable-file', None, _('add single file mergeable changes')),
126 126 ('o', 'overwritten-file', None, _('add single file all revs overwrite')),
127 127 ('n', 'new-file', None, _('add new file at each rev'))],
128 128 _('[OPTION]... [TEXT]'))
129 129 def debugbuilddag(ui, repo, text=None,
130 130 mergeable_file=False,
131 131 overwritten_file=False,
132 132 new_file=False):
133 133 """builds a repo with a given DAG from scratch in the current empty repo
134 134
135 135 The description of the DAG is read from stdin if not given on the
136 136 command line.
137 137
138 138 Elements:
139 139
140 140 - "+n" is a linear run of n nodes based on the current default parent
141 141 - "." is a single node based on the current default parent
142 142 - "$" resets the default parent to null (implied at the start);
143 143 otherwise the default parent is always the last node created
144 144 - "<p" sets the default parent to the backref p
145 145 - "*p" is a fork at parent p, which is a backref
146 146 - "*p1/p2" is a merge of parents p1 and p2, which are backrefs
147 147 - "/p2" is a merge of the preceding node and p2
148 148 - ":tag" defines a local tag for the preceding node
149 149 - "@branch" sets the named branch for subsequent nodes
150 150 - "#...\\n" is a comment up to the end of the line
151 151
152 152 Whitespace between the above elements is ignored.
153 153
154 154 A backref is either
155 155
156 156 - a number n, which references the node curr-n, where curr is the current
157 157 node, or
158 158 - the name of a local tag you placed earlier using ":tag", or
159 159 - empty to denote the default parent.
160 160
161 161 All string valued-elements are either strictly alphanumeric, or must
162 162 be enclosed in double quotes ("..."), with "\\" as escape character.
163 163 """
164 164
165 165 if text is None:
166 166 ui.status(_("reading DAG from stdin\n"))
167 167 text = ui.fin.read()
168 168
169 169 cl = repo.changelog
170 170 if len(cl) > 0:
171 171 raise error.Abort(_('repository is not empty'))
172 172
173 173 # determine number of revs in DAG
174 174 total = 0
175 175 for type, data in dagparser.parsedag(text):
176 176 if type == 'n':
177 177 total += 1
178 178
179 179 if mergeable_file:
180 180 linesperrev = 2
181 181 # make a file with k lines per rev
182 182 initialmergedlines = ['%d' % i
183 183 for i in pycompat.xrange(0, total * linesperrev)]
184 184 initialmergedlines.append("")
185 185
186 186 tags = []
187 187 progress = ui.makeprogress(_('building'), unit=_('revisions'),
188 188 total=total)
189 189 with progress, repo.wlock(), repo.lock(), repo.transaction("builddag"):
190 190 at = -1
191 191 atbranch = 'default'
192 192 nodeids = []
193 193 id = 0
194 194 progress.update(id)
195 195 for type, data in dagparser.parsedag(text):
196 196 if type == 'n':
197 197 ui.note(('node %s\n' % pycompat.bytestr(data)))
198 198 id, ps = data
199 199
200 200 files = []
201 201 filecontent = {}
202 202
203 203 p2 = None
204 204 if mergeable_file:
205 205 fn = "mf"
206 206 p1 = repo[ps[0]]
207 207 if len(ps) > 1:
208 208 p2 = repo[ps[1]]
209 209 pa = p1.ancestor(p2)
210 210 base, local, other = [x[fn].data() for x in (pa, p1,
211 211 p2)]
212 212 m3 = simplemerge.Merge3Text(base, local, other)
213 213 ml = [l.strip() for l in m3.merge_lines()]
214 214 ml.append("")
215 215 elif at > 0:
216 216 ml = p1[fn].data().split("\n")
217 217 else:
218 218 ml = initialmergedlines
219 219 ml[id * linesperrev] += " r%i" % id
220 220 mergedtext = "\n".join(ml)
221 221 files.append(fn)
222 222 filecontent[fn] = mergedtext
223 223
224 224 if overwritten_file:
225 225 fn = "of"
226 226 files.append(fn)
227 227 filecontent[fn] = "r%i\n" % id
228 228
229 229 if new_file:
230 230 fn = "nf%i" % id
231 231 files.append(fn)
232 232 filecontent[fn] = "r%i\n" % id
233 233 if len(ps) > 1:
234 234 if not p2:
235 235 p2 = repo[ps[1]]
236 236 for fn in p2:
237 237 if fn.startswith("nf"):
238 238 files.append(fn)
239 239 filecontent[fn] = p2[fn].data()
240 240
241 241 def fctxfn(repo, cx, path):
242 242 if path in filecontent:
243 243 return context.memfilectx(repo, cx, path,
244 244 filecontent[path])
245 245 return None
246 246
247 247 if len(ps) == 0 or ps[0] < 0:
248 248 pars = [None, None]
249 249 elif len(ps) == 1:
250 250 pars = [nodeids[ps[0]], None]
251 251 else:
252 252 pars = [nodeids[p] for p in ps]
253 253 cx = context.memctx(repo, pars, "r%i" % id, files, fctxfn,
254 254 date=(id, 0),
255 255 user="debugbuilddag",
256 256 extra={'branch': atbranch})
257 257 nodeid = repo.commitctx(cx)
258 258 nodeids.append(nodeid)
259 259 at = id
260 260 elif type == 'l':
261 261 id, name = data
262 262 ui.note(('tag %s\n' % name))
263 263 tags.append("%s %s\n" % (hex(repo.changelog.node(id)), name))
264 264 elif type == 'a':
265 265 ui.note(('branch %s\n' % data))
266 266 atbranch = data
267 267 progress.update(id)
268 268
269 269 if tags:
270 270 repo.vfs.write("localtags", "".join(tags))
271 271
272 272 def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
273 273 indent_string = ' ' * indent
274 274 if all:
275 275 ui.write(("%sformat: id, p1, p2, cset, delta base, len(delta)\n")
276 276 % indent_string)
277 277
278 278 def showchunks(named):
279 279 ui.write("\n%s%s\n" % (indent_string, named))
280 280 for deltadata in gen.deltaiter():
281 281 node, p1, p2, cs, deltabase, delta, flags = deltadata
282 282 ui.write("%s%s %s %s %s %s %d\n" %
283 283 (indent_string, hex(node), hex(p1), hex(p2),
284 284 hex(cs), hex(deltabase), len(delta)))
285 285
286 286 chunkdata = gen.changelogheader()
287 287 showchunks("changelog")
288 288 chunkdata = gen.manifestheader()
289 289 showchunks("manifest")
290 290 for chunkdata in iter(gen.filelogheader, {}):
291 291 fname = chunkdata['filename']
292 292 showchunks(fname)
293 293 else:
294 294 if isinstance(gen, bundle2.unbundle20):
295 295 raise error.Abort(_('use debugbundle2 for this file'))
296 296 chunkdata = gen.changelogheader()
297 297 for deltadata in gen.deltaiter():
298 298 node, p1, p2, cs, deltabase, delta, flags = deltadata
299 299 ui.write("%s%s\n" % (indent_string, hex(node)))
300 300
301 301 def _debugobsmarkers(ui, part, indent=0, **opts):
302 302 """display version and markers contained in 'data'"""
303 303 opts = pycompat.byteskwargs(opts)
304 304 data = part.read()
305 305 indent_string = ' ' * indent
306 306 try:
307 307 version, markers = obsolete._readmarkers(data)
308 308 except error.UnknownVersion as exc:
309 309 msg = "%sunsupported version: %s (%d bytes)\n"
310 310 msg %= indent_string, exc.version, len(data)
311 311 ui.write(msg)
312 312 else:
313 313 msg = "%sversion: %d (%d bytes)\n"
314 314 msg %= indent_string, version, len(data)
315 315 ui.write(msg)
316 316 fm = ui.formatter('debugobsolete', opts)
317 317 for rawmarker in sorted(markers):
318 318 m = obsutil.marker(None, rawmarker)
319 319 fm.startitem()
320 320 fm.plain(indent_string)
321 321 cmdutil.showmarker(fm, m)
322 322 fm.end()
323 323
324 324 def _debugphaseheads(ui, data, indent=0):
325 325 """display version and markers contained in 'data'"""
326 326 indent_string = ' ' * indent
327 327 headsbyphase = phases.binarydecode(data)
328 328 for phase in phases.allphases:
329 329 for head in headsbyphase[phase]:
330 330 ui.write(indent_string)
331 331 ui.write('%s %s\n' % (hex(head), phases.phasenames[phase]))
332 332
333 333 def _quasirepr(thing):
334 334 if isinstance(thing, (dict, util.sortdict, collections.OrderedDict)):
335 335 return '{%s}' % (
336 336 b', '.join(b'%s: %s' % (k, thing[k]) for k in sorted(thing)))
337 337 return pycompat.bytestr(repr(thing))
338 338
339 339 def _debugbundle2(ui, gen, all=None, **opts):
340 340 """lists the contents of a bundle2"""
341 341 if not isinstance(gen, bundle2.unbundle20):
342 342 raise error.Abort(_('not a bundle2 file'))
343 343 ui.write(('Stream params: %s\n' % _quasirepr(gen.params)))
344 344 parttypes = opts.get(r'part_type', [])
345 345 for part in gen.iterparts():
346 346 if parttypes and part.type not in parttypes:
347 347 continue
348 348 msg = '%s -- %s (mandatory: %r)\n'
349 349 ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory)))
350 350 if part.type == 'changegroup':
351 351 version = part.params.get('version', '01')
352 352 cg = changegroup.getunbundler(version, part, 'UN')
353 353 if not ui.quiet:
354 354 _debugchangegroup(ui, cg, all=all, indent=4, **opts)
355 355 if part.type == 'obsmarkers':
356 356 if not ui.quiet:
357 357 _debugobsmarkers(ui, part, indent=4, **opts)
358 358 if part.type == 'phase-heads':
359 359 if not ui.quiet:
360 360 _debugphaseheads(ui, part, indent=4)
361 361
362 362 @command('debugbundle',
363 363 [('a', 'all', None, _('show all details')),
364 364 ('', 'part-type', [], _('show only the named part type')),
365 365 ('', 'spec', None, _('print the bundlespec of the bundle'))],
366 366 _('FILE'),
367 367 norepo=True)
368 368 def debugbundle(ui, bundlepath, all=None, spec=None, **opts):
369 369 """lists the contents of a bundle"""
370 370 with hg.openpath(ui, bundlepath) as f:
371 371 if spec:
372 372 spec = exchange.getbundlespec(ui, f)
373 373 ui.write('%s\n' % spec)
374 374 return
375 375
376 376 gen = exchange.readbundle(ui, f, bundlepath)
377 377 if isinstance(gen, bundle2.unbundle20):
378 378 return _debugbundle2(ui, gen, all=all, **opts)
379 379 _debugchangegroup(ui, gen, all=all, **opts)
380 380
381 381 @command('debugcapabilities',
382 382 [], _('PATH'),
383 383 norepo=True)
384 384 def debugcapabilities(ui, path, **opts):
385 385 """lists the capabilities of a remote peer"""
386 386 opts = pycompat.byteskwargs(opts)
387 387 peer = hg.peer(ui, opts, path)
388 388 caps = peer.capabilities()
389 389 ui.write(('Main capabilities:\n'))
390 390 for c in sorted(caps):
391 391 ui.write((' %s\n') % c)
392 392 b2caps = bundle2.bundle2caps(peer)
393 393 if b2caps:
394 394 ui.write(('Bundle2 capabilities:\n'))
395 395 for key, values in sorted(b2caps.iteritems()):
396 396 ui.write((' %s\n') % key)
397 397 for v in values:
398 398 ui.write((' %s\n') % v)
399 399
400 400 @command('debugcheckstate', [], '')
401 401 def debugcheckstate(ui, repo):
402 402 """validate the correctness of the current dirstate"""
403 403 parent1, parent2 = repo.dirstate.parents()
404 404 m1 = repo[parent1].manifest()
405 405 m2 = repo[parent2].manifest()
406 406 errors = 0
407 407 for f in repo.dirstate:
408 408 state = repo.dirstate[f]
409 409 if state in "nr" and f not in m1:
410 410 ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state))
411 411 errors += 1
412 412 if state in "a" and f in m1:
413 413 ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state))
414 414 errors += 1
415 415 if state in "m" and f not in m1 and f not in m2:
416 416 ui.warn(_("%s in state %s, but not in either manifest\n") %
417 417 (f, state))
418 418 errors += 1
419 419 for f in m1:
420 420 state = repo.dirstate[f]
421 421 if state not in "nrm":
422 422 ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
423 423 errors += 1
424 424 if errors:
425 425 error = _(".hg/dirstate inconsistent with current parent's manifest")
426 426 raise error.Abort(error)
427 427
428 428 @command('debugcolor',
429 429 [('', 'style', None, _('show all configured styles'))],
430 430 'hg debugcolor')
431 431 def debugcolor(ui, repo, **opts):
432 432 """show available color, effects or style"""
433 433 ui.write(('color mode: %s\n') % stringutil.pprint(ui._colormode))
434 434 if opts.get(r'style'):
435 435 return _debugdisplaystyle(ui)
436 436 else:
437 437 return _debugdisplaycolor(ui)
438 438
439 439 def _debugdisplaycolor(ui):
440 440 ui = ui.copy()
441 441 ui._styles.clear()
442 442 for effect in color._activeeffects(ui).keys():
443 443 ui._styles[effect] = effect
444 444 if ui._terminfoparams:
445 445 for k, v in ui.configitems('color'):
446 446 if k.startswith('color.'):
447 447 ui._styles[k] = k[6:]
448 448 elif k.startswith('terminfo.'):
449 449 ui._styles[k] = k[9:]
450 450 ui.write(_('available colors:\n'))
451 451 # sort label with a '_' after the other to group '_background' entry.
452 452 items = sorted(ui._styles.items(),
453 453 key=lambda i: ('_' in i[0], i[0], i[1]))
454 454 for colorname, label in items:
455 455 ui.write(('%s\n') % colorname, label=label)
456 456
457 457 def _debugdisplaystyle(ui):
458 458 ui.write(_('available style:\n'))
459 459 if not ui._styles:
460 460 return
461 461 width = max(len(s) for s in ui._styles)
462 462 for label, effects in sorted(ui._styles.items()):
463 463 ui.write('%s' % label, label=label)
464 464 if effects:
465 465 # 50
466 466 ui.write(': ')
467 467 ui.write(' ' * (max(0, width - len(label))))
468 468 ui.write(', '.join(ui.label(e, e) for e in effects.split()))
469 469 ui.write('\n')
470 470
471 471 @command('debugcreatestreamclonebundle', [], 'FILE')
472 472 def debugcreatestreamclonebundle(ui, repo, fname):
473 473 """create a stream clone bundle file
474 474
475 475 Stream bundles are special bundles that are essentially archives of
476 476 revlog files. They are commonly used for cloning very quickly.
477 477 """
478 478 # TODO we may want to turn this into an abort when this functionality
479 479 # is moved into `hg bundle`.
480 480 if phases.hassecret(repo):
481 481 ui.warn(_('(warning: stream clone bundle will contain secret '
482 482 'revisions)\n'))
483 483
484 484 requirements, gen = streamclone.generatebundlev1(repo)
485 485 changegroup.writechunks(ui, gen, fname)
486 486
487 487 ui.write(_('bundle requirements: %s\n') % ', '.join(sorted(requirements)))
488 488
489 489 @command('debugdag',
490 490 [('t', 'tags', None, _('use tags as labels')),
491 491 ('b', 'branches', None, _('annotate with branch names')),
492 492 ('', 'dots', None, _('use dots for runs')),
493 493 ('s', 'spaces', None, _('separate elements by spaces'))],
494 494 _('[OPTION]... [FILE [REV]...]'),
495 495 optionalrepo=True)
496 496 def debugdag(ui, repo, file_=None, *revs, **opts):
497 497 """format the changelog or an index DAG as a concise textual description
498 498
499 499 If you pass a revlog index, the revlog's DAG is emitted. If you list
500 500 revision numbers, they get labeled in the output as rN.
501 501
502 502 Otherwise, the changelog DAG of the current repo is emitted.
503 503 """
504 504 spaces = opts.get(r'spaces')
505 505 dots = opts.get(r'dots')
506 506 if file_:
507 507 rlog = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False),
508 508 file_)
509 509 revs = set((int(r) for r in revs))
510 510 def events():
511 511 for r in rlog:
512 512 yield 'n', (r, list(p for p in rlog.parentrevs(r)
513 513 if p != -1))
514 514 if r in revs:
515 515 yield 'l', (r, "r%i" % r)
516 516 elif repo:
517 517 cl = repo.changelog
518 518 tags = opts.get(r'tags')
519 519 branches = opts.get(r'branches')
520 520 if tags:
521 521 labels = {}
522 522 for l, n in repo.tags().items():
523 523 labels.setdefault(cl.rev(n), []).append(l)
524 524 def events():
525 525 b = "default"
526 526 for r in cl:
527 527 if branches:
528 528 newb = cl.read(cl.node(r))[5]['branch']
529 529 if newb != b:
530 530 yield 'a', newb
531 531 b = newb
532 532 yield 'n', (r, list(p for p in cl.parentrevs(r)
533 533 if p != -1))
534 534 if tags:
535 535 ls = labels.get(r)
536 536 if ls:
537 537 for l in ls:
538 538 yield 'l', (r, l)
539 539 else:
540 540 raise error.Abort(_('need repo for changelog dag'))
541 541
542 542 for line in dagparser.dagtextlines(events(),
543 543 addspaces=spaces,
544 544 wraplabels=True,
545 545 wrapannotations=True,
546 546 wrapnonlinear=dots,
547 547 usedots=dots,
548 548 maxlinewidth=70):
549 549 ui.write(line)
550 550 ui.write("\n")
551 551
552 552 @command('debugdata', cmdutil.debugrevlogopts, _('-c|-m|FILE REV'))
553 553 def debugdata(ui, repo, file_, rev=None, **opts):
554 554 """dump the contents of a data file revision"""
555 555 opts = pycompat.byteskwargs(opts)
556 556 if opts.get('changelog') or opts.get('manifest') or opts.get('dir'):
557 557 if rev is not None:
558 558 raise error.CommandError('debugdata', _('invalid arguments'))
559 559 file_, rev = None, file_
560 560 elif rev is None:
561 561 raise error.CommandError('debugdata', _('invalid arguments'))
562 562 r = cmdutil.openstorage(repo, 'debugdata', file_, opts)
563 563 try:
564 564 ui.write(r.revision(r.lookup(rev), raw=True))
565 565 except KeyError:
566 566 raise error.Abort(_('invalid revision identifier %s') % rev)
567 567
568 568 @command('debugdate',
569 569 [('e', 'extended', None, _('try extended date formats'))],
570 570 _('[-e] DATE [RANGE]'),
571 571 norepo=True, optionalrepo=True)
572 572 def debugdate(ui, date, range=None, **opts):
573 573 """parse and display a date"""
574 574 if opts[r"extended"]:
575 575 d = dateutil.parsedate(date, util.extendeddateformats)
576 576 else:
577 577 d = dateutil.parsedate(date)
578 578 ui.write(("internal: %d %d\n") % d)
579 579 ui.write(("standard: %s\n") % dateutil.datestr(d))
580 580 if range:
581 581 m = dateutil.matchdate(range)
582 582 ui.write(("match: %s\n") % m(d[0]))
583 583
584 584 @command('debugdeltachain',
585 585 cmdutil.debugrevlogopts + cmdutil.formatteropts,
586 586 _('-c|-m|FILE'),
587 587 optionalrepo=True)
588 588 def debugdeltachain(ui, repo, file_=None, **opts):
589 589 """dump information about delta chains in a revlog
590 590
591 591 Output can be templatized. Available template keywords are:
592 592
593 593 :``rev``: revision number
594 594 :``chainid``: delta chain identifier (numbered by unique base)
595 595 :``chainlen``: delta chain length to this revision
596 596 :``prevrev``: previous revision in delta chain
597 597 :``deltatype``: role of delta / how it was computed
598 598 :``compsize``: compressed size of revision
599 599 :``uncompsize``: uncompressed size of revision
600 600 :``chainsize``: total size of compressed revisions in chain
601 601 :``chainratio``: total chain size divided by uncompressed revision size
602 602 (new delta chains typically start at ratio 2.00)
603 603 :``lindist``: linear distance from base revision in delta chain to end
604 604 of this revision
605 605 :``extradist``: total size of revisions not part of this delta chain from
606 606 base of delta chain to end of this revision; a measurement
607 607 of how much extra data we need to read/seek across to read
608 608 the delta chain for this revision
609 609 :``extraratio``: extradist divided by chainsize; another representation of
610 610 how much unrelated data is needed to load this delta chain
611 611
612 612 If the repository is configured to use the sparse read, additional keywords
613 613 are available:
614 614
615 615 :``readsize``: total size of data read from the disk for a revision
616 616 (sum of the sizes of all the blocks)
617 617 :``largestblock``: size of the largest block of data read from the disk
618 618 :``readdensity``: density of useful bytes in the data read from the disk
619 619 :``srchunks``: in how many data hunks the whole revision would be read
620 620
621 621 The sparse read can be enabled with experimental.sparse-read = True
622 622 """
623 623 opts = pycompat.byteskwargs(opts)
624 624 r = cmdutil.openrevlog(repo, 'debugdeltachain', file_, opts)
625 625 index = r.index
626 626 start = r.start
627 627 length = r.length
628 628 generaldelta = r.version & revlog.FLAG_GENERALDELTA
629 629 withsparseread = getattr(r, '_withsparseread', False)
630 630
631 631 def revinfo(rev):
632 632 e = index[rev]
633 633 compsize = e[1]
634 634 uncompsize = e[2]
635 635 chainsize = 0
636 636
637 637 if generaldelta:
638 638 if e[3] == e[5]:
639 639 deltatype = 'p1'
640 640 elif e[3] == e[6]:
641 641 deltatype = 'p2'
642 642 elif e[3] == rev - 1:
643 643 deltatype = 'prev'
644 644 elif e[3] == rev:
645 645 deltatype = 'base'
646 646 else:
647 647 deltatype = 'other'
648 648 else:
649 649 if e[3] == rev:
650 650 deltatype = 'base'
651 651 else:
652 652 deltatype = 'prev'
653 653
654 654 chain = r._deltachain(rev)[0]
655 655 for iterrev in chain:
656 656 e = index[iterrev]
657 657 chainsize += e[1]
658 658
659 659 return compsize, uncompsize, deltatype, chain, chainsize
660 660
661 661 fm = ui.formatter('debugdeltachain', opts)
662 662
663 663 fm.plain(' rev chain# chainlen prev delta '
664 664 'size rawsize chainsize ratio lindist extradist '
665 665 'extraratio')
666 666 if withsparseread:
667 667 fm.plain(' readsize largestblk rddensity srchunks')
668 668 fm.plain('\n')
669 669
670 670 chainbases = {}
671 671 for rev in r:
672 672 comp, uncomp, deltatype, chain, chainsize = revinfo(rev)
673 673 chainbase = chain[0]
674 674 chainid = chainbases.setdefault(chainbase, len(chainbases) + 1)
675 675 basestart = start(chainbase)
676 676 revstart = start(rev)
677 677 lineardist = revstart + comp - basestart
678 678 extradist = lineardist - chainsize
679 679 try:
680 680 prevrev = chain[-2]
681 681 except IndexError:
682 682 prevrev = -1
683 683
684 684 if uncomp != 0:
685 685 chainratio = float(chainsize) / float(uncomp)
686 686 else:
687 687 chainratio = chainsize
688 688
689 689 if chainsize != 0:
690 690 extraratio = float(extradist) / float(chainsize)
691 691 else:
692 692 extraratio = extradist
693 693
694 694 fm.startitem()
695 695 fm.write('rev chainid chainlen prevrev deltatype compsize '
696 696 'uncompsize chainsize chainratio lindist extradist '
697 697 'extraratio',
698 698 '%7d %7d %8d %8d %7s %10d %10d %10d %9.5f %9d %9d %10.5f',
699 699 rev, chainid, len(chain), prevrev, deltatype, comp,
700 700 uncomp, chainsize, chainratio, lineardist, extradist,
701 701 extraratio,
702 702 rev=rev, chainid=chainid, chainlen=len(chain),
703 703 prevrev=prevrev, deltatype=deltatype, compsize=comp,
704 704 uncompsize=uncomp, chainsize=chainsize,
705 705 chainratio=chainratio, lindist=lineardist,
706 706 extradist=extradist, extraratio=extraratio)
707 707 if withsparseread:
708 708 readsize = 0
709 709 largestblock = 0
710 710 srchunks = 0
711 711
712 712 for revschunk in deltautil.slicechunk(r, chain):
713 713 srchunks += 1
714 714 blkend = start(revschunk[-1]) + length(revschunk[-1])
715 715 blksize = blkend - start(revschunk[0])
716 716
717 717 readsize += blksize
718 718 if largestblock < blksize:
719 719 largestblock = blksize
720 720
721 721 if readsize:
722 722 readdensity = float(chainsize) / float(readsize)
723 723 else:
724 724 readdensity = 1
725 725
726 726 fm.write('readsize largestblock readdensity srchunks',
727 727 ' %10d %10d %9.5f %8d',
728 728 readsize, largestblock, readdensity, srchunks,
729 729 readsize=readsize, largestblock=largestblock,
730 730 readdensity=readdensity, srchunks=srchunks)
731 731
732 732 fm.plain('\n')
733 733
734 734 fm.end()
735 735
736 736 @command('debugdirstate|debugstate',
737 737 [('', 'nodates', None, _('do not display the saved mtime (DEPRECATED)')),
738 738 ('', 'dates', True, _('display the saved mtime')),
739 739 ('', 'datesort', None, _('sort by saved mtime'))],
740 740 _('[OPTION]...'))
741 741 def debugstate(ui, repo, **opts):
742 742 """show the contents of the current dirstate"""
743 743
744 744 nodates = not opts[r'dates']
745 745 if opts.get(r'nodates') is not None:
746 746 nodates = True
747 747 datesort = opts.get(r'datesort')
748 748
749 749 if datesort:
750 750 keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
751 751 else:
752 752 keyfunc = None # sort by filename
753 753 for file_, ent in sorted(repo.dirstate._map.iteritems(), key=keyfunc):
754 754 if ent[3] == -1:
755 755 timestr = 'unset '
756 756 elif nodates:
757 757 timestr = 'set '
758 758 else:
759 759 timestr = time.strftime(r"%Y-%m-%d %H:%M:%S ",
760 760 time.localtime(ent[3]))
761 761 timestr = encoding.strtolocal(timestr)
762 762 if ent[1] & 0o20000:
763 763 mode = 'lnk'
764 764 else:
765 765 mode = '%3o' % (ent[1] & 0o777 & ~util.umask)
766 766 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
767 767 for f in repo.dirstate.copies():
768 768 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
769 769
770 770 @command('debugdiscovery',
771 771 [('', 'old', None, _('use old-style discovery')),
772 772 ('', 'nonheads', None,
773 773 _('use old-style discovery with non-heads included')),
774 774 ('', 'rev', [], 'restrict discovery to this set of revs'),
775 775 ] + cmdutil.remoteopts,
776 776 _('[--rev REV] [OTHER]'))
777 777 def debugdiscovery(ui, repo, remoteurl="default", **opts):
778 778 """runs the changeset discovery protocol in isolation"""
779 779 opts = pycompat.byteskwargs(opts)
780 780 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl))
781 781 remote = hg.peer(repo, opts, remoteurl)
782 782 ui.status(_('comparing with %s\n') % util.hidepassword(remoteurl))
783 783
784 784 # make sure tests are repeatable
785 785 random.seed(12323)
786 786
787 787 def doit(pushedrevs, remoteheads, remote=remote):
788 788 if opts.get('old'):
789 789 if not util.safehasattr(remote, 'branches'):
790 790 # enable in-client legacy support
791 791 remote = localrepo.locallegacypeer(remote.local())
792 792 common, _in, hds = treediscovery.findcommonincoming(repo, remote,
793 793 force=True)
794 794 common = set(common)
795 795 if not opts.get('nonheads'):
796 796 ui.write(("unpruned common: %s\n") %
797 797 " ".join(sorted(short(n) for n in common)))
798 798
799 799 clnode = repo.changelog.node
800 800 common = repo.revs('heads(::%ln)', common)
801 801 common = {clnode(r) for r in common}
802 802 else:
803 803 nodes = None
804 804 if pushedrevs:
805 805 revs = scmutil.revrange(repo, pushedrevs)
806 806 nodes = [repo[r].node() for r in revs]
807 807 common, any, hds = setdiscovery.findcommonheads(ui, repo, remote,
808 808 ancestorsof=nodes)
809 809 common = set(common)
810 810 rheads = set(hds)
811 811 lheads = set(repo.heads())
812 812 ui.write(("common heads: %s\n") %
813 813 " ".join(sorted(short(n) for n in common)))
814 814 if lheads <= common:
815 815 ui.write(("local is subset\n"))
816 816 elif rheads <= common:
817 817 ui.write(("remote is subset\n"))
818 818
819 819 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
820 820 localrevs = opts['rev']
821 821 doit(localrevs, remoterevs)
822 822
823 823 _chunksize = 4 << 10
824 824
825 825 @command('debugdownload',
826 826 [
827 827 ('o', 'output', '', _('path')),
828 828 ],
829 829 optionalrepo=True)
830 830 def debugdownload(ui, repo, url, output=None, **opts):
831 831 """download a resource using Mercurial logic and config
832 832 """
833 833 fh = urlmod.open(ui, url, output)
834 834
835 835 dest = ui
836 836 if output:
837 837 dest = open(output, "wb", _chunksize)
838 838 try:
839 839 data = fh.read(_chunksize)
840 840 while data:
841 841 dest.write(data)
842 842 data = fh.read(_chunksize)
843 843 finally:
844 844 if output:
845 845 dest.close()
846 846
847 847 @command('debugextensions', cmdutil.formatteropts, [], optionalrepo=True)
848 848 def debugextensions(ui, repo, **opts):
849 849 '''show information about active extensions'''
850 850 opts = pycompat.byteskwargs(opts)
851 851 exts = extensions.extensions(ui)
852 852 hgver = util.version()
853 853 fm = ui.formatter('debugextensions', opts)
854 854 for extname, extmod in sorted(exts, key=operator.itemgetter(0)):
855 855 isinternal = extensions.ismoduleinternal(extmod)
856 856 extsource = pycompat.fsencode(extmod.__file__)
857 857 if isinternal:
858 858 exttestedwith = [] # never expose magic string to users
859 859 else:
860 860 exttestedwith = getattr(extmod, 'testedwith', '').split()
861 861 extbuglink = getattr(extmod, 'buglink', None)
862 862
863 863 fm.startitem()
864 864
865 865 if ui.quiet or ui.verbose:
866 866 fm.write('name', '%s\n', extname)
867 867 else:
868 868 fm.write('name', '%s', extname)
869 869 if isinternal or hgver in exttestedwith:
870 870 fm.plain('\n')
871 871 elif not exttestedwith:
872 872 fm.plain(_(' (untested!)\n'))
873 873 else:
874 874 lasttestedversion = exttestedwith[-1]
875 875 fm.plain(' (%s!)\n' % lasttestedversion)
876 876
877 877 fm.condwrite(ui.verbose and extsource, 'source',
878 878 _(' location: %s\n'), extsource or "")
879 879
880 880 if ui.verbose:
881 881 fm.plain(_(' bundled: %s\n') % ['no', 'yes'][isinternal])
882 882 fm.data(bundled=isinternal)
883 883
884 884 fm.condwrite(ui.verbose and exttestedwith, 'testedwith',
885 885 _(' tested with: %s\n'),
886 886 fm.formatlist(exttestedwith, name='ver'))
887 887
888 888 fm.condwrite(ui.verbose and extbuglink, 'buglink',
889 889 _(' bug reporting: %s\n'), extbuglink or "")
890 890
891 891 fm.end()
892 892
893 893 @command('debugfileset',
894 894 [('r', 'rev', '', _('apply the filespec on this revision'), _('REV')),
895 895 ('', 'all-files', False,
896 896 _('test files from all revisions and working directory')),
897 897 ('s', 'show-matcher', None,
898 898 _('print internal representation of matcher')),
899 899 ('p', 'show-stage', [],
900 900 _('print parsed tree at the given stage'), _('NAME'))],
901 901 _('[-r REV] [--all-files] [OPTION]... FILESPEC'))
902 902 def debugfileset(ui, repo, expr, **opts):
903 903 '''parse and apply a fileset specification'''
904 904 from . import fileset
905 905 fileset.symbols # force import of fileset so we have predicates to optimize
906 906 opts = pycompat.byteskwargs(opts)
907 907 ctx = scmutil.revsingle(repo, opts.get('rev'), None)
908 908
909 909 stages = [
910 910 ('parsed', pycompat.identity),
911 911 ('analyzed', filesetlang.analyze),
912 912 ('optimized', filesetlang.optimize),
913 913 ]
914 914 stagenames = set(n for n, f in stages)
915 915
916 916 showalways = set()
917 917 if ui.verbose and not opts['show_stage']:
918 918 # show parsed tree by --verbose (deprecated)
919 919 showalways.add('parsed')
920 920 if opts['show_stage'] == ['all']:
921 921 showalways.update(stagenames)
922 922 else:
923 923 for n in opts['show_stage']:
924 924 if n not in stagenames:
925 925 raise error.Abort(_('invalid stage name: %s') % n)
926 926 showalways.update(opts['show_stage'])
927 927
928 928 tree = filesetlang.parse(expr)
929 929 for n, f in stages:
930 930 tree = f(tree)
931 931 if n in showalways:
932 932 if opts['show_stage'] or n != 'parsed':
933 933 ui.write(("* %s:\n") % n)
934 934 ui.write(filesetlang.prettyformat(tree), "\n")
935 935
936 936 files = set()
937 937 if opts['all_files']:
938 938 for r in repo:
939 939 c = repo[r]
940 940 files.update(c.files())
941 941 files.update(c.substate)
942 942 if opts['all_files'] or ctx.rev() is None:
943 943 wctx = repo[None]
944 944 files.update(repo.dirstate.walk(scmutil.matchall(repo),
945 945 subrepos=list(wctx.substate),
946 946 unknown=True, ignored=True))
947 947 files.update(wctx.substate)
948 948 else:
949 949 files.update(ctx.files())
950 950 files.update(ctx.substate)
951 951
952 952 m = ctx.matchfileset(expr)
953 953 if opts['show_matcher'] or (opts['show_matcher'] is None and ui.verbose):
954 954 ui.write(('* matcher:\n'), stringutil.prettyrepr(m), '\n')
955 955 for f in sorted(files):
956 956 if not m(f):
957 957 continue
958 958 ui.write("%s\n" % f)
959 959
960 960 @command('debugformat',
961 961 [] + cmdutil.formatteropts)
962 962 def debugformat(ui, repo, **opts):
963 963 """display format information about the current repository
964 964
965 965 Use --verbose to get extra information about current config value and
966 966 Mercurial default."""
967 967 opts = pycompat.byteskwargs(opts)
968 968 maxvariantlength = max(len(fv.name) for fv in upgrade.allformatvariant)
969 969 maxvariantlength = max(len('format-variant'), maxvariantlength)
970 970
971 971 def makeformatname(name):
972 972 return '%s:' + (' ' * (maxvariantlength - len(name)))
973 973
974 974 fm = ui.formatter('debugformat', opts)
975 975 if fm.isplain():
976 976 def formatvalue(value):
977 977 if util.safehasattr(value, 'startswith'):
978 978 return value
979 979 if value:
980 980 return 'yes'
981 981 else:
982 982 return 'no'
983 983 else:
984 984 formatvalue = pycompat.identity
985 985
986 986 fm.plain('format-variant')
987 987 fm.plain(' ' * (maxvariantlength - len('format-variant')))
988 988 fm.plain(' repo')
989 989 if ui.verbose:
990 990 fm.plain(' config default')
991 991 fm.plain('\n')
992 992 for fv in upgrade.allformatvariant:
993 993 fm.startitem()
994 994 repovalue = fv.fromrepo(repo)
995 995 configvalue = fv.fromconfig(repo)
996 996
997 997 if repovalue != configvalue:
998 998 namelabel = 'formatvariant.name.mismatchconfig'
999 999 repolabel = 'formatvariant.repo.mismatchconfig'
1000 1000 elif repovalue != fv.default:
1001 1001 namelabel = 'formatvariant.name.mismatchdefault'
1002 1002 repolabel = 'formatvariant.repo.mismatchdefault'
1003 1003 else:
1004 1004 namelabel = 'formatvariant.name.uptodate'
1005 1005 repolabel = 'formatvariant.repo.uptodate'
1006 1006
1007 1007 fm.write('name', makeformatname(fv.name), fv.name,
1008 1008 label=namelabel)
1009 1009 fm.write('repo', ' %3s', formatvalue(repovalue),
1010 1010 label=repolabel)
1011 1011 if fv.default != configvalue:
1012 1012 configlabel = 'formatvariant.config.special'
1013 1013 else:
1014 1014 configlabel = 'formatvariant.config.default'
1015 1015 fm.condwrite(ui.verbose, 'config', ' %6s', formatvalue(configvalue),
1016 1016 label=configlabel)
1017 1017 fm.condwrite(ui.verbose, 'default', ' %7s', formatvalue(fv.default),
1018 1018 label='formatvariant.default')
1019 1019 fm.plain('\n')
1020 1020 fm.end()
1021 1021
1022 1022 @command('debugfsinfo', [], _('[PATH]'), norepo=True)
1023 1023 def debugfsinfo(ui, path="."):
1024 1024 """show information detected about current filesystem"""
1025 1025 ui.write(('path: %s\n') % path)
1026 1026 ui.write(('mounted on: %s\n') % (util.getfsmountpoint(path) or '(unknown)'))
1027 1027 ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
1028 1028 ui.write(('fstype: %s\n') % (util.getfstype(path) or '(unknown)'))
1029 1029 ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
1030 1030 ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
1031 1031 casesensitive = '(unknown)'
1032 1032 try:
1033 1033 with pycompat.namedtempfile(prefix='.debugfsinfo', dir=path) as f:
1034 1034 casesensitive = util.fscasesensitive(f.name) and 'yes' or 'no'
1035 1035 except OSError:
1036 1036 pass
1037 1037 ui.write(('case-sensitive: %s\n') % casesensitive)
1038 1038
1039 1039 @command('debuggetbundle',
1040 1040 [('H', 'head', [], _('id of head node'), _('ID')),
1041 1041 ('C', 'common', [], _('id of common node'), _('ID')),
1042 1042 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
1043 1043 _('REPO FILE [-H|-C ID]...'),
1044 1044 norepo=True)
1045 1045 def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
1046 1046 """retrieves a bundle from a repo
1047 1047
1048 1048 Every ID must be a full-length hex node id string. Saves the bundle to the
1049 1049 given file.
1050 1050 """
1051 1051 opts = pycompat.byteskwargs(opts)
1052 1052 repo = hg.peer(ui, opts, repopath)
1053 1053 if not repo.capable('getbundle'):
1054 1054 raise error.Abort("getbundle() not supported by target repository")
1055 1055 args = {}
1056 1056 if common:
1057 1057 args[r'common'] = [bin(s) for s in common]
1058 1058 if head:
1059 1059 args[r'heads'] = [bin(s) for s in head]
1060 1060 # TODO: get desired bundlecaps from command line.
1061 1061 args[r'bundlecaps'] = None
1062 1062 bundle = repo.getbundle('debug', **args)
1063 1063
1064 1064 bundletype = opts.get('type', 'bzip2').lower()
1065 1065 btypes = {'none': 'HG10UN',
1066 1066 'bzip2': 'HG10BZ',
1067 1067 'gzip': 'HG10GZ',
1068 1068 'bundle2': 'HG20'}
1069 1069 bundletype = btypes.get(bundletype)
1070 1070 if bundletype not in bundle2.bundletypes:
1071 1071 raise error.Abort(_('unknown bundle type specified with --type'))
1072 1072 bundle2.writebundle(ui, bundle, bundlepath, bundletype)
1073 1073
1074 1074 @command('debugignore', [], '[FILE]')
1075 1075 def debugignore(ui, repo, *files, **opts):
1076 1076 """display the combined ignore pattern and information about ignored files
1077 1077
1078 1078 With no argument display the combined ignore pattern.
1079 1079
1080 1080 Given space separated file names, shows if the given file is ignored and
1081 1081 if so, show the ignore rule (file and line number) that matched it.
1082 1082 """
1083 1083 ignore = repo.dirstate._ignore
1084 1084 if not files:
1085 1085 # Show all the patterns
1086 1086 ui.write("%s\n" % pycompat.byterepr(ignore))
1087 1087 else:
1088 1088 m = scmutil.match(repo[None], pats=files)
1089 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
1089 1090 for f in m.files():
1090 1091 nf = util.normpath(f)
1091 1092 ignored = None
1092 1093 ignoredata = None
1093 1094 if nf != '.':
1094 1095 if ignore(nf):
1095 1096 ignored = nf
1096 1097 ignoredata = repo.dirstate._ignorefileandline(nf)
1097 1098 else:
1098 1099 for p in util.finddirs(nf):
1099 1100 if ignore(p):
1100 1101 ignored = p
1101 1102 ignoredata = repo.dirstate._ignorefileandline(p)
1102 1103 break
1103 1104 if ignored:
1104 1105 if ignored == nf:
1105 ui.write(_("%s is ignored\n") % m.uipath(f))
1106 ui.write(_("%s is ignored\n") % uipathfn(f))
1106 1107 else:
1107 1108 ui.write(_("%s is ignored because of "
1108 1109 "containing folder %s\n")
1109 % (m.uipath(f), ignored))
1110 % (uipathfn(f), ignored))
1110 1111 ignorefile, lineno, line = ignoredata
1111 1112 ui.write(_("(ignore rule in %s, line %d: '%s')\n")
1112 1113 % (ignorefile, lineno, line))
1113 1114 else:
1114 ui.write(_("%s is not ignored\n") % m.uipath(f))
1115 ui.write(_("%s is not ignored\n") % uipathfn(f))
1115 1116
1116 1117 @command('debugindex', cmdutil.debugrevlogopts + cmdutil.formatteropts,
1117 1118 _('-c|-m|FILE'))
1118 1119 def debugindex(ui, repo, file_=None, **opts):
1119 1120 """dump index data for a storage primitive"""
1120 1121 opts = pycompat.byteskwargs(opts)
1121 1122 store = cmdutil.openstorage(repo, 'debugindex', file_, opts)
1122 1123
1123 1124 if ui.debugflag:
1124 1125 shortfn = hex
1125 1126 else:
1126 1127 shortfn = short
1127 1128
1128 1129 idlen = 12
1129 1130 for i in store:
1130 1131 idlen = len(shortfn(store.node(i)))
1131 1132 break
1132 1133
1133 1134 fm = ui.formatter('debugindex', opts)
1134 1135 fm.plain(b' rev linkrev %s %s p2\n' % (
1135 1136 b'nodeid'.ljust(idlen),
1136 1137 b'p1'.ljust(idlen)))
1137 1138
1138 1139 for rev in store:
1139 1140 node = store.node(rev)
1140 1141 parents = store.parents(node)
1141 1142
1142 1143 fm.startitem()
1143 1144 fm.write(b'rev', b'%6d ', rev)
1144 1145 fm.write(b'linkrev', '%7d ', store.linkrev(rev))
1145 1146 fm.write(b'node', '%s ', shortfn(node))
1146 1147 fm.write(b'p1', '%s ', shortfn(parents[0]))
1147 1148 fm.write(b'p2', '%s', shortfn(parents[1]))
1148 1149 fm.plain(b'\n')
1149 1150
1150 1151 fm.end()
1151 1152
1152 1153 @command('debugindexdot', cmdutil.debugrevlogopts,
1153 1154 _('-c|-m|FILE'), optionalrepo=True)
1154 1155 def debugindexdot(ui, repo, file_=None, **opts):
1155 1156 """dump an index DAG as a graphviz dot file"""
1156 1157 opts = pycompat.byteskwargs(opts)
1157 1158 r = cmdutil.openstorage(repo, 'debugindexdot', file_, opts)
1158 1159 ui.write(("digraph G {\n"))
1159 1160 for i in r:
1160 1161 node = r.node(i)
1161 1162 pp = r.parents(node)
1162 1163 ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
1163 1164 if pp[1] != nullid:
1164 1165 ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
1165 1166 ui.write("}\n")
1166 1167
1167 1168 @command('debugindexstats', [])
1168 1169 def debugindexstats(ui, repo):
1169 1170 """show stats related to the changelog index"""
1170 1171 repo.changelog.shortest(nullid, 1)
1171 1172 index = repo.changelog.index
1172 1173 if not util.safehasattr(index, 'stats'):
1173 1174 raise error.Abort(_('debugindexstats only works with native code'))
1174 1175 for k, v in sorted(index.stats().items()):
1175 1176 ui.write('%s: %d\n' % (k, v))
1176 1177
1177 1178 @command('debuginstall', [] + cmdutil.formatteropts, '', norepo=True)
1178 1179 def debuginstall(ui, **opts):
1179 1180 '''test Mercurial installation
1180 1181
1181 1182 Returns 0 on success.
1182 1183 '''
1183 1184 opts = pycompat.byteskwargs(opts)
1184 1185
1185 1186 problems = 0
1186 1187
1187 1188 fm = ui.formatter('debuginstall', opts)
1188 1189 fm.startitem()
1189 1190
1190 1191 # encoding
1191 1192 fm.write('encoding', _("checking encoding (%s)...\n"), encoding.encoding)
1192 1193 err = None
1193 1194 try:
1194 1195 codecs.lookup(pycompat.sysstr(encoding.encoding))
1195 1196 except LookupError as inst:
1196 1197 err = stringutil.forcebytestr(inst)
1197 1198 problems += 1
1198 1199 fm.condwrite(err, 'encodingerror', _(" %s\n"
1199 1200 " (check that your locale is properly set)\n"), err)
1200 1201
1201 1202 # Python
1202 1203 fm.write('pythonexe', _("checking Python executable (%s)\n"),
1203 1204 pycompat.sysexecutable)
1204 1205 fm.write('pythonver', _("checking Python version (%s)\n"),
1205 1206 ("%d.%d.%d" % sys.version_info[:3]))
1206 1207 fm.write('pythonlib', _("checking Python lib (%s)...\n"),
1207 1208 os.path.dirname(pycompat.fsencode(os.__file__)))
1208 1209
1209 1210 security = set(sslutil.supportedprotocols)
1210 1211 if sslutil.hassni:
1211 1212 security.add('sni')
1212 1213
1213 1214 fm.write('pythonsecurity', _("checking Python security support (%s)\n"),
1214 1215 fm.formatlist(sorted(security), name='protocol',
1215 1216 fmt='%s', sep=','))
1216 1217
1217 1218 # These are warnings, not errors. So don't increment problem count. This
1218 1219 # may change in the future.
1219 1220 if 'tls1.2' not in security:
1220 1221 fm.plain(_(' TLS 1.2 not supported by Python install; '
1221 1222 'network connections lack modern security\n'))
1222 1223 if 'sni' not in security:
1223 1224 fm.plain(_(' SNI not supported by Python install; may have '
1224 1225 'connectivity issues with some servers\n'))
1225 1226
1226 1227 # TODO print CA cert info
1227 1228
1228 1229 # hg version
1229 1230 hgver = util.version()
1230 1231 fm.write('hgver', _("checking Mercurial version (%s)\n"),
1231 1232 hgver.split('+')[0])
1232 1233 fm.write('hgverextra', _("checking Mercurial custom build (%s)\n"),
1233 1234 '+'.join(hgver.split('+')[1:]))
1234 1235
1235 1236 # compiled modules
1236 1237 fm.write('hgmodulepolicy', _("checking module policy (%s)\n"),
1237 1238 policy.policy)
1238 1239 fm.write('hgmodules', _("checking installed modules (%s)...\n"),
1239 1240 os.path.dirname(pycompat.fsencode(__file__)))
1240 1241
1241 1242 if policy.policy in ('c', 'allow'):
1242 1243 err = None
1243 1244 try:
1244 1245 from .cext import (
1245 1246 base85,
1246 1247 bdiff,
1247 1248 mpatch,
1248 1249 osutil,
1249 1250 )
1250 1251 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
1251 1252 except Exception as inst:
1252 1253 err = stringutil.forcebytestr(inst)
1253 1254 problems += 1
1254 1255 fm.condwrite(err, 'extensionserror', " %s\n", err)
1255 1256
1256 1257 compengines = util.compengines._engines.values()
1257 1258 fm.write('compengines', _('checking registered compression engines (%s)\n'),
1258 1259 fm.formatlist(sorted(e.name() for e in compengines),
1259 1260 name='compengine', fmt='%s', sep=', '))
1260 1261 fm.write('compenginesavail', _('checking available compression engines '
1261 1262 '(%s)\n'),
1262 1263 fm.formatlist(sorted(e.name() for e in compengines
1263 1264 if e.available()),
1264 1265 name='compengine', fmt='%s', sep=', '))
1265 1266 wirecompengines = util.compengines.supportedwireengines(util.SERVERROLE)
1266 1267 fm.write('compenginesserver', _('checking available compression engines '
1267 1268 'for wire protocol (%s)\n'),
1268 1269 fm.formatlist([e.name() for e in wirecompengines
1269 1270 if e.wireprotosupport()],
1270 1271 name='compengine', fmt='%s', sep=', '))
1271 1272 re2 = 'missing'
1272 1273 if util._re2:
1273 1274 re2 = 'available'
1274 1275 fm.plain(_('checking "re2" regexp engine (%s)\n') % re2)
1275 1276 fm.data(re2=bool(util._re2))
1276 1277
1277 1278 # templates
1278 1279 p = templater.templatepaths()
1279 1280 fm.write('templatedirs', 'checking templates (%s)...\n', ' '.join(p))
1280 1281 fm.condwrite(not p, '', _(" no template directories found\n"))
1281 1282 if p:
1282 1283 m = templater.templatepath("map-cmdline.default")
1283 1284 if m:
1284 1285 # template found, check if it is working
1285 1286 err = None
1286 1287 try:
1287 1288 templater.templater.frommapfile(m)
1288 1289 except Exception as inst:
1289 1290 err = stringutil.forcebytestr(inst)
1290 1291 p = None
1291 1292 fm.condwrite(err, 'defaulttemplateerror', " %s\n", err)
1292 1293 else:
1293 1294 p = None
1294 1295 fm.condwrite(p, 'defaulttemplate',
1295 1296 _("checking default template (%s)\n"), m)
1296 1297 fm.condwrite(not m, 'defaulttemplatenotfound',
1297 1298 _(" template '%s' not found\n"), "default")
1298 1299 if not p:
1299 1300 problems += 1
1300 1301 fm.condwrite(not p, '',
1301 1302 _(" (templates seem to have been installed incorrectly)\n"))
1302 1303
1303 1304 # editor
1304 1305 editor = ui.geteditor()
1305 1306 editor = util.expandpath(editor)
1306 1307 editorbin = procutil.shellsplit(editor)[0]
1307 1308 fm.write('editor', _("checking commit editor... (%s)\n"), editorbin)
1308 1309 cmdpath = procutil.findexe(editorbin)
1309 1310 fm.condwrite(not cmdpath and editor == 'vi', 'vinotfound',
1310 1311 _(" No commit editor set and can't find %s in PATH\n"
1311 1312 " (specify a commit editor in your configuration"
1312 1313 " file)\n"), not cmdpath and editor == 'vi' and editorbin)
1313 1314 fm.condwrite(not cmdpath and editor != 'vi', 'editornotfound',
1314 1315 _(" Can't find editor '%s' in PATH\n"
1315 1316 " (specify a commit editor in your configuration"
1316 1317 " file)\n"), not cmdpath and editorbin)
1317 1318 if not cmdpath and editor != 'vi':
1318 1319 problems += 1
1319 1320
1320 1321 # check username
1321 1322 username = None
1322 1323 err = None
1323 1324 try:
1324 1325 username = ui.username()
1325 1326 except error.Abort as e:
1326 1327 err = stringutil.forcebytestr(e)
1327 1328 problems += 1
1328 1329
1329 1330 fm.condwrite(username, 'username', _("checking username (%s)\n"), username)
1330 1331 fm.condwrite(err, 'usernameerror', _("checking username...\n %s\n"
1331 1332 " (specify a username in your configuration file)\n"), err)
1332 1333
1333 1334 fm.condwrite(not problems, '',
1334 1335 _("no problems detected\n"))
1335 1336 if not problems:
1336 1337 fm.data(problems=problems)
1337 1338 fm.condwrite(problems, 'problems',
1338 1339 _("%d problems detected,"
1339 1340 " please check your install!\n"), problems)
1340 1341 fm.end()
1341 1342
1342 1343 return problems
1343 1344
1344 1345 @command('debugknown', [], _('REPO ID...'), norepo=True)
1345 1346 def debugknown(ui, repopath, *ids, **opts):
1346 1347 """test whether node ids are known to a repo
1347 1348
1348 1349 Every ID must be a full-length hex node id string. Returns a list of 0s
1349 1350 and 1s indicating unknown/known.
1350 1351 """
1351 1352 opts = pycompat.byteskwargs(opts)
1352 1353 repo = hg.peer(ui, opts, repopath)
1353 1354 if not repo.capable('known'):
1354 1355 raise error.Abort("known() not supported by target repository")
1355 1356 flags = repo.known([bin(s) for s in ids])
1356 1357 ui.write("%s\n" % ("".join([f and "1" or "0" for f in flags])))
1357 1358
1358 1359 @command('debuglabelcomplete', [], _('LABEL...'))
1359 1360 def debuglabelcomplete(ui, repo, *args):
1360 1361 '''backwards compatibility with old bash completion scripts (DEPRECATED)'''
1361 1362 debugnamecomplete(ui, repo, *args)
1362 1363
1363 1364 @command('debuglocks',
1364 1365 [('L', 'force-lock', None, _('free the store lock (DANGEROUS)')),
1365 1366 ('W', 'force-wlock', None,
1366 1367 _('free the working state lock (DANGEROUS)')),
1367 1368 ('s', 'set-lock', None, _('set the store lock until stopped')),
1368 1369 ('S', 'set-wlock', None,
1369 1370 _('set the working state lock until stopped'))],
1370 1371 _('[OPTION]...'))
1371 1372 def debuglocks(ui, repo, **opts):
1372 1373 """show or modify state of locks
1373 1374
1374 1375 By default, this command will show which locks are held. This
1375 1376 includes the user and process holding the lock, the amount of time
1376 1377 the lock has been held, and the machine name where the process is
1377 1378 running if it's not local.
1378 1379
1379 1380 Locks protect the integrity of Mercurial's data, so should be
1380 1381 treated with care. System crashes or other interruptions may cause
1381 1382 locks to not be properly released, though Mercurial will usually
1382 1383 detect and remove such stale locks automatically.
1383 1384
1384 1385 However, detecting stale locks may not always be possible (for
1385 1386 instance, on a shared filesystem). Removing locks may also be
1386 1387 blocked by filesystem permissions.
1387 1388
1388 1389 Setting a lock will prevent other commands from changing the data.
1389 1390 The command will wait until an interruption (SIGINT, SIGTERM, ...) occurs.
1390 1391 The set locks are removed when the command exits.
1391 1392
1392 1393 Returns 0 if no locks are held.
1393 1394
1394 1395 """
1395 1396
1396 1397 if opts.get(r'force_lock'):
1397 1398 repo.svfs.unlink('lock')
1398 1399 if opts.get(r'force_wlock'):
1399 1400 repo.vfs.unlink('wlock')
1400 1401 if opts.get(r'force_lock') or opts.get(r'force_wlock'):
1401 1402 return 0
1402 1403
1403 1404 locks = []
1404 1405 try:
1405 1406 if opts.get(r'set_wlock'):
1406 1407 try:
1407 1408 locks.append(repo.wlock(False))
1408 1409 except error.LockHeld:
1409 1410 raise error.Abort(_('wlock is already held'))
1410 1411 if opts.get(r'set_lock'):
1411 1412 try:
1412 1413 locks.append(repo.lock(False))
1413 1414 except error.LockHeld:
1414 1415 raise error.Abort(_('lock is already held'))
1415 1416 if len(locks):
1416 1417 ui.promptchoice(_("ready to release the lock (y)? $$ &Yes"))
1417 1418 return 0
1418 1419 finally:
1419 1420 release(*locks)
1420 1421
1421 1422 now = time.time()
1422 1423 held = 0
1423 1424
1424 1425 def report(vfs, name, method):
1425 1426 # this causes stale locks to get reaped for more accurate reporting
1426 1427 try:
1427 1428 l = method(False)
1428 1429 except error.LockHeld:
1429 1430 l = None
1430 1431
1431 1432 if l:
1432 1433 l.release()
1433 1434 else:
1434 1435 try:
1435 1436 st = vfs.lstat(name)
1436 1437 age = now - st[stat.ST_MTIME]
1437 1438 user = util.username(st.st_uid)
1438 1439 locker = vfs.readlock(name)
1439 1440 if ":" in locker:
1440 1441 host, pid = locker.split(':')
1441 1442 if host == socket.gethostname():
1442 1443 locker = 'user %s, process %s' % (user or b'None', pid)
1443 1444 else:
1444 1445 locker = 'user %s, process %s, host %s' \
1445 1446 % (user or b'None', pid, host)
1446 1447 ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age))
1447 1448 return 1
1448 1449 except OSError as e:
1449 1450 if e.errno != errno.ENOENT:
1450 1451 raise
1451 1452
1452 1453 ui.write(("%-6s free\n") % (name + ":"))
1453 1454 return 0
1454 1455
1455 1456 held += report(repo.svfs, "lock", repo.lock)
1456 1457 held += report(repo.vfs, "wlock", repo.wlock)
1457 1458
1458 1459 return held
1459 1460
1460 1461 @command('debugmanifestfulltextcache', [
1461 1462 ('', 'clear', False, _('clear the cache')),
1462 1463 ('a', 'add', '', _('add the given manifest node to the cache'),
1463 1464 _('NODE'))
1464 1465 ], '')
1465 1466 def debugmanifestfulltextcache(ui, repo, add=None, **opts):
1466 1467 """show, clear or amend the contents of the manifest fulltext cache"""
1467 1468 with repo.lock():
1468 1469 r = repo.manifestlog.getstorage(b'')
1469 1470 try:
1470 1471 cache = r._fulltextcache
1471 1472 except AttributeError:
1472 1473 ui.warn(_(
1473 1474 "Current revlog implementation doesn't appear to have a "
1474 1475 'manifest fulltext cache\n'))
1475 1476 return
1476 1477
1477 1478 if opts.get(r'clear'):
1478 1479 cache.clear()
1479 1480
1480 1481 if add:
1481 1482 try:
1482 1483 manifest = repo.manifestlog[r.lookup(add)]
1483 1484 except error.LookupError as e:
1484 1485 raise error.Abort(e, hint="Check your manifest node id")
1485 1486 manifest.read() # stores revisision in cache too
1486 1487
1487 1488 if not len(cache):
1488 1489 ui.write(_('Cache empty'))
1489 1490 else:
1490 1491 ui.write(
1491 1492 _('Cache contains %d manifest entries, in order of most to '
1492 1493 'least recent:\n') % (len(cache),))
1493 1494 totalsize = 0
1494 1495 for nodeid in cache:
1495 1496 # Use cache.get to not update the LRU order
1496 1497 data = cache.get(nodeid)
1497 1498 size = len(data)
1498 1499 totalsize += size + 24 # 20 bytes nodeid, 4 bytes size
1499 1500 ui.write(_('id: %s, size %s\n') % (
1500 1501 hex(nodeid), util.bytecount(size)))
1501 1502 ondisk = cache._opener.stat('manifestfulltextcache').st_size
1502 1503 ui.write(
1503 1504 _('Total cache data size %s, on-disk %s\n') % (
1504 1505 util.bytecount(totalsize), util.bytecount(ondisk))
1505 1506 )
1506 1507
1507 1508 @command('debugmergestate', [], '')
1508 1509 def debugmergestate(ui, repo, *args):
1509 1510 """print merge state
1510 1511
1511 1512 Use --verbose to print out information about whether v1 or v2 merge state
1512 1513 was chosen."""
1513 1514 def _hashornull(h):
1514 1515 if h == nullhex:
1515 1516 return 'null'
1516 1517 else:
1517 1518 return h
1518 1519
1519 1520 def printrecords(version):
1520 1521 ui.write(('* version %d records\n') % version)
1521 1522 if version == 1:
1522 1523 records = v1records
1523 1524 else:
1524 1525 records = v2records
1525 1526
1526 1527 for rtype, record in records:
1527 1528 # pretty print some record types
1528 1529 if rtype == 'L':
1529 1530 ui.write(('local: %s\n') % record)
1530 1531 elif rtype == 'O':
1531 1532 ui.write(('other: %s\n') % record)
1532 1533 elif rtype == 'm':
1533 1534 driver, mdstate = record.split('\0', 1)
1534 1535 ui.write(('merge driver: %s (state "%s")\n')
1535 1536 % (driver, mdstate))
1536 1537 elif rtype in 'FDC':
1537 1538 r = record.split('\0')
1538 1539 f, state, hash, lfile, afile, anode, ofile = r[0:7]
1539 1540 if version == 1:
1540 1541 onode = 'not stored in v1 format'
1541 1542 flags = r[7]
1542 1543 else:
1543 1544 onode, flags = r[7:9]
1544 1545 ui.write(('file: %s (record type "%s", state "%s", hash %s)\n')
1545 1546 % (f, rtype, state, _hashornull(hash)))
1546 1547 ui.write((' local path: %s (flags "%s")\n') % (lfile, flags))
1547 1548 ui.write((' ancestor path: %s (node %s)\n')
1548 1549 % (afile, _hashornull(anode)))
1549 1550 ui.write((' other path: %s (node %s)\n')
1550 1551 % (ofile, _hashornull(onode)))
1551 1552 elif rtype == 'f':
1552 1553 filename, rawextras = record.split('\0', 1)
1553 1554 extras = rawextras.split('\0')
1554 1555 i = 0
1555 1556 extrastrings = []
1556 1557 while i < len(extras):
1557 1558 extrastrings.append('%s = %s' % (extras[i], extras[i + 1]))
1558 1559 i += 2
1559 1560
1560 1561 ui.write(('file extras: %s (%s)\n')
1561 1562 % (filename, ', '.join(extrastrings)))
1562 1563 elif rtype == 'l':
1563 1564 labels = record.split('\0', 2)
1564 1565 labels = [l for l in labels if len(l) > 0]
1565 1566 ui.write(('labels:\n'))
1566 1567 ui.write((' local: %s\n' % labels[0]))
1567 1568 ui.write((' other: %s\n' % labels[1]))
1568 1569 if len(labels) > 2:
1569 1570 ui.write((' base: %s\n' % labels[2]))
1570 1571 else:
1571 1572 ui.write(('unrecognized entry: %s\t%s\n')
1572 1573 % (rtype, record.replace('\0', '\t')))
1573 1574
1574 1575 # Avoid mergestate.read() since it may raise an exception for unsupported
1575 1576 # merge state records. We shouldn't be doing this, but this is OK since this
1576 1577 # command is pretty low-level.
1577 1578 ms = mergemod.mergestate(repo)
1578 1579
1579 1580 # sort so that reasonable information is on top
1580 1581 v1records = ms._readrecordsv1()
1581 1582 v2records = ms._readrecordsv2()
1582 1583 order = 'LOml'
1583 1584 def key(r):
1584 1585 idx = order.find(r[0])
1585 1586 if idx == -1:
1586 1587 return (1, r[1])
1587 1588 else:
1588 1589 return (0, idx)
1589 1590 v1records.sort(key=key)
1590 1591 v2records.sort(key=key)
1591 1592
1592 1593 if not v1records and not v2records:
1593 1594 ui.write(('no merge state found\n'))
1594 1595 elif not v2records:
1595 1596 ui.note(('no version 2 merge state\n'))
1596 1597 printrecords(1)
1597 1598 elif ms._v1v2match(v1records, v2records):
1598 1599 ui.note(('v1 and v2 states match: using v2\n'))
1599 1600 printrecords(2)
1600 1601 else:
1601 1602 ui.note(('v1 and v2 states mismatch: using v1\n'))
1602 1603 printrecords(1)
1603 1604 if ui.verbose:
1604 1605 printrecords(2)
1605 1606
1606 1607 @command('debugnamecomplete', [], _('NAME...'))
1607 1608 def debugnamecomplete(ui, repo, *args):
1608 1609 '''complete "names" - tags, open branch names, bookmark names'''
1609 1610
1610 1611 names = set()
1611 1612 # since we previously only listed open branches, we will handle that
1612 1613 # specially (after this for loop)
1613 1614 for name, ns in repo.names.iteritems():
1614 1615 if name != 'branches':
1615 1616 names.update(ns.listnames(repo))
1616 1617 names.update(tag for (tag, heads, tip, closed)
1617 1618 in repo.branchmap().iterbranches() if not closed)
1618 1619 completions = set()
1619 1620 if not args:
1620 1621 args = ['']
1621 1622 for a in args:
1622 1623 completions.update(n for n in names if n.startswith(a))
1623 1624 ui.write('\n'.join(sorted(completions)))
1624 1625 ui.write('\n')
1625 1626
1626 1627 @command('debugobsolete',
1627 1628 [('', 'flags', 0, _('markers flag')),
1628 1629 ('', 'record-parents', False,
1629 1630 _('record parent information for the precursor')),
1630 1631 ('r', 'rev', [], _('display markers relevant to REV')),
1631 1632 ('', 'exclusive', False, _('restrict display to markers only '
1632 1633 'relevant to REV')),
1633 1634 ('', 'index', False, _('display index of the marker')),
1634 1635 ('', 'delete', [], _('delete markers specified by indices')),
1635 1636 ] + cmdutil.commitopts2 + cmdutil.formatteropts,
1636 1637 _('[OBSOLETED [REPLACEMENT ...]]'))
1637 1638 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
1638 1639 """create arbitrary obsolete marker
1639 1640
1640 1641 With no arguments, displays the list of obsolescence markers."""
1641 1642
1642 1643 opts = pycompat.byteskwargs(opts)
1643 1644
1644 1645 def parsenodeid(s):
1645 1646 try:
1646 1647 # We do not use revsingle/revrange functions here to accept
1647 1648 # arbitrary node identifiers, possibly not present in the
1648 1649 # local repository.
1649 1650 n = bin(s)
1650 1651 if len(n) != len(nullid):
1651 1652 raise TypeError()
1652 1653 return n
1653 1654 except TypeError:
1654 1655 raise error.Abort('changeset references must be full hexadecimal '
1655 1656 'node identifiers')
1656 1657
1657 1658 if opts.get('delete'):
1658 1659 indices = []
1659 1660 for v in opts.get('delete'):
1660 1661 try:
1661 1662 indices.append(int(v))
1662 1663 except ValueError:
1663 1664 raise error.Abort(_('invalid index value: %r') % v,
1664 1665 hint=_('use integers for indices'))
1665 1666
1666 1667 if repo.currenttransaction():
1667 1668 raise error.Abort(_('cannot delete obsmarkers in the middle '
1668 1669 'of transaction.'))
1669 1670
1670 1671 with repo.lock():
1671 1672 n = repair.deleteobsmarkers(repo.obsstore, indices)
1672 1673 ui.write(_('deleted %i obsolescence markers\n') % n)
1673 1674
1674 1675 return
1675 1676
1676 1677 if precursor is not None:
1677 1678 if opts['rev']:
1678 1679 raise error.Abort('cannot select revision when creating marker')
1679 1680 metadata = {}
1680 1681 metadata['user'] = encoding.fromlocal(opts['user'] or ui.username())
1681 1682 succs = tuple(parsenodeid(succ) for succ in successors)
1682 1683 l = repo.lock()
1683 1684 try:
1684 1685 tr = repo.transaction('debugobsolete')
1685 1686 try:
1686 1687 date = opts.get('date')
1687 1688 if date:
1688 1689 date = dateutil.parsedate(date)
1689 1690 else:
1690 1691 date = None
1691 1692 prec = parsenodeid(precursor)
1692 1693 parents = None
1693 1694 if opts['record_parents']:
1694 1695 if prec not in repo.unfiltered():
1695 1696 raise error.Abort('cannot used --record-parents on '
1696 1697 'unknown changesets')
1697 1698 parents = repo.unfiltered()[prec].parents()
1698 1699 parents = tuple(p.node() for p in parents)
1699 1700 repo.obsstore.create(tr, prec, succs, opts['flags'],
1700 1701 parents=parents, date=date,
1701 1702 metadata=metadata, ui=ui)
1702 1703 tr.close()
1703 1704 except ValueError as exc:
1704 1705 raise error.Abort(_('bad obsmarker input: %s') %
1705 1706 pycompat.bytestr(exc))
1706 1707 finally:
1707 1708 tr.release()
1708 1709 finally:
1709 1710 l.release()
1710 1711 else:
1711 1712 if opts['rev']:
1712 1713 revs = scmutil.revrange(repo, opts['rev'])
1713 1714 nodes = [repo[r].node() for r in revs]
1714 1715 markers = list(obsutil.getmarkers(repo, nodes=nodes,
1715 1716 exclusive=opts['exclusive']))
1716 1717 markers.sort(key=lambda x: x._data)
1717 1718 else:
1718 1719 markers = obsutil.getmarkers(repo)
1719 1720
1720 1721 markerstoiter = markers
1721 1722 isrelevant = lambda m: True
1722 1723 if opts.get('rev') and opts.get('index'):
1723 1724 markerstoiter = obsutil.getmarkers(repo)
1724 1725 markerset = set(markers)
1725 1726 isrelevant = lambda m: m in markerset
1726 1727
1727 1728 fm = ui.formatter('debugobsolete', opts)
1728 1729 for i, m in enumerate(markerstoiter):
1729 1730 if not isrelevant(m):
1730 1731 # marker can be irrelevant when we're iterating over a set
1731 1732 # of markers (markerstoiter) which is bigger than the set
1732 1733 # of markers we want to display (markers)
1733 1734 # this can happen if both --index and --rev options are
1734 1735 # provided and thus we need to iterate over all of the markers
1735 1736 # to get the correct indices, but only display the ones that
1736 1737 # are relevant to --rev value
1737 1738 continue
1738 1739 fm.startitem()
1739 1740 ind = i if opts.get('index') else None
1740 1741 cmdutil.showmarker(fm, m, index=ind)
1741 1742 fm.end()
1742 1743
1743 1744 @command('debugpathcomplete',
1744 1745 [('f', 'full', None, _('complete an entire path')),
1745 1746 ('n', 'normal', None, _('show only normal files')),
1746 1747 ('a', 'added', None, _('show only added files')),
1747 1748 ('r', 'removed', None, _('show only removed files'))],
1748 1749 _('FILESPEC...'))
1749 1750 def debugpathcomplete(ui, repo, *specs, **opts):
1750 1751 '''complete part or all of a tracked path
1751 1752
1752 1753 This command supports shells that offer path name completion. It
1753 1754 currently completes only files already known to the dirstate.
1754 1755
1755 1756 Completion extends only to the next path segment unless
1756 1757 --full is specified, in which case entire paths are used.'''
1757 1758
1758 1759 def complete(path, acceptable):
1759 1760 dirstate = repo.dirstate
1760 1761 spec = os.path.normpath(os.path.join(encoding.getcwd(), path))
1761 1762 rootdir = repo.root + pycompat.ossep
1762 1763 if spec != repo.root and not spec.startswith(rootdir):
1763 1764 return [], []
1764 1765 if os.path.isdir(spec):
1765 1766 spec += '/'
1766 1767 spec = spec[len(rootdir):]
1767 1768 fixpaths = pycompat.ossep != '/'
1768 1769 if fixpaths:
1769 1770 spec = spec.replace(pycompat.ossep, '/')
1770 1771 speclen = len(spec)
1771 1772 fullpaths = opts[r'full']
1772 1773 files, dirs = set(), set()
1773 1774 adddir, addfile = dirs.add, files.add
1774 1775 for f, st in dirstate.iteritems():
1775 1776 if f.startswith(spec) and st[0] in acceptable:
1776 1777 if fixpaths:
1777 1778 f = f.replace('/', pycompat.ossep)
1778 1779 if fullpaths:
1779 1780 addfile(f)
1780 1781 continue
1781 1782 s = f.find(pycompat.ossep, speclen)
1782 1783 if s >= 0:
1783 1784 adddir(f[:s])
1784 1785 else:
1785 1786 addfile(f)
1786 1787 return files, dirs
1787 1788
1788 1789 acceptable = ''
1789 1790 if opts[r'normal']:
1790 1791 acceptable += 'nm'
1791 1792 if opts[r'added']:
1792 1793 acceptable += 'a'
1793 1794 if opts[r'removed']:
1794 1795 acceptable += 'r'
1795 1796 cwd = repo.getcwd()
1796 1797 if not specs:
1797 1798 specs = ['.']
1798 1799
1799 1800 files, dirs = set(), set()
1800 1801 for spec in specs:
1801 1802 f, d = complete(spec, acceptable or 'nmar')
1802 1803 files.update(f)
1803 1804 dirs.update(d)
1804 1805 files.update(dirs)
1805 1806 ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
1806 1807 ui.write('\n')
1807 1808
1808 1809 @command('debugpathcopies',
1809 1810 cmdutil.walkopts,
1810 1811 'hg debugcopies REV1 REV2 [FILE]',
1811 1812 inferrepo=True)
1812 1813 def debugpathcopies(ui, repo, rev1, rev2, *pats, **opts):
1813 1814 """show copies between two revisions"""
1814 1815 ctx1 = scmutil.revsingle(repo, rev1)
1815 1816 ctx2 = scmutil.revsingle(repo, rev2)
1816 1817 m = scmutil.match(ctx1, pats, opts)
1817 1818 for dst, src in copies.pathcopies(ctx1, ctx2, m).items():
1818 1819 ui.write('%s -> %s\n' % (src, dst))
1819 1820
1820 1821 @command('debugpeer', [], _('PATH'), norepo=True)
1821 1822 def debugpeer(ui, path):
1822 1823 """establish a connection to a peer repository"""
1823 1824 # Always enable peer request logging. Requires --debug to display
1824 1825 # though.
1825 1826 overrides = {
1826 1827 ('devel', 'debug.peer-request'): True,
1827 1828 }
1828 1829
1829 1830 with ui.configoverride(overrides):
1830 1831 peer = hg.peer(ui, {}, path)
1831 1832
1832 1833 local = peer.local() is not None
1833 1834 canpush = peer.canpush()
1834 1835
1835 1836 ui.write(_('url: %s\n') % peer.url())
1836 1837 ui.write(_('local: %s\n') % (_('yes') if local else _('no')))
1837 1838 ui.write(_('pushable: %s\n') % (_('yes') if canpush else _('no')))
1838 1839
1839 1840 @command('debugpickmergetool',
1840 1841 [('r', 'rev', '', _('check for files in this revision'), _('REV')),
1841 1842 ('', 'changedelete', None, _('emulate merging change and delete')),
1842 1843 ] + cmdutil.walkopts + cmdutil.mergetoolopts,
1843 1844 _('[PATTERN]...'),
1844 1845 inferrepo=True)
1845 1846 def debugpickmergetool(ui, repo, *pats, **opts):
1846 1847 """examine which merge tool is chosen for specified file
1847 1848
1848 1849 As described in :hg:`help merge-tools`, Mercurial examines
1849 1850 configurations below in this order to decide which merge tool is
1850 1851 chosen for specified file.
1851 1852
1852 1853 1. ``--tool`` option
1853 1854 2. ``HGMERGE`` environment variable
1854 1855 3. configurations in ``merge-patterns`` section
1855 1856 4. configuration of ``ui.merge``
1856 1857 5. configurations in ``merge-tools`` section
1857 1858 6. ``hgmerge`` tool (for historical reason only)
1858 1859 7. default tool for fallback (``:merge`` or ``:prompt``)
1859 1860
1860 1861 This command writes out examination result in the style below::
1861 1862
1862 1863 FILE = MERGETOOL
1863 1864
1864 1865 By default, all files known in the first parent context of the
1865 1866 working directory are examined. Use file patterns and/or -I/-X
1866 1867 options to limit target files. -r/--rev is also useful to examine
1867 1868 files in another context without actual updating to it.
1868 1869
1869 1870 With --debug, this command shows warning messages while matching
1870 1871 against ``merge-patterns`` and so on, too. It is recommended to
1871 1872 use this option with explicit file patterns and/or -I/-X options,
1872 1873 because this option increases amount of output per file according
1873 1874 to configurations in hgrc.
1874 1875
1875 1876 With -v/--verbose, this command shows configurations below at
1876 1877 first (only if specified).
1877 1878
1878 1879 - ``--tool`` option
1879 1880 - ``HGMERGE`` environment variable
1880 1881 - configuration of ``ui.merge``
1881 1882
1882 1883 If merge tool is chosen before matching against
1883 1884 ``merge-patterns``, this command can't show any helpful
1884 1885 information, even with --debug. In such case, information above is
1885 1886 useful to know why a merge tool is chosen.
1886 1887 """
1887 1888 opts = pycompat.byteskwargs(opts)
1888 1889 overrides = {}
1889 1890 if opts['tool']:
1890 1891 overrides[('ui', 'forcemerge')] = opts['tool']
1891 1892 ui.note(('with --tool %r\n') % (pycompat.bytestr(opts['tool'])))
1892 1893
1893 1894 with ui.configoverride(overrides, 'debugmergepatterns'):
1894 1895 hgmerge = encoding.environ.get("HGMERGE")
1895 1896 if hgmerge is not None:
1896 1897 ui.note(('with HGMERGE=%r\n') % (pycompat.bytestr(hgmerge)))
1897 1898 uimerge = ui.config("ui", "merge")
1898 1899 if uimerge:
1899 1900 ui.note(('with ui.merge=%r\n') % (pycompat.bytestr(uimerge)))
1900 1901
1901 1902 ctx = scmutil.revsingle(repo, opts.get('rev'))
1902 1903 m = scmutil.match(ctx, pats, opts)
1903 1904 changedelete = opts['changedelete']
1904 1905 for path in ctx.walk(m):
1905 1906 fctx = ctx[path]
1906 1907 try:
1907 1908 if not ui.debugflag:
1908 1909 ui.pushbuffer(error=True)
1909 1910 tool, toolpath = filemerge._picktool(repo, ui, path,
1910 1911 fctx.isbinary(),
1911 1912 'l' in fctx.flags(),
1912 1913 changedelete)
1913 1914 finally:
1914 1915 if not ui.debugflag:
1915 1916 ui.popbuffer()
1916 1917 ui.write(('%s = %s\n') % (path, tool))
1917 1918
1918 1919 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
1919 1920 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
1920 1921 '''access the pushkey key/value protocol
1921 1922
1922 1923 With two args, list the keys in the given namespace.
1923 1924
1924 1925 With five args, set a key to new if it currently is set to old.
1925 1926 Reports success or failure.
1926 1927 '''
1927 1928
1928 1929 target = hg.peer(ui, {}, repopath)
1929 1930 if keyinfo:
1930 1931 key, old, new = keyinfo
1931 1932 with target.commandexecutor() as e:
1932 1933 r = e.callcommand('pushkey', {
1933 1934 'namespace': namespace,
1934 1935 'key': key,
1935 1936 'old': old,
1936 1937 'new': new,
1937 1938 }).result()
1938 1939
1939 1940 ui.status(pycompat.bytestr(r) + '\n')
1940 1941 return not r
1941 1942 else:
1942 1943 for k, v in sorted(target.listkeys(namespace).iteritems()):
1943 1944 ui.write("%s\t%s\n" % (stringutil.escapestr(k),
1944 1945 stringutil.escapestr(v)))
1945 1946
1946 1947 @command('debugpvec', [], _('A B'))
1947 1948 def debugpvec(ui, repo, a, b=None):
1948 1949 ca = scmutil.revsingle(repo, a)
1949 1950 cb = scmutil.revsingle(repo, b)
1950 1951 pa = pvec.ctxpvec(ca)
1951 1952 pb = pvec.ctxpvec(cb)
1952 1953 if pa == pb:
1953 1954 rel = "="
1954 1955 elif pa > pb:
1955 1956 rel = ">"
1956 1957 elif pa < pb:
1957 1958 rel = "<"
1958 1959 elif pa | pb:
1959 1960 rel = "|"
1960 1961 ui.write(_("a: %s\n") % pa)
1961 1962 ui.write(_("b: %s\n") % pb)
1962 1963 ui.write(_("depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth))
1963 1964 ui.write(_("delta: %d hdist: %d distance: %d relation: %s\n") %
1964 1965 (abs(pa._depth - pb._depth), pvec._hamming(pa._vec, pb._vec),
1965 1966 pa.distance(pb), rel))
1966 1967
1967 1968 @command('debugrebuilddirstate|debugrebuildstate',
1968 1969 [('r', 'rev', '', _('revision to rebuild to'), _('REV')),
1969 1970 ('', 'minimal', None, _('only rebuild files that are inconsistent with '
1970 1971 'the working copy parent')),
1971 1972 ],
1972 1973 _('[-r REV]'))
1973 1974 def debugrebuilddirstate(ui, repo, rev, **opts):
1974 1975 """rebuild the dirstate as it would look like for the given revision
1975 1976
1976 1977 If no revision is specified the first current parent will be used.
1977 1978
1978 1979 The dirstate will be set to the files of the given revision.
1979 1980 The actual working directory content or existing dirstate
1980 1981 information such as adds or removes is not considered.
1981 1982
1982 1983 ``minimal`` will only rebuild the dirstate status for files that claim to be
1983 1984 tracked but are not in the parent manifest, or that exist in the parent
1984 1985 manifest but are not in the dirstate. It will not change adds, removes, or
1985 1986 modified files that are in the working copy parent.
1986 1987
1987 1988 One use of this command is to make the next :hg:`status` invocation
1988 1989 check the actual file content.
1989 1990 """
1990 1991 ctx = scmutil.revsingle(repo, rev)
1991 1992 with repo.wlock():
1992 1993 dirstate = repo.dirstate
1993 1994 changedfiles = None
1994 1995 # See command doc for what minimal does.
1995 1996 if opts.get(r'minimal'):
1996 1997 manifestfiles = set(ctx.manifest().keys())
1997 1998 dirstatefiles = set(dirstate)
1998 1999 manifestonly = manifestfiles - dirstatefiles
1999 2000 dsonly = dirstatefiles - manifestfiles
2000 2001 dsnotadded = set(f for f in dsonly if dirstate[f] != 'a')
2001 2002 changedfiles = manifestonly | dsnotadded
2002 2003
2003 2004 dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles)
2004 2005
2005 2006 @command('debugrebuildfncache', [], '')
2006 2007 def debugrebuildfncache(ui, repo):
2007 2008 """rebuild the fncache file"""
2008 2009 repair.rebuildfncache(ui, repo)
2009 2010
2010 2011 @command('debugrename',
2011 2012 [('r', 'rev', '', _('revision to debug'), _('REV'))],
2012 2013 _('[-r REV] FILE'))
2013 2014 def debugrename(ui, repo, file1, *pats, **opts):
2014 2015 """dump rename information"""
2015 2016
2016 2017 opts = pycompat.byteskwargs(opts)
2017 2018 ctx = scmutil.revsingle(repo, opts.get('rev'))
2018 2019 m = scmutil.match(ctx, (file1,) + pats, opts)
2019 2020 for abs in ctx.walk(m):
2020 2021 fctx = ctx[abs]
2021 2022 o = fctx.filelog().renamed(fctx.filenode())
2022 2023 rel = m.rel(abs)
2023 2024 if o:
2024 2025 ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
2025 2026 else:
2026 2027 ui.write(_("%s not renamed\n") % rel)
2027 2028
2028 2029 @command('debugrevlog', cmdutil.debugrevlogopts +
2029 2030 [('d', 'dump', False, _('dump index data'))],
2030 2031 _('-c|-m|FILE'),
2031 2032 optionalrepo=True)
2032 2033 def debugrevlog(ui, repo, file_=None, **opts):
2033 2034 """show data and statistics about a revlog"""
2034 2035 opts = pycompat.byteskwargs(opts)
2035 2036 r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
2036 2037
2037 2038 if opts.get("dump"):
2038 2039 numrevs = len(r)
2039 2040 ui.write(("# rev p1rev p2rev start end deltastart base p1 p2"
2040 2041 " rawsize totalsize compression heads chainlen\n"))
2041 2042 ts = 0
2042 2043 heads = set()
2043 2044
2044 2045 for rev in pycompat.xrange(numrevs):
2045 2046 dbase = r.deltaparent(rev)
2046 2047 if dbase == -1:
2047 2048 dbase = rev
2048 2049 cbase = r.chainbase(rev)
2049 2050 clen = r.chainlen(rev)
2050 2051 p1, p2 = r.parentrevs(rev)
2051 2052 rs = r.rawsize(rev)
2052 2053 ts = ts + rs
2053 2054 heads -= set(r.parentrevs(rev))
2054 2055 heads.add(rev)
2055 2056 try:
2056 2057 compression = ts / r.end(rev)
2057 2058 except ZeroDivisionError:
2058 2059 compression = 0
2059 2060 ui.write("%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
2060 2061 "%11d %5d %8d\n" %
2061 2062 (rev, p1, p2, r.start(rev), r.end(rev),
2062 2063 r.start(dbase), r.start(cbase),
2063 2064 r.start(p1), r.start(p2),
2064 2065 rs, ts, compression, len(heads), clen))
2065 2066 return 0
2066 2067
2067 2068 v = r.version
2068 2069 format = v & 0xFFFF
2069 2070 flags = []
2070 2071 gdelta = False
2071 2072 if v & revlog.FLAG_INLINE_DATA:
2072 2073 flags.append('inline')
2073 2074 if v & revlog.FLAG_GENERALDELTA:
2074 2075 gdelta = True
2075 2076 flags.append('generaldelta')
2076 2077 if not flags:
2077 2078 flags = ['(none)']
2078 2079
2079 2080 ### tracks merge vs single parent
2080 2081 nummerges = 0
2081 2082
2082 2083 ### tracks ways the "delta" are build
2083 2084 # nodelta
2084 2085 numempty = 0
2085 2086 numemptytext = 0
2086 2087 numemptydelta = 0
2087 2088 # full file content
2088 2089 numfull = 0
2089 2090 # intermediate snapshot against a prior snapshot
2090 2091 numsemi = 0
2091 2092 # snapshot count per depth
2092 2093 numsnapdepth = collections.defaultdict(lambda: 0)
2093 2094 # delta against previous revision
2094 2095 numprev = 0
2095 2096 # delta against first or second parent (not prev)
2096 2097 nump1 = 0
2097 2098 nump2 = 0
2098 2099 # delta against neither prev nor parents
2099 2100 numother = 0
2100 2101 # delta against prev that are also first or second parent
2101 2102 # (details of `numprev`)
2102 2103 nump1prev = 0
2103 2104 nump2prev = 0
2104 2105
2105 2106 # data about delta chain of each revs
2106 2107 chainlengths = []
2107 2108 chainbases = []
2108 2109 chainspans = []
2109 2110
2110 2111 # data about each revision
2111 2112 datasize = [None, 0, 0]
2112 2113 fullsize = [None, 0, 0]
2113 2114 semisize = [None, 0, 0]
2114 2115 # snapshot count per depth
2115 2116 snapsizedepth = collections.defaultdict(lambda: [None, 0, 0])
2116 2117 deltasize = [None, 0, 0]
2117 2118 chunktypecounts = {}
2118 2119 chunktypesizes = {}
2119 2120
2120 2121 def addsize(size, l):
2121 2122 if l[0] is None or size < l[0]:
2122 2123 l[0] = size
2123 2124 if size > l[1]:
2124 2125 l[1] = size
2125 2126 l[2] += size
2126 2127
2127 2128 numrevs = len(r)
2128 2129 for rev in pycompat.xrange(numrevs):
2129 2130 p1, p2 = r.parentrevs(rev)
2130 2131 delta = r.deltaparent(rev)
2131 2132 if format > 0:
2132 2133 addsize(r.rawsize(rev), datasize)
2133 2134 if p2 != nullrev:
2134 2135 nummerges += 1
2135 2136 size = r.length(rev)
2136 2137 if delta == nullrev:
2137 2138 chainlengths.append(0)
2138 2139 chainbases.append(r.start(rev))
2139 2140 chainspans.append(size)
2140 2141 if size == 0:
2141 2142 numempty += 1
2142 2143 numemptytext += 1
2143 2144 else:
2144 2145 numfull += 1
2145 2146 numsnapdepth[0] += 1
2146 2147 addsize(size, fullsize)
2147 2148 addsize(size, snapsizedepth[0])
2148 2149 else:
2149 2150 chainlengths.append(chainlengths[delta] + 1)
2150 2151 baseaddr = chainbases[delta]
2151 2152 revaddr = r.start(rev)
2152 2153 chainbases.append(baseaddr)
2153 2154 chainspans.append((revaddr - baseaddr) + size)
2154 2155 if size == 0:
2155 2156 numempty += 1
2156 2157 numemptydelta += 1
2157 2158 elif r.issnapshot(rev):
2158 2159 addsize(size, semisize)
2159 2160 numsemi += 1
2160 2161 depth = r.snapshotdepth(rev)
2161 2162 numsnapdepth[depth] += 1
2162 2163 addsize(size, snapsizedepth[depth])
2163 2164 else:
2164 2165 addsize(size, deltasize)
2165 2166 if delta == rev - 1:
2166 2167 numprev += 1
2167 2168 if delta == p1:
2168 2169 nump1prev += 1
2169 2170 elif delta == p2:
2170 2171 nump2prev += 1
2171 2172 elif delta == p1:
2172 2173 nump1 += 1
2173 2174 elif delta == p2:
2174 2175 nump2 += 1
2175 2176 elif delta != nullrev:
2176 2177 numother += 1
2177 2178
2178 2179 # Obtain data on the raw chunks in the revlog.
2179 2180 if util.safehasattr(r, '_getsegmentforrevs'):
2180 2181 segment = r._getsegmentforrevs(rev, rev)[1]
2181 2182 else:
2182 2183 segment = r._revlog._getsegmentforrevs(rev, rev)[1]
2183 2184 if segment:
2184 2185 chunktype = bytes(segment[0:1])
2185 2186 else:
2186 2187 chunktype = 'empty'
2187 2188
2188 2189 if chunktype not in chunktypecounts:
2189 2190 chunktypecounts[chunktype] = 0
2190 2191 chunktypesizes[chunktype] = 0
2191 2192
2192 2193 chunktypecounts[chunktype] += 1
2193 2194 chunktypesizes[chunktype] += size
2194 2195
2195 2196 # Adjust size min value for empty cases
2196 2197 for size in (datasize, fullsize, semisize, deltasize):
2197 2198 if size[0] is None:
2198 2199 size[0] = 0
2199 2200
2200 2201 numdeltas = numrevs - numfull - numempty - numsemi
2201 2202 numoprev = numprev - nump1prev - nump2prev
2202 2203 totalrawsize = datasize[2]
2203 2204 datasize[2] /= numrevs
2204 2205 fulltotal = fullsize[2]
2205 2206 fullsize[2] /= numfull
2206 2207 semitotal = semisize[2]
2207 2208 snaptotal = {}
2208 2209 if numsemi > 0:
2209 2210 semisize[2] /= numsemi
2210 2211 for depth in snapsizedepth:
2211 2212 snaptotal[depth] = snapsizedepth[depth][2]
2212 2213 snapsizedepth[depth][2] /= numsnapdepth[depth]
2213 2214
2214 2215 deltatotal = deltasize[2]
2215 2216 if numdeltas > 0:
2216 2217 deltasize[2] /= numdeltas
2217 2218 totalsize = fulltotal + semitotal + deltatotal
2218 2219 avgchainlen = sum(chainlengths) / numrevs
2219 2220 maxchainlen = max(chainlengths)
2220 2221 maxchainspan = max(chainspans)
2221 2222 compratio = 1
2222 2223 if totalsize:
2223 2224 compratio = totalrawsize / totalsize
2224 2225
2225 2226 basedfmtstr = '%%%dd\n'
2226 2227 basepcfmtstr = '%%%dd %s(%%5.2f%%%%)\n'
2227 2228
2228 2229 def dfmtstr(max):
2229 2230 return basedfmtstr % len(str(max))
2230 2231 def pcfmtstr(max, padding=0):
2231 2232 return basepcfmtstr % (len(str(max)), ' ' * padding)
2232 2233
2233 2234 def pcfmt(value, total):
2234 2235 if total:
2235 2236 return (value, 100 * float(value) / total)
2236 2237 else:
2237 2238 return value, 100.0
2238 2239
2239 2240 ui.write(('format : %d\n') % format)
2240 2241 ui.write(('flags : %s\n') % ', '.join(flags))
2241 2242
2242 2243 ui.write('\n')
2243 2244 fmt = pcfmtstr(totalsize)
2244 2245 fmt2 = dfmtstr(totalsize)
2245 2246 ui.write(('revisions : ') + fmt2 % numrevs)
2246 2247 ui.write((' merges : ') + fmt % pcfmt(nummerges, numrevs))
2247 2248 ui.write((' normal : ') + fmt % pcfmt(numrevs - nummerges, numrevs))
2248 2249 ui.write(('revisions : ') + fmt2 % numrevs)
2249 2250 ui.write((' empty : ') + fmt % pcfmt(numempty, numrevs))
2250 2251 ui.write((' text : ')
2251 2252 + fmt % pcfmt(numemptytext, numemptytext + numemptydelta))
2252 2253 ui.write((' delta : ')
2253 2254 + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta))
2254 2255 ui.write((' snapshot : ') + fmt % pcfmt(numfull + numsemi, numrevs))
2255 2256 for depth in sorted(numsnapdepth):
2256 2257 ui.write((' lvl-%-3d : ' % depth)
2257 2258 + fmt % pcfmt(numsnapdepth[depth], numrevs))
2258 2259 ui.write((' deltas : ') + fmt % pcfmt(numdeltas, numrevs))
2259 2260 ui.write(('revision size : ') + fmt2 % totalsize)
2260 2261 ui.write((' snapshot : ')
2261 2262 + fmt % pcfmt(fulltotal + semitotal, totalsize))
2262 2263 for depth in sorted(numsnapdepth):
2263 2264 ui.write((' lvl-%-3d : ' % depth)
2264 2265 + fmt % pcfmt(snaptotal[depth], totalsize))
2265 2266 ui.write((' deltas : ') + fmt % pcfmt(deltatotal, totalsize))
2266 2267
2267 2268 def fmtchunktype(chunktype):
2268 2269 if chunktype == 'empty':
2269 2270 return ' %s : ' % chunktype
2270 2271 elif chunktype in pycompat.bytestr(string.ascii_letters):
2271 2272 return ' 0x%s (%s) : ' % (hex(chunktype), chunktype)
2272 2273 else:
2273 2274 return ' 0x%s : ' % hex(chunktype)
2274 2275
2275 2276 ui.write('\n')
2276 2277 ui.write(('chunks : ') + fmt2 % numrevs)
2277 2278 for chunktype in sorted(chunktypecounts):
2278 2279 ui.write(fmtchunktype(chunktype))
2279 2280 ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs))
2280 2281 ui.write(('chunks size : ') + fmt2 % totalsize)
2281 2282 for chunktype in sorted(chunktypecounts):
2282 2283 ui.write(fmtchunktype(chunktype))
2283 2284 ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize))
2284 2285
2285 2286 ui.write('\n')
2286 2287 fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio))
2287 2288 ui.write(('avg chain length : ') + fmt % avgchainlen)
2288 2289 ui.write(('max chain length : ') + fmt % maxchainlen)
2289 2290 ui.write(('max chain reach : ') + fmt % maxchainspan)
2290 2291 ui.write(('compression ratio : ') + fmt % compratio)
2291 2292
2292 2293 if format > 0:
2293 2294 ui.write('\n')
2294 2295 ui.write(('uncompressed data size (min/max/avg) : %d / %d / %d\n')
2295 2296 % tuple(datasize))
2296 2297 ui.write(('full revision size (min/max/avg) : %d / %d / %d\n')
2297 2298 % tuple(fullsize))
2298 2299 ui.write(('inter-snapshot size (min/max/avg) : %d / %d / %d\n')
2299 2300 % tuple(semisize))
2300 2301 for depth in sorted(snapsizedepth):
2301 2302 if depth == 0:
2302 2303 continue
2303 2304 ui.write((' level-%-3d (min/max/avg) : %d / %d / %d\n')
2304 2305 % ((depth,) + tuple(snapsizedepth[depth])))
2305 2306 ui.write(('delta size (min/max/avg) : %d / %d / %d\n')
2306 2307 % tuple(deltasize))
2307 2308
2308 2309 if numdeltas > 0:
2309 2310 ui.write('\n')
2310 2311 fmt = pcfmtstr(numdeltas)
2311 2312 fmt2 = pcfmtstr(numdeltas, 4)
2312 2313 ui.write(('deltas against prev : ') + fmt % pcfmt(numprev, numdeltas))
2313 2314 if numprev > 0:
2314 2315 ui.write((' where prev = p1 : ') + fmt2 % pcfmt(nump1prev,
2315 2316 numprev))
2316 2317 ui.write((' where prev = p2 : ') + fmt2 % pcfmt(nump2prev,
2317 2318 numprev))
2318 2319 ui.write((' other : ') + fmt2 % pcfmt(numoprev,
2319 2320 numprev))
2320 2321 if gdelta:
2321 2322 ui.write(('deltas against p1 : ')
2322 2323 + fmt % pcfmt(nump1, numdeltas))
2323 2324 ui.write(('deltas against p2 : ')
2324 2325 + fmt % pcfmt(nump2, numdeltas))
2325 2326 ui.write(('deltas against other : ') + fmt % pcfmt(numother,
2326 2327 numdeltas))
2327 2328
2328 2329 @command('debugrevlogindex', cmdutil.debugrevlogopts +
2329 2330 [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
2330 2331 _('[-f FORMAT] -c|-m|FILE'),
2331 2332 optionalrepo=True)
2332 2333 def debugrevlogindex(ui, repo, file_=None, **opts):
2333 2334 """dump the contents of a revlog index"""
2334 2335 opts = pycompat.byteskwargs(opts)
2335 2336 r = cmdutil.openrevlog(repo, 'debugrevlogindex', file_, opts)
2336 2337 format = opts.get('format', 0)
2337 2338 if format not in (0, 1):
2338 2339 raise error.Abort(_("unknown format %d") % format)
2339 2340
2340 2341 if ui.debugflag:
2341 2342 shortfn = hex
2342 2343 else:
2343 2344 shortfn = short
2344 2345
2345 2346 # There might not be anything in r, so have a sane default
2346 2347 idlen = 12
2347 2348 for i in r:
2348 2349 idlen = len(shortfn(r.node(i)))
2349 2350 break
2350 2351
2351 2352 if format == 0:
2352 2353 if ui.verbose:
2353 2354 ui.write((" rev offset length linkrev"
2354 2355 " %s %s p2\n") % ("nodeid".ljust(idlen),
2355 2356 "p1".ljust(idlen)))
2356 2357 else:
2357 2358 ui.write((" rev linkrev %s %s p2\n") % (
2358 2359 "nodeid".ljust(idlen), "p1".ljust(idlen)))
2359 2360 elif format == 1:
2360 2361 if ui.verbose:
2361 2362 ui.write((" rev flag offset length size link p1"
2362 2363 " p2 %s\n") % "nodeid".rjust(idlen))
2363 2364 else:
2364 2365 ui.write((" rev flag size link p1 p2 %s\n") %
2365 2366 "nodeid".rjust(idlen))
2366 2367
2367 2368 for i in r:
2368 2369 node = r.node(i)
2369 2370 if format == 0:
2370 2371 try:
2371 2372 pp = r.parents(node)
2372 2373 except Exception:
2373 2374 pp = [nullid, nullid]
2374 2375 if ui.verbose:
2375 2376 ui.write("% 6d % 9d % 7d % 7d %s %s %s\n" % (
2376 2377 i, r.start(i), r.length(i), r.linkrev(i),
2377 2378 shortfn(node), shortfn(pp[0]), shortfn(pp[1])))
2378 2379 else:
2379 2380 ui.write("% 6d % 7d %s %s %s\n" % (
2380 2381 i, r.linkrev(i), shortfn(node), shortfn(pp[0]),
2381 2382 shortfn(pp[1])))
2382 2383 elif format == 1:
2383 2384 pr = r.parentrevs(i)
2384 2385 if ui.verbose:
2385 2386 ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d %s\n" % (
2386 2387 i, r.flags(i), r.start(i), r.length(i), r.rawsize(i),
2387 2388 r.linkrev(i), pr[0], pr[1], shortfn(node)))
2388 2389 else:
2389 2390 ui.write("% 6d %04x % 8d % 6d % 6d % 6d %s\n" % (
2390 2391 i, r.flags(i), r.rawsize(i), r.linkrev(i), pr[0], pr[1],
2391 2392 shortfn(node)))
2392 2393
2393 2394 @command('debugrevspec',
2394 2395 [('', 'optimize', None,
2395 2396 _('print parsed tree after optimizing (DEPRECATED)')),
2396 2397 ('', 'show-revs', True, _('print list of result revisions (default)')),
2397 2398 ('s', 'show-set', None, _('print internal representation of result set')),
2398 2399 ('p', 'show-stage', [],
2399 2400 _('print parsed tree at the given stage'), _('NAME')),
2400 2401 ('', 'no-optimized', False, _('evaluate tree without optimization')),
2401 2402 ('', 'verify-optimized', False, _('verify optimized result')),
2402 2403 ],
2403 2404 ('REVSPEC'))
2404 2405 def debugrevspec(ui, repo, expr, **opts):
2405 2406 """parse and apply a revision specification
2406 2407
2407 2408 Use -p/--show-stage option to print the parsed tree at the given stages.
2408 2409 Use -p all to print tree at every stage.
2409 2410
2410 2411 Use --no-show-revs option with -s or -p to print only the set
2411 2412 representation or the parsed tree respectively.
2412 2413
2413 2414 Use --verify-optimized to compare the optimized result with the unoptimized
2414 2415 one. Returns 1 if the optimized result differs.
2415 2416 """
2416 2417 opts = pycompat.byteskwargs(opts)
2417 2418 aliases = ui.configitems('revsetalias')
2418 2419 stages = [
2419 2420 ('parsed', lambda tree: tree),
2420 2421 ('expanded', lambda tree: revsetlang.expandaliases(tree, aliases,
2421 2422 ui.warn)),
2422 2423 ('concatenated', revsetlang.foldconcat),
2423 2424 ('analyzed', revsetlang.analyze),
2424 2425 ('optimized', revsetlang.optimize),
2425 2426 ]
2426 2427 if opts['no_optimized']:
2427 2428 stages = stages[:-1]
2428 2429 if opts['verify_optimized'] and opts['no_optimized']:
2429 2430 raise error.Abort(_('cannot use --verify-optimized with '
2430 2431 '--no-optimized'))
2431 2432 stagenames = set(n for n, f in stages)
2432 2433
2433 2434 showalways = set()
2434 2435 showchanged = set()
2435 2436 if ui.verbose and not opts['show_stage']:
2436 2437 # show parsed tree by --verbose (deprecated)
2437 2438 showalways.add('parsed')
2438 2439 showchanged.update(['expanded', 'concatenated'])
2439 2440 if opts['optimize']:
2440 2441 showalways.add('optimized')
2441 2442 if opts['show_stage'] and opts['optimize']:
2442 2443 raise error.Abort(_('cannot use --optimize with --show-stage'))
2443 2444 if opts['show_stage'] == ['all']:
2444 2445 showalways.update(stagenames)
2445 2446 else:
2446 2447 for n in opts['show_stage']:
2447 2448 if n not in stagenames:
2448 2449 raise error.Abort(_('invalid stage name: %s') % n)
2449 2450 showalways.update(opts['show_stage'])
2450 2451
2451 2452 treebystage = {}
2452 2453 printedtree = None
2453 2454 tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
2454 2455 for n, f in stages:
2455 2456 treebystage[n] = tree = f(tree)
2456 2457 if n in showalways or (n in showchanged and tree != printedtree):
2457 2458 if opts['show_stage'] or n != 'parsed':
2458 2459 ui.write(("* %s:\n") % n)
2459 2460 ui.write(revsetlang.prettyformat(tree), "\n")
2460 2461 printedtree = tree
2461 2462
2462 2463 if opts['verify_optimized']:
2463 2464 arevs = revset.makematcher(treebystage['analyzed'])(repo)
2464 2465 brevs = revset.makematcher(treebystage['optimized'])(repo)
2465 2466 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2466 2467 ui.write(("* analyzed set:\n"), stringutil.prettyrepr(arevs), "\n")
2467 2468 ui.write(("* optimized set:\n"), stringutil.prettyrepr(brevs), "\n")
2468 2469 arevs = list(arevs)
2469 2470 brevs = list(brevs)
2470 2471 if arevs == brevs:
2471 2472 return 0
2472 2473 ui.write(('--- analyzed\n'), label='diff.file_a')
2473 2474 ui.write(('+++ optimized\n'), label='diff.file_b')
2474 2475 sm = difflib.SequenceMatcher(None, arevs, brevs)
2475 2476 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
2476 2477 if tag in ('delete', 'replace'):
2477 2478 for c in arevs[alo:ahi]:
2478 2479 ui.write('-%s\n' % c, label='diff.deleted')
2479 2480 if tag in ('insert', 'replace'):
2480 2481 for c in brevs[blo:bhi]:
2481 2482 ui.write('+%s\n' % c, label='diff.inserted')
2482 2483 if tag == 'equal':
2483 2484 for c in arevs[alo:ahi]:
2484 2485 ui.write(' %s\n' % c)
2485 2486 return 1
2486 2487
2487 2488 func = revset.makematcher(tree)
2488 2489 revs = func(repo)
2489 2490 if opts['show_set'] or (opts['show_set'] is None and ui.verbose):
2490 2491 ui.write(("* set:\n"), stringutil.prettyrepr(revs), "\n")
2491 2492 if not opts['show_revs']:
2492 2493 return
2493 2494 for c in revs:
2494 2495 ui.write("%d\n" % c)
2495 2496
2496 2497 @command('debugserve', [
2497 2498 ('', 'sshstdio', False, _('run an SSH server bound to process handles')),
2498 2499 ('', 'logiofd', '', _('file descriptor to log server I/O to')),
2499 2500 ('', 'logiofile', '', _('file to log server I/O to')),
2500 2501 ], '')
2501 2502 def debugserve(ui, repo, **opts):
2502 2503 """run a server with advanced settings
2503 2504
2504 2505 This command is similar to :hg:`serve`. It exists partially as a
2505 2506 workaround to the fact that ``hg serve --stdio`` must have specific
2506 2507 arguments for security reasons.
2507 2508 """
2508 2509 opts = pycompat.byteskwargs(opts)
2509 2510
2510 2511 if not opts['sshstdio']:
2511 2512 raise error.Abort(_('only --sshstdio is currently supported'))
2512 2513
2513 2514 logfh = None
2514 2515
2515 2516 if opts['logiofd'] and opts['logiofile']:
2516 2517 raise error.Abort(_('cannot use both --logiofd and --logiofile'))
2517 2518
2518 2519 if opts['logiofd']:
2519 2520 # Line buffered because output is line based.
2520 2521 try:
2521 2522 logfh = os.fdopen(int(opts['logiofd']), r'ab', 1)
2522 2523 except OSError as e:
2523 2524 if e.errno != errno.ESPIPE:
2524 2525 raise
2525 2526 # can't seek a pipe, so `ab` mode fails on py3
2526 2527 logfh = os.fdopen(int(opts['logiofd']), r'wb', 1)
2527 2528 elif opts['logiofile']:
2528 2529 logfh = open(opts['logiofile'], 'ab', 1)
2529 2530
2530 2531 s = wireprotoserver.sshserver(ui, repo, logfh=logfh)
2531 2532 s.serve_forever()
2532 2533
2533 2534 @command('debugsetparents', [], _('REV1 [REV2]'))
2534 2535 def debugsetparents(ui, repo, rev1, rev2=None):
2535 2536 """manually set the parents of the current working directory
2536 2537
2537 2538 This is useful for writing repository conversion tools, but should
2538 2539 be used with care. For example, neither the working directory nor the
2539 2540 dirstate is updated, so file status may be incorrect after running this
2540 2541 command.
2541 2542
2542 2543 Returns 0 on success.
2543 2544 """
2544 2545
2545 2546 node1 = scmutil.revsingle(repo, rev1).node()
2546 2547 node2 = scmutil.revsingle(repo, rev2, 'null').node()
2547 2548
2548 2549 with repo.wlock():
2549 2550 repo.setparents(node1, node2)
2550 2551
2551 2552 @command('debugssl', [], '[SOURCE]', optionalrepo=True)
2552 2553 def debugssl(ui, repo, source=None, **opts):
2553 2554 '''test a secure connection to a server
2554 2555
2555 2556 This builds the certificate chain for the server on Windows, installing the
2556 2557 missing intermediates and trusted root via Windows Update if necessary. It
2557 2558 does nothing on other platforms.
2558 2559
2559 2560 If SOURCE is omitted, the 'default' path will be used. If a URL is given,
2560 2561 that server is used. See :hg:`help urls` for more information.
2561 2562
2562 2563 If the update succeeds, retry the original operation. Otherwise, the cause
2563 2564 of the SSL error is likely another issue.
2564 2565 '''
2565 2566 if not pycompat.iswindows:
2566 2567 raise error.Abort(_('certificate chain building is only possible on '
2567 2568 'Windows'))
2568 2569
2569 2570 if not source:
2570 2571 if not repo:
2571 2572 raise error.Abort(_("there is no Mercurial repository here, and no "
2572 2573 "server specified"))
2573 2574 source = "default"
2574 2575
2575 2576 source, branches = hg.parseurl(ui.expandpath(source))
2576 2577 url = util.url(source)
2577 2578
2578 2579 defaultport = {'https': 443, 'ssh': 22}
2579 2580 if url.scheme in defaultport:
2580 2581 try:
2581 2582 addr = (url.host, int(url.port or defaultport[url.scheme]))
2582 2583 except ValueError:
2583 2584 raise error.Abort(_("malformed port number in URL"))
2584 2585 else:
2585 2586 raise error.Abort(_("only https and ssh connections are supported"))
2586 2587
2587 2588 from . import win32
2588 2589
2589 2590 s = ssl.wrap_socket(socket.socket(), ssl_version=ssl.PROTOCOL_TLS,
2590 2591 cert_reqs=ssl.CERT_NONE, ca_certs=None)
2591 2592
2592 2593 try:
2593 2594 s.connect(addr)
2594 2595 cert = s.getpeercert(True)
2595 2596
2596 2597 ui.status(_('checking the certificate chain for %s\n') % url.host)
2597 2598
2598 2599 complete = win32.checkcertificatechain(cert, build=False)
2599 2600
2600 2601 if not complete:
2601 2602 ui.status(_('certificate chain is incomplete, updating... '))
2602 2603
2603 2604 if not win32.checkcertificatechain(cert):
2604 2605 ui.status(_('failed.\n'))
2605 2606 else:
2606 2607 ui.status(_('done.\n'))
2607 2608 else:
2608 2609 ui.status(_('full certificate chain is available\n'))
2609 2610 finally:
2610 2611 s.close()
2611 2612
2612 2613 @command('debugsub',
2613 2614 [('r', 'rev', '',
2614 2615 _('revision to check'), _('REV'))],
2615 2616 _('[-r REV] [REV]'))
2616 2617 def debugsub(ui, repo, rev=None):
2617 2618 ctx = scmutil.revsingle(repo, rev, None)
2618 2619 for k, v in sorted(ctx.substate.items()):
2619 2620 ui.write(('path %s\n') % k)
2620 2621 ui.write((' source %s\n') % v[0])
2621 2622 ui.write((' revision %s\n') % v[1])
2622 2623
2623 2624 @command('debugsuccessorssets',
2624 2625 [('', 'closest', False, _('return closest successors sets only'))],
2625 2626 _('[REV]'))
2626 2627 def debugsuccessorssets(ui, repo, *revs, **opts):
2627 2628 """show set of successors for revision
2628 2629
2629 2630 A successors set of changeset A is a consistent group of revisions that
2630 2631 succeed A. It contains non-obsolete changesets only unless closests
2631 2632 successors set is set.
2632 2633
2633 2634 In most cases a changeset A has a single successors set containing a single
2634 2635 successor (changeset A replaced by A').
2635 2636
2636 2637 A changeset that is made obsolete with no successors are called "pruned".
2637 2638 Such changesets have no successors sets at all.
2638 2639
2639 2640 A changeset that has been "split" will have a successors set containing
2640 2641 more than one successor.
2641 2642
2642 2643 A changeset that has been rewritten in multiple different ways is called
2643 2644 "divergent". Such changesets have multiple successor sets (each of which
2644 2645 may also be split, i.e. have multiple successors).
2645 2646
2646 2647 Results are displayed as follows::
2647 2648
2648 2649 <rev1>
2649 2650 <successors-1A>
2650 2651 <rev2>
2651 2652 <successors-2A>
2652 2653 <successors-2B1> <successors-2B2> <successors-2B3>
2653 2654
2654 2655 Here rev2 has two possible (i.e. divergent) successors sets. The first
2655 2656 holds one element, whereas the second holds three (i.e. the changeset has
2656 2657 been split).
2657 2658 """
2658 2659 # passed to successorssets caching computation from one call to another
2659 2660 cache = {}
2660 2661 ctx2str = bytes
2661 2662 node2str = short
2662 2663 for rev in scmutil.revrange(repo, revs):
2663 2664 ctx = repo[rev]
2664 2665 ui.write('%s\n'% ctx2str(ctx))
2665 2666 for succsset in obsutil.successorssets(repo, ctx.node(),
2666 2667 closest=opts[r'closest'],
2667 2668 cache=cache):
2668 2669 if succsset:
2669 2670 ui.write(' ')
2670 2671 ui.write(node2str(succsset[0]))
2671 2672 for node in succsset[1:]:
2672 2673 ui.write(' ')
2673 2674 ui.write(node2str(node))
2674 2675 ui.write('\n')
2675 2676
2676 2677 @command('debugtemplate',
2677 2678 [('r', 'rev', [], _('apply template on changesets'), _('REV')),
2678 2679 ('D', 'define', [], _('define template keyword'), _('KEY=VALUE'))],
2679 2680 _('[-r REV]... [-D KEY=VALUE]... TEMPLATE'),
2680 2681 optionalrepo=True)
2681 2682 def debugtemplate(ui, repo, tmpl, **opts):
2682 2683 """parse and apply a template
2683 2684
2684 2685 If -r/--rev is given, the template is processed as a log template and
2685 2686 applied to the given changesets. Otherwise, it is processed as a generic
2686 2687 template.
2687 2688
2688 2689 Use --verbose to print the parsed tree.
2689 2690 """
2690 2691 revs = None
2691 2692 if opts[r'rev']:
2692 2693 if repo is None:
2693 2694 raise error.RepoError(_('there is no Mercurial repository here '
2694 2695 '(.hg not found)'))
2695 2696 revs = scmutil.revrange(repo, opts[r'rev'])
2696 2697
2697 2698 props = {}
2698 2699 for d in opts[r'define']:
2699 2700 try:
2700 2701 k, v = (e.strip() for e in d.split('=', 1))
2701 2702 if not k or k == 'ui':
2702 2703 raise ValueError
2703 2704 props[k] = v
2704 2705 except ValueError:
2705 2706 raise error.Abort(_('malformed keyword definition: %s') % d)
2706 2707
2707 2708 if ui.verbose:
2708 2709 aliases = ui.configitems('templatealias')
2709 2710 tree = templater.parse(tmpl)
2710 2711 ui.note(templater.prettyformat(tree), '\n')
2711 2712 newtree = templater.expandaliases(tree, aliases)
2712 2713 if newtree != tree:
2713 2714 ui.note(("* expanded:\n"), templater.prettyformat(newtree), '\n')
2714 2715
2715 2716 if revs is None:
2716 2717 tres = formatter.templateresources(ui, repo)
2717 2718 t = formatter.maketemplater(ui, tmpl, resources=tres)
2718 2719 if ui.verbose:
2719 2720 kwds, funcs = t.symbolsuseddefault()
2720 2721 ui.write(("* keywords: %s\n") % ', '.join(sorted(kwds)))
2721 2722 ui.write(("* functions: %s\n") % ', '.join(sorted(funcs)))
2722 2723 ui.write(t.renderdefault(props))
2723 2724 else:
2724 2725 displayer = logcmdutil.maketemplater(ui, repo, tmpl)
2725 2726 if ui.verbose:
2726 2727 kwds, funcs = displayer.t.symbolsuseddefault()
2727 2728 ui.write(("* keywords: %s\n") % ', '.join(sorted(kwds)))
2728 2729 ui.write(("* functions: %s\n") % ', '.join(sorted(funcs)))
2729 2730 for r in revs:
2730 2731 displayer.show(repo[r], **pycompat.strkwargs(props))
2731 2732 displayer.close()
2732 2733
2733 2734 @command('debuguigetpass', [
2734 2735 ('p', 'prompt', '', _('prompt text'), _('TEXT')),
2735 2736 ], _('[-p TEXT]'), norepo=True)
2736 2737 def debuguigetpass(ui, prompt=''):
2737 2738 """show prompt to type password"""
2738 2739 r = ui.getpass(prompt)
2739 2740 ui.write(('respose: %s\n') % r)
2740 2741
2741 2742 @command('debuguiprompt', [
2742 2743 ('p', 'prompt', '', _('prompt text'), _('TEXT')),
2743 2744 ], _('[-p TEXT]'), norepo=True)
2744 2745 def debuguiprompt(ui, prompt=''):
2745 2746 """show plain prompt"""
2746 2747 r = ui.prompt(prompt)
2747 2748 ui.write(('response: %s\n') % r)
2748 2749
2749 2750 @command('debugupdatecaches', [])
2750 2751 def debugupdatecaches(ui, repo, *pats, **opts):
2751 2752 """warm all known caches in the repository"""
2752 2753 with repo.wlock(), repo.lock():
2753 2754 repo.updatecaches(full=True)
2754 2755
2755 2756 @command('debugupgraderepo', [
2756 2757 ('o', 'optimize', [], _('extra optimization to perform'), _('NAME')),
2757 2758 ('', 'run', False, _('performs an upgrade')),
2758 2759 ('', 'backup', True, _('keep the old repository content around')),
2759 2760 ])
2760 2761 def debugupgraderepo(ui, repo, run=False, optimize=None, backup=True):
2761 2762 """upgrade a repository to use different features
2762 2763
2763 2764 If no arguments are specified, the repository is evaluated for upgrade
2764 2765 and a list of problems and potential optimizations is printed.
2765 2766
2766 2767 With ``--run``, a repository upgrade is performed. Behavior of the upgrade
2767 2768 can be influenced via additional arguments. More details will be provided
2768 2769 by the command output when run without ``--run``.
2769 2770
2770 2771 During the upgrade, the repository will be locked and no writes will be
2771 2772 allowed.
2772 2773
2773 2774 At the end of the upgrade, the repository may not be readable while new
2774 2775 repository data is swapped in. This window will be as long as it takes to
2775 2776 rename some directories inside the ``.hg`` directory. On most machines, this
2776 2777 should complete almost instantaneously and the chances of a consumer being
2777 2778 unable to access the repository should be low.
2778 2779 """
2779 2780 return upgrade.upgraderepo(ui, repo, run=run, optimize=optimize,
2780 2781 backup=backup)
2781 2782
2782 2783 @command('debugwalk', cmdutil.walkopts, _('[OPTION]... [FILE]...'),
2783 2784 inferrepo=True)
2784 2785 def debugwalk(ui, repo, *pats, **opts):
2785 2786 """show how files match on given patterns"""
2786 2787 opts = pycompat.byteskwargs(opts)
2787 2788 m = scmutil.match(repo[None], pats, opts)
2788 2789 if ui.verbose:
2789 2790 ui.write(('* matcher:\n'), stringutil.prettyrepr(m), '\n')
2790 2791 items = list(repo[None].walk(m))
2791 2792 if not items:
2792 2793 return
2793 2794 f = lambda fn: fn
2794 2795 if ui.configbool('ui', 'slash') and pycompat.ossep != '/':
2795 2796 f = lambda fn: util.normpath(fn)
2796 2797 fmt = 'f %%-%ds %%-%ds %%s' % (
2797 2798 max([len(abs) for abs in items]),
2798 2799 max([len(m.rel(abs)) for abs in items]))
2799 2800 for abs in items:
2800 2801 line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '')
2801 2802 ui.write("%s\n" % line.rstrip())
2802 2803
2803 2804 @command('debugwhyunstable', [], _('REV'))
2804 2805 def debugwhyunstable(ui, repo, rev):
2805 2806 """explain instabilities of a changeset"""
2806 2807 for entry in obsutil.whyunstable(repo, scmutil.revsingle(repo, rev)):
2807 2808 dnodes = ''
2808 2809 if entry.get('divergentnodes'):
2809 2810 dnodes = ' '.join('%s (%s)' % (ctx.hex(), ctx.phasestr())
2810 2811 for ctx in entry['divergentnodes']) + ' '
2811 2812 ui.write('%s: %s%s %s\n' % (entry['instability'], dnodes,
2812 2813 entry['reason'], entry['node']))
2813 2814
2814 2815 @command('debugwireargs',
2815 2816 [('', 'three', '', 'three'),
2816 2817 ('', 'four', '', 'four'),
2817 2818 ('', 'five', '', 'five'),
2818 2819 ] + cmdutil.remoteopts,
2819 2820 _('REPO [OPTIONS]... [ONE [TWO]]'),
2820 2821 norepo=True)
2821 2822 def debugwireargs(ui, repopath, *vals, **opts):
2822 2823 opts = pycompat.byteskwargs(opts)
2823 2824 repo = hg.peer(ui, opts, repopath)
2824 2825 for opt in cmdutil.remoteopts:
2825 2826 del opts[opt[1]]
2826 2827 args = {}
2827 2828 for k, v in opts.iteritems():
2828 2829 if v:
2829 2830 args[k] = v
2830 2831 args = pycompat.strkwargs(args)
2831 2832 # run twice to check that we don't mess up the stream for the next command
2832 2833 res1 = repo.debugwireargs(*vals, **args)
2833 2834 res2 = repo.debugwireargs(*vals, **args)
2834 2835 ui.write("%s\n" % res1)
2835 2836 if res1 != res2:
2836 2837 ui.warn("%s\n" % res2)
2837 2838
2838 2839 def _parsewirelangblocks(fh):
2839 2840 activeaction = None
2840 2841 blocklines = []
2841 2842 lastindent = 0
2842 2843
2843 2844 for line in fh:
2844 2845 line = line.rstrip()
2845 2846 if not line:
2846 2847 continue
2847 2848
2848 2849 if line.startswith(b'#'):
2849 2850 continue
2850 2851
2851 2852 if not line.startswith(b' '):
2852 2853 # New block. Flush previous one.
2853 2854 if activeaction:
2854 2855 yield activeaction, blocklines
2855 2856
2856 2857 activeaction = line
2857 2858 blocklines = []
2858 2859 lastindent = 0
2859 2860 continue
2860 2861
2861 2862 # Else we start with an indent.
2862 2863
2863 2864 if not activeaction:
2864 2865 raise error.Abort(_('indented line outside of block'))
2865 2866
2866 2867 indent = len(line) - len(line.lstrip())
2867 2868
2868 2869 # If this line is indented more than the last line, concatenate it.
2869 2870 if indent > lastindent and blocklines:
2870 2871 blocklines[-1] += line.lstrip()
2871 2872 else:
2872 2873 blocklines.append(line)
2873 2874 lastindent = indent
2874 2875
2875 2876 # Flush last block.
2876 2877 if activeaction:
2877 2878 yield activeaction, blocklines
2878 2879
2879 2880 @command('debugwireproto',
2880 2881 [
2881 2882 ('', 'localssh', False, _('start an SSH server for this repo')),
2882 2883 ('', 'peer', '', _('construct a specific version of the peer')),
2883 2884 ('', 'noreadstderr', False, _('do not read from stderr of the remote')),
2884 2885 ('', 'nologhandshake', False,
2885 2886 _('do not log I/O related to the peer handshake')),
2886 2887 ] + cmdutil.remoteopts,
2887 2888 _('[PATH]'),
2888 2889 optionalrepo=True)
2889 2890 def debugwireproto(ui, repo, path=None, **opts):
2890 2891 """send wire protocol commands to a server
2891 2892
2892 2893 This command can be used to issue wire protocol commands to remote
2893 2894 peers and to debug the raw data being exchanged.
2894 2895
2895 2896 ``--localssh`` will start an SSH server against the current repository
2896 2897 and connect to that. By default, the connection will perform a handshake
2897 2898 and establish an appropriate peer instance.
2898 2899
2899 2900 ``--peer`` can be used to bypass the handshake protocol and construct a
2900 2901 peer instance using the specified class type. Valid values are ``raw``,
2901 2902 ``http2``, ``ssh1``, and ``ssh2``. ``raw`` instances only allow sending
2902 2903 raw data payloads and don't support higher-level command actions.
2903 2904
2904 2905 ``--noreadstderr`` can be used to disable automatic reading from stderr
2905 2906 of the peer (for SSH connections only). Disabling automatic reading of
2906 2907 stderr is useful for making output more deterministic.
2907 2908
2908 2909 Commands are issued via a mini language which is specified via stdin.
2909 2910 The language consists of individual actions to perform. An action is
2910 2911 defined by a block. A block is defined as a line with no leading
2911 2912 space followed by 0 or more lines with leading space. Blocks are
2912 2913 effectively a high-level command with additional metadata.
2913 2914
2914 2915 Lines beginning with ``#`` are ignored.
2915 2916
2916 2917 The following sections denote available actions.
2917 2918
2918 2919 raw
2919 2920 ---
2920 2921
2921 2922 Send raw data to the server.
2922 2923
2923 2924 The block payload contains the raw data to send as one atomic send
2924 2925 operation. The data may not actually be delivered in a single system
2925 2926 call: it depends on the abilities of the transport being used.
2926 2927
2927 2928 Each line in the block is de-indented and concatenated. Then, that
2928 2929 value is evaluated as a Python b'' literal. This allows the use of
2929 2930 backslash escaping, etc.
2930 2931
2931 2932 raw+
2932 2933 ----
2933 2934
2934 2935 Behaves like ``raw`` except flushes output afterwards.
2935 2936
2936 2937 command <X>
2937 2938 -----------
2938 2939
2939 2940 Send a request to run a named command, whose name follows the ``command``
2940 2941 string.
2941 2942
2942 2943 Arguments to the command are defined as lines in this block. The format of
2943 2944 each line is ``<key> <value>``. e.g.::
2944 2945
2945 2946 command listkeys
2946 2947 namespace bookmarks
2947 2948
2948 2949 If the value begins with ``eval:``, it will be interpreted as a Python
2949 2950 literal expression. Otherwise values are interpreted as Python b'' literals.
2950 2951 This allows sending complex types and encoding special byte sequences via
2951 2952 backslash escaping.
2952 2953
2953 2954 The following arguments have special meaning:
2954 2955
2955 2956 ``PUSHFILE``
2956 2957 When defined, the *push* mechanism of the peer will be used instead
2957 2958 of the static request-response mechanism and the content of the
2958 2959 file specified in the value of this argument will be sent as the
2959 2960 command payload.
2960 2961
2961 2962 This can be used to submit a local bundle file to the remote.
2962 2963
2963 2964 batchbegin
2964 2965 ----------
2965 2966
2966 2967 Instruct the peer to begin a batched send.
2967 2968
2968 2969 All ``command`` blocks are queued for execution until the next
2969 2970 ``batchsubmit`` block.
2970 2971
2971 2972 batchsubmit
2972 2973 -----------
2973 2974
2974 2975 Submit previously queued ``command`` blocks as a batch request.
2975 2976
2976 2977 This action MUST be paired with a ``batchbegin`` action.
2977 2978
2978 2979 httprequest <method> <path>
2979 2980 ---------------------------
2980 2981
2981 2982 (HTTP peer only)
2982 2983
2983 2984 Send an HTTP request to the peer.
2984 2985
2985 2986 The HTTP request line follows the ``httprequest`` action. e.g. ``GET /foo``.
2986 2987
2987 2988 Arguments of the form ``<key>: <value>`` are interpreted as HTTP request
2988 2989 headers to add to the request. e.g. ``Accept: foo``.
2989 2990
2990 2991 The following arguments are special:
2991 2992
2992 2993 ``BODYFILE``
2993 2994 The content of the file defined as the value to this argument will be
2994 2995 transferred verbatim as the HTTP request body.
2995 2996
2996 2997 ``frame <type> <flags> <payload>``
2997 2998 Send a unified protocol frame as part of the request body.
2998 2999
2999 3000 All frames will be collected and sent as the body to the HTTP
3000 3001 request.
3001 3002
3002 3003 close
3003 3004 -----
3004 3005
3005 3006 Close the connection to the server.
3006 3007
3007 3008 flush
3008 3009 -----
3009 3010
3010 3011 Flush data written to the server.
3011 3012
3012 3013 readavailable
3013 3014 -------------
3014 3015
3015 3016 Close the write end of the connection and read all available data from
3016 3017 the server.
3017 3018
3018 3019 If the connection to the server encompasses multiple pipes, we poll both
3019 3020 pipes and read available data.
3020 3021
3021 3022 readline
3022 3023 --------
3023 3024
3024 3025 Read a line of output from the server. If there are multiple output
3025 3026 pipes, reads only the main pipe.
3026 3027
3027 3028 ereadline
3028 3029 ---------
3029 3030
3030 3031 Like ``readline``, but read from the stderr pipe, if available.
3031 3032
3032 3033 read <X>
3033 3034 --------
3034 3035
3035 3036 ``read()`` N bytes from the server's main output pipe.
3036 3037
3037 3038 eread <X>
3038 3039 ---------
3039 3040
3040 3041 ``read()`` N bytes from the server's stderr pipe, if available.
3041 3042
3042 3043 Specifying Unified Frame-Based Protocol Frames
3043 3044 ----------------------------------------------
3044 3045
3045 3046 It is possible to emit a *Unified Frame-Based Protocol* by using special
3046 3047 syntax.
3047 3048
3048 3049 A frame is composed as a type, flags, and payload. These can be parsed
3049 3050 from a string of the form:
3050 3051
3051 3052 <request-id> <stream-id> <stream-flags> <type> <flags> <payload>
3052 3053
3053 3054 ``request-id`` and ``stream-id`` are integers defining the request and
3054 3055 stream identifiers.
3055 3056
3056 3057 ``type`` can be an integer value for the frame type or the string name
3057 3058 of the type. The strings are defined in ``wireprotoframing.py``. e.g.
3058 3059 ``command-name``.
3059 3060
3060 3061 ``stream-flags`` and ``flags`` are a ``|`` delimited list of flag
3061 3062 components. Each component (and there can be just one) can be an integer
3062 3063 or a flag name for stream flags or frame flags, respectively. Values are
3063 3064 resolved to integers and then bitwise OR'd together.
3064 3065
3065 3066 ``payload`` represents the raw frame payload. If it begins with
3066 3067 ``cbor:``, the following string is evaluated as Python code and the
3067 3068 resulting object is fed into a CBOR encoder. Otherwise it is interpreted
3068 3069 as a Python byte string literal.
3069 3070 """
3070 3071 opts = pycompat.byteskwargs(opts)
3071 3072
3072 3073 if opts['localssh'] and not repo:
3073 3074 raise error.Abort(_('--localssh requires a repository'))
3074 3075
3075 3076 if opts['peer'] and opts['peer'] not in ('raw', 'http2', 'ssh1', 'ssh2'):
3076 3077 raise error.Abort(_('invalid value for --peer'),
3077 3078 hint=_('valid values are "raw", "ssh1", and "ssh2"'))
3078 3079
3079 3080 if path and opts['localssh']:
3080 3081 raise error.Abort(_('cannot specify --localssh with an explicit '
3081 3082 'path'))
3082 3083
3083 3084 if ui.interactive():
3084 3085 ui.write(_('(waiting for commands on stdin)\n'))
3085 3086
3086 3087 blocks = list(_parsewirelangblocks(ui.fin))
3087 3088
3088 3089 proc = None
3089 3090 stdin = None
3090 3091 stdout = None
3091 3092 stderr = None
3092 3093 opener = None
3093 3094
3094 3095 if opts['localssh']:
3095 3096 # We start the SSH server in its own process so there is process
3096 3097 # separation. This prevents a whole class of potential bugs around
3097 3098 # shared state from interfering with server operation.
3098 3099 args = procutil.hgcmd() + [
3099 3100 '-R', repo.root,
3100 3101 'debugserve', '--sshstdio',
3101 3102 ]
3102 3103 proc = subprocess.Popen(pycompat.rapply(procutil.tonativestr, args),
3103 3104 stdin=subprocess.PIPE,
3104 3105 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
3105 3106 bufsize=0)
3106 3107
3107 3108 stdin = proc.stdin
3108 3109 stdout = proc.stdout
3109 3110 stderr = proc.stderr
3110 3111
3111 3112 # We turn the pipes into observers so we can log I/O.
3112 3113 if ui.verbose or opts['peer'] == 'raw':
3113 3114 stdin = util.makeloggingfileobject(ui, proc.stdin, b'i',
3114 3115 logdata=True)
3115 3116 stdout = util.makeloggingfileobject(ui, proc.stdout, b'o',
3116 3117 logdata=True)
3117 3118 stderr = util.makeloggingfileobject(ui, proc.stderr, b'e',
3118 3119 logdata=True)
3119 3120
3120 3121 # --localssh also implies the peer connection settings.
3121 3122
3122 3123 url = 'ssh://localserver'
3123 3124 autoreadstderr = not opts['noreadstderr']
3124 3125
3125 3126 if opts['peer'] == 'ssh1':
3126 3127 ui.write(_('creating ssh peer for wire protocol version 1\n'))
3127 3128 peer = sshpeer.sshv1peer(ui, url, proc, stdin, stdout, stderr,
3128 3129 None, autoreadstderr=autoreadstderr)
3129 3130 elif opts['peer'] == 'ssh2':
3130 3131 ui.write(_('creating ssh peer for wire protocol version 2\n'))
3131 3132 peer = sshpeer.sshv2peer(ui, url, proc, stdin, stdout, stderr,
3132 3133 None, autoreadstderr=autoreadstderr)
3133 3134 elif opts['peer'] == 'raw':
3134 3135 ui.write(_('using raw connection to peer\n'))
3135 3136 peer = None
3136 3137 else:
3137 3138 ui.write(_('creating ssh peer from handshake results\n'))
3138 3139 peer = sshpeer.makepeer(ui, url, proc, stdin, stdout, stderr,
3139 3140 autoreadstderr=autoreadstderr)
3140 3141
3141 3142 elif path:
3142 3143 # We bypass hg.peer() so we can proxy the sockets.
3143 3144 # TODO consider not doing this because we skip
3144 3145 # ``hg.wirepeersetupfuncs`` and potentially other useful functionality.
3145 3146 u = util.url(path)
3146 3147 if u.scheme != 'http':
3147 3148 raise error.Abort(_('only http:// paths are currently supported'))
3148 3149
3149 3150 url, authinfo = u.authinfo()
3150 3151 openerargs = {
3151 3152 r'useragent': b'Mercurial debugwireproto',
3152 3153 }
3153 3154
3154 3155 # Turn pipes/sockets into observers so we can log I/O.
3155 3156 if ui.verbose:
3156 3157 openerargs.update({
3157 3158 r'loggingfh': ui,
3158 3159 r'loggingname': b's',
3159 3160 r'loggingopts': {
3160 3161 r'logdata': True,
3161 3162 r'logdataapis': False,
3162 3163 },
3163 3164 })
3164 3165
3165 3166 if ui.debugflag:
3166 3167 openerargs[r'loggingopts'][r'logdataapis'] = True
3167 3168
3168 3169 # Don't send default headers when in raw mode. This allows us to
3169 3170 # bypass most of the behavior of our URL handling code so we can
3170 3171 # have near complete control over what's sent on the wire.
3171 3172 if opts['peer'] == 'raw':
3172 3173 openerargs[r'sendaccept'] = False
3173 3174
3174 3175 opener = urlmod.opener(ui, authinfo, **openerargs)
3175 3176
3176 3177 if opts['peer'] == 'http2':
3177 3178 ui.write(_('creating http peer for wire protocol version 2\n'))
3178 3179 # We go through makepeer() because we need an API descriptor for
3179 3180 # the peer instance to be useful.
3180 3181 with ui.configoverride({
3181 3182 ('experimental', 'httppeer.advertise-v2'): True}):
3182 3183 if opts['nologhandshake']:
3183 3184 ui.pushbuffer()
3184 3185
3185 3186 peer = httppeer.makepeer(ui, path, opener=opener)
3186 3187
3187 3188 if opts['nologhandshake']:
3188 3189 ui.popbuffer()
3189 3190
3190 3191 if not isinstance(peer, httppeer.httpv2peer):
3191 3192 raise error.Abort(_('could not instantiate HTTP peer for '
3192 3193 'wire protocol version 2'),
3193 3194 hint=_('the server may not have the feature '
3194 3195 'enabled or is not allowing this '
3195 3196 'client version'))
3196 3197
3197 3198 elif opts['peer'] == 'raw':
3198 3199 ui.write(_('using raw connection to peer\n'))
3199 3200 peer = None
3200 3201 elif opts['peer']:
3201 3202 raise error.Abort(_('--peer %s not supported with HTTP peers') %
3202 3203 opts['peer'])
3203 3204 else:
3204 3205 peer = httppeer.makepeer(ui, path, opener=opener)
3205 3206
3206 3207 # We /could/ populate stdin/stdout with sock.makefile()...
3207 3208 else:
3208 3209 raise error.Abort(_('unsupported connection configuration'))
3209 3210
3210 3211 batchedcommands = None
3211 3212
3212 3213 # Now perform actions based on the parsed wire language instructions.
3213 3214 for action, lines in blocks:
3214 3215 if action in ('raw', 'raw+'):
3215 3216 if not stdin:
3216 3217 raise error.Abort(_('cannot call raw/raw+ on this peer'))
3217 3218
3218 3219 # Concatenate the data together.
3219 3220 data = ''.join(l.lstrip() for l in lines)
3220 3221 data = stringutil.unescapestr(data)
3221 3222 stdin.write(data)
3222 3223
3223 3224 if action == 'raw+':
3224 3225 stdin.flush()
3225 3226 elif action == 'flush':
3226 3227 if not stdin:
3227 3228 raise error.Abort(_('cannot call flush on this peer'))
3228 3229 stdin.flush()
3229 3230 elif action.startswith('command'):
3230 3231 if not peer:
3231 3232 raise error.Abort(_('cannot send commands unless peer instance '
3232 3233 'is available'))
3233 3234
3234 3235 command = action.split(' ', 1)[1]
3235 3236
3236 3237 args = {}
3237 3238 for line in lines:
3238 3239 # We need to allow empty values.
3239 3240 fields = line.lstrip().split(' ', 1)
3240 3241 if len(fields) == 1:
3241 3242 key = fields[0]
3242 3243 value = ''
3243 3244 else:
3244 3245 key, value = fields
3245 3246
3246 3247 if value.startswith('eval:'):
3247 3248 value = stringutil.evalpythonliteral(value[5:])
3248 3249 else:
3249 3250 value = stringutil.unescapestr(value)
3250 3251
3251 3252 args[key] = value
3252 3253
3253 3254 if batchedcommands is not None:
3254 3255 batchedcommands.append((command, args))
3255 3256 continue
3256 3257
3257 3258 ui.status(_('sending %s command\n') % command)
3258 3259
3259 3260 if 'PUSHFILE' in args:
3260 3261 with open(args['PUSHFILE'], r'rb') as fh:
3261 3262 del args['PUSHFILE']
3262 3263 res, output = peer._callpush(command, fh,
3263 3264 **pycompat.strkwargs(args))
3264 3265 ui.status(_('result: %s\n') % stringutil.escapestr(res))
3265 3266 ui.status(_('remote output: %s\n') %
3266 3267 stringutil.escapestr(output))
3267 3268 else:
3268 3269 with peer.commandexecutor() as e:
3269 3270 res = e.callcommand(command, args).result()
3270 3271
3271 3272 if isinstance(res, wireprotov2peer.commandresponse):
3272 3273 val = res.objects()
3273 3274 ui.status(_('response: %s\n') %
3274 3275 stringutil.pprint(val, bprefix=True, indent=2))
3275 3276 else:
3276 3277 ui.status(_('response: %s\n') %
3277 3278 stringutil.pprint(res, bprefix=True, indent=2))
3278 3279
3279 3280 elif action == 'batchbegin':
3280 3281 if batchedcommands is not None:
3281 3282 raise error.Abort(_('nested batchbegin not allowed'))
3282 3283
3283 3284 batchedcommands = []
3284 3285 elif action == 'batchsubmit':
3285 3286 # There is a batching API we could go through. But it would be
3286 3287 # difficult to normalize requests into function calls. It is easier
3287 3288 # to bypass this layer and normalize to commands + args.
3288 3289 ui.status(_('sending batch with %d sub-commands\n') %
3289 3290 len(batchedcommands))
3290 3291 for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
3291 3292 ui.status(_('response #%d: %s\n') %
3292 3293 (i, stringutil.escapestr(chunk)))
3293 3294
3294 3295 batchedcommands = None
3295 3296
3296 3297 elif action.startswith('httprequest '):
3297 3298 if not opener:
3298 3299 raise error.Abort(_('cannot use httprequest without an HTTP '
3299 3300 'peer'))
3300 3301
3301 3302 request = action.split(' ', 2)
3302 3303 if len(request) != 3:
3303 3304 raise error.Abort(_('invalid httprequest: expected format is '
3304 3305 '"httprequest <method> <path>'))
3305 3306
3306 3307 method, httppath = request[1:]
3307 3308 headers = {}
3308 3309 body = None
3309 3310 frames = []
3310 3311 for line in lines:
3311 3312 line = line.lstrip()
3312 3313 m = re.match(b'^([a-zA-Z0-9_-]+): (.*)$', line)
3313 3314 if m:
3314 3315 # Headers need to use native strings.
3315 3316 key = pycompat.strurl(m.group(1))
3316 3317 value = pycompat.strurl(m.group(2))
3317 3318 headers[key] = value
3318 3319 continue
3319 3320
3320 3321 if line.startswith(b'BODYFILE '):
3321 3322 with open(line.split(b' ', 1), 'rb') as fh:
3322 3323 body = fh.read()
3323 3324 elif line.startswith(b'frame '):
3324 3325 frame = wireprotoframing.makeframefromhumanstring(
3325 3326 line[len(b'frame '):])
3326 3327
3327 3328 frames.append(frame)
3328 3329 else:
3329 3330 raise error.Abort(_('unknown argument to httprequest: %s') %
3330 3331 line)
3331 3332
3332 3333 url = path + httppath
3333 3334
3334 3335 if frames:
3335 3336 body = b''.join(bytes(f) for f in frames)
3336 3337
3337 3338 req = urlmod.urlreq.request(pycompat.strurl(url), body, headers)
3338 3339
3339 3340 # urllib.Request insists on using has_data() as a proxy for
3340 3341 # determining the request method. Override that to use our
3341 3342 # explicitly requested method.
3342 3343 req.get_method = lambda: pycompat.sysstr(method)
3343 3344
3344 3345 try:
3345 3346 res = opener.open(req)
3346 3347 body = res.read()
3347 3348 except util.urlerr.urlerror as e:
3348 3349 # read() method must be called, but only exists in Python 2
3349 3350 getattr(e, 'read', lambda: None)()
3350 3351 continue
3351 3352
3352 3353 ct = res.headers.get(r'Content-Type')
3353 3354 if ct == r'application/mercurial-cbor':
3354 3355 ui.write(_('cbor> %s\n') %
3355 3356 stringutil.pprint(cborutil.decodeall(body),
3356 3357 bprefix=True,
3357 3358 indent=2))
3358 3359
3359 3360 elif action == 'close':
3360 3361 peer.close()
3361 3362 elif action == 'readavailable':
3362 3363 if not stdout or not stderr:
3363 3364 raise error.Abort(_('readavailable not available on this peer'))
3364 3365
3365 3366 stdin.close()
3366 3367 stdout.read()
3367 3368 stderr.read()
3368 3369
3369 3370 elif action == 'readline':
3370 3371 if not stdout:
3371 3372 raise error.Abort(_('readline not available on this peer'))
3372 3373 stdout.readline()
3373 3374 elif action == 'ereadline':
3374 3375 if not stderr:
3375 3376 raise error.Abort(_('ereadline not available on this peer'))
3376 3377 stderr.readline()
3377 3378 elif action.startswith('read '):
3378 3379 count = int(action.split(' ', 1)[1])
3379 3380 if not stdout:
3380 3381 raise error.Abort(_('read not available on this peer'))
3381 3382 stdout.read(count)
3382 3383 elif action.startswith('eread '):
3383 3384 count = int(action.split(' ', 1)[1])
3384 3385 if not stderr:
3385 3386 raise error.Abort(_('eread not available on this peer'))
3386 3387 stderr.read(count)
3387 3388 else:
3388 3389 raise error.Abort(_('unknown action: %s') % action)
3389 3390
3390 3391 if batchedcommands is not None:
3391 3392 raise error.Abort(_('unclosed "batchbegin" request'))
3392 3393
3393 3394 if peer:
3394 3395 peer.close()
3395 3396
3396 3397 if proc:
3397 3398 proc.kill()
General Comments 0
You need to be logged in to leave comments. Login now