##// END OF EJS Templates
annotate: add support to specify hidden revs if directaccess config is set...
Pulkit Goyal -
r35552:b6ce3568 default
parent child Browse files
Show More
@@ -1,5617 +1,5620 b''
1 1 # commands.py - command processing for mercurial
2 2 #
3 3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import difflib
11 11 import errno
12 12 import os
13 13 import re
14 14 import sys
15 15
16 16 from .i18n import _
17 17 from .node import (
18 18 hex,
19 19 nullid,
20 20 nullrev,
21 21 short,
22 22 )
23 23 from . import (
24 24 archival,
25 25 bookmarks,
26 26 bundle2,
27 27 changegroup,
28 28 cmdutil,
29 29 copies,
30 30 debugcommands as debugcommandsmod,
31 31 destutil,
32 32 dirstateguard,
33 33 discovery,
34 34 encoding,
35 35 error,
36 36 exchange,
37 37 extensions,
38 38 formatter,
39 39 graphmod,
40 40 hbisect,
41 41 help,
42 42 hg,
43 43 lock as lockmod,
44 44 merge as mergemod,
45 45 obsolete,
46 46 patch,
47 47 phases,
48 48 pycompat,
49 49 rcutil,
50 50 registrar,
51 51 revsetlang,
52 52 rewriteutil,
53 53 scmutil,
54 54 server,
55 55 sshserver,
56 56 streamclone,
57 57 tags as tagsmod,
58 58 templatekw,
59 59 ui as uimod,
60 60 util,
61 61 )
62 62
63 63 release = lockmod.release
64 64
65 65 table = {}
66 66 table.update(debugcommandsmod.command._table)
67 67
68 68 command = registrar.command(table)
69 69 readonly = registrar.command.readonly
70 70
71 71 # common command options
72 72
73 73 globalopts = [
74 74 ('R', 'repository', '',
75 75 _('repository root directory or name of overlay bundle file'),
76 76 _('REPO')),
77 77 ('', 'cwd', '',
78 78 _('change working directory'), _('DIR')),
79 79 ('y', 'noninteractive', None,
80 80 _('do not prompt, automatically pick the first choice for all prompts')),
81 81 ('q', 'quiet', None, _('suppress output')),
82 82 ('v', 'verbose', None, _('enable additional output')),
83 83 ('', 'color', '',
84 84 # i18n: 'always', 'auto', 'never', and 'debug' are keywords
85 85 # and should not be translated
86 86 _("when to colorize (boolean, always, auto, never, or debug)"),
87 87 _('TYPE')),
88 88 ('', 'config', [],
89 89 _('set/override config option (use \'section.name=value\')'),
90 90 _('CONFIG')),
91 91 ('', 'debug', None, _('enable debugging output')),
92 92 ('', 'debugger', None, _('start debugger')),
93 93 ('', 'encoding', encoding.encoding, _('set the charset encoding'),
94 94 _('ENCODE')),
95 95 ('', 'encodingmode', encoding.encodingmode,
96 96 _('set the charset encoding mode'), _('MODE')),
97 97 ('', 'traceback', None, _('always print a traceback on exception')),
98 98 ('', 'time', None, _('time how long the command takes')),
99 99 ('', 'profile', None, _('print command execution profile')),
100 100 ('', 'version', None, _('output version information and exit')),
101 101 ('h', 'help', None, _('display help and exit')),
102 102 ('', 'hidden', False, _('consider hidden changesets')),
103 103 ('', 'pager', 'auto',
104 104 _("when to paginate (boolean, always, auto, or never)"), _('TYPE')),
105 105 ]
106 106
107 107 dryrunopts = cmdutil.dryrunopts
108 108 remoteopts = cmdutil.remoteopts
109 109 walkopts = cmdutil.walkopts
110 110 commitopts = cmdutil.commitopts
111 111 commitopts2 = cmdutil.commitopts2
112 112 formatteropts = cmdutil.formatteropts
113 113 templateopts = cmdutil.templateopts
114 114 logopts = cmdutil.logopts
115 115 diffopts = cmdutil.diffopts
116 116 diffwsopts = cmdutil.diffwsopts
117 117 diffopts2 = cmdutil.diffopts2
118 118 mergetoolopts = cmdutil.mergetoolopts
119 119 similarityopts = cmdutil.similarityopts
120 120 subrepoopts = cmdutil.subrepoopts
121 121 debugrevlogopts = cmdutil.debugrevlogopts
122 122
123 123 # Commands start here, listed alphabetically
124 124
125 125 @command('^add',
126 126 walkopts + subrepoopts + dryrunopts,
127 127 _('[OPTION]... [FILE]...'),
128 128 inferrepo=True)
129 129 def add(ui, repo, *pats, **opts):
130 130 """add the specified files on the next commit
131 131
132 132 Schedule files to be version controlled and added to the
133 133 repository.
134 134
135 135 The files will be added to the repository at the next commit. To
136 136 undo an add before that, see :hg:`forget`.
137 137
138 138 If no names are given, add all files to the repository (except
139 139 files matching ``.hgignore``).
140 140
141 141 .. container:: verbose
142 142
143 143 Examples:
144 144
145 145 - New (unknown) files are added
146 146 automatically by :hg:`add`::
147 147
148 148 $ ls
149 149 foo.c
150 150 $ hg status
151 151 ? foo.c
152 152 $ hg add
153 153 adding foo.c
154 154 $ hg status
155 155 A foo.c
156 156
157 157 - Specific files to be added can be specified::
158 158
159 159 $ ls
160 160 bar.c foo.c
161 161 $ hg status
162 162 ? bar.c
163 163 ? foo.c
164 164 $ hg add bar.c
165 165 $ hg status
166 166 A bar.c
167 167 ? foo.c
168 168
169 169 Returns 0 if all files are successfully added.
170 170 """
171 171
172 172 m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts))
173 173 rejected = cmdutil.add(ui, repo, m, "", False, **opts)
174 174 return rejected and 1 or 0
175 175
176 176 @command('addremove',
177 177 similarityopts + subrepoopts + walkopts + dryrunopts,
178 178 _('[OPTION]... [FILE]...'),
179 179 inferrepo=True)
180 180 def addremove(ui, repo, *pats, **opts):
181 181 """add all new files, delete all missing files
182 182
183 183 Add all new files and remove all missing files from the
184 184 repository.
185 185
186 186 Unless names are given, new files are ignored if they match any of
187 187 the patterns in ``.hgignore``. As with add, these changes take
188 188 effect at the next commit.
189 189
190 190 Use the -s/--similarity option to detect renamed files. This
191 191 option takes a percentage between 0 (disabled) and 100 (files must
192 192 be identical) as its parameter. With a parameter greater than 0,
193 193 this compares every removed file with every added file and records
194 194 those similar enough as renames. Detecting renamed files this way
195 195 can be expensive. After using this option, :hg:`status -C` can be
196 196 used to check which files were identified as moved or renamed. If
197 197 not specified, -s/--similarity defaults to 100 and only renames of
198 198 identical files are detected.
199 199
200 200 .. container:: verbose
201 201
202 202 Examples:
203 203
204 204 - A number of files (bar.c and foo.c) are new,
205 205 while foobar.c has been removed (without using :hg:`remove`)
206 206 from the repository::
207 207
208 208 $ ls
209 209 bar.c foo.c
210 210 $ hg status
211 211 ! foobar.c
212 212 ? bar.c
213 213 ? foo.c
214 214 $ hg addremove
215 215 adding bar.c
216 216 adding foo.c
217 217 removing foobar.c
218 218 $ hg status
219 219 A bar.c
220 220 A foo.c
221 221 R foobar.c
222 222
223 223 - A file foobar.c was moved to foo.c without using :hg:`rename`.
224 224 Afterwards, it was edited slightly::
225 225
226 226 $ ls
227 227 foo.c
228 228 $ hg status
229 229 ! foobar.c
230 230 ? foo.c
231 231 $ hg addremove --similarity 90
232 232 removing foobar.c
233 233 adding foo.c
234 234 recording removal of foobar.c as rename to foo.c (94% similar)
235 235 $ hg status -C
236 236 A foo.c
237 237 foobar.c
238 238 R foobar.c
239 239
240 240 Returns 0 if all files are successfully added.
241 241 """
242 242 opts = pycompat.byteskwargs(opts)
243 243 try:
244 244 sim = float(opts.get('similarity') or 100)
245 245 except ValueError:
246 246 raise error.Abort(_('similarity must be a number'))
247 247 if sim < 0 or sim > 100:
248 248 raise error.Abort(_('similarity must be between 0 and 100'))
249 249 matcher = scmutil.match(repo[None], pats, opts)
250 250 return scmutil.addremove(repo, matcher, "", opts, similarity=sim / 100.0)
251 251
252 252 @command('^annotate|blame',
253 253 [('r', 'rev', '', _('annotate the specified revision'), _('REV')),
254 254 ('', 'follow', None,
255 255 _('follow copies/renames and list the filename (DEPRECATED)')),
256 256 ('', 'no-follow', None, _("don't follow copies and renames")),
257 257 ('a', 'text', None, _('treat all files as text')),
258 258 ('u', 'user', None, _('list the author (long with -v)')),
259 259 ('f', 'file', None, _('list the filename')),
260 260 ('d', 'date', None, _('list the date (short with -q)')),
261 261 ('n', 'number', None, _('list the revision number (default)')),
262 262 ('c', 'changeset', None, _('list the changeset')),
263 263 ('l', 'line-number', None, _('show line number at the first appearance')),
264 264 ('', 'skip', [], _('revision to not display (EXPERIMENTAL)'), _('REV')),
265 265 ] + diffwsopts + walkopts + formatteropts,
266 266 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
267 267 inferrepo=True)
268 268 def annotate(ui, repo, *pats, **opts):
269 269 """show changeset information by line for each file
270 270
271 271 List changes in files, showing the revision id responsible for
272 272 each line.
273 273
274 274 This command is useful for discovering when a change was made and
275 275 by whom.
276 276
277 277 If you include --file, --user, or --date, the revision number is
278 278 suppressed unless you also include --number.
279 279
280 280 Without the -a/--text option, annotate will avoid processing files
281 281 it detects as binary. With -a, annotate will annotate the file
282 282 anyway, although the results will probably be neither useful
283 283 nor desirable.
284 284
285 285 Returns 0 on success.
286 286 """
287 287 opts = pycompat.byteskwargs(opts)
288 288 if not pats:
289 289 raise error.Abort(_('at least one filename or pattern is required'))
290 290
291 291 if opts.get('follow'):
292 292 # --follow is deprecated and now just an alias for -f/--file
293 293 # to mimic the behavior of Mercurial before version 1.5
294 294 opts['file'] = True
295 295
296 ctx = scmutil.revsingle(repo, opts.get('rev'))
296 rev = opts.get('rev')
297 if rev:
298 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
299 ctx = scmutil.revsingle(repo, rev)
297 300
298 301 rootfm = ui.formatter('annotate', opts)
299 302 if ui.quiet:
300 303 datefunc = util.shortdate
301 304 else:
302 305 datefunc = util.datestr
303 306 if ctx.rev() is None:
304 307 def hexfn(node):
305 308 if node is None:
306 309 return None
307 310 else:
308 311 return rootfm.hexfunc(node)
309 312 if opts.get('changeset'):
310 313 # omit "+" suffix which is appended to node hex
311 314 def formatrev(rev):
312 315 if rev is None:
313 316 return '%d' % ctx.p1().rev()
314 317 else:
315 318 return '%d' % rev
316 319 else:
317 320 def formatrev(rev):
318 321 if rev is None:
319 322 return '%d+' % ctx.p1().rev()
320 323 else:
321 324 return '%d ' % rev
322 325 def formathex(hex):
323 326 if hex is None:
324 327 return '%s+' % rootfm.hexfunc(ctx.p1().node())
325 328 else:
326 329 return '%s ' % hex
327 330 else:
328 331 hexfn = rootfm.hexfunc
329 332 formatrev = formathex = pycompat.bytestr
330 333
331 334 opmap = [('user', ' ', lambda x: x.fctx.user(), ui.shortuser),
332 335 ('number', ' ', lambda x: x.fctx.rev(), formatrev),
333 336 ('changeset', ' ', lambda x: hexfn(x.fctx.node()), formathex),
334 337 ('date', ' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
335 338 ('file', ' ', lambda x: x.fctx.path(), str),
336 339 ('line_number', ':', lambda x: x.lineno, str),
337 340 ]
338 341 fieldnamemap = {'number': 'rev', 'changeset': 'node'}
339 342
340 343 if (not opts.get('user') and not opts.get('changeset')
341 344 and not opts.get('date') and not opts.get('file')):
342 345 opts['number'] = True
343 346
344 347 linenumber = opts.get('line_number') is not None
345 348 if linenumber and (not opts.get('changeset')) and (not opts.get('number')):
346 349 raise error.Abort(_('at least one of -n/-c is required for -l'))
347 350
348 351 ui.pager('annotate')
349 352
350 353 if rootfm.isplain():
351 354 def makefunc(get, fmt):
352 355 return lambda x: fmt(get(x))
353 356 else:
354 357 def makefunc(get, fmt):
355 358 return get
356 359 funcmap = [(makefunc(get, fmt), sep) for op, sep, get, fmt in opmap
357 360 if opts.get(op)]
358 361 funcmap[0] = (funcmap[0][0], '') # no separator in front of first column
359 362 fields = ' '.join(fieldnamemap.get(op, op) for op, sep, get, fmt in opmap
360 363 if opts.get(op))
361 364
362 365 def bad(x, y):
363 366 raise error.Abort("%s: %s" % (x, y))
364 367
365 368 m = scmutil.match(ctx, pats, opts, badfn=bad)
366 369
367 370 follow = not opts.get('no_follow')
368 371 diffopts = patch.difffeatureopts(ui, opts, section='annotate',
369 372 whitespace=True)
370 373 skiprevs = opts.get('skip')
371 374 if skiprevs:
372 375 skiprevs = scmutil.revrange(repo, skiprevs)
373 376
374 377 for abs in ctx.walk(m):
375 378 fctx = ctx[abs]
376 379 rootfm.startitem()
377 380 rootfm.data(abspath=abs, path=m.rel(abs))
378 381 if not opts.get('text') and fctx.isbinary():
379 382 rootfm.plain(_("%s: binary file\n")
380 383 % ((pats and m.rel(abs)) or abs))
381 384 continue
382 385
383 386 fm = rootfm.nested('lines')
384 387 lines = fctx.annotate(follow=follow, linenumber=linenumber,
385 388 skiprevs=skiprevs, diffopts=diffopts)
386 389 if not lines:
387 390 fm.end()
388 391 continue
389 392 formats = []
390 393 pieces = []
391 394
392 395 for f, sep in funcmap:
393 396 l = [f(n) for n, dummy in lines]
394 397 if fm.isplain():
395 398 sizes = [encoding.colwidth(x) for x in l]
396 399 ml = max(sizes)
397 400 formats.append([sep + ' ' * (ml - w) + '%s' for w in sizes])
398 401 else:
399 402 formats.append(['%s' for x in l])
400 403 pieces.append(l)
401 404
402 405 for f, p, l in zip(zip(*formats), zip(*pieces), lines):
403 406 fm.startitem()
404 407 fm.write(fields, "".join(f), *p)
405 408 if l[0].skip:
406 409 fmt = "* %s"
407 410 else:
408 411 fmt = ": %s"
409 412 fm.write('line', fmt, l[1])
410 413
411 414 if not lines[-1][1].endswith('\n'):
412 415 fm.plain('\n')
413 416 fm.end()
414 417
415 418 rootfm.end()
416 419
417 420 @command('archive',
418 421 [('', 'no-decode', None, _('do not pass files through decoders')),
419 422 ('p', 'prefix', '', _('directory prefix for files in archive'),
420 423 _('PREFIX')),
421 424 ('r', 'rev', '', _('revision to distribute'), _('REV')),
422 425 ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
423 426 ] + subrepoopts + walkopts,
424 427 _('[OPTION]... DEST'))
425 428 def archive(ui, repo, dest, **opts):
426 429 '''create an unversioned archive of a repository revision
427 430
428 431 By default, the revision used is the parent of the working
429 432 directory; use -r/--rev to specify a different revision.
430 433
431 434 The archive type is automatically detected based on file
432 435 extension (to override, use -t/--type).
433 436
434 437 .. container:: verbose
435 438
436 439 Examples:
437 440
438 441 - create a zip file containing the 1.0 release::
439 442
440 443 hg archive -r 1.0 project-1.0.zip
441 444
442 445 - create a tarball excluding .hg files::
443 446
444 447 hg archive project.tar.gz -X ".hg*"
445 448
446 449 Valid types are:
447 450
448 451 :``files``: a directory full of files (default)
449 452 :``tar``: tar archive, uncompressed
450 453 :``tbz2``: tar archive, compressed using bzip2
451 454 :``tgz``: tar archive, compressed using gzip
452 455 :``uzip``: zip archive, uncompressed
453 456 :``zip``: zip archive, compressed using deflate
454 457
455 458 The exact name of the destination archive or directory is given
456 459 using a format string; see :hg:`help export` for details.
457 460
458 461 Each member added to an archive file has a directory prefix
459 462 prepended. Use -p/--prefix to specify a format string for the
460 463 prefix. The default is the basename of the archive, with suffixes
461 464 removed.
462 465
463 466 Returns 0 on success.
464 467 '''
465 468
466 469 opts = pycompat.byteskwargs(opts)
467 470 ctx = scmutil.revsingle(repo, opts.get('rev'))
468 471 if not ctx:
469 472 raise error.Abort(_('no working directory: please specify a revision'))
470 473 node = ctx.node()
471 474 dest = cmdutil.makefilename(repo, dest, node)
472 475 if os.path.realpath(dest) == repo.root:
473 476 raise error.Abort(_('repository root cannot be destination'))
474 477
475 478 kind = opts.get('type') or archival.guesskind(dest) or 'files'
476 479 prefix = opts.get('prefix')
477 480
478 481 if dest == '-':
479 482 if kind == 'files':
480 483 raise error.Abort(_('cannot archive plain files to stdout'))
481 484 dest = cmdutil.makefileobj(repo, dest)
482 485 if not prefix:
483 486 prefix = os.path.basename(repo.root) + '-%h'
484 487
485 488 prefix = cmdutil.makefilename(repo, prefix, node)
486 489 match = scmutil.match(ctx, [], opts)
487 490 archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
488 491 match, prefix, subrepos=opts.get('subrepos'))
489 492
490 493 @command('backout',
491 494 [('', 'merge', None, _('merge with old dirstate parent after backout')),
492 495 ('', 'commit', None,
493 496 _('commit if no conflicts were encountered (DEPRECATED)')),
494 497 ('', 'no-commit', None, _('do not commit')),
495 498 ('', 'parent', '',
496 499 _('parent to choose when backing out merge (DEPRECATED)'), _('REV')),
497 500 ('r', 'rev', '', _('revision to backout'), _('REV')),
498 501 ('e', 'edit', False, _('invoke editor on commit messages')),
499 502 ] + mergetoolopts + walkopts + commitopts + commitopts2,
500 503 _('[OPTION]... [-r] REV'))
501 504 def backout(ui, repo, node=None, rev=None, **opts):
502 505 '''reverse effect of earlier changeset
503 506
504 507 Prepare a new changeset with the effect of REV undone in the
505 508 current working directory. If no conflicts were encountered,
506 509 it will be committed immediately.
507 510
508 511 If REV is the parent of the working directory, then this new changeset
509 512 is committed automatically (unless --no-commit is specified).
510 513
511 514 .. note::
512 515
513 516 :hg:`backout` cannot be used to fix either an unwanted or
514 517 incorrect merge.
515 518
516 519 .. container:: verbose
517 520
518 521 Examples:
519 522
520 523 - Reverse the effect of the parent of the working directory.
521 524 This backout will be committed immediately::
522 525
523 526 hg backout -r .
524 527
525 528 - Reverse the effect of previous bad revision 23::
526 529
527 530 hg backout -r 23
528 531
529 532 - Reverse the effect of previous bad revision 23 and
530 533 leave changes uncommitted::
531 534
532 535 hg backout -r 23 --no-commit
533 536 hg commit -m "Backout revision 23"
534 537
535 538 By default, the pending changeset will have one parent,
536 539 maintaining a linear history. With --merge, the pending
537 540 changeset will instead have two parents: the old parent of the
538 541 working directory and a new child of REV that simply undoes REV.
539 542
540 543 Before version 1.7, the behavior without --merge was equivalent
541 544 to specifying --merge followed by :hg:`update --clean .` to
542 545 cancel the merge and leave the child of REV as a head to be
543 546 merged separately.
544 547
545 548 See :hg:`help dates` for a list of formats valid for -d/--date.
546 549
547 550 See :hg:`help revert` for a way to restore files to the state
548 551 of another revision.
549 552
550 553 Returns 0 on success, 1 if nothing to backout or there are unresolved
551 554 files.
552 555 '''
553 556 wlock = lock = None
554 557 try:
555 558 wlock = repo.wlock()
556 559 lock = repo.lock()
557 560 return _dobackout(ui, repo, node, rev, **opts)
558 561 finally:
559 562 release(lock, wlock)
560 563
561 564 def _dobackout(ui, repo, node=None, rev=None, **opts):
562 565 opts = pycompat.byteskwargs(opts)
563 566 if opts.get('commit') and opts.get('no_commit'):
564 567 raise error.Abort(_("cannot use --commit with --no-commit"))
565 568 if opts.get('merge') and opts.get('no_commit'):
566 569 raise error.Abort(_("cannot use --merge with --no-commit"))
567 570
568 571 if rev and node:
569 572 raise error.Abort(_("please specify just one revision"))
570 573
571 574 if not rev:
572 575 rev = node
573 576
574 577 if not rev:
575 578 raise error.Abort(_("please specify a revision to backout"))
576 579
577 580 date = opts.get('date')
578 581 if date:
579 582 opts['date'] = util.parsedate(date)
580 583
581 584 cmdutil.checkunfinished(repo)
582 585 cmdutil.bailifchanged(repo)
583 586 node = scmutil.revsingle(repo, rev).node()
584 587
585 588 op1, op2 = repo.dirstate.parents()
586 589 if not repo.changelog.isancestor(node, op1):
587 590 raise error.Abort(_('cannot backout change that is not an ancestor'))
588 591
589 592 p1, p2 = repo.changelog.parents(node)
590 593 if p1 == nullid:
591 594 raise error.Abort(_('cannot backout a change with no parents'))
592 595 if p2 != nullid:
593 596 if not opts.get('parent'):
594 597 raise error.Abort(_('cannot backout a merge changeset'))
595 598 p = repo.lookup(opts['parent'])
596 599 if p not in (p1, p2):
597 600 raise error.Abort(_('%s is not a parent of %s') %
598 601 (short(p), short(node)))
599 602 parent = p
600 603 else:
601 604 if opts.get('parent'):
602 605 raise error.Abort(_('cannot use --parent on non-merge changeset'))
603 606 parent = p1
604 607
605 608 # the backout should appear on the same branch
606 609 branch = repo.dirstate.branch()
607 610 bheads = repo.branchheads(branch)
608 611 rctx = scmutil.revsingle(repo, hex(parent))
609 612 if not opts.get('merge') and op1 != node:
610 613 dsguard = dirstateguard.dirstateguard(repo, 'backout')
611 614 try:
612 615 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
613 616 'backout')
614 617 stats = mergemod.update(repo, parent, True, True, node, False)
615 618 repo.setparents(op1, op2)
616 619 dsguard.close()
617 620 hg._showstats(repo, stats)
618 621 if stats[3]:
619 622 repo.ui.status(_("use 'hg resolve' to retry unresolved "
620 623 "file merges\n"))
621 624 return 1
622 625 finally:
623 626 ui.setconfig('ui', 'forcemerge', '', '')
624 627 lockmod.release(dsguard)
625 628 else:
626 629 hg.clean(repo, node, show_stats=False)
627 630 repo.dirstate.setbranch(branch)
628 631 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents())
629 632
630 633 if opts.get('no_commit'):
631 634 msg = _("changeset %s backed out, "
632 635 "don't forget to commit.\n")
633 636 ui.status(msg % short(node))
634 637 return 0
635 638
636 639 def commitfunc(ui, repo, message, match, opts):
637 640 editform = 'backout'
638 641 e = cmdutil.getcommiteditor(editform=editform,
639 642 **pycompat.strkwargs(opts))
640 643 if not message:
641 644 # we don't translate commit messages
642 645 message = "Backed out changeset %s" % short(node)
643 646 e = cmdutil.getcommiteditor(edit=True, editform=editform)
644 647 return repo.commit(message, opts.get('user'), opts.get('date'),
645 648 match, editor=e)
646 649 newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
647 650 if not newnode:
648 651 ui.status(_("nothing changed\n"))
649 652 return 1
650 653 cmdutil.commitstatus(repo, newnode, branch, bheads)
651 654
652 655 def nice(node):
653 656 return '%d:%s' % (repo.changelog.rev(node), short(node))
654 657 ui.status(_('changeset %s backs out changeset %s\n') %
655 658 (nice(repo.changelog.tip()), nice(node)))
656 659 if opts.get('merge') and op1 != node:
657 660 hg.clean(repo, op1, show_stats=False)
658 661 ui.status(_('merging with changeset %s\n')
659 662 % nice(repo.changelog.tip()))
660 663 try:
661 664 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
662 665 'backout')
663 666 return hg.merge(repo, hex(repo.changelog.tip()))
664 667 finally:
665 668 ui.setconfig('ui', 'forcemerge', '', '')
666 669 return 0
667 670
668 671 @command('bisect',
669 672 [('r', 'reset', False, _('reset bisect state')),
670 673 ('g', 'good', False, _('mark changeset good')),
671 674 ('b', 'bad', False, _('mark changeset bad')),
672 675 ('s', 'skip', False, _('skip testing changeset')),
673 676 ('e', 'extend', False, _('extend the bisect range')),
674 677 ('c', 'command', '', _('use command to check changeset state'), _('CMD')),
675 678 ('U', 'noupdate', False, _('do not update to target'))],
676 679 _("[-gbsr] [-U] [-c CMD] [REV]"))
677 680 def bisect(ui, repo, rev=None, extra=None, command=None,
678 681 reset=None, good=None, bad=None, skip=None, extend=None,
679 682 noupdate=None):
680 683 """subdivision search of changesets
681 684
682 685 This command helps to find changesets which introduce problems. To
683 686 use, mark the earliest changeset you know exhibits the problem as
684 687 bad, then mark the latest changeset which is free from the problem
685 688 as good. Bisect will update your working directory to a revision
686 689 for testing (unless the -U/--noupdate option is specified). Once
687 690 you have performed tests, mark the working directory as good or
688 691 bad, and bisect will either update to another candidate changeset
689 692 or announce that it has found the bad revision.
690 693
691 694 As a shortcut, you can also use the revision argument to mark a
692 695 revision as good or bad without checking it out first.
693 696
694 697 If you supply a command, it will be used for automatic bisection.
695 698 The environment variable HG_NODE will contain the ID of the
696 699 changeset being tested. The exit status of the command will be
697 700 used to mark revisions as good or bad: status 0 means good, 125
698 701 means to skip the revision, 127 (command not found) will abort the
699 702 bisection, and any other non-zero exit status means the revision
700 703 is bad.
701 704
702 705 .. container:: verbose
703 706
704 707 Some examples:
705 708
706 709 - start a bisection with known bad revision 34, and good revision 12::
707 710
708 711 hg bisect --bad 34
709 712 hg bisect --good 12
710 713
711 714 - advance the current bisection by marking current revision as good or
712 715 bad::
713 716
714 717 hg bisect --good
715 718 hg bisect --bad
716 719
717 720 - mark the current revision, or a known revision, to be skipped (e.g. if
718 721 that revision is not usable because of another issue)::
719 722
720 723 hg bisect --skip
721 724 hg bisect --skip 23
722 725
723 726 - skip all revisions that do not touch directories ``foo`` or ``bar``::
724 727
725 728 hg bisect --skip "!( file('path:foo') & file('path:bar') )"
726 729
727 730 - forget the current bisection::
728 731
729 732 hg bisect --reset
730 733
731 734 - use 'make && make tests' to automatically find the first broken
732 735 revision::
733 736
734 737 hg bisect --reset
735 738 hg bisect --bad 34
736 739 hg bisect --good 12
737 740 hg bisect --command "make && make tests"
738 741
739 742 - see all changesets whose states are already known in the current
740 743 bisection::
741 744
742 745 hg log -r "bisect(pruned)"
743 746
744 747 - see the changeset currently being bisected (especially useful
745 748 if running with -U/--noupdate)::
746 749
747 750 hg log -r "bisect(current)"
748 751
749 752 - see all changesets that took part in the current bisection::
750 753
751 754 hg log -r "bisect(range)"
752 755
753 756 - you can even get a nice graph::
754 757
755 758 hg log --graph -r "bisect(range)"
756 759
757 760 See :hg:`help revisions.bisect` for more about the `bisect()` predicate.
758 761
759 762 Returns 0 on success.
760 763 """
761 764 # backward compatibility
762 765 if rev in "good bad reset init".split():
763 766 ui.warn(_("(use of 'hg bisect <cmd>' is deprecated)\n"))
764 767 cmd, rev, extra = rev, extra, None
765 768 if cmd == "good":
766 769 good = True
767 770 elif cmd == "bad":
768 771 bad = True
769 772 else:
770 773 reset = True
771 774 elif extra:
772 775 raise error.Abort(_('incompatible arguments'))
773 776
774 777 incompatibles = {
775 778 '--bad': bad,
776 779 '--command': bool(command),
777 780 '--extend': extend,
778 781 '--good': good,
779 782 '--reset': reset,
780 783 '--skip': skip,
781 784 }
782 785
783 786 enabled = [x for x in incompatibles if incompatibles[x]]
784 787
785 788 if len(enabled) > 1:
786 789 raise error.Abort(_('%s and %s are incompatible') %
787 790 tuple(sorted(enabled)[0:2]))
788 791
789 792 if reset:
790 793 hbisect.resetstate(repo)
791 794 return
792 795
793 796 state = hbisect.load_state(repo)
794 797
795 798 # update state
796 799 if good or bad or skip:
797 800 if rev:
798 801 nodes = [repo.lookup(i) for i in scmutil.revrange(repo, [rev])]
799 802 else:
800 803 nodes = [repo.lookup('.')]
801 804 if good:
802 805 state['good'] += nodes
803 806 elif bad:
804 807 state['bad'] += nodes
805 808 elif skip:
806 809 state['skip'] += nodes
807 810 hbisect.save_state(repo, state)
808 811 if not (state['good'] and state['bad']):
809 812 return
810 813
811 814 def mayupdate(repo, node, show_stats=True):
812 815 """common used update sequence"""
813 816 if noupdate:
814 817 return
815 818 cmdutil.checkunfinished(repo)
816 819 cmdutil.bailifchanged(repo)
817 820 return hg.clean(repo, node, show_stats=show_stats)
818 821
819 822 displayer = cmdutil.show_changeset(ui, repo, {})
820 823
821 824 if command:
822 825 changesets = 1
823 826 if noupdate:
824 827 try:
825 828 node = state['current'][0]
826 829 except LookupError:
827 830 raise error.Abort(_('current bisect revision is unknown - '
828 831 'start a new bisect to fix'))
829 832 else:
830 833 node, p2 = repo.dirstate.parents()
831 834 if p2 != nullid:
832 835 raise error.Abort(_('current bisect revision is a merge'))
833 836 if rev:
834 837 node = repo[scmutil.revsingle(repo, rev, node)].node()
835 838 try:
836 839 while changesets:
837 840 # update state
838 841 state['current'] = [node]
839 842 hbisect.save_state(repo, state)
840 843 status = ui.system(command, environ={'HG_NODE': hex(node)},
841 844 blockedtag='bisect_check')
842 845 if status == 125:
843 846 transition = "skip"
844 847 elif status == 0:
845 848 transition = "good"
846 849 # status < 0 means process was killed
847 850 elif status == 127:
848 851 raise error.Abort(_("failed to execute %s") % command)
849 852 elif status < 0:
850 853 raise error.Abort(_("%s killed") % command)
851 854 else:
852 855 transition = "bad"
853 856 state[transition].append(node)
854 857 ctx = repo[node]
855 858 ui.status(_('changeset %d:%s: %s\n') % (ctx, ctx, transition))
856 859 hbisect.checkstate(state)
857 860 # bisect
858 861 nodes, changesets, bgood = hbisect.bisect(repo, state)
859 862 # update to next check
860 863 node = nodes[0]
861 864 mayupdate(repo, node, show_stats=False)
862 865 finally:
863 866 state['current'] = [node]
864 867 hbisect.save_state(repo, state)
865 868 hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
866 869 return
867 870
868 871 hbisect.checkstate(state)
869 872
870 873 # actually bisect
871 874 nodes, changesets, good = hbisect.bisect(repo, state)
872 875 if extend:
873 876 if not changesets:
874 877 extendnode = hbisect.extendrange(repo, state, nodes, good)
875 878 if extendnode is not None:
876 879 ui.write(_("Extending search to changeset %d:%s\n")
877 880 % (extendnode.rev(), extendnode))
878 881 state['current'] = [extendnode.node()]
879 882 hbisect.save_state(repo, state)
880 883 return mayupdate(repo, extendnode.node())
881 884 raise error.Abort(_("nothing to extend"))
882 885
883 886 if changesets == 0:
884 887 hbisect.printresult(ui, repo, state, displayer, nodes, good)
885 888 else:
886 889 assert len(nodes) == 1 # only a single node can be tested next
887 890 node = nodes[0]
888 891 # compute the approximate number of remaining tests
889 892 tests, size = 0, 2
890 893 while size <= changesets:
891 894 tests, size = tests + 1, size * 2
892 895 rev = repo.changelog.rev(node)
893 896 ui.write(_("Testing changeset %d:%s "
894 897 "(%d changesets remaining, ~%d tests)\n")
895 898 % (rev, short(node), changesets, tests))
896 899 state['current'] = [node]
897 900 hbisect.save_state(repo, state)
898 901 return mayupdate(repo, node)
899 902
900 903 @command('bookmarks|bookmark',
901 904 [('f', 'force', False, _('force')),
902 905 ('r', 'rev', '', _('revision for bookmark action'), _('REV')),
903 906 ('d', 'delete', False, _('delete a given bookmark')),
904 907 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
905 908 ('i', 'inactive', False, _('mark a bookmark inactive')),
906 909 ] + formatteropts,
907 910 _('hg bookmarks [OPTIONS]... [NAME]...'))
908 911 def bookmark(ui, repo, *names, **opts):
909 912 '''create a new bookmark or list existing bookmarks
910 913
911 914 Bookmarks are labels on changesets to help track lines of development.
912 915 Bookmarks are unversioned and can be moved, renamed and deleted.
913 916 Deleting or moving a bookmark has no effect on the associated changesets.
914 917
915 918 Creating or updating to a bookmark causes it to be marked as 'active'.
916 919 The active bookmark is indicated with a '*'.
917 920 When a commit is made, the active bookmark will advance to the new commit.
918 921 A plain :hg:`update` will also advance an active bookmark, if possible.
919 922 Updating away from a bookmark will cause it to be deactivated.
920 923
921 924 Bookmarks can be pushed and pulled between repositories (see
922 925 :hg:`help push` and :hg:`help pull`). If a shared bookmark has
923 926 diverged, a new 'divergent bookmark' of the form 'name@path' will
924 927 be created. Using :hg:`merge` will resolve the divergence.
925 928
926 929 Specifying bookmark as '.' to -m or -d options is equivalent to specifying
927 930 the active bookmark's name.
928 931
929 932 A bookmark named '@' has the special property that :hg:`clone` will
930 933 check it out by default if it exists.
931 934
932 935 .. container:: verbose
933 936
934 937 Examples:
935 938
936 939 - create an active bookmark for a new line of development::
937 940
938 941 hg book new-feature
939 942
940 943 - create an inactive bookmark as a place marker::
941 944
942 945 hg book -i reviewed
943 946
944 947 - create an inactive bookmark on another changeset::
945 948
946 949 hg book -r .^ tested
947 950
948 951 - rename bookmark turkey to dinner::
949 952
950 953 hg book -m turkey dinner
951 954
952 955 - move the '@' bookmark from another branch::
953 956
954 957 hg book -f @
955 958 '''
956 959 force = opts.get(r'force')
957 960 rev = opts.get(r'rev')
958 961 delete = opts.get(r'delete')
959 962 rename = opts.get(r'rename')
960 963 inactive = opts.get(r'inactive')
961 964
962 965 if delete and rename:
963 966 raise error.Abort(_("--delete and --rename are incompatible"))
964 967 if delete and rev:
965 968 raise error.Abort(_("--rev is incompatible with --delete"))
966 969 if rename and rev:
967 970 raise error.Abort(_("--rev is incompatible with --rename"))
968 971 if not names and (delete or rev):
969 972 raise error.Abort(_("bookmark name required"))
970 973
971 974 if delete or rename or names or inactive:
972 975 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
973 976 if delete:
974 977 names = pycompat.maplist(repo._bookmarks.expandname, names)
975 978 bookmarks.delete(repo, tr, names)
976 979 elif rename:
977 980 if not names:
978 981 raise error.Abort(_("new bookmark name required"))
979 982 elif len(names) > 1:
980 983 raise error.Abort(_("only one new bookmark name allowed"))
981 984 rename = repo._bookmarks.expandname(rename)
982 985 bookmarks.rename(repo, tr, rename, names[0], force, inactive)
983 986 elif names:
984 987 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
985 988 elif inactive:
986 989 if len(repo._bookmarks) == 0:
987 990 ui.status(_("no bookmarks set\n"))
988 991 elif not repo._activebookmark:
989 992 ui.status(_("no active bookmark\n"))
990 993 else:
991 994 bookmarks.deactivate(repo)
992 995 else: # show bookmarks
993 996 bookmarks.printbookmarks(ui, repo, **opts)
994 997
995 998 @command('branch',
996 999 [('f', 'force', None,
997 1000 _('set branch name even if it shadows an existing branch')),
998 1001 ('C', 'clean', None, _('reset branch name to parent branch name'))],
999 1002 _('[-fC] [NAME]'))
1000 1003 def branch(ui, repo, label=None, **opts):
1001 1004 """set or show the current branch name
1002 1005
1003 1006 .. note::
1004 1007
1005 1008 Branch names are permanent and global. Use :hg:`bookmark` to create a
1006 1009 light-weight bookmark instead. See :hg:`help glossary` for more
1007 1010 information about named branches and bookmarks.
1008 1011
1009 1012 With no argument, show the current branch name. With one argument,
1010 1013 set the working directory branch name (the branch will not exist
1011 1014 in the repository until the next commit). Standard practice
1012 1015 recommends that primary development take place on the 'default'
1013 1016 branch.
1014 1017
1015 1018 Unless -f/--force is specified, branch will not let you set a
1016 1019 branch name that already exists.
1017 1020
1018 1021 Use -C/--clean to reset the working directory branch to that of
1019 1022 the parent of the working directory, negating a previous branch
1020 1023 change.
1021 1024
1022 1025 Use the command :hg:`update` to switch to an existing branch. Use
1023 1026 :hg:`commit --close-branch` to mark this branch head as closed.
1024 1027 When all heads of a branch are closed, the branch will be
1025 1028 considered closed.
1026 1029
1027 1030 Returns 0 on success.
1028 1031 """
1029 1032 opts = pycompat.byteskwargs(opts)
1030 1033 if label:
1031 1034 label = label.strip()
1032 1035
1033 1036 if not opts.get('clean') and not label:
1034 1037 ui.write("%s\n" % repo.dirstate.branch())
1035 1038 return
1036 1039
1037 1040 with repo.wlock():
1038 1041 if opts.get('clean'):
1039 1042 label = repo[None].p1().branch()
1040 1043 repo.dirstate.setbranch(label)
1041 1044 ui.status(_('reset working directory to branch %s\n') % label)
1042 1045 elif label:
1043 1046 if not opts.get('force') and label in repo.branchmap():
1044 1047 if label not in [p.branch() for p in repo[None].parents()]:
1045 1048 raise error.Abort(_('a branch of the same name already'
1046 1049 ' exists'),
1047 1050 # i18n: "it" refers to an existing branch
1048 1051 hint=_("use 'hg update' to switch to it"))
1049 1052 scmutil.checknewlabel(repo, label, 'branch')
1050 1053 repo.dirstate.setbranch(label)
1051 1054 ui.status(_('marked working directory as branch %s\n') % label)
1052 1055
1053 1056 # find any open named branches aside from default
1054 1057 others = [n for n, h, t, c in repo.branchmap().iterbranches()
1055 1058 if n != "default" and not c]
1056 1059 if not others:
1057 1060 ui.status(_('(branches are permanent and global, '
1058 1061 'did you want a bookmark?)\n'))
1059 1062
1060 1063 @command('branches',
1061 1064 [('a', 'active', False,
1062 1065 _('show only branches that have unmerged heads (DEPRECATED)')),
1063 1066 ('c', 'closed', False, _('show normal and closed branches')),
1064 1067 ] + formatteropts,
1065 1068 _('[-c]'), cmdtype=readonly)
1066 1069 def branches(ui, repo, active=False, closed=False, **opts):
1067 1070 """list repository named branches
1068 1071
1069 1072 List the repository's named branches, indicating which ones are
1070 1073 inactive. If -c/--closed is specified, also list branches which have
1071 1074 been marked closed (see :hg:`commit --close-branch`).
1072 1075
1073 1076 Use the command :hg:`update` to switch to an existing branch.
1074 1077
1075 1078 Returns 0.
1076 1079 """
1077 1080
1078 1081 opts = pycompat.byteskwargs(opts)
1079 1082 ui.pager('branches')
1080 1083 fm = ui.formatter('branches', opts)
1081 1084 hexfunc = fm.hexfunc
1082 1085
1083 1086 allheads = set(repo.heads())
1084 1087 branches = []
1085 1088 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1086 1089 isactive = False
1087 1090 if not isclosed:
1088 1091 openheads = set(repo.branchmap().iteropen(heads))
1089 1092 isactive = bool(openheads & allheads)
1090 1093 branches.append((tag, repo[tip], isactive, not isclosed))
1091 1094 branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]),
1092 1095 reverse=True)
1093 1096
1094 1097 for tag, ctx, isactive, isopen in branches:
1095 1098 if active and not isactive:
1096 1099 continue
1097 1100 if isactive:
1098 1101 label = 'branches.active'
1099 1102 notice = ''
1100 1103 elif not isopen:
1101 1104 if not closed:
1102 1105 continue
1103 1106 label = 'branches.closed'
1104 1107 notice = _(' (closed)')
1105 1108 else:
1106 1109 label = 'branches.inactive'
1107 1110 notice = _(' (inactive)')
1108 1111 current = (tag == repo.dirstate.branch())
1109 1112 if current:
1110 1113 label = 'branches.current'
1111 1114
1112 1115 fm.startitem()
1113 1116 fm.write('branch', '%s', tag, label=label)
1114 1117 rev = ctx.rev()
1115 1118 padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0)
1116 1119 fmt = ' ' * padsize + ' %d:%s'
1117 1120 fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()),
1118 1121 label='log.changeset changeset.%s' % ctx.phasestr())
1119 1122 fm.context(ctx=ctx)
1120 1123 fm.data(active=isactive, closed=not isopen, current=current)
1121 1124 if not ui.quiet:
1122 1125 fm.plain(notice)
1123 1126 fm.plain('\n')
1124 1127 fm.end()
1125 1128
1126 1129 @command('bundle',
1127 1130 [('f', 'force', None, _('run even when the destination is unrelated')),
1128 1131 ('r', 'rev', [], _('a changeset intended to be added to the destination'),
1129 1132 _('REV')),
1130 1133 ('b', 'branch', [], _('a specific branch you would like to bundle'),
1131 1134 _('BRANCH')),
1132 1135 ('', 'base', [],
1133 1136 _('a base changeset assumed to be available at the destination'),
1134 1137 _('REV')),
1135 1138 ('a', 'all', None, _('bundle all changesets in the repository')),
1136 1139 ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE')),
1137 1140 ] + remoteopts,
1138 1141 _('[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]'))
1139 1142 def bundle(ui, repo, fname, dest=None, **opts):
1140 1143 """create a bundle file
1141 1144
1142 1145 Generate a bundle file containing data to be added to a repository.
1143 1146
1144 1147 To create a bundle containing all changesets, use -a/--all
1145 1148 (or --base null). Otherwise, hg assumes the destination will have
1146 1149 all the nodes you specify with --base parameters. Otherwise, hg
1147 1150 will assume the repository has all the nodes in destination, or
1148 1151 default-push/default if no destination is specified.
1149 1152
1150 1153 You can change bundle format with the -t/--type option. See
1151 1154 :hg:`help bundlespec` for documentation on this format. By default,
1152 1155 the most appropriate format is used and compression defaults to
1153 1156 bzip2.
1154 1157
1155 1158 The bundle file can then be transferred using conventional means
1156 1159 and applied to another repository with the unbundle or pull
1157 1160 command. This is useful when direct push and pull are not
1158 1161 available or when exporting an entire repository is undesirable.
1159 1162
1160 1163 Applying bundles preserves all changeset contents including
1161 1164 permissions, copy/rename information, and revision history.
1162 1165
1163 1166 Returns 0 on success, 1 if no changes found.
1164 1167 """
1165 1168 opts = pycompat.byteskwargs(opts)
1166 1169 revs = None
1167 1170 if 'rev' in opts:
1168 1171 revstrings = opts['rev']
1169 1172 revs = scmutil.revrange(repo, revstrings)
1170 1173 if revstrings and not revs:
1171 1174 raise error.Abort(_('no commits to bundle'))
1172 1175
1173 1176 bundletype = opts.get('type', 'bzip2').lower()
1174 1177 try:
1175 1178 bcompression, cgversion, params = exchange.parsebundlespec(
1176 1179 repo, bundletype, strict=False)
1177 1180 except error.UnsupportedBundleSpecification as e:
1178 1181 raise error.Abort(str(e),
1179 1182 hint=_("see 'hg help bundlespec' for supported "
1180 1183 "values for --type"))
1181 1184
1182 1185 # Packed bundles are a pseudo bundle format for now.
1183 1186 if cgversion == 's1':
1184 1187 raise error.Abort(_('packed bundles cannot be produced by "hg bundle"'),
1185 1188 hint=_("use 'hg debugcreatestreamclonebundle'"))
1186 1189
1187 1190 if opts.get('all'):
1188 1191 if dest:
1189 1192 raise error.Abort(_("--all is incompatible with specifying "
1190 1193 "a destination"))
1191 1194 if opts.get('base'):
1192 1195 ui.warn(_("ignoring --base because --all was specified\n"))
1193 1196 base = ['null']
1194 1197 else:
1195 1198 base = scmutil.revrange(repo, opts.get('base'))
1196 1199 if cgversion not in changegroup.supportedoutgoingversions(repo):
1197 1200 raise error.Abort(_("repository does not support bundle version %s") %
1198 1201 cgversion)
1199 1202
1200 1203 if base:
1201 1204 if dest:
1202 1205 raise error.Abort(_("--base is incompatible with specifying "
1203 1206 "a destination"))
1204 1207 common = [repo.lookup(rev) for rev in base]
1205 1208 heads = revs and map(repo.lookup, revs) or None
1206 1209 outgoing = discovery.outgoing(repo, common, heads)
1207 1210 else:
1208 1211 dest = ui.expandpath(dest or 'default-push', dest or 'default')
1209 1212 dest, branches = hg.parseurl(dest, opts.get('branch'))
1210 1213 other = hg.peer(repo, opts, dest)
1211 1214 revs, checkout = hg.addbranchrevs(repo, repo, branches, revs)
1212 1215 heads = revs and map(repo.lookup, revs) or revs
1213 1216 outgoing = discovery.findcommonoutgoing(repo, other,
1214 1217 onlyheads=heads,
1215 1218 force=opts.get('force'),
1216 1219 portable=True)
1217 1220
1218 1221 if not outgoing.missing:
1219 1222 scmutil.nochangesfound(ui, repo, not base and outgoing.excluded)
1220 1223 return 1
1221 1224
1222 1225 if cgversion == '01': #bundle1
1223 1226 if bcompression is None:
1224 1227 bcompression = 'UN'
1225 1228 bversion = 'HG10' + bcompression
1226 1229 bcompression = None
1227 1230 elif cgversion in ('02', '03'):
1228 1231 bversion = 'HG20'
1229 1232 else:
1230 1233 raise error.ProgrammingError(
1231 1234 'bundle: unexpected changegroup version %s' % cgversion)
1232 1235
1233 1236 # TODO compression options should be derived from bundlespec parsing.
1234 1237 # This is a temporary hack to allow adjusting bundle compression
1235 1238 # level without a) formalizing the bundlespec changes to declare it
1236 1239 # b) introducing a command flag.
1237 1240 compopts = {}
1238 1241 complevel = ui.configint('experimental', 'bundlecomplevel')
1239 1242 if complevel is not None:
1240 1243 compopts['level'] = complevel
1241 1244
1242 1245
1243 1246 contentopts = {'cg.version': cgversion}
1244 1247 if repo.ui.configbool('experimental', 'evolution.bundle-obsmarker'):
1245 1248 contentopts['obsolescence'] = True
1246 1249 if repo.ui.configbool('experimental', 'bundle-phases'):
1247 1250 contentopts['phases'] = True
1248 1251 bundle2.writenewbundle(ui, repo, 'bundle', fname, bversion, outgoing,
1249 1252 contentopts, compression=bcompression,
1250 1253 compopts=compopts)
1251 1254
1252 1255 @command('cat',
1253 1256 [('o', 'output', '',
1254 1257 _('print output to file with formatted name'), _('FORMAT')),
1255 1258 ('r', 'rev', '', _('print the given revision'), _('REV')),
1256 1259 ('', 'decode', None, _('apply any matching decode filter')),
1257 1260 ] + walkopts + formatteropts,
1258 1261 _('[OPTION]... FILE...'),
1259 1262 inferrepo=True, cmdtype=readonly)
1260 1263 def cat(ui, repo, file1, *pats, **opts):
1261 1264 """output the current or given revision of files
1262 1265
1263 1266 Print the specified files as they were at the given revision. If
1264 1267 no revision is given, the parent of the working directory is used.
1265 1268
1266 1269 Output may be to a file, in which case the name of the file is
1267 1270 given using a format string. The formatting rules as follows:
1268 1271
1269 1272 :``%%``: literal "%" character
1270 1273 :``%s``: basename of file being printed
1271 1274 :``%d``: dirname of file being printed, or '.' if in repository root
1272 1275 :``%p``: root-relative path name of file being printed
1273 1276 :``%H``: changeset hash (40 hexadecimal digits)
1274 1277 :``%R``: changeset revision number
1275 1278 :``%h``: short-form changeset hash (12 hexadecimal digits)
1276 1279 :``%r``: zero-padded changeset revision number
1277 1280 :``%b``: basename of the exporting repository
1278 1281
1279 1282 Returns 0 on success.
1280 1283 """
1281 1284 opts = pycompat.byteskwargs(opts)
1282 1285 rev = opts.get('rev')
1283 1286 if rev:
1284 1287 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
1285 1288 ctx = scmutil.revsingle(repo, rev)
1286 1289 m = scmutil.match(ctx, (file1,) + pats, opts)
1287 1290 fntemplate = opts.pop('output', '')
1288 1291 if cmdutil.isstdiofilename(fntemplate):
1289 1292 fntemplate = ''
1290 1293
1291 1294 if fntemplate:
1292 1295 fm = formatter.nullformatter(ui, 'cat')
1293 1296 else:
1294 1297 ui.pager('cat')
1295 1298 fm = ui.formatter('cat', opts)
1296 1299 with fm:
1297 1300 return cmdutil.cat(ui, repo, ctx, m, fm, fntemplate, '',
1298 1301 **pycompat.strkwargs(opts))
1299 1302
1300 1303 @command('^clone',
1301 1304 [('U', 'noupdate', None, _('the clone will include an empty working '
1302 1305 'directory (only a repository)')),
1303 1306 ('u', 'updaterev', '', _('revision, tag, or branch to check out'),
1304 1307 _('REV')),
1305 1308 ('r', 'rev', [], _('include the specified changeset'), _('REV')),
1306 1309 ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
1307 1310 ('', 'pull', None, _('use pull protocol to copy metadata')),
1308 1311 ('', 'uncompressed', None,
1309 1312 _('an alias to --stream (DEPRECATED)')),
1310 1313 ('', 'stream', None,
1311 1314 _('clone with minimal data processing')),
1312 1315 ] + remoteopts,
1313 1316 _('[OPTION]... SOURCE [DEST]'),
1314 1317 norepo=True)
1315 1318 def clone(ui, source, dest=None, **opts):
1316 1319 """make a copy of an existing repository
1317 1320
1318 1321 Create a copy of an existing repository in a new directory.
1319 1322
1320 1323 If no destination directory name is specified, it defaults to the
1321 1324 basename of the source.
1322 1325
1323 1326 The location of the source is added to the new repository's
1324 1327 ``.hg/hgrc`` file, as the default to be used for future pulls.
1325 1328
1326 1329 Only local paths and ``ssh://`` URLs are supported as
1327 1330 destinations. For ``ssh://`` destinations, no working directory or
1328 1331 ``.hg/hgrc`` will be created on the remote side.
1329 1332
1330 1333 If the source repository has a bookmark called '@' set, that
1331 1334 revision will be checked out in the new repository by default.
1332 1335
1333 1336 To check out a particular version, use -u/--update, or
1334 1337 -U/--noupdate to create a clone with no working directory.
1335 1338
1336 1339 To pull only a subset of changesets, specify one or more revisions
1337 1340 identifiers with -r/--rev or branches with -b/--branch. The
1338 1341 resulting clone will contain only the specified changesets and
1339 1342 their ancestors. These options (or 'clone src#rev dest') imply
1340 1343 --pull, even for local source repositories.
1341 1344
1342 1345 In normal clone mode, the remote normalizes repository data into a common
1343 1346 exchange format and the receiving end translates this data into its local
1344 1347 storage format. --stream activates a different clone mode that essentially
1345 1348 copies repository files from the remote with minimal data processing. This
1346 1349 significantly reduces the CPU cost of a clone both remotely and locally.
1347 1350 However, it often increases the transferred data size by 30-40%. This can
1348 1351 result in substantially faster clones where I/O throughput is plentiful,
1349 1352 especially for larger repositories. A side-effect of --stream clones is
1350 1353 that storage settings and requirements on the remote are applied locally:
1351 1354 a modern client may inherit legacy or inefficient storage used by the
1352 1355 remote or a legacy Mercurial client may not be able to clone from a
1353 1356 modern Mercurial remote.
1354 1357
1355 1358 .. note::
1356 1359
1357 1360 Specifying a tag will include the tagged changeset but not the
1358 1361 changeset containing the tag.
1359 1362
1360 1363 .. container:: verbose
1361 1364
1362 1365 For efficiency, hardlinks are used for cloning whenever the
1363 1366 source and destination are on the same filesystem (note this
1364 1367 applies only to the repository data, not to the working
1365 1368 directory). Some filesystems, such as AFS, implement hardlinking
1366 1369 incorrectly, but do not report errors. In these cases, use the
1367 1370 --pull option to avoid hardlinking.
1368 1371
1369 1372 Mercurial will update the working directory to the first applicable
1370 1373 revision from this list:
1371 1374
1372 1375 a) null if -U or the source repository has no changesets
1373 1376 b) if -u . and the source repository is local, the first parent of
1374 1377 the source repository's working directory
1375 1378 c) the changeset specified with -u (if a branch name, this means the
1376 1379 latest head of that branch)
1377 1380 d) the changeset specified with -r
1378 1381 e) the tipmost head specified with -b
1379 1382 f) the tipmost head specified with the url#branch source syntax
1380 1383 g) the revision marked with the '@' bookmark, if present
1381 1384 h) the tipmost head of the default branch
1382 1385 i) tip
1383 1386
1384 1387 When cloning from servers that support it, Mercurial may fetch
1385 1388 pre-generated data from a server-advertised URL. When this is done,
1386 1389 hooks operating on incoming changesets and changegroups may fire twice,
1387 1390 once for the bundle fetched from the URL and another for any additional
1388 1391 data not fetched from this URL. In addition, if an error occurs, the
1389 1392 repository may be rolled back to a partial clone. This behavior may
1390 1393 change in future releases. See :hg:`help -e clonebundles` for more.
1391 1394
1392 1395 Examples:
1393 1396
1394 1397 - clone a remote repository to a new directory named hg/::
1395 1398
1396 1399 hg clone https://www.mercurial-scm.org/repo/hg/
1397 1400
1398 1401 - create a lightweight local clone::
1399 1402
1400 1403 hg clone project/ project-feature/
1401 1404
1402 1405 - clone from an absolute path on an ssh server (note double-slash)::
1403 1406
1404 1407 hg clone ssh://user@server//home/projects/alpha/
1405 1408
1406 1409 - do a streaming clone while checking out a specified version::
1407 1410
1408 1411 hg clone --stream http://server/repo -u 1.5
1409 1412
1410 1413 - create a repository without changesets after a particular revision::
1411 1414
1412 1415 hg clone -r 04e544 experimental/ good/
1413 1416
1414 1417 - clone (and track) a particular named branch::
1415 1418
1416 1419 hg clone https://www.mercurial-scm.org/repo/hg/#stable
1417 1420
1418 1421 See :hg:`help urls` for details on specifying URLs.
1419 1422
1420 1423 Returns 0 on success.
1421 1424 """
1422 1425 opts = pycompat.byteskwargs(opts)
1423 1426 if opts.get('noupdate') and opts.get('updaterev'):
1424 1427 raise error.Abort(_("cannot specify both --noupdate and --updaterev"))
1425 1428
1426 1429 r = hg.clone(ui, opts, source, dest,
1427 1430 pull=opts.get('pull'),
1428 1431 stream=opts.get('stream') or opts.get('uncompressed'),
1429 1432 rev=opts.get('rev'),
1430 1433 update=opts.get('updaterev') or not opts.get('noupdate'),
1431 1434 branch=opts.get('branch'),
1432 1435 shareopts=opts.get('shareopts'))
1433 1436
1434 1437 return r is None
1435 1438
1436 1439 @command('^commit|ci',
1437 1440 [('A', 'addremove', None,
1438 1441 _('mark new/missing files as added/removed before committing')),
1439 1442 ('', 'close-branch', None,
1440 1443 _('mark a branch head as closed')),
1441 1444 ('', 'amend', None, _('amend the parent of the working directory')),
1442 1445 ('s', 'secret', None, _('use the secret phase for committing')),
1443 1446 ('e', 'edit', None, _('invoke editor on commit messages')),
1444 1447 ('i', 'interactive', None, _('use interactive mode')),
1445 1448 ] + walkopts + commitopts + commitopts2 + subrepoopts,
1446 1449 _('[OPTION]... [FILE]...'),
1447 1450 inferrepo=True)
1448 1451 def commit(ui, repo, *pats, **opts):
1449 1452 """commit the specified files or all outstanding changes
1450 1453
1451 1454 Commit changes to the given files into the repository. Unlike a
1452 1455 centralized SCM, this operation is a local operation. See
1453 1456 :hg:`push` for a way to actively distribute your changes.
1454 1457
1455 1458 If a list of files is omitted, all changes reported by :hg:`status`
1456 1459 will be committed.
1457 1460
1458 1461 If you are committing the result of a merge, do not provide any
1459 1462 filenames or -I/-X filters.
1460 1463
1461 1464 If no commit message is specified, Mercurial starts your
1462 1465 configured editor where you can enter a message. In case your
1463 1466 commit fails, you will find a backup of your message in
1464 1467 ``.hg/last-message.txt``.
1465 1468
1466 1469 The --close-branch flag can be used to mark the current branch
1467 1470 head closed. When all heads of a branch are closed, the branch
1468 1471 will be considered closed and no longer listed.
1469 1472
1470 1473 The --amend flag can be used to amend the parent of the
1471 1474 working directory with a new commit that contains the changes
1472 1475 in the parent in addition to those currently reported by :hg:`status`,
1473 1476 if there are any. The old commit is stored in a backup bundle in
1474 1477 ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle`
1475 1478 on how to restore it).
1476 1479
1477 1480 Message, user and date are taken from the amended commit unless
1478 1481 specified. When a message isn't specified on the command line,
1479 1482 the editor will open with the message of the amended commit.
1480 1483
1481 1484 It is not possible to amend public changesets (see :hg:`help phases`)
1482 1485 or changesets that have children.
1483 1486
1484 1487 See :hg:`help dates` for a list of formats valid for -d/--date.
1485 1488
1486 1489 Returns 0 on success, 1 if nothing changed.
1487 1490
1488 1491 .. container:: verbose
1489 1492
1490 1493 Examples:
1491 1494
1492 1495 - commit all files ending in .py::
1493 1496
1494 1497 hg commit --include "set:**.py"
1495 1498
1496 1499 - commit all non-binary files::
1497 1500
1498 1501 hg commit --exclude "set:binary()"
1499 1502
1500 1503 - amend the current commit and set the date to now::
1501 1504
1502 1505 hg commit --amend --date now
1503 1506 """
1504 1507 wlock = lock = None
1505 1508 try:
1506 1509 wlock = repo.wlock()
1507 1510 lock = repo.lock()
1508 1511 return _docommit(ui, repo, *pats, **opts)
1509 1512 finally:
1510 1513 release(lock, wlock)
1511 1514
1512 1515 def _docommit(ui, repo, *pats, **opts):
1513 1516 if opts.get(r'interactive'):
1514 1517 opts.pop(r'interactive')
1515 1518 ret = cmdutil.dorecord(ui, repo, commit, None, False,
1516 1519 cmdutil.recordfilter, *pats,
1517 1520 **opts)
1518 1521 # ret can be 0 (no changes to record) or the value returned by
1519 1522 # commit(), 1 if nothing changed or None on success.
1520 1523 return 1 if ret == 0 else ret
1521 1524
1522 1525 opts = pycompat.byteskwargs(opts)
1523 1526 if opts.get('subrepos'):
1524 1527 if opts.get('amend'):
1525 1528 raise error.Abort(_('cannot amend with --subrepos'))
1526 1529 # Let --subrepos on the command line override config setting.
1527 1530 ui.setconfig('ui', 'commitsubrepos', True, 'commit')
1528 1531
1529 1532 cmdutil.checkunfinished(repo, commit=True)
1530 1533
1531 1534 branch = repo[None].branch()
1532 1535 bheads = repo.branchheads(branch)
1533 1536
1534 1537 extra = {}
1535 1538 if opts.get('close_branch'):
1536 1539 extra['close'] = 1
1537 1540
1538 1541 if not bheads:
1539 1542 raise error.Abort(_('can only close branch heads'))
1540 1543 elif opts.get('amend'):
1541 1544 if repo[None].parents()[0].p1().branch() != branch and \
1542 1545 repo[None].parents()[0].p2().branch() != branch:
1543 1546 raise error.Abort(_('can only close branch heads'))
1544 1547
1545 1548 if opts.get('amend'):
1546 1549 if ui.configbool('ui', 'commitsubrepos'):
1547 1550 raise error.Abort(_('cannot amend with ui.commitsubrepos enabled'))
1548 1551
1549 1552 old = repo['.']
1550 1553 rewriteutil.precheck(repo, [old.rev()], 'amend')
1551 1554
1552 1555 # Currently histedit gets confused if an amend happens while histedit
1553 1556 # is in progress. Since we have a checkunfinished command, we are
1554 1557 # temporarily honoring it.
1555 1558 #
1556 1559 # Note: eventually this guard will be removed. Please do not expect
1557 1560 # this behavior to remain.
1558 1561 if not obsolete.isenabled(repo, obsolete.createmarkersopt):
1559 1562 cmdutil.checkunfinished(repo)
1560 1563
1561 1564 node = cmdutil.amend(ui, repo, old, extra, pats, opts)
1562 1565 if node == old.node():
1563 1566 ui.status(_("nothing changed\n"))
1564 1567 return 1
1565 1568 else:
1566 1569 def commitfunc(ui, repo, message, match, opts):
1567 1570 overrides = {}
1568 1571 if opts.get('secret'):
1569 1572 overrides[('phases', 'new-commit')] = 'secret'
1570 1573
1571 1574 baseui = repo.baseui
1572 1575 with baseui.configoverride(overrides, 'commit'):
1573 1576 with ui.configoverride(overrides, 'commit'):
1574 1577 editform = cmdutil.mergeeditform(repo[None],
1575 1578 'commit.normal')
1576 1579 editor = cmdutil.getcommiteditor(
1577 1580 editform=editform, **pycompat.strkwargs(opts))
1578 1581 return repo.commit(message,
1579 1582 opts.get('user'),
1580 1583 opts.get('date'),
1581 1584 match,
1582 1585 editor=editor,
1583 1586 extra=extra)
1584 1587
1585 1588 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
1586 1589
1587 1590 if not node:
1588 1591 stat = cmdutil.postcommitstatus(repo, pats, opts)
1589 1592 if stat[3]:
1590 1593 ui.status(_("nothing changed (%d missing files, see "
1591 1594 "'hg status')\n") % len(stat[3]))
1592 1595 else:
1593 1596 ui.status(_("nothing changed\n"))
1594 1597 return 1
1595 1598
1596 1599 cmdutil.commitstatus(repo, node, branch, bheads, opts)
1597 1600
1598 1601 @command('config|showconfig|debugconfig',
1599 1602 [('u', 'untrusted', None, _('show untrusted configuration options')),
1600 1603 ('e', 'edit', None, _('edit user config')),
1601 1604 ('l', 'local', None, _('edit repository config')),
1602 1605 ('g', 'global', None, _('edit global config'))] + formatteropts,
1603 1606 _('[-u] [NAME]...'),
1604 1607 optionalrepo=True, cmdtype=readonly)
1605 1608 def config(ui, repo, *values, **opts):
1606 1609 """show combined config settings from all hgrc files
1607 1610
1608 1611 With no arguments, print names and values of all config items.
1609 1612
1610 1613 With one argument of the form section.name, print just the value
1611 1614 of that config item.
1612 1615
1613 1616 With multiple arguments, print names and values of all config
1614 1617 items with matching section names.
1615 1618
1616 1619 With --edit, start an editor on the user-level config file. With
1617 1620 --global, edit the system-wide config file. With --local, edit the
1618 1621 repository-level config file.
1619 1622
1620 1623 With --debug, the source (filename and line number) is printed
1621 1624 for each config item.
1622 1625
1623 1626 See :hg:`help config` for more information about config files.
1624 1627
1625 1628 Returns 0 on success, 1 if NAME does not exist.
1626 1629
1627 1630 """
1628 1631
1629 1632 opts = pycompat.byteskwargs(opts)
1630 1633 if opts.get('edit') or opts.get('local') or opts.get('global'):
1631 1634 if opts.get('local') and opts.get('global'):
1632 1635 raise error.Abort(_("can't use --local and --global together"))
1633 1636
1634 1637 if opts.get('local'):
1635 1638 if not repo:
1636 1639 raise error.Abort(_("can't use --local outside a repository"))
1637 1640 paths = [repo.vfs.join('hgrc')]
1638 1641 elif opts.get('global'):
1639 1642 paths = rcutil.systemrcpath()
1640 1643 else:
1641 1644 paths = rcutil.userrcpath()
1642 1645
1643 1646 for f in paths:
1644 1647 if os.path.exists(f):
1645 1648 break
1646 1649 else:
1647 1650 if opts.get('global'):
1648 1651 samplehgrc = uimod.samplehgrcs['global']
1649 1652 elif opts.get('local'):
1650 1653 samplehgrc = uimod.samplehgrcs['local']
1651 1654 else:
1652 1655 samplehgrc = uimod.samplehgrcs['user']
1653 1656
1654 1657 f = paths[0]
1655 1658 fp = open(f, "wb")
1656 1659 fp.write(util.tonativeeol(samplehgrc))
1657 1660 fp.close()
1658 1661
1659 1662 editor = ui.geteditor()
1660 1663 ui.system("%s \"%s\"" % (editor, f),
1661 1664 onerr=error.Abort, errprefix=_("edit failed"),
1662 1665 blockedtag='config_edit')
1663 1666 return
1664 1667 ui.pager('config')
1665 1668 fm = ui.formatter('config', opts)
1666 1669 for t, f in rcutil.rccomponents():
1667 1670 if t == 'path':
1668 1671 ui.debug('read config from: %s\n' % f)
1669 1672 elif t == 'items':
1670 1673 for section, name, value, source in f:
1671 1674 ui.debug('set config by: %s\n' % source)
1672 1675 else:
1673 1676 raise error.ProgrammingError('unknown rctype: %s' % t)
1674 1677 untrusted = bool(opts.get('untrusted'))
1675 1678 if values:
1676 1679 sections = [v for v in values if '.' not in v]
1677 1680 items = [v for v in values if '.' in v]
1678 1681 if len(items) > 1 or items and sections:
1679 1682 raise error.Abort(_('only one config item permitted'))
1680 1683 matched = False
1681 1684 for section, name, value in ui.walkconfig(untrusted=untrusted):
1682 1685 source = ui.configsource(section, name, untrusted)
1683 1686 value = pycompat.bytestr(value)
1684 1687 if fm.isplain():
1685 1688 source = source or 'none'
1686 1689 value = value.replace('\n', '\\n')
1687 1690 entryname = section + '.' + name
1688 1691 if values:
1689 1692 for v in values:
1690 1693 if v == section:
1691 1694 fm.startitem()
1692 1695 fm.condwrite(ui.debugflag, 'source', '%s: ', source)
1693 1696 fm.write('name value', '%s=%s\n', entryname, value)
1694 1697 matched = True
1695 1698 elif v == entryname:
1696 1699 fm.startitem()
1697 1700 fm.condwrite(ui.debugflag, 'source', '%s: ', source)
1698 1701 fm.write('value', '%s\n', value)
1699 1702 fm.data(name=entryname)
1700 1703 matched = True
1701 1704 else:
1702 1705 fm.startitem()
1703 1706 fm.condwrite(ui.debugflag, 'source', '%s: ', source)
1704 1707 fm.write('name value', '%s=%s\n', entryname, value)
1705 1708 matched = True
1706 1709 fm.end()
1707 1710 if matched:
1708 1711 return 0
1709 1712 return 1
1710 1713
1711 1714 @command('copy|cp',
1712 1715 [('A', 'after', None, _('record a copy that has already occurred')),
1713 1716 ('f', 'force', None, _('forcibly copy over an existing managed file')),
1714 1717 ] + walkopts + dryrunopts,
1715 1718 _('[OPTION]... [SOURCE]... DEST'))
1716 1719 def copy(ui, repo, *pats, **opts):
1717 1720 """mark files as copied for the next commit
1718 1721
1719 1722 Mark dest as having copies of source files. If dest is a
1720 1723 directory, copies are put in that directory. If dest is a file,
1721 1724 the source must be a single file.
1722 1725
1723 1726 By default, this command copies the contents of files as they
1724 1727 exist in the working directory. If invoked with -A/--after, the
1725 1728 operation is recorded, but no copying is performed.
1726 1729
1727 1730 This command takes effect with the next commit. To undo a copy
1728 1731 before that, see :hg:`revert`.
1729 1732
1730 1733 Returns 0 on success, 1 if errors are encountered.
1731 1734 """
1732 1735 opts = pycompat.byteskwargs(opts)
1733 1736 with repo.wlock(False):
1734 1737 return cmdutil.copy(ui, repo, pats, opts)
1735 1738
1736 1739 @command('debugcommands', [], _('[COMMAND]'), norepo=True)
1737 1740 def debugcommands(ui, cmd='', *args):
1738 1741 """list all available commands and options"""
1739 1742 for cmd, vals in sorted(table.iteritems()):
1740 1743 cmd = cmd.split('|')[0].strip('^')
1741 1744 opts = ', '.join([i[1] for i in vals[1]])
1742 1745 ui.write('%s: %s\n' % (cmd, opts))
1743 1746
1744 1747 @command('debugcomplete',
1745 1748 [('o', 'options', None, _('show the command options'))],
1746 1749 _('[-o] CMD'),
1747 1750 norepo=True)
1748 1751 def debugcomplete(ui, cmd='', **opts):
1749 1752 """returns the completion list associated with the given command"""
1750 1753
1751 1754 if opts.get(r'options'):
1752 1755 options = []
1753 1756 otables = [globalopts]
1754 1757 if cmd:
1755 1758 aliases, entry = cmdutil.findcmd(cmd, table, False)
1756 1759 otables.append(entry[1])
1757 1760 for t in otables:
1758 1761 for o in t:
1759 1762 if "(DEPRECATED)" in o[3]:
1760 1763 continue
1761 1764 if o[0]:
1762 1765 options.append('-%s' % o[0])
1763 1766 options.append('--%s' % o[1])
1764 1767 ui.write("%s\n" % "\n".join(options))
1765 1768 return
1766 1769
1767 1770 cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table)
1768 1771 if ui.verbose:
1769 1772 cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
1770 1773 ui.write("%s\n" % "\n".join(sorted(cmdlist)))
1771 1774
1772 1775 @command('^diff',
1773 1776 [('r', 'rev', [], _('revision'), _('REV')),
1774 1777 ('c', 'change', '', _('change made by revision'), _('REV'))
1775 1778 ] + diffopts + diffopts2 + walkopts + subrepoopts,
1776 1779 _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'),
1777 1780 inferrepo=True, cmdtype=readonly)
1778 1781 def diff(ui, repo, *pats, **opts):
1779 1782 """diff repository (or selected files)
1780 1783
1781 1784 Show differences between revisions for the specified files.
1782 1785
1783 1786 Differences between files are shown using the unified diff format.
1784 1787
1785 1788 .. note::
1786 1789
1787 1790 :hg:`diff` may generate unexpected results for merges, as it will
1788 1791 default to comparing against the working directory's first
1789 1792 parent changeset if no revisions are specified.
1790 1793
1791 1794 When two revision arguments are given, then changes are shown
1792 1795 between those revisions. If only one revision is specified then
1793 1796 that revision is compared to the working directory, and, when no
1794 1797 revisions are specified, the working directory files are compared
1795 1798 to its first parent.
1796 1799
1797 1800 Alternatively you can specify -c/--change with a revision to see
1798 1801 the changes in that changeset relative to its first parent.
1799 1802
1800 1803 Without the -a/--text option, diff will avoid generating diffs of
1801 1804 files it detects as binary. With -a, diff will generate a diff
1802 1805 anyway, probably with undesirable results.
1803 1806
1804 1807 Use the -g/--git option to generate diffs in the git extended diff
1805 1808 format. For more information, read :hg:`help diffs`.
1806 1809
1807 1810 .. container:: verbose
1808 1811
1809 1812 Examples:
1810 1813
1811 1814 - compare a file in the current working directory to its parent::
1812 1815
1813 1816 hg diff foo.c
1814 1817
1815 1818 - compare two historical versions of a directory, with rename info::
1816 1819
1817 1820 hg diff --git -r 1.0:1.2 lib/
1818 1821
1819 1822 - get change stats relative to the last change on some date::
1820 1823
1821 1824 hg diff --stat -r "date('may 2')"
1822 1825
1823 1826 - diff all newly-added files that contain a keyword::
1824 1827
1825 1828 hg diff "set:added() and grep(GNU)"
1826 1829
1827 1830 - compare a revision and its parents::
1828 1831
1829 1832 hg diff -c 9353 # compare against first parent
1830 1833 hg diff -r 9353^:9353 # same using revset syntax
1831 1834 hg diff -r 9353^2:9353 # compare against the second parent
1832 1835
1833 1836 Returns 0 on success.
1834 1837 """
1835 1838
1836 1839 opts = pycompat.byteskwargs(opts)
1837 1840 revs = opts.get('rev')
1838 1841 change = opts.get('change')
1839 1842 stat = opts.get('stat')
1840 1843 reverse = opts.get('reverse')
1841 1844
1842 1845 if revs and change:
1843 1846 msg = _('cannot specify --rev and --change at the same time')
1844 1847 raise error.Abort(msg)
1845 1848 elif change:
1846 1849 repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn')
1847 1850 node2 = scmutil.revsingle(repo, change, None).node()
1848 1851 node1 = repo[node2].p1().node()
1849 1852 else:
1850 1853 repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn')
1851 1854 node1, node2 = scmutil.revpair(repo, revs)
1852 1855
1853 1856 if reverse:
1854 1857 node1, node2 = node2, node1
1855 1858
1856 1859 diffopts = patch.diffallopts(ui, opts)
1857 1860 m = scmutil.match(repo[node2], pats, opts)
1858 1861 ui.pager('diff')
1859 1862 cmdutil.diffordiffstat(ui, repo, diffopts, node1, node2, m, stat=stat,
1860 1863 listsubrepos=opts.get('subrepos'),
1861 1864 root=opts.get('root'))
1862 1865
1863 1866 @command('^export',
1864 1867 [('o', 'output', '',
1865 1868 _('print output to file with formatted name'), _('FORMAT')),
1866 1869 ('', 'switch-parent', None, _('diff against the second parent')),
1867 1870 ('r', 'rev', [], _('revisions to export'), _('REV')),
1868 1871 ] + diffopts,
1869 1872 _('[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'), cmdtype=readonly)
1870 1873 def export(ui, repo, *changesets, **opts):
1871 1874 """dump the header and diffs for one or more changesets
1872 1875
1873 1876 Print the changeset header and diffs for one or more revisions.
1874 1877 If no revision is given, the parent of the working directory is used.
1875 1878
1876 1879 The information shown in the changeset header is: author, date,
1877 1880 branch name (if non-default), changeset hash, parent(s) and commit
1878 1881 comment.
1879 1882
1880 1883 .. note::
1881 1884
1882 1885 :hg:`export` may generate unexpected diff output for merge
1883 1886 changesets, as it will compare the merge changeset against its
1884 1887 first parent only.
1885 1888
1886 1889 Output may be to a file, in which case the name of the file is
1887 1890 given using a format string. The formatting rules are as follows:
1888 1891
1889 1892 :``%%``: literal "%" character
1890 1893 :``%H``: changeset hash (40 hexadecimal digits)
1891 1894 :``%N``: number of patches being generated
1892 1895 :``%R``: changeset revision number
1893 1896 :``%b``: basename of the exporting repository
1894 1897 :``%h``: short-form changeset hash (12 hexadecimal digits)
1895 1898 :``%m``: first line of the commit message (only alphanumeric characters)
1896 1899 :``%n``: zero-padded sequence number, starting at 1
1897 1900 :``%r``: zero-padded changeset revision number
1898 1901
1899 1902 Without the -a/--text option, export will avoid generating diffs
1900 1903 of files it detects as binary. With -a, export will generate a
1901 1904 diff anyway, probably with undesirable results.
1902 1905
1903 1906 Use the -g/--git option to generate diffs in the git extended diff
1904 1907 format. See :hg:`help diffs` for more information.
1905 1908
1906 1909 With the --switch-parent option, the diff will be against the
1907 1910 second parent. It can be useful to review a merge.
1908 1911
1909 1912 .. container:: verbose
1910 1913
1911 1914 Examples:
1912 1915
1913 1916 - use export and import to transplant a bugfix to the current
1914 1917 branch::
1915 1918
1916 1919 hg export -r 9353 | hg import -
1917 1920
1918 1921 - export all the changesets between two revisions to a file with
1919 1922 rename information::
1920 1923
1921 1924 hg export --git -r 123:150 > changes.txt
1922 1925
1923 1926 - split outgoing changes into a series of patches with
1924 1927 descriptive names::
1925 1928
1926 1929 hg export -r "outgoing()" -o "%n-%m.patch"
1927 1930
1928 1931 Returns 0 on success.
1929 1932 """
1930 1933 opts = pycompat.byteskwargs(opts)
1931 1934 changesets += tuple(opts.get('rev', []))
1932 1935 if not changesets:
1933 1936 changesets = ['.']
1934 1937 repo = scmutil.unhidehashlikerevs(repo, changesets, 'nowarn')
1935 1938 revs = scmutil.revrange(repo, changesets)
1936 1939 if not revs:
1937 1940 raise error.Abort(_("export requires at least one changeset"))
1938 1941 if len(revs) > 1:
1939 1942 ui.note(_('exporting patches:\n'))
1940 1943 else:
1941 1944 ui.note(_('exporting patch:\n'))
1942 1945 ui.pager('export')
1943 1946 cmdutil.export(repo, revs, fntemplate=opts.get('output'),
1944 1947 switch_parent=opts.get('switch_parent'),
1945 1948 opts=patch.diffallopts(ui, opts))
1946 1949
1947 1950 @command('files',
1948 1951 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
1949 1952 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
1950 1953 ] + walkopts + formatteropts + subrepoopts,
1951 1954 _('[OPTION]... [FILE]...'), cmdtype=readonly)
1952 1955 def files(ui, repo, *pats, **opts):
1953 1956 """list tracked files
1954 1957
1955 1958 Print files under Mercurial control in the working directory or
1956 1959 specified revision for given files (excluding removed files).
1957 1960 Files can be specified as filenames or filesets.
1958 1961
1959 1962 If no files are given to match, this command prints the names
1960 1963 of all files under Mercurial control.
1961 1964
1962 1965 .. container:: verbose
1963 1966
1964 1967 Examples:
1965 1968
1966 1969 - list all files under the current directory::
1967 1970
1968 1971 hg files .
1969 1972
1970 1973 - shows sizes and flags for current revision::
1971 1974
1972 1975 hg files -vr .
1973 1976
1974 1977 - list all files named README::
1975 1978
1976 1979 hg files -I "**/README"
1977 1980
1978 1981 - list all binary files::
1979 1982
1980 1983 hg files "set:binary()"
1981 1984
1982 1985 - find files containing a regular expression::
1983 1986
1984 1987 hg files "set:grep('bob')"
1985 1988
1986 1989 - search tracked file contents with xargs and grep::
1987 1990
1988 1991 hg files -0 | xargs -0 grep foo
1989 1992
1990 1993 See :hg:`help patterns` and :hg:`help filesets` for more information
1991 1994 on specifying file patterns.
1992 1995
1993 1996 Returns 0 if a match is found, 1 otherwise.
1994 1997
1995 1998 """
1996 1999
1997 2000 opts = pycompat.byteskwargs(opts)
1998 2001 rev = opts.get('rev')
1999 2002 if rev:
2000 2003 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
2001 2004 ctx = scmutil.revsingle(repo, rev, None)
2002 2005
2003 2006 end = '\n'
2004 2007 if opts.get('print0'):
2005 2008 end = '\0'
2006 2009 fmt = '%s' + end
2007 2010
2008 2011 m = scmutil.match(ctx, pats, opts)
2009 2012 ui.pager('files')
2010 2013 with ui.formatter('files', opts) as fm:
2011 2014 return cmdutil.files(ui, ctx, m, fm, fmt, opts.get('subrepos'))
2012 2015
2013 2016 @command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True)
2014 2017 def forget(ui, repo, *pats, **opts):
2015 2018 """forget the specified files on the next commit
2016 2019
2017 2020 Mark the specified files so they will no longer be tracked
2018 2021 after the next commit.
2019 2022
2020 2023 This only removes files from the current branch, not from the
2021 2024 entire project history, and it does not delete them from the
2022 2025 working directory.
2023 2026
2024 2027 To delete the file from the working directory, see :hg:`remove`.
2025 2028
2026 2029 To undo a forget before the next commit, see :hg:`add`.
2027 2030
2028 2031 .. container:: verbose
2029 2032
2030 2033 Examples:
2031 2034
2032 2035 - forget newly-added binary files::
2033 2036
2034 2037 hg forget "set:added() and binary()"
2035 2038
2036 2039 - forget files that would be excluded by .hgignore::
2037 2040
2038 2041 hg forget "set:hgignore()"
2039 2042
2040 2043 Returns 0 on success.
2041 2044 """
2042 2045
2043 2046 opts = pycompat.byteskwargs(opts)
2044 2047 if not pats:
2045 2048 raise error.Abort(_('no files specified'))
2046 2049
2047 2050 m = scmutil.match(repo[None], pats, opts)
2048 2051 rejected = cmdutil.forget(ui, repo, m, prefix="", explicitonly=False)[0]
2049 2052 return rejected and 1 or 0
2050 2053
2051 2054 @command(
2052 2055 'graft',
2053 2056 [('r', 'rev', [], _('revisions to graft'), _('REV')),
2054 2057 ('c', 'continue', False, _('resume interrupted graft')),
2055 2058 ('e', 'edit', False, _('invoke editor on commit messages')),
2056 2059 ('', 'log', None, _('append graft info to log message')),
2057 2060 ('f', 'force', False, _('force graft')),
2058 2061 ('D', 'currentdate', False,
2059 2062 _('record the current date as commit date')),
2060 2063 ('U', 'currentuser', False,
2061 2064 _('record the current user as committer'), _('DATE'))]
2062 2065 + commitopts2 + mergetoolopts + dryrunopts,
2063 2066 _('[OPTION]... [-r REV]... REV...'))
2064 2067 def graft(ui, repo, *revs, **opts):
2065 2068 '''copy changes from other branches onto the current branch
2066 2069
2067 2070 This command uses Mercurial's merge logic to copy individual
2068 2071 changes from other branches without merging branches in the
2069 2072 history graph. This is sometimes known as 'backporting' or
2070 2073 'cherry-picking'. By default, graft will copy user, date, and
2071 2074 description from the source changesets.
2072 2075
2073 2076 Changesets that are ancestors of the current revision, that have
2074 2077 already been grafted, or that are merges will be skipped.
2075 2078
2076 2079 If --log is specified, log messages will have a comment appended
2077 2080 of the form::
2078 2081
2079 2082 (grafted from CHANGESETHASH)
2080 2083
2081 2084 If --force is specified, revisions will be grafted even if they
2082 2085 are already ancestors of, or have been grafted to, the destination.
2083 2086 This is useful when the revisions have since been backed out.
2084 2087
2085 2088 If a graft merge results in conflicts, the graft process is
2086 2089 interrupted so that the current merge can be manually resolved.
2087 2090 Once all conflicts are addressed, the graft process can be
2088 2091 continued with the -c/--continue option.
2089 2092
2090 2093 .. note::
2091 2094
2092 2095 The -c/--continue option does not reapply earlier options, except
2093 2096 for --force.
2094 2097
2095 2098 .. container:: verbose
2096 2099
2097 2100 Examples:
2098 2101
2099 2102 - copy a single change to the stable branch and edit its description::
2100 2103
2101 2104 hg update stable
2102 2105 hg graft --edit 9393
2103 2106
2104 2107 - graft a range of changesets with one exception, updating dates::
2105 2108
2106 2109 hg graft -D "2085::2093 and not 2091"
2107 2110
2108 2111 - continue a graft after resolving conflicts::
2109 2112
2110 2113 hg graft -c
2111 2114
2112 2115 - show the source of a grafted changeset::
2113 2116
2114 2117 hg log --debug -r .
2115 2118
2116 2119 - show revisions sorted by date::
2117 2120
2118 2121 hg log -r "sort(all(), date)"
2119 2122
2120 2123 See :hg:`help revisions` for more about specifying revisions.
2121 2124
2122 2125 Returns 0 on successful completion.
2123 2126 '''
2124 2127 with repo.wlock():
2125 2128 return _dograft(ui, repo, *revs, **opts)
2126 2129
2127 2130 def _dograft(ui, repo, *revs, **opts):
2128 2131 opts = pycompat.byteskwargs(opts)
2129 2132 if revs and opts.get('rev'):
2130 2133 ui.warn(_('warning: inconsistent use of --rev might give unexpected '
2131 2134 'revision ordering!\n'))
2132 2135
2133 2136 revs = list(revs)
2134 2137 revs.extend(opts.get('rev'))
2135 2138
2136 2139 if not opts.get('user') and opts.get('currentuser'):
2137 2140 opts['user'] = ui.username()
2138 2141 if not opts.get('date') and opts.get('currentdate'):
2139 2142 opts['date'] = "%d %d" % util.makedate()
2140 2143
2141 2144 editor = cmdutil.getcommiteditor(editform='graft',
2142 2145 **pycompat.strkwargs(opts))
2143 2146
2144 2147 cont = False
2145 2148 if opts.get('continue'):
2146 2149 cont = True
2147 2150 if revs:
2148 2151 raise error.Abort(_("can't specify --continue and revisions"))
2149 2152 # read in unfinished revisions
2150 2153 try:
2151 2154 nodes = repo.vfs.read('graftstate').splitlines()
2152 2155 revs = [repo[node].rev() for node in nodes]
2153 2156 except IOError as inst:
2154 2157 if inst.errno != errno.ENOENT:
2155 2158 raise
2156 2159 cmdutil.wrongtooltocontinue(repo, _('graft'))
2157 2160 else:
2158 2161 cmdutil.checkunfinished(repo)
2159 2162 cmdutil.bailifchanged(repo)
2160 2163 if not revs:
2161 2164 raise error.Abort(_('no revisions specified'))
2162 2165 revs = scmutil.revrange(repo, revs)
2163 2166
2164 2167 skipped = set()
2165 2168 # check for merges
2166 2169 for rev in repo.revs('%ld and merge()', revs):
2167 2170 ui.warn(_('skipping ungraftable merge revision %d\n') % rev)
2168 2171 skipped.add(rev)
2169 2172 revs = [r for r in revs if r not in skipped]
2170 2173 if not revs:
2171 2174 return -1
2172 2175
2173 2176 # Don't check in the --continue case, in effect retaining --force across
2174 2177 # --continues. That's because without --force, any revisions we decided to
2175 2178 # skip would have been filtered out here, so they wouldn't have made their
2176 2179 # way to the graftstate. With --force, any revisions we would have otherwise
2177 2180 # skipped would not have been filtered out, and if they hadn't been applied
2178 2181 # already, they'd have been in the graftstate.
2179 2182 if not (cont or opts.get('force')):
2180 2183 # check for ancestors of dest branch
2181 2184 crev = repo['.'].rev()
2182 2185 ancestors = repo.changelog.ancestors([crev], inclusive=True)
2183 2186 # XXX make this lazy in the future
2184 2187 # don't mutate while iterating, create a copy
2185 2188 for rev in list(revs):
2186 2189 if rev in ancestors:
2187 2190 ui.warn(_('skipping ancestor revision %d:%s\n') %
2188 2191 (rev, repo[rev]))
2189 2192 # XXX remove on list is slow
2190 2193 revs.remove(rev)
2191 2194 if not revs:
2192 2195 return -1
2193 2196
2194 2197 # analyze revs for earlier grafts
2195 2198 ids = {}
2196 2199 for ctx in repo.set("%ld", revs):
2197 2200 ids[ctx.hex()] = ctx.rev()
2198 2201 n = ctx.extra().get('source')
2199 2202 if n:
2200 2203 ids[n] = ctx.rev()
2201 2204
2202 2205 # check ancestors for earlier grafts
2203 2206 ui.debug('scanning for duplicate grafts\n')
2204 2207
2205 2208 # The only changesets we can be sure doesn't contain grafts of any
2206 2209 # revs, are the ones that are common ancestors of *all* revs:
2207 2210 for rev in repo.revs('only(%d,ancestor(%ld))', crev, revs):
2208 2211 ctx = repo[rev]
2209 2212 n = ctx.extra().get('source')
2210 2213 if n in ids:
2211 2214 try:
2212 2215 r = repo[n].rev()
2213 2216 except error.RepoLookupError:
2214 2217 r = None
2215 2218 if r in revs:
2216 2219 ui.warn(_('skipping revision %d:%s '
2217 2220 '(already grafted to %d:%s)\n')
2218 2221 % (r, repo[r], rev, ctx))
2219 2222 revs.remove(r)
2220 2223 elif ids[n] in revs:
2221 2224 if r is None:
2222 2225 ui.warn(_('skipping already grafted revision %d:%s '
2223 2226 '(%d:%s also has unknown origin %s)\n')
2224 2227 % (ids[n], repo[ids[n]], rev, ctx, n[:12]))
2225 2228 else:
2226 2229 ui.warn(_('skipping already grafted revision %d:%s '
2227 2230 '(%d:%s also has origin %d:%s)\n')
2228 2231 % (ids[n], repo[ids[n]], rev, ctx, r, n[:12]))
2229 2232 revs.remove(ids[n])
2230 2233 elif ctx.hex() in ids:
2231 2234 r = ids[ctx.hex()]
2232 2235 ui.warn(_('skipping already grafted revision %d:%s '
2233 2236 '(was grafted from %d:%s)\n') %
2234 2237 (r, repo[r], rev, ctx))
2235 2238 revs.remove(r)
2236 2239 if not revs:
2237 2240 return -1
2238 2241
2239 2242 for pos, ctx in enumerate(repo.set("%ld", revs)):
2240 2243 desc = '%d:%s "%s"' % (ctx.rev(), ctx,
2241 2244 ctx.description().split('\n', 1)[0])
2242 2245 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
2243 2246 if names:
2244 2247 desc += ' (%s)' % ' '.join(names)
2245 2248 ui.status(_('grafting %s\n') % desc)
2246 2249 if opts.get('dry_run'):
2247 2250 continue
2248 2251
2249 2252 source = ctx.extra().get('source')
2250 2253 extra = {}
2251 2254 if source:
2252 2255 extra['source'] = source
2253 2256 extra['intermediate-source'] = ctx.hex()
2254 2257 else:
2255 2258 extra['source'] = ctx.hex()
2256 2259 user = ctx.user()
2257 2260 if opts.get('user'):
2258 2261 user = opts['user']
2259 2262 date = ctx.date()
2260 2263 if opts.get('date'):
2261 2264 date = opts['date']
2262 2265 message = ctx.description()
2263 2266 if opts.get('log'):
2264 2267 message += '\n(grafted from %s)' % ctx.hex()
2265 2268
2266 2269 # we don't merge the first commit when continuing
2267 2270 if not cont:
2268 2271 # perform the graft merge with p1(rev) as 'ancestor'
2269 2272 try:
2270 2273 # ui.forcemerge is an internal variable, do not document
2271 2274 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
2272 2275 'graft')
2273 2276 stats = mergemod.graft(repo, ctx, ctx.p1(),
2274 2277 ['local', 'graft'])
2275 2278 finally:
2276 2279 repo.ui.setconfig('ui', 'forcemerge', '', 'graft')
2277 2280 # report any conflicts
2278 2281 if stats and stats[3] > 0:
2279 2282 # write out state for --continue
2280 2283 nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]]
2281 2284 repo.vfs.write('graftstate', ''.join(nodelines))
2282 2285 extra = ''
2283 2286 if opts.get('user'):
2284 2287 extra += ' --user %s' % util.shellquote(opts['user'])
2285 2288 if opts.get('date'):
2286 2289 extra += ' --date %s' % util.shellquote(opts['date'])
2287 2290 if opts.get('log'):
2288 2291 extra += ' --log'
2289 2292 hint=_("use 'hg resolve' and 'hg graft --continue%s'") % extra
2290 2293 raise error.Abort(
2291 2294 _("unresolved conflicts, can't continue"),
2292 2295 hint=hint)
2293 2296 else:
2294 2297 cont = False
2295 2298
2296 2299 # commit
2297 2300 node = repo.commit(text=message, user=user,
2298 2301 date=date, extra=extra, editor=editor)
2299 2302 if node is None:
2300 2303 ui.warn(
2301 2304 _('note: graft of %d:%s created no changes to commit\n') %
2302 2305 (ctx.rev(), ctx))
2303 2306
2304 2307 # remove state when we complete successfully
2305 2308 if not opts.get('dry_run'):
2306 2309 repo.vfs.unlinkpath('graftstate', ignoremissing=True)
2307 2310
2308 2311 return 0
2309 2312
2310 2313 @command('grep',
2311 2314 [('0', 'print0', None, _('end fields with NUL')),
2312 2315 ('', 'all', None, _('print all revisions that match')),
2313 2316 ('a', 'text', None, _('treat all files as text')),
2314 2317 ('f', 'follow', None,
2315 2318 _('follow changeset history,'
2316 2319 ' or file history across copies and renames')),
2317 2320 ('i', 'ignore-case', None, _('ignore case when matching')),
2318 2321 ('l', 'files-with-matches', None,
2319 2322 _('print only filenames and revisions that match')),
2320 2323 ('n', 'line-number', None, _('print matching line numbers')),
2321 2324 ('r', 'rev', [],
2322 2325 _('only search files changed within revision range'), _('REV')),
2323 2326 ('u', 'user', None, _('list the author (long with -v)')),
2324 2327 ('d', 'date', None, _('list the date (short with -q)')),
2325 2328 ] + formatteropts + walkopts,
2326 2329 _('[OPTION]... PATTERN [FILE]...'),
2327 2330 inferrepo=True, cmdtype=readonly)
2328 2331 def grep(ui, repo, pattern, *pats, **opts):
2329 2332 """search revision history for a pattern in specified files
2330 2333
2331 2334 Search revision history for a regular expression in the specified
2332 2335 files or the entire project.
2333 2336
2334 2337 By default, grep prints the most recent revision number for each
2335 2338 file in which it finds a match. To get it to print every revision
2336 2339 that contains a change in match status ("-" for a match that becomes
2337 2340 a non-match, or "+" for a non-match that becomes a match), use the
2338 2341 --all flag.
2339 2342
2340 2343 PATTERN can be any Python (roughly Perl-compatible) regular
2341 2344 expression.
2342 2345
2343 2346 If no FILEs are specified (and -f/--follow isn't set), all files in
2344 2347 the repository are searched, including those that don't exist in the
2345 2348 current branch or have been deleted in a prior changeset.
2346 2349
2347 2350 Returns 0 if a match is found, 1 otherwise.
2348 2351 """
2349 2352 opts = pycompat.byteskwargs(opts)
2350 2353 reflags = re.M
2351 2354 if opts.get('ignore_case'):
2352 2355 reflags |= re.I
2353 2356 try:
2354 2357 regexp = util.re.compile(pattern, reflags)
2355 2358 except re.error as inst:
2356 2359 ui.warn(_("grep: invalid match pattern: %s\n") % inst)
2357 2360 return 1
2358 2361 sep, eol = ':', '\n'
2359 2362 if opts.get('print0'):
2360 2363 sep = eol = '\0'
2361 2364
2362 2365 getfile = util.lrucachefunc(repo.file)
2363 2366
2364 2367 def matchlines(body):
2365 2368 begin = 0
2366 2369 linenum = 0
2367 2370 while begin < len(body):
2368 2371 match = regexp.search(body, begin)
2369 2372 if not match:
2370 2373 break
2371 2374 mstart, mend = match.span()
2372 2375 linenum += body.count('\n', begin, mstart) + 1
2373 2376 lstart = body.rfind('\n', begin, mstart) + 1 or begin
2374 2377 begin = body.find('\n', mend) + 1 or len(body) + 1
2375 2378 lend = begin - 1
2376 2379 yield linenum, mstart - lstart, mend - lstart, body[lstart:lend]
2377 2380
2378 2381 class linestate(object):
2379 2382 def __init__(self, line, linenum, colstart, colend):
2380 2383 self.line = line
2381 2384 self.linenum = linenum
2382 2385 self.colstart = colstart
2383 2386 self.colend = colend
2384 2387
2385 2388 def __hash__(self):
2386 2389 return hash((self.linenum, self.line))
2387 2390
2388 2391 def __eq__(self, other):
2389 2392 return self.line == other.line
2390 2393
2391 2394 def findpos(self):
2392 2395 """Iterate all (start, end) indices of matches"""
2393 2396 yield self.colstart, self.colend
2394 2397 p = self.colend
2395 2398 while p < len(self.line):
2396 2399 m = regexp.search(self.line, p)
2397 2400 if not m:
2398 2401 break
2399 2402 yield m.span()
2400 2403 p = m.end()
2401 2404
2402 2405 matches = {}
2403 2406 copies = {}
2404 2407 def grepbody(fn, rev, body):
2405 2408 matches[rev].setdefault(fn, [])
2406 2409 m = matches[rev][fn]
2407 2410 for lnum, cstart, cend, line in matchlines(body):
2408 2411 s = linestate(line, lnum, cstart, cend)
2409 2412 m.append(s)
2410 2413
2411 2414 def difflinestates(a, b):
2412 2415 sm = difflib.SequenceMatcher(None, a, b)
2413 2416 for tag, alo, ahi, blo, bhi in sm.get_opcodes():
2414 2417 if tag == 'insert':
2415 2418 for i in xrange(blo, bhi):
2416 2419 yield ('+', b[i])
2417 2420 elif tag == 'delete':
2418 2421 for i in xrange(alo, ahi):
2419 2422 yield ('-', a[i])
2420 2423 elif tag == 'replace':
2421 2424 for i in xrange(alo, ahi):
2422 2425 yield ('-', a[i])
2423 2426 for i in xrange(blo, bhi):
2424 2427 yield ('+', b[i])
2425 2428
2426 2429 def display(fm, fn, ctx, pstates, states):
2427 2430 rev = ctx.rev()
2428 2431 if fm.isplain():
2429 2432 formatuser = ui.shortuser
2430 2433 else:
2431 2434 formatuser = str
2432 2435 if ui.quiet:
2433 2436 datefmt = '%Y-%m-%d'
2434 2437 else:
2435 2438 datefmt = '%a %b %d %H:%M:%S %Y %1%2'
2436 2439 found = False
2437 2440 @util.cachefunc
2438 2441 def binary():
2439 2442 flog = getfile(fn)
2440 2443 return util.binary(flog.read(ctx.filenode(fn)))
2441 2444
2442 2445 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
2443 2446 if opts.get('all'):
2444 2447 iter = difflinestates(pstates, states)
2445 2448 else:
2446 2449 iter = [('', l) for l in states]
2447 2450 for change, l in iter:
2448 2451 fm.startitem()
2449 2452 fm.data(node=fm.hexfunc(ctx.node()))
2450 2453 cols = [
2451 2454 ('filename', fn, True),
2452 2455 ('rev', rev, True),
2453 2456 ('linenumber', l.linenum, opts.get('line_number')),
2454 2457 ]
2455 2458 if opts.get('all'):
2456 2459 cols.append(('change', change, True))
2457 2460 cols.extend([
2458 2461 ('user', formatuser(ctx.user()), opts.get('user')),
2459 2462 ('date', fm.formatdate(ctx.date(), datefmt), opts.get('date')),
2460 2463 ])
2461 2464 lastcol = next(name for name, data, cond in reversed(cols) if cond)
2462 2465 for name, data, cond in cols:
2463 2466 field = fieldnamemap.get(name, name)
2464 2467 fm.condwrite(cond, field, '%s', data, label='grep.%s' % name)
2465 2468 if cond and name != lastcol:
2466 2469 fm.plain(sep, label='grep.sep')
2467 2470 if not opts.get('files_with_matches'):
2468 2471 fm.plain(sep, label='grep.sep')
2469 2472 if not opts.get('text') and binary():
2470 2473 fm.plain(_(" Binary file matches"))
2471 2474 else:
2472 2475 displaymatches(fm.nested('texts'), l)
2473 2476 fm.plain(eol)
2474 2477 found = True
2475 2478 if opts.get('files_with_matches'):
2476 2479 break
2477 2480 return found
2478 2481
2479 2482 def displaymatches(fm, l):
2480 2483 p = 0
2481 2484 for s, e in l.findpos():
2482 2485 if p < s:
2483 2486 fm.startitem()
2484 2487 fm.write('text', '%s', l.line[p:s])
2485 2488 fm.data(matched=False)
2486 2489 fm.startitem()
2487 2490 fm.write('text', '%s', l.line[s:e], label='grep.match')
2488 2491 fm.data(matched=True)
2489 2492 p = e
2490 2493 if p < len(l.line):
2491 2494 fm.startitem()
2492 2495 fm.write('text', '%s', l.line[p:])
2493 2496 fm.data(matched=False)
2494 2497 fm.end()
2495 2498
2496 2499 skip = {}
2497 2500 revfiles = {}
2498 2501 match = scmutil.match(repo[None], pats, opts)
2499 2502 found = False
2500 2503 follow = opts.get('follow')
2501 2504
2502 2505 def prep(ctx, fns):
2503 2506 rev = ctx.rev()
2504 2507 pctx = ctx.p1()
2505 2508 parent = pctx.rev()
2506 2509 matches.setdefault(rev, {})
2507 2510 matches.setdefault(parent, {})
2508 2511 files = revfiles.setdefault(rev, [])
2509 2512 for fn in fns:
2510 2513 flog = getfile(fn)
2511 2514 try:
2512 2515 fnode = ctx.filenode(fn)
2513 2516 except error.LookupError:
2514 2517 continue
2515 2518
2516 2519 copied = flog.renamed(fnode)
2517 2520 copy = follow and copied and copied[0]
2518 2521 if copy:
2519 2522 copies.setdefault(rev, {})[fn] = copy
2520 2523 if fn in skip:
2521 2524 if copy:
2522 2525 skip[copy] = True
2523 2526 continue
2524 2527 files.append(fn)
2525 2528
2526 2529 if fn not in matches[rev]:
2527 2530 grepbody(fn, rev, flog.read(fnode))
2528 2531
2529 2532 pfn = copy or fn
2530 2533 if pfn not in matches[parent]:
2531 2534 try:
2532 2535 fnode = pctx.filenode(pfn)
2533 2536 grepbody(pfn, parent, flog.read(fnode))
2534 2537 except error.LookupError:
2535 2538 pass
2536 2539
2537 2540 ui.pager('grep')
2538 2541 fm = ui.formatter('grep', opts)
2539 2542 for ctx in cmdutil.walkchangerevs(repo, match, opts, prep):
2540 2543 rev = ctx.rev()
2541 2544 parent = ctx.p1().rev()
2542 2545 for fn in sorted(revfiles.get(rev, [])):
2543 2546 states = matches[rev][fn]
2544 2547 copy = copies.get(rev, {}).get(fn)
2545 2548 if fn in skip:
2546 2549 if copy:
2547 2550 skip[copy] = True
2548 2551 continue
2549 2552 pstates = matches.get(parent, {}).get(copy or fn, [])
2550 2553 if pstates or states:
2551 2554 r = display(fm, fn, ctx, pstates, states)
2552 2555 found = found or r
2553 2556 if r and not opts.get('all'):
2554 2557 skip[fn] = True
2555 2558 if copy:
2556 2559 skip[copy] = True
2557 2560 del matches[rev]
2558 2561 del revfiles[rev]
2559 2562 fm.end()
2560 2563
2561 2564 return not found
2562 2565
2563 2566 @command('heads',
2564 2567 [('r', 'rev', '',
2565 2568 _('show only heads which are descendants of STARTREV'), _('STARTREV')),
2566 2569 ('t', 'topo', False, _('show topological heads only')),
2567 2570 ('a', 'active', False, _('show active branchheads only (DEPRECATED)')),
2568 2571 ('c', 'closed', False, _('show normal and closed branch heads')),
2569 2572 ] + templateopts,
2570 2573 _('[-ct] [-r STARTREV] [REV]...'), cmdtype=readonly)
2571 2574 def heads(ui, repo, *branchrevs, **opts):
2572 2575 """show branch heads
2573 2576
2574 2577 With no arguments, show all open branch heads in the repository.
2575 2578 Branch heads are changesets that have no descendants on the
2576 2579 same branch. They are where development generally takes place and
2577 2580 are the usual targets for update and merge operations.
2578 2581
2579 2582 If one or more REVs are given, only open branch heads on the
2580 2583 branches associated with the specified changesets are shown. This
2581 2584 means that you can use :hg:`heads .` to see the heads on the
2582 2585 currently checked-out branch.
2583 2586
2584 2587 If -c/--closed is specified, also show branch heads marked closed
2585 2588 (see :hg:`commit --close-branch`).
2586 2589
2587 2590 If STARTREV is specified, only those heads that are descendants of
2588 2591 STARTREV will be displayed.
2589 2592
2590 2593 If -t/--topo is specified, named branch mechanics will be ignored and only
2591 2594 topological heads (changesets with no children) will be shown.
2592 2595
2593 2596 Returns 0 if matching heads are found, 1 if not.
2594 2597 """
2595 2598
2596 2599 opts = pycompat.byteskwargs(opts)
2597 2600 start = None
2598 2601 rev = opts.get('rev')
2599 2602 if rev:
2600 2603 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
2601 2604 start = scmutil.revsingle(repo, rev, None).node()
2602 2605
2603 2606 if opts.get('topo'):
2604 2607 heads = [repo[h] for h in repo.heads(start)]
2605 2608 else:
2606 2609 heads = []
2607 2610 for branch in repo.branchmap():
2608 2611 heads += repo.branchheads(branch, start, opts.get('closed'))
2609 2612 heads = [repo[h] for h in heads]
2610 2613
2611 2614 if branchrevs:
2612 2615 branches = set(repo[br].branch() for br in branchrevs)
2613 2616 heads = [h for h in heads if h.branch() in branches]
2614 2617
2615 2618 if opts.get('active') and branchrevs:
2616 2619 dagheads = repo.heads(start)
2617 2620 heads = [h for h in heads if h.node() in dagheads]
2618 2621
2619 2622 if branchrevs:
2620 2623 haveheads = set(h.branch() for h in heads)
2621 2624 if branches - haveheads:
2622 2625 headless = ', '.join(b for b in branches - haveheads)
2623 2626 msg = _('no open branch heads found on branches %s')
2624 2627 if opts.get('rev'):
2625 2628 msg += _(' (started at %s)') % opts['rev']
2626 2629 ui.warn((msg + '\n') % headless)
2627 2630
2628 2631 if not heads:
2629 2632 return 1
2630 2633
2631 2634 ui.pager('heads')
2632 2635 heads = sorted(heads, key=lambda x: -x.rev())
2633 2636 displayer = cmdutil.show_changeset(ui, repo, opts)
2634 2637 for ctx in heads:
2635 2638 displayer.show(ctx)
2636 2639 displayer.close()
2637 2640
2638 2641 @command('help',
2639 2642 [('e', 'extension', None, _('show only help for extensions')),
2640 2643 ('c', 'command', None, _('show only help for commands')),
2641 2644 ('k', 'keyword', None, _('show topics matching keyword')),
2642 2645 ('s', 'system', [], _('show help for specific platform(s)')),
2643 2646 ],
2644 2647 _('[-ecks] [TOPIC]'),
2645 2648 norepo=True, cmdtype=readonly)
2646 2649 def help_(ui, name=None, **opts):
2647 2650 """show help for a given topic or a help overview
2648 2651
2649 2652 With no arguments, print a list of commands with short help messages.
2650 2653
2651 2654 Given a topic, extension, or command name, print help for that
2652 2655 topic.
2653 2656
2654 2657 Returns 0 if successful.
2655 2658 """
2656 2659
2657 2660 keep = opts.get(r'system') or []
2658 2661 if len(keep) == 0:
2659 2662 if pycompat.sysplatform.startswith('win'):
2660 2663 keep.append('windows')
2661 2664 elif pycompat.sysplatform == 'OpenVMS':
2662 2665 keep.append('vms')
2663 2666 elif pycompat.sysplatform == 'plan9':
2664 2667 keep.append('plan9')
2665 2668 else:
2666 2669 keep.append('unix')
2667 2670 keep.append(pycompat.sysplatform.lower())
2668 2671 if ui.verbose:
2669 2672 keep.append('verbose')
2670 2673
2671 2674 commands = sys.modules[__name__]
2672 2675 formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts)
2673 2676 ui.pager('help')
2674 2677 ui.write(formatted)
2675 2678
2676 2679
2677 2680 @command('identify|id',
2678 2681 [('r', 'rev', '',
2679 2682 _('identify the specified revision'), _('REV')),
2680 2683 ('n', 'num', None, _('show local revision number')),
2681 2684 ('i', 'id', None, _('show global revision id')),
2682 2685 ('b', 'branch', None, _('show branch')),
2683 2686 ('t', 'tags', None, _('show tags')),
2684 2687 ('B', 'bookmarks', None, _('show bookmarks')),
2685 2688 ] + remoteopts + formatteropts,
2686 2689 _('[-nibtB] [-r REV] [SOURCE]'),
2687 2690 optionalrepo=True, cmdtype=readonly)
2688 2691 def identify(ui, repo, source=None, rev=None,
2689 2692 num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
2690 2693 """identify the working directory or specified revision
2691 2694
2692 2695 Print a summary identifying the repository state at REV using one or
2693 2696 two parent hash identifiers, followed by a "+" if the working
2694 2697 directory has uncommitted changes, the branch name (if not default),
2695 2698 a list of tags, and a list of bookmarks.
2696 2699
2697 2700 When REV is not given, print a summary of the current state of the
2698 2701 repository.
2699 2702
2700 2703 Specifying a path to a repository root or Mercurial bundle will
2701 2704 cause lookup to operate on that repository/bundle.
2702 2705
2703 2706 .. container:: verbose
2704 2707
2705 2708 Examples:
2706 2709
2707 2710 - generate a build identifier for the working directory::
2708 2711
2709 2712 hg id --id > build-id.dat
2710 2713
2711 2714 - find the revision corresponding to a tag::
2712 2715
2713 2716 hg id -n -r 1.3
2714 2717
2715 2718 - check the most recent revision of a remote repository::
2716 2719
2717 2720 hg id -r tip https://www.mercurial-scm.org/repo/hg/
2718 2721
2719 2722 See :hg:`log` for generating more information about specific revisions,
2720 2723 including full hash identifiers.
2721 2724
2722 2725 Returns 0 if successful.
2723 2726 """
2724 2727
2725 2728 opts = pycompat.byteskwargs(opts)
2726 2729 if not repo and not source:
2727 2730 raise error.Abort(_("there is no Mercurial repository here "
2728 2731 "(.hg not found)"))
2729 2732
2730 2733 if ui.debugflag:
2731 2734 hexfunc = hex
2732 2735 else:
2733 2736 hexfunc = short
2734 2737 default = not (num or id or branch or tags or bookmarks)
2735 2738 output = []
2736 2739 revs = []
2737 2740
2738 2741 if source:
2739 2742 source, branches = hg.parseurl(ui.expandpath(source))
2740 2743 peer = hg.peer(repo or ui, opts, source) # only pass ui when no repo
2741 2744 repo = peer.local()
2742 2745 revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
2743 2746
2744 2747 fm = ui.formatter('identify', opts)
2745 2748 fm.startitem()
2746 2749
2747 2750 if not repo:
2748 2751 if num or branch or tags:
2749 2752 raise error.Abort(
2750 2753 _("can't query remote revision number, branch, or tags"))
2751 2754 if not rev and revs:
2752 2755 rev = revs[0]
2753 2756 if not rev:
2754 2757 rev = "tip"
2755 2758
2756 2759 remoterev = peer.lookup(rev)
2757 2760 hexrev = hexfunc(remoterev)
2758 2761 if default or id:
2759 2762 output = [hexrev]
2760 2763 fm.data(id=hexrev)
2761 2764
2762 2765 def getbms():
2763 2766 bms = []
2764 2767
2765 2768 if 'bookmarks' in peer.listkeys('namespaces'):
2766 2769 hexremoterev = hex(remoterev)
2767 2770 bms = [bm for bm, bmr in peer.listkeys('bookmarks').iteritems()
2768 2771 if bmr == hexremoterev]
2769 2772
2770 2773 return sorted(bms)
2771 2774
2772 2775 bms = getbms()
2773 2776 if bookmarks:
2774 2777 output.extend(bms)
2775 2778 elif default and not ui.quiet:
2776 2779 # multiple bookmarks for a single parent separated by '/'
2777 2780 bm = '/'.join(bms)
2778 2781 if bm:
2779 2782 output.append(bm)
2780 2783
2781 2784 fm.data(node=hex(remoterev))
2782 2785 fm.data(bookmarks=fm.formatlist(bms, name='bookmark'))
2783 2786 else:
2784 2787 if rev:
2785 2788 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
2786 2789 ctx = scmutil.revsingle(repo, rev, None)
2787 2790
2788 2791 if ctx.rev() is None:
2789 2792 ctx = repo[None]
2790 2793 parents = ctx.parents()
2791 2794 taglist = []
2792 2795 for p in parents:
2793 2796 taglist.extend(p.tags())
2794 2797
2795 2798 dirty = ""
2796 2799 if ctx.dirty(missing=True, merge=False, branch=False):
2797 2800 dirty = '+'
2798 2801 fm.data(dirty=dirty)
2799 2802
2800 2803 hexoutput = [hexfunc(p.node()) for p in parents]
2801 2804 if default or id:
2802 2805 output = ["%s%s" % ('+'.join(hexoutput), dirty)]
2803 2806 fm.data(id="%s%s" % ('+'.join(hexoutput), dirty))
2804 2807
2805 2808 if num:
2806 2809 numoutput = ["%d" % p.rev() for p in parents]
2807 2810 output.append("%s%s" % ('+'.join(numoutput), dirty))
2808 2811
2809 2812 fn = fm.nested('parents')
2810 2813 for p in parents:
2811 2814 fn.startitem()
2812 2815 fn.data(rev=p.rev())
2813 2816 fn.data(node=p.hex())
2814 2817 fn.context(ctx=p)
2815 2818 fn.end()
2816 2819 else:
2817 2820 hexoutput = hexfunc(ctx.node())
2818 2821 if default or id:
2819 2822 output = [hexoutput]
2820 2823 fm.data(id=hexoutput)
2821 2824
2822 2825 if num:
2823 2826 output.append(pycompat.bytestr(ctx.rev()))
2824 2827 taglist = ctx.tags()
2825 2828
2826 2829 if default and not ui.quiet:
2827 2830 b = ctx.branch()
2828 2831 if b != 'default':
2829 2832 output.append("(%s)" % b)
2830 2833
2831 2834 # multiple tags for a single parent separated by '/'
2832 2835 t = '/'.join(taglist)
2833 2836 if t:
2834 2837 output.append(t)
2835 2838
2836 2839 # multiple bookmarks for a single parent separated by '/'
2837 2840 bm = '/'.join(ctx.bookmarks())
2838 2841 if bm:
2839 2842 output.append(bm)
2840 2843 else:
2841 2844 if branch:
2842 2845 output.append(ctx.branch())
2843 2846
2844 2847 if tags:
2845 2848 output.extend(taglist)
2846 2849
2847 2850 if bookmarks:
2848 2851 output.extend(ctx.bookmarks())
2849 2852
2850 2853 fm.data(node=ctx.hex())
2851 2854 fm.data(branch=ctx.branch())
2852 2855 fm.data(tags=fm.formatlist(taglist, name='tag', sep=':'))
2853 2856 fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name='bookmark'))
2854 2857 fm.context(ctx=ctx)
2855 2858
2856 2859 fm.plain("%s\n" % ' '.join(output))
2857 2860 fm.end()
2858 2861
2859 2862 @command('import|patch',
2860 2863 [('p', 'strip', 1,
2861 2864 _('directory strip option for patch. This has the same '
2862 2865 'meaning as the corresponding patch option'), _('NUM')),
2863 2866 ('b', 'base', '', _('base path (DEPRECATED)'), _('PATH')),
2864 2867 ('e', 'edit', False, _('invoke editor on commit messages')),
2865 2868 ('f', 'force', None,
2866 2869 _('skip check for outstanding uncommitted changes (DEPRECATED)')),
2867 2870 ('', 'no-commit', None,
2868 2871 _("don't commit, just update the working directory")),
2869 2872 ('', 'bypass', None,
2870 2873 _("apply patch without touching the working directory")),
2871 2874 ('', 'partial', None,
2872 2875 _('commit even if some hunks fail')),
2873 2876 ('', 'exact', None,
2874 2877 _('abort if patch would apply lossily')),
2875 2878 ('', 'prefix', '',
2876 2879 _('apply patch to subdirectory'), _('DIR')),
2877 2880 ('', 'import-branch', None,
2878 2881 _('use any branch information in patch (implied by --exact)'))] +
2879 2882 commitopts + commitopts2 + similarityopts,
2880 2883 _('[OPTION]... PATCH...'))
2881 2884 def import_(ui, repo, patch1=None, *patches, **opts):
2882 2885 """import an ordered set of patches
2883 2886
2884 2887 Import a list of patches and commit them individually (unless
2885 2888 --no-commit is specified).
2886 2889
2887 2890 To read a patch from standard input (stdin), use "-" as the patch
2888 2891 name. If a URL is specified, the patch will be downloaded from
2889 2892 there.
2890 2893
2891 2894 Import first applies changes to the working directory (unless
2892 2895 --bypass is specified), import will abort if there are outstanding
2893 2896 changes.
2894 2897
2895 2898 Use --bypass to apply and commit patches directly to the
2896 2899 repository, without affecting the working directory. Without
2897 2900 --exact, patches will be applied on top of the working directory
2898 2901 parent revision.
2899 2902
2900 2903 You can import a patch straight from a mail message. Even patches
2901 2904 as attachments work (to use the body part, it must have type
2902 2905 text/plain or text/x-patch). From and Subject headers of email
2903 2906 message are used as default committer and commit message. All
2904 2907 text/plain body parts before first diff are added to the commit
2905 2908 message.
2906 2909
2907 2910 If the imported patch was generated by :hg:`export`, user and
2908 2911 description from patch override values from message headers and
2909 2912 body. Values given on command line with -m/--message and -u/--user
2910 2913 override these.
2911 2914
2912 2915 If --exact is specified, import will set the working directory to
2913 2916 the parent of each patch before applying it, and will abort if the
2914 2917 resulting changeset has a different ID than the one recorded in
2915 2918 the patch. This will guard against various ways that portable
2916 2919 patch formats and mail systems might fail to transfer Mercurial
2917 2920 data or metadata. See :hg:`bundle` for lossless transmission.
2918 2921
2919 2922 Use --partial to ensure a changeset will be created from the patch
2920 2923 even if some hunks fail to apply. Hunks that fail to apply will be
2921 2924 written to a <target-file>.rej file. Conflicts can then be resolved
2922 2925 by hand before :hg:`commit --amend` is run to update the created
2923 2926 changeset. This flag exists to let people import patches that
2924 2927 partially apply without losing the associated metadata (author,
2925 2928 date, description, ...).
2926 2929
2927 2930 .. note::
2928 2931
2929 2932 When no hunks apply cleanly, :hg:`import --partial` will create
2930 2933 an empty changeset, importing only the patch metadata.
2931 2934
2932 2935 With -s/--similarity, hg will attempt to discover renames and
2933 2936 copies in the patch in the same way as :hg:`addremove`.
2934 2937
2935 2938 It is possible to use external patch programs to perform the patch
2936 2939 by setting the ``ui.patch`` configuration option. For the default
2937 2940 internal tool, the fuzz can also be configured via ``patch.fuzz``.
2938 2941 See :hg:`help config` for more information about configuration
2939 2942 files and how to use these options.
2940 2943
2941 2944 See :hg:`help dates` for a list of formats valid for -d/--date.
2942 2945
2943 2946 .. container:: verbose
2944 2947
2945 2948 Examples:
2946 2949
2947 2950 - import a traditional patch from a website and detect renames::
2948 2951
2949 2952 hg import -s 80 http://example.com/bugfix.patch
2950 2953
2951 2954 - import a changeset from an hgweb server::
2952 2955
2953 2956 hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa
2954 2957
2955 2958 - import all the patches in an Unix-style mbox::
2956 2959
2957 2960 hg import incoming-patches.mbox
2958 2961
2959 2962 - import patches from stdin::
2960 2963
2961 2964 hg import -
2962 2965
2963 2966 - attempt to exactly restore an exported changeset (not always
2964 2967 possible)::
2965 2968
2966 2969 hg import --exact proposed-fix.patch
2967 2970
2968 2971 - use an external tool to apply a patch which is too fuzzy for
2969 2972 the default internal tool.
2970 2973
2971 2974 hg import --config ui.patch="patch --merge" fuzzy.patch
2972 2975
2973 2976 - change the default fuzzing from 2 to a less strict 7
2974 2977
2975 2978 hg import --config ui.fuzz=7 fuzz.patch
2976 2979
2977 2980 Returns 0 on success, 1 on partial success (see --partial).
2978 2981 """
2979 2982
2980 2983 opts = pycompat.byteskwargs(opts)
2981 2984 if not patch1:
2982 2985 raise error.Abort(_('need at least one patch to import'))
2983 2986
2984 2987 patches = (patch1,) + patches
2985 2988
2986 2989 date = opts.get('date')
2987 2990 if date:
2988 2991 opts['date'] = util.parsedate(date)
2989 2992
2990 2993 exact = opts.get('exact')
2991 2994 update = not opts.get('bypass')
2992 2995 if not update and opts.get('no_commit'):
2993 2996 raise error.Abort(_('cannot use --no-commit with --bypass'))
2994 2997 try:
2995 2998 sim = float(opts.get('similarity') or 0)
2996 2999 except ValueError:
2997 3000 raise error.Abort(_('similarity must be a number'))
2998 3001 if sim < 0 or sim > 100:
2999 3002 raise error.Abort(_('similarity must be between 0 and 100'))
3000 3003 if sim and not update:
3001 3004 raise error.Abort(_('cannot use --similarity with --bypass'))
3002 3005 if exact:
3003 3006 if opts.get('edit'):
3004 3007 raise error.Abort(_('cannot use --exact with --edit'))
3005 3008 if opts.get('prefix'):
3006 3009 raise error.Abort(_('cannot use --exact with --prefix'))
3007 3010
3008 3011 base = opts["base"]
3009 3012 wlock = dsguard = lock = tr = None
3010 3013 msgs = []
3011 3014 ret = 0
3012 3015
3013 3016
3014 3017 try:
3015 3018 wlock = repo.wlock()
3016 3019
3017 3020 if update:
3018 3021 cmdutil.checkunfinished(repo)
3019 3022 if (exact or not opts.get('force')):
3020 3023 cmdutil.bailifchanged(repo)
3021 3024
3022 3025 if not opts.get('no_commit'):
3023 3026 lock = repo.lock()
3024 3027 tr = repo.transaction('import')
3025 3028 else:
3026 3029 dsguard = dirstateguard.dirstateguard(repo, 'import')
3027 3030 parents = repo[None].parents()
3028 3031 for patchurl in patches:
3029 3032 if patchurl == '-':
3030 3033 ui.status(_('applying patch from stdin\n'))
3031 3034 patchfile = ui.fin
3032 3035 patchurl = 'stdin' # for error message
3033 3036 else:
3034 3037 patchurl = os.path.join(base, patchurl)
3035 3038 ui.status(_('applying %s\n') % patchurl)
3036 3039 patchfile = hg.openpath(ui, patchurl)
3037 3040
3038 3041 haspatch = False
3039 3042 for hunk in patch.split(patchfile):
3040 3043 (msg, node, rej) = cmdutil.tryimportone(ui, repo, hunk,
3041 3044 parents, opts,
3042 3045 msgs, hg.clean)
3043 3046 if msg:
3044 3047 haspatch = True
3045 3048 ui.note(msg + '\n')
3046 3049 if update or exact:
3047 3050 parents = repo[None].parents()
3048 3051 else:
3049 3052 parents = [repo[node]]
3050 3053 if rej:
3051 3054 ui.write_err(_("patch applied partially\n"))
3052 3055 ui.write_err(_("(fix the .rej files and run "
3053 3056 "`hg commit --amend`)\n"))
3054 3057 ret = 1
3055 3058 break
3056 3059
3057 3060 if not haspatch:
3058 3061 raise error.Abort(_('%s: no diffs found') % patchurl)
3059 3062
3060 3063 if tr:
3061 3064 tr.close()
3062 3065 if msgs:
3063 3066 repo.savecommitmessage('\n* * *\n'.join(msgs))
3064 3067 if dsguard:
3065 3068 dsguard.close()
3066 3069 return ret
3067 3070 finally:
3068 3071 if tr:
3069 3072 tr.release()
3070 3073 release(lock, dsguard, wlock)
3071 3074
3072 3075 @command('incoming|in',
3073 3076 [('f', 'force', None,
3074 3077 _('run even if remote repository is unrelated')),
3075 3078 ('n', 'newest-first', None, _('show newest record first')),
3076 3079 ('', 'bundle', '',
3077 3080 _('file to store the bundles into'), _('FILE')),
3078 3081 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
3079 3082 ('B', 'bookmarks', False, _("compare bookmarks")),
3080 3083 ('b', 'branch', [],
3081 3084 _('a specific branch you would like to pull'), _('BRANCH')),
3082 3085 ] + logopts + remoteopts + subrepoopts,
3083 3086 _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]'))
3084 3087 def incoming(ui, repo, source="default", **opts):
3085 3088 """show new changesets found in source
3086 3089
3087 3090 Show new changesets found in the specified path/URL or the default
3088 3091 pull location. These are the changesets that would have been pulled
3089 3092 by :hg:`pull` at the time you issued this command.
3090 3093
3091 3094 See pull for valid source format details.
3092 3095
3093 3096 .. container:: verbose
3094 3097
3095 3098 With -B/--bookmarks, the result of bookmark comparison between
3096 3099 local and remote repositories is displayed. With -v/--verbose,
3097 3100 status is also displayed for each bookmark like below::
3098 3101
3099 3102 BM1 01234567890a added
3100 3103 BM2 1234567890ab advanced
3101 3104 BM3 234567890abc diverged
3102 3105 BM4 34567890abcd changed
3103 3106
3104 3107 The action taken locally when pulling depends on the
3105 3108 status of each bookmark:
3106 3109
3107 3110 :``added``: pull will create it
3108 3111 :``advanced``: pull will update it
3109 3112 :``diverged``: pull will create a divergent bookmark
3110 3113 :``changed``: result depends on remote changesets
3111 3114
3112 3115 From the point of view of pulling behavior, bookmark
3113 3116 existing only in the remote repository are treated as ``added``,
3114 3117 even if it is in fact locally deleted.
3115 3118
3116 3119 .. container:: verbose
3117 3120
3118 3121 For remote repository, using --bundle avoids downloading the
3119 3122 changesets twice if the incoming is followed by a pull.
3120 3123
3121 3124 Examples:
3122 3125
3123 3126 - show incoming changes with patches and full description::
3124 3127
3125 3128 hg incoming -vp
3126 3129
3127 3130 - show incoming changes excluding merges, store a bundle::
3128 3131
3129 3132 hg in -vpM --bundle incoming.hg
3130 3133 hg pull incoming.hg
3131 3134
3132 3135 - briefly list changes inside a bundle::
3133 3136
3134 3137 hg in changes.hg -T "{desc|firstline}\\n"
3135 3138
3136 3139 Returns 0 if there are incoming changes, 1 otherwise.
3137 3140 """
3138 3141 opts = pycompat.byteskwargs(opts)
3139 3142 if opts.get('graph'):
3140 3143 cmdutil.checkunsupportedgraphflags([], opts)
3141 3144 def display(other, chlist, displayer):
3142 3145 revdag = cmdutil.graphrevs(other, chlist, opts)
3143 3146 cmdutil.displaygraph(ui, repo, revdag, displayer,
3144 3147 graphmod.asciiedges)
3145 3148
3146 3149 hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True)
3147 3150 return 0
3148 3151
3149 3152 if opts.get('bundle') and opts.get('subrepos'):
3150 3153 raise error.Abort(_('cannot combine --bundle and --subrepos'))
3151 3154
3152 3155 if opts.get('bookmarks'):
3153 3156 source, branches = hg.parseurl(ui.expandpath(source),
3154 3157 opts.get('branch'))
3155 3158 other = hg.peer(repo, opts, source)
3156 3159 if 'bookmarks' not in other.listkeys('namespaces'):
3157 3160 ui.warn(_("remote doesn't support bookmarks\n"))
3158 3161 return 0
3159 3162 ui.pager('incoming')
3160 3163 ui.status(_('comparing with %s\n') % util.hidepassword(source))
3161 3164 return bookmarks.incoming(ui, repo, other)
3162 3165
3163 3166 repo._subtoppath = ui.expandpath(source)
3164 3167 try:
3165 3168 return hg.incoming(ui, repo, source, opts)
3166 3169 finally:
3167 3170 del repo._subtoppath
3168 3171
3169 3172
3170 3173 @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'),
3171 3174 norepo=True)
3172 3175 def init(ui, dest=".", **opts):
3173 3176 """create a new repository in the given directory
3174 3177
3175 3178 Initialize a new repository in the given directory. If the given
3176 3179 directory does not exist, it will be created.
3177 3180
3178 3181 If no directory is given, the current directory is used.
3179 3182
3180 3183 It is possible to specify an ``ssh://`` URL as the destination.
3181 3184 See :hg:`help urls` for more information.
3182 3185
3183 3186 Returns 0 on success.
3184 3187 """
3185 3188 opts = pycompat.byteskwargs(opts)
3186 3189 hg.peer(ui, opts, ui.expandpath(dest), create=True)
3187 3190
3188 3191 @command('locate',
3189 3192 [('r', 'rev', '', _('search the repository as it is in REV'), _('REV')),
3190 3193 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
3191 3194 ('f', 'fullpath', None, _('print complete paths from the filesystem root')),
3192 3195 ] + walkopts,
3193 3196 _('[OPTION]... [PATTERN]...'))
3194 3197 def locate(ui, repo, *pats, **opts):
3195 3198 """locate files matching specific patterns (DEPRECATED)
3196 3199
3197 3200 Print files under Mercurial control in the working directory whose
3198 3201 names match the given patterns.
3199 3202
3200 3203 By default, this command searches all directories in the working
3201 3204 directory. To search just the current directory and its
3202 3205 subdirectories, use "--include .".
3203 3206
3204 3207 If no patterns are given to match, this command prints the names
3205 3208 of all files under Mercurial control in the working directory.
3206 3209
3207 3210 If you want to feed the output of this command into the "xargs"
3208 3211 command, use the -0 option to both this command and "xargs". This
3209 3212 will avoid the problem of "xargs" treating single filenames that
3210 3213 contain whitespace as multiple filenames.
3211 3214
3212 3215 See :hg:`help files` for a more versatile command.
3213 3216
3214 3217 Returns 0 if a match is found, 1 otherwise.
3215 3218 """
3216 3219 opts = pycompat.byteskwargs(opts)
3217 3220 if opts.get('print0'):
3218 3221 end = '\0'
3219 3222 else:
3220 3223 end = '\n'
3221 3224 rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
3222 3225
3223 3226 ret = 1
3224 3227 ctx = repo[rev]
3225 3228 m = scmutil.match(ctx, pats, opts, default='relglob',
3226 3229 badfn=lambda x, y: False)
3227 3230
3228 3231 ui.pager('locate')
3229 3232 for abs in ctx.matches(m):
3230 3233 if opts.get('fullpath'):
3231 3234 ui.write(repo.wjoin(abs), end)
3232 3235 else:
3233 3236 ui.write(((pats and m.rel(abs)) or abs), end)
3234 3237 ret = 0
3235 3238
3236 3239 return ret
3237 3240
3238 3241 @command('^log|history',
3239 3242 [('f', 'follow', None,
3240 3243 _('follow changeset history, or file history across copies and renames')),
3241 3244 ('', 'follow-first', None,
3242 3245 _('only follow the first parent of merge changesets (DEPRECATED)')),
3243 3246 ('d', 'date', '', _('show revisions matching date spec'), _('DATE')),
3244 3247 ('C', 'copies', None, _('show copied files')),
3245 3248 ('k', 'keyword', [],
3246 3249 _('do case-insensitive search for a given text'), _('TEXT')),
3247 3250 ('r', 'rev', [], _('show the specified revision or revset'), _('REV')),
3248 3251 ('L', 'line-range', [],
3249 3252 _('follow line range of specified file (EXPERIMENTAL)'),
3250 3253 _('FILE,RANGE')),
3251 3254 ('', 'removed', None, _('include revisions where files were removed')),
3252 3255 ('m', 'only-merges', None, _('show only merges (DEPRECATED)')),
3253 3256 ('u', 'user', [], _('revisions committed by user'), _('USER')),
3254 3257 ('', 'only-branch', [],
3255 3258 _('show only changesets within the given named branch (DEPRECATED)'),
3256 3259 _('BRANCH')),
3257 3260 ('b', 'branch', [],
3258 3261 _('show changesets within the given named branch'), _('BRANCH')),
3259 3262 ('P', 'prune', [],
3260 3263 _('do not display revision or any of its ancestors'), _('REV')),
3261 3264 ] + logopts + walkopts,
3262 3265 _('[OPTION]... [FILE]'),
3263 3266 inferrepo=True, cmdtype=readonly)
3264 3267 def log(ui, repo, *pats, **opts):
3265 3268 """show revision history of entire repository or files
3266 3269
3267 3270 Print the revision history of the specified files or the entire
3268 3271 project.
3269 3272
3270 3273 If no revision range is specified, the default is ``tip:0`` unless
3271 3274 --follow is set, in which case the working directory parent is
3272 3275 used as the starting revision.
3273 3276
3274 3277 File history is shown without following rename or copy history of
3275 3278 files. Use -f/--follow with a filename to follow history across
3276 3279 renames and copies. --follow without a filename will only show
3277 3280 ancestors or descendants of the starting revision.
3278 3281
3279 3282 By default this command prints revision number and changeset id,
3280 3283 tags, non-trivial parents, user, date and time, and a summary for
3281 3284 each commit. When the -v/--verbose switch is used, the list of
3282 3285 changed files and full commit message are shown.
3283 3286
3284 3287 With --graph the revisions are shown as an ASCII art DAG with the most
3285 3288 recent changeset at the top.
3286 3289 'o' is a changeset, '@' is a working directory parent, 'x' is obsolete,
3287 3290 and '+' represents a fork where the changeset from the lines below is a
3288 3291 parent of the 'o' merge on the same line.
3289 3292 Paths in the DAG are represented with '|', '/' and so forth. ':' in place
3290 3293 of a '|' indicates one or more revisions in a path are omitted.
3291 3294
3292 3295 .. container:: verbose
3293 3296
3294 3297 Use -L/--line-range FILE,M:N options to follow the history of lines
3295 3298 from M to N in FILE. With -p/--patch only diff hunks affecting
3296 3299 specified line range will be shown. This option requires --follow;
3297 3300 it can be specified multiple times. Currently, this option is not
3298 3301 compatible with --graph. This option is experimental.
3299 3302
3300 3303 .. note::
3301 3304
3302 3305 :hg:`log --patch` may generate unexpected diff output for merge
3303 3306 changesets, as it will only compare the merge changeset against
3304 3307 its first parent. Also, only files different from BOTH parents
3305 3308 will appear in files:.
3306 3309
3307 3310 .. note::
3308 3311
3309 3312 For performance reasons, :hg:`log FILE` may omit duplicate changes
3310 3313 made on branches and will not show removals or mode changes. To
3311 3314 see all such changes, use the --removed switch.
3312 3315
3313 3316 .. container:: verbose
3314 3317
3315 3318 .. note::
3316 3319
3317 3320 The history resulting from -L/--line-range options depends on diff
3318 3321 options; for instance if white-spaces are ignored, respective changes
3319 3322 with only white-spaces in specified line range will not be listed.
3320 3323
3321 3324 .. container:: verbose
3322 3325
3323 3326 Some examples:
3324 3327
3325 3328 - changesets with full descriptions and file lists::
3326 3329
3327 3330 hg log -v
3328 3331
3329 3332 - changesets ancestral to the working directory::
3330 3333
3331 3334 hg log -f
3332 3335
3333 3336 - last 10 commits on the current branch::
3334 3337
3335 3338 hg log -l 10 -b .
3336 3339
3337 3340 - changesets showing all modifications of a file, including removals::
3338 3341
3339 3342 hg log --removed file.c
3340 3343
3341 3344 - all changesets that touch a directory, with diffs, excluding merges::
3342 3345
3343 3346 hg log -Mp lib/
3344 3347
3345 3348 - all revision numbers that match a keyword::
3346 3349
3347 3350 hg log -k bug --template "{rev}\\n"
3348 3351
3349 3352 - the full hash identifier of the working directory parent::
3350 3353
3351 3354 hg log -r . --template "{node}\\n"
3352 3355
3353 3356 - list available log templates::
3354 3357
3355 3358 hg log -T list
3356 3359
3357 3360 - check if a given changeset is included in a tagged release::
3358 3361
3359 3362 hg log -r "a21ccf and ancestor(1.9)"
3360 3363
3361 3364 - find all changesets by some user in a date range::
3362 3365
3363 3366 hg log -k alice -d "may 2008 to jul 2008"
3364 3367
3365 3368 - summary of all changesets after the last tag::
3366 3369
3367 3370 hg log -r "last(tagged())::" --template "{desc|firstline}\\n"
3368 3371
3369 3372 - changesets touching lines 13 to 23 for file.c::
3370 3373
3371 3374 hg log -L file.c,13:23
3372 3375
3373 3376 - changesets touching lines 13 to 23 for file.c and lines 2 to 6 of
3374 3377 main.c with patch::
3375 3378
3376 3379 hg log -L file.c,13:23 -L main.c,2:6 -p
3377 3380
3378 3381 See :hg:`help dates` for a list of formats valid for -d/--date.
3379 3382
3380 3383 See :hg:`help revisions` for more about specifying and ordering
3381 3384 revisions.
3382 3385
3383 3386 See :hg:`help templates` for more about pre-packaged styles and
3384 3387 specifying custom templates. The default template used by the log
3385 3388 command can be customized via the ``ui.logtemplate`` configuration
3386 3389 setting.
3387 3390
3388 3391 Returns 0 on success.
3389 3392
3390 3393 """
3391 3394 opts = pycompat.byteskwargs(opts)
3392 3395 linerange = opts.get('line_range')
3393 3396
3394 3397 if linerange and not opts.get('follow'):
3395 3398 raise error.Abort(_('--line-range requires --follow'))
3396 3399
3397 3400 if linerange and pats:
3398 3401 raise error.Abort(
3399 3402 _('FILE arguments are not compatible with --line-range option')
3400 3403 )
3401 3404
3402 3405 if opts.get('follow') and opts.get('rev'):
3403 3406 opts['rev'] = [revsetlang.formatspec('reverse(::%lr)', opts.get('rev'))]
3404 3407 del opts['follow']
3405 3408
3406 3409 if opts.get('graph'):
3407 3410 if linerange:
3408 3411 raise error.Abort(_('graph not supported with line range patterns'))
3409 3412 return cmdutil.graphlog(ui, repo, pats, opts)
3410 3413
3411 3414 repo = scmutil.unhidehashlikerevs(repo, opts.get('rev'), 'nowarn')
3412 3415 revs, expr, filematcher = cmdutil.getlogrevs(repo, pats, opts)
3413 3416 hunksfilter = None
3414 3417
3415 3418 if linerange:
3416 3419 revs, lrfilematcher, hunksfilter = cmdutil.getloglinerangerevs(
3417 3420 repo, revs, opts)
3418 3421
3419 3422 if filematcher is not None and lrfilematcher is not None:
3420 3423 basefilematcher = filematcher
3421 3424
3422 3425 def filematcher(rev):
3423 3426 files = (basefilematcher(rev).files()
3424 3427 + lrfilematcher(rev).files())
3425 3428 return scmutil.matchfiles(repo, files)
3426 3429
3427 3430 elif filematcher is None:
3428 3431 filematcher = lrfilematcher
3429 3432
3430 3433 limit = cmdutil.loglimit(opts)
3431 3434 count = 0
3432 3435
3433 3436 getrenamed = None
3434 3437 if opts.get('copies'):
3435 3438 endrev = None
3436 3439 if opts.get('rev'):
3437 3440 endrev = scmutil.revrange(repo, opts.get('rev')).max() + 1
3438 3441 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev)
3439 3442
3440 3443 ui.pager('log')
3441 3444 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
3442 3445 for rev in revs:
3443 3446 if count == limit:
3444 3447 break
3445 3448 ctx = repo[rev]
3446 3449 copies = None
3447 3450 if getrenamed is not None and rev:
3448 3451 copies = []
3449 3452 for fn in ctx.files():
3450 3453 rename = getrenamed(fn, rev)
3451 3454 if rename:
3452 3455 copies.append((fn, rename[0]))
3453 3456 if filematcher:
3454 3457 revmatchfn = filematcher(ctx.rev())
3455 3458 else:
3456 3459 revmatchfn = None
3457 3460 if hunksfilter:
3458 3461 revhunksfilter = hunksfilter(rev)
3459 3462 else:
3460 3463 revhunksfilter = None
3461 3464 displayer.show(ctx, copies=copies, matchfn=revmatchfn,
3462 3465 hunksfilterfn=revhunksfilter)
3463 3466 if displayer.flush(ctx):
3464 3467 count += 1
3465 3468
3466 3469 displayer.close()
3467 3470
3468 3471 @command('manifest',
3469 3472 [('r', 'rev', '', _('revision to display'), _('REV')),
3470 3473 ('', 'all', False, _("list files from all revisions"))]
3471 3474 + formatteropts,
3472 3475 _('[-r REV]'), cmdtype=readonly)
3473 3476 def manifest(ui, repo, node=None, rev=None, **opts):
3474 3477 """output the current or given revision of the project manifest
3475 3478
3476 3479 Print a list of version controlled files for the given revision.
3477 3480 If no revision is given, the first parent of the working directory
3478 3481 is used, or the null revision if no revision is checked out.
3479 3482
3480 3483 With -v, print file permissions, symlink and executable bits.
3481 3484 With --debug, print file revision hashes.
3482 3485
3483 3486 If option --all is specified, the list of all files from all revisions
3484 3487 is printed. This includes deleted and renamed files.
3485 3488
3486 3489 Returns 0 on success.
3487 3490 """
3488 3491 opts = pycompat.byteskwargs(opts)
3489 3492 fm = ui.formatter('manifest', opts)
3490 3493
3491 3494 if opts.get('all'):
3492 3495 if rev or node:
3493 3496 raise error.Abort(_("can't specify a revision with --all"))
3494 3497
3495 3498 res = []
3496 3499 prefix = "data/"
3497 3500 suffix = ".i"
3498 3501 plen = len(prefix)
3499 3502 slen = len(suffix)
3500 3503 with repo.lock():
3501 3504 for fn, b, size in repo.store.datafiles():
3502 3505 if size != 0 and fn[-slen:] == suffix and fn[:plen] == prefix:
3503 3506 res.append(fn[plen:-slen])
3504 3507 ui.pager('manifest')
3505 3508 for f in res:
3506 3509 fm.startitem()
3507 3510 fm.write("path", '%s\n', f)
3508 3511 fm.end()
3509 3512 return
3510 3513
3511 3514 if rev and node:
3512 3515 raise error.Abort(_("please specify just one revision"))
3513 3516
3514 3517 if not node:
3515 3518 node = rev
3516 3519
3517 3520 char = {'l': '@', 'x': '*', '': ''}
3518 3521 mode = {'l': '644', 'x': '755', '': '644'}
3519 3522 if node:
3520 3523 repo = scmutil.unhidehashlikerevs(repo, [node], 'nowarn')
3521 3524 ctx = scmutil.revsingle(repo, node)
3522 3525 mf = ctx.manifest()
3523 3526 ui.pager('manifest')
3524 3527 for f in ctx:
3525 3528 fm.startitem()
3526 3529 fl = ctx[f].flags()
3527 3530 fm.condwrite(ui.debugflag, 'hash', '%s ', hex(mf[f]))
3528 3531 fm.condwrite(ui.verbose, 'mode type', '%s %1s ', mode[fl], char[fl])
3529 3532 fm.write('path', '%s\n', f)
3530 3533 fm.end()
3531 3534
3532 3535 @command('^merge',
3533 3536 [('f', 'force', None,
3534 3537 _('force a merge including outstanding changes (DEPRECATED)')),
3535 3538 ('r', 'rev', '', _('revision to merge'), _('REV')),
3536 3539 ('P', 'preview', None,
3537 3540 _('review revisions to merge (no merge is performed)'))
3538 3541 ] + mergetoolopts,
3539 3542 _('[-P] [[-r] REV]'))
3540 3543 def merge(ui, repo, node=None, **opts):
3541 3544 """merge another revision into working directory
3542 3545
3543 3546 The current working directory is updated with all changes made in
3544 3547 the requested revision since the last common predecessor revision.
3545 3548
3546 3549 Files that changed between either parent are marked as changed for
3547 3550 the next commit and a commit must be performed before any further
3548 3551 updates to the repository are allowed. The next commit will have
3549 3552 two parents.
3550 3553
3551 3554 ``--tool`` can be used to specify the merge tool used for file
3552 3555 merges. It overrides the HGMERGE environment variable and your
3553 3556 configuration files. See :hg:`help merge-tools` for options.
3554 3557
3555 3558 If no revision is specified, the working directory's parent is a
3556 3559 head revision, and the current branch contains exactly one other
3557 3560 head, the other head is merged with by default. Otherwise, an
3558 3561 explicit revision with which to merge with must be provided.
3559 3562
3560 3563 See :hg:`help resolve` for information on handling file conflicts.
3561 3564
3562 3565 To undo an uncommitted merge, use :hg:`update --clean .` which
3563 3566 will check out a clean copy of the original merge parent, losing
3564 3567 all changes.
3565 3568
3566 3569 Returns 0 on success, 1 if there are unresolved files.
3567 3570 """
3568 3571
3569 3572 opts = pycompat.byteskwargs(opts)
3570 3573 if opts.get('rev') and node:
3571 3574 raise error.Abort(_("please specify just one revision"))
3572 3575 if not node:
3573 3576 node = opts.get('rev')
3574 3577
3575 3578 if node:
3576 3579 node = scmutil.revsingle(repo, node).node()
3577 3580
3578 3581 if not node:
3579 3582 node = repo[destutil.destmerge(repo)].node()
3580 3583
3581 3584 if opts.get('preview'):
3582 3585 # find nodes that are ancestors of p2 but not of p1
3583 3586 p1 = repo.lookup('.')
3584 3587 p2 = repo.lookup(node)
3585 3588 nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
3586 3589
3587 3590 displayer = cmdutil.show_changeset(ui, repo, opts)
3588 3591 for node in nodes:
3589 3592 displayer.show(repo[node])
3590 3593 displayer.close()
3591 3594 return 0
3592 3595
3593 3596 try:
3594 3597 # ui.forcemerge is an internal variable, do not document
3595 3598 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'merge')
3596 3599 force = opts.get('force')
3597 3600 labels = ['working copy', 'merge rev']
3598 3601 return hg.merge(repo, node, force=force, mergeforce=force,
3599 3602 labels=labels)
3600 3603 finally:
3601 3604 ui.setconfig('ui', 'forcemerge', '', 'merge')
3602 3605
3603 3606 @command('outgoing|out',
3604 3607 [('f', 'force', None, _('run even when the destination is unrelated')),
3605 3608 ('r', 'rev', [],
3606 3609 _('a changeset intended to be included in the destination'), _('REV')),
3607 3610 ('n', 'newest-first', None, _('show newest record first')),
3608 3611 ('B', 'bookmarks', False, _('compare bookmarks')),
3609 3612 ('b', 'branch', [], _('a specific branch you would like to push'),
3610 3613 _('BRANCH')),
3611 3614 ] + logopts + remoteopts + subrepoopts,
3612 3615 _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]'))
3613 3616 def outgoing(ui, repo, dest=None, **opts):
3614 3617 """show changesets not found in the destination
3615 3618
3616 3619 Show changesets not found in the specified destination repository
3617 3620 or the default push location. These are the changesets that would
3618 3621 be pushed if a push was requested.
3619 3622
3620 3623 See pull for details of valid destination formats.
3621 3624
3622 3625 .. container:: verbose
3623 3626
3624 3627 With -B/--bookmarks, the result of bookmark comparison between
3625 3628 local and remote repositories is displayed. With -v/--verbose,
3626 3629 status is also displayed for each bookmark like below::
3627 3630
3628 3631 BM1 01234567890a added
3629 3632 BM2 deleted
3630 3633 BM3 234567890abc advanced
3631 3634 BM4 34567890abcd diverged
3632 3635 BM5 4567890abcde changed
3633 3636
3634 3637 The action taken when pushing depends on the
3635 3638 status of each bookmark:
3636 3639
3637 3640 :``added``: push with ``-B`` will create it
3638 3641 :``deleted``: push with ``-B`` will delete it
3639 3642 :``advanced``: push will update it
3640 3643 :``diverged``: push with ``-B`` will update it
3641 3644 :``changed``: push with ``-B`` will update it
3642 3645
3643 3646 From the point of view of pushing behavior, bookmarks
3644 3647 existing only in the remote repository are treated as
3645 3648 ``deleted``, even if it is in fact added remotely.
3646 3649
3647 3650 Returns 0 if there are outgoing changes, 1 otherwise.
3648 3651 """
3649 3652 opts = pycompat.byteskwargs(opts)
3650 3653 if opts.get('graph'):
3651 3654 cmdutil.checkunsupportedgraphflags([], opts)
3652 3655 o, other = hg._outgoing(ui, repo, dest, opts)
3653 3656 if not o:
3654 3657 cmdutil.outgoinghooks(ui, repo, other, opts, o)
3655 3658 return
3656 3659
3657 3660 revdag = cmdutil.graphrevs(repo, o, opts)
3658 3661 ui.pager('outgoing')
3659 3662 displayer = cmdutil.show_changeset(ui, repo, opts, buffered=True)
3660 3663 cmdutil.displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges)
3661 3664 cmdutil.outgoinghooks(ui, repo, other, opts, o)
3662 3665 return 0
3663 3666
3664 3667 if opts.get('bookmarks'):
3665 3668 dest = ui.expandpath(dest or 'default-push', dest or 'default')
3666 3669 dest, branches = hg.parseurl(dest, opts.get('branch'))
3667 3670 other = hg.peer(repo, opts, dest)
3668 3671 if 'bookmarks' not in other.listkeys('namespaces'):
3669 3672 ui.warn(_("remote doesn't support bookmarks\n"))
3670 3673 return 0
3671 3674 ui.status(_('comparing with %s\n') % util.hidepassword(dest))
3672 3675 ui.pager('outgoing')
3673 3676 return bookmarks.outgoing(ui, repo, other)
3674 3677
3675 3678 repo._subtoppath = ui.expandpath(dest or 'default-push', dest or 'default')
3676 3679 try:
3677 3680 return hg.outgoing(ui, repo, dest, opts)
3678 3681 finally:
3679 3682 del repo._subtoppath
3680 3683
3681 3684 @command('parents',
3682 3685 [('r', 'rev', '', _('show parents of the specified revision'), _('REV')),
3683 3686 ] + templateopts,
3684 3687 _('[-r REV] [FILE]'),
3685 3688 inferrepo=True)
3686 3689 def parents(ui, repo, file_=None, **opts):
3687 3690 """show the parents of the working directory or revision (DEPRECATED)
3688 3691
3689 3692 Print the working directory's parent revisions. If a revision is
3690 3693 given via -r/--rev, the parent of that revision will be printed.
3691 3694 If a file argument is given, the revision in which the file was
3692 3695 last changed (before the working directory revision or the
3693 3696 argument to --rev if given) is printed.
3694 3697
3695 3698 This command is equivalent to::
3696 3699
3697 3700 hg log -r "p1()+p2()" or
3698 3701 hg log -r "p1(REV)+p2(REV)" or
3699 3702 hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or
3700 3703 hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))"
3701 3704
3702 3705 See :hg:`summary` and :hg:`help revsets` for related information.
3703 3706
3704 3707 Returns 0 on success.
3705 3708 """
3706 3709
3707 3710 opts = pycompat.byteskwargs(opts)
3708 3711 rev = opts.get('rev')
3709 3712 if rev:
3710 3713 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
3711 3714 ctx = scmutil.revsingle(repo, rev, None)
3712 3715
3713 3716 if file_:
3714 3717 m = scmutil.match(ctx, (file_,), opts)
3715 3718 if m.anypats() or len(m.files()) != 1:
3716 3719 raise error.Abort(_('can only specify an explicit filename'))
3717 3720 file_ = m.files()[0]
3718 3721 filenodes = []
3719 3722 for cp in ctx.parents():
3720 3723 if not cp:
3721 3724 continue
3722 3725 try:
3723 3726 filenodes.append(cp.filenode(file_))
3724 3727 except error.LookupError:
3725 3728 pass
3726 3729 if not filenodes:
3727 3730 raise error.Abort(_("'%s' not found in manifest!") % file_)
3728 3731 p = []
3729 3732 for fn in filenodes:
3730 3733 fctx = repo.filectx(file_, fileid=fn)
3731 3734 p.append(fctx.node())
3732 3735 else:
3733 3736 p = [cp.node() for cp in ctx.parents()]
3734 3737
3735 3738 displayer = cmdutil.show_changeset(ui, repo, opts)
3736 3739 for n in p:
3737 3740 if n != nullid:
3738 3741 displayer.show(repo[n])
3739 3742 displayer.close()
3740 3743
3741 3744 @command('paths', formatteropts, _('[NAME]'), optionalrepo=True,
3742 3745 cmdtype=readonly)
3743 3746 def paths(ui, repo, search=None, **opts):
3744 3747 """show aliases for remote repositories
3745 3748
3746 3749 Show definition of symbolic path name NAME. If no name is given,
3747 3750 show definition of all available names.
3748 3751
3749 3752 Option -q/--quiet suppresses all output when searching for NAME
3750 3753 and shows only the path names when listing all definitions.
3751 3754
3752 3755 Path names are defined in the [paths] section of your
3753 3756 configuration file and in ``/etc/mercurial/hgrc``. If run inside a
3754 3757 repository, ``.hg/hgrc`` is used, too.
3755 3758
3756 3759 The path names ``default`` and ``default-push`` have a special
3757 3760 meaning. When performing a push or pull operation, they are used
3758 3761 as fallbacks if no location is specified on the command-line.
3759 3762 When ``default-push`` is set, it will be used for push and
3760 3763 ``default`` will be used for pull; otherwise ``default`` is used
3761 3764 as the fallback for both. When cloning a repository, the clone
3762 3765 source is written as ``default`` in ``.hg/hgrc``.
3763 3766
3764 3767 .. note::
3765 3768
3766 3769 ``default`` and ``default-push`` apply to all inbound (e.g.
3767 3770 :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email`
3768 3771 and :hg:`bundle`) operations.
3769 3772
3770 3773 See :hg:`help urls` for more information.
3771 3774
3772 3775 Returns 0 on success.
3773 3776 """
3774 3777
3775 3778 opts = pycompat.byteskwargs(opts)
3776 3779 ui.pager('paths')
3777 3780 if search:
3778 3781 pathitems = [(name, path) for name, path in ui.paths.iteritems()
3779 3782 if name == search]
3780 3783 else:
3781 3784 pathitems = sorted(ui.paths.iteritems())
3782 3785
3783 3786 fm = ui.formatter('paths', opts)
3784 3787 if fm.isplain():
3785 3788 hidepassword = util.hidepassword
3786 3789 else:
3787 3790 hidepassword = str
3788 3791 if ui.quiet:
3789 3792 namefmt = '%s\n'
3790 3793 else:
3791 3794 namefmt = '%s = '
3792 3795 showsubopts = not search and not ui.quiet
3793 3796
3794 3797 for name, path in pathitems:
3795 3798 fm.startitem()
3796 3799 fm.condwrite(not search, 'name', namefmt, name)
3797 3800 fm.condwrite(not ui.quiet, 'url', '%s\n', hidepassword(path.rawloc))
3798 3801 for subopt, value in sorted(path.suboptions.items()):
3799 3802 assert subopt not in ('name', 'url')
3800 3803 if showsubopts:
3801 3804 fm.plain('%s:%s = ' % (name, subopt))
3802 3805 fm.condwrite(showsubopts, subopt, '%s\n', value)
3803 3806
3804 3807 fm.end()
3805 3808
3806 3809 if search and not pathitems:
3807 3810 if not ui.quiet:
3808 3811 ui.warn(_("not found!\n"))
3809 3812 return 1
3810 3813 else:
3811 3814 return 0
3812 3815
3813 3816 @command('phase',
3814 3817 [('p', 'public', False, _('set changeset phase to public')),
3815 3818 ('d', 'draft', False, _('set changeset phase to draft')),
3816 3819 ('s', 'secret', False, _('set changeset phase to secret')),
3817 3820 ('f', 'force', False, _('allow to move boundary backward')),
3818 3821 ('r', 'rev', [], _('target revision'), _('REV')),
3819 3822 ],
3820 3823 _('[-p|-d|-s] [-f] [-r] [REV...]'))
3821 3824 def phase(ui, repo, *revs, **opts):
3822 3825 """set or show the current phase name
3823 3826
3824 3827 With no argument, show the phase name of the current revision(s).
3825 3828
3826 3829 With one of -p/--public, -d/--draft or -s/--secret, change the
3827 3830 phase value of the specified revisions.
3828 3831
3829 3832 Unless -f/--force is specified, :hg:`phase` won't move changesets from a
3830 3833 lower phase to a higher phase. Phases are ordered as follows::
3831 3834
3832 3835 public < draft < secret
3833 3836
3834 3837 Returns 0 on success, 1 if some phases could not be changed.
3835 3838
3836 3839 (For more information about the phases concept, see :hg:`help phases`.)
3837 3840 """
3838 3841 opts = pycompat.byteskwargs(opts)
3839 3842 # search for a unique phase argument
3840 3843 targetphase = None
3841 3844 for idx, name in enumerate(phases.phasenames):
3842 3845 if opts[name]:
3843 3846 if targetphase is not None:
3844 3847 raise error.Abort(_('only one phase can be specified'))
3845 3848 targetphase = idx
3846 3849
3847 3850 # look for specified revision
3848 3851 revs = list(revs)
3849 3852 revs.extend(opts['rev'])
3850 3853 if not revs:
3851 3854 # display both parents as the second parent phase can influence
3852 3855 # the phase of a merge commit
3853 3856 revs = [c.rev() for c in repo[None].parents()]
3854 3857
3855 3858 revs = scmutil.revrange(repo, revs)
3856 3859
3857 3860 lock = None
3858 3861 ret = 0
3859 3862 if targetphase is None:
3860 3863 # display
3861 3864 for r in revs:
3862 3865 ctx = repo[r]
3863 3866 ui.write('%i: %s\n' % (ctx.rev(), ctx.phasestr()))
3864 3867 else:
3865 3868 tr = None
3866 3869 lock = repo.lock()
3867 3870 try:
3868 3871 tr = repo.transaction("phase")
3869 3872 # set phase
3870 3873 if not revs:
3871 3874 raise error.Abort(_('empty revision set'))
3872 3875 nodes = [repo[r].node() for r in revs]
3873 3876 # moving revision from public to draft may hide them
3874 3877 # We have to check result on an unfiltered repository
3875 3878 unfi = repo.unfiltered()
3876 3879 getphase = unfi._phasecache.phase
3877 3880 olddata = [getphase(unfi, r) for r in unfi]
3878 3881 phases.advanceboundary(repo, tr, targetphase, nodes)
3879 3882 if opts['force']:
3880 3883 phases.retractboundary(repo, tr, targetphase, nodes)
3881 3884 tr.close()
3882 3885 finally:
3883 3886 if tr is not None:
3884 3887 tr.release()
3885 3888 lock.release()
3886 3889 getphase = unfi._phasecache.phase
3887 3890 newdata = [getphase(unfi, r) for r in unfi]
3888 3891 changes = sum(newdata[r] != olddata[r] for r in unfi)
3889 3892 cl = unfi.changelog
3890 3893 rejected = [n for n in nodes
3891 3894 if newdata[cl.rev(n)] < targetphase]
3892 3895 if rejected:
3893 3896 ui.warn(_('cannot move %i changesets to a higher '
3894 3897 'phase, use --force\n') % len(rejected))
3895 3898 ret = 1
3896 3899 if changes:
3897 3900 msg = _('phase changed for %i changesets\n') % changes
3898 3901 if ret:
3899 3902 ui.status(msg)
3900 3903 else:
3901 3904 ui.note(msg)
3902 3905 else:
3903 3906 ui.warn(_('no phases changed\n'))
3904 3907 return ret
3905 3908
3906 3909 def postincoming(ui, repo, modheads, optupdate, checkout, brev):
3907 3910 """Run after a changegroup has been added via pull/unbundle
3908 3911
3909 3912 This takes arguments below:
3910 3913
3911 3914 :modheads: change of heads by pull/unbundle
3912 3915 :optupdate: updating working directory is needed or not
3913 3916 :checkout: update destination revision (or None to default destination)
3914 3917 :brev: a name, which might be a bookmark to be activated after updating
3915 3918 """
3916 3919 if modheads == 0:
3917 3920 return
3918 3921 if optupdate:
3919 3922 try:
3920 3923 return hg.updatetotally(ui, repo, checkout, brev)
3921 3924 except error.UpdateAbort as inst:
3922 3925 msg = _("not updating: %s") % str(inst)
3923 3926 hint = inst.hint
3924 3927 raise error.UpdateAbort(msg, hint=hint)
3925 3928 if modheads > 1:
3926 3929 currentbranchheads = len(repo.branchheads())
3927 3930 if currentbranchheads == modheads:
3928 3931 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
3929 3932 elif currentbranchheads > 1:
3930 3933 ui.status(_("(run 'hg heads .' to see heads, 'hg merge' to "
3931 3934 "merge)\n"))
3932 3935 else:
3933 3936 ui.status(_("(run 'hg heads' to see heads)\n"))
3934 3937 elif not ui.configbool('commands', 'update.requiredest'):
3935 3938 ui.status(_("(run 'hg update' to get a working copy)\n"))
3936 3939
3937 3940 @command('^pull',
3938 3941 [('u', 'update', None,
3939 3942 _('update to new branch head if new descendants were pulled')),
3940 3943 ('f', 'force', None, _('run even when remote repository is unrelated')),
3941 3944 ('r', 'rev', [], _('a remote changeset intended to be added'), _('REV')),
3942 3945 ('B', 'bookmark', [], _("bookmark to pull"), _('BOOKMARK')),
3943 3946 ('b', 'branch', [], _('a specific branch you would like to pull'),
3944 3947 _('BRANCH')),
3945 3948 ] + remoteopts,
3946 3949 _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]'))
3947 3950 def pull(ui, repo, source="default", **opts):
3948 3951 """pull changes from the specified source
3949 3952
3950 3953 Pull changes from a remote repository to a local one.
3951 3954
3952 3955 This finds all changes from the repository at the specified path
3953 3956 or URL and adds them to a local repository (the current one unless
3954 3957 -R is specified). By default, this does not update the copy of the
3955 3958 project in the working directory.
3956 3959
3957 3960 Use :hg:`incoming` if you want to see what would have been added
3958 3961 by a pull at the time you issued this command. If you then decide
3959 3962 to add those changes to the repository, you should use :hg:`pull
3960 3963 -r X` where ``X`` is the last changeset listed by :hg:`incoming`.
3961 3964
3962 3965 If SOURCE is omitted, the 'default' path will be used.
3963 3966 See :hg:`help urls` for more information.
3964 3967
3965 3968 Specifying bookmark as ``.`` is equivalent to specifying the active
3966 3969 bookmark's name.
3967 3970
3968 3971 Returns 0 on success, 1 if an update had unresolved files.
3969 3972 """
3970 3973
3971 3974 opts = pycompat.byteskwargs(opts)
3972 3975 if ui.configbool('commands', 'update.requiredest') and opts.get('update'):
3973 3976 msg = _('update destination required by configuration')
3974 3977 hint = _('use hg pull followed by hg update DEST')
3975 3978 raise error.Abort(msg, hint=hint)
3976 3979
3977 3980 source, branches = hg.parseurl(ui.expandpath(source), opts.get('branch'))
3978 3981 ui.status(_('pulling from %s\n') % util.hidepassword(source))
3979 3982 other = hg.peer(repo, opts, source)
3980 3983 try:
3981 3984 revs, checkout = hg.addbranchrevs(repo, other, branches,
3982 3985 opts.get('rev'))
3983 3986
3984 3987
3985 3988 pullopargs = {}
3986 3989 if opts.get('bookmark'):
3987 3990 if not revs:
3988 3991 revs = []
3989 3992 # The list of bookmark used here is not the one used to actually
3990 3993 # update the bookmark name. This can result in the revision pulled
3991 3994 # not ending up with the name of the bookmark because of a race
3992 3995 # condition on the server. (See issue 4689 for details)
3993 3996 remotebookmarks = other.listkeys('bookmarks')
3994 3997 remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks)
3995 3998 pullopargs['remotebookmarks'] = remotebookmarks
3996 3999 for b in opts['bookmark']:
3997 4000 b = repo._bookmarks.expandname(b)
3998 4001 if b not in remotebookmarks:
3999 4002 raise error.Abort(_('remote bookmark %s not found!') % b)
4000 4003 revs.append(hex(remotebookmarks[b]))
4001 4004
4002 4005 if revs:
4003 4006 try:
4004 4007 # When 'rev' is a bookmark name, we cannot guarantee that it
4005 4008 # will be updated with that name because of a race condition
4006 4009 # server side. (See issue 4689 for details)
4007 4010 oldrevs = revs
4008 4011 revs = [] # actually, nodes
4009 4012 for r in oldrevs:
4010 4013 node = other.lookup(r)
4011 4014 revs.append(node)
4012 4015 if r == checkout:
4013 4016 checkout = node
4014 4017 except error.CapabilityError:
4015 4018 err = _("other repository doesn't support revision lookup, "
4016 4019 "so a rev cannot be specified.")
4017 4020 raise error.Abort(err)
4018 4021
4019 4022 pullopargs.update(opts.get('opargs', {}))
4020 4023 modheads = exchange.pull(repo, other, heads=revs,
4021 4024 force=opts.get('force'),
4022 4025 bookmarks=opts.get('bookmark', ()),
4023 4026 opargs=pullopargs).cgresult
4024 4027
4025 4028 # brev is a name, which might be a bookmark to be activated at
4026 4029 # the end of the update. In other words, it is an explicit
4027 4030 # destination of the update
4028 4031 brev = None
4029 4032
4030 4033 if checkout:
4031 4034 checkout = str(repo.changelog.rev(checkout))
4032 4035
4033 4036 # order below depends on implementation of
4034 4037 # hg.addbranchrevs(). opts['bookmark'] is ignored,
4035 4038 # because 'checkout' is determined without it.
4036 4039 if opts.get('rev'):
4037 4040 brev = opts['rev'][0]
4038 4041 elif opts.get('branch'):
4039 4042 brev = opts['branch'][0]
4040 4043 else:
4041 4044 brev = branches[0]
4042 4045 repo._subtoppath = source
4043 4046 try:
4044 4047 ret = postincoming(ui, repo, modheads, opts.get('update'),
4045 4048 checkout, brev)
4046 4049
4047 4050 finally:
4048 4051 del repo._subtoppath
4049 4052
4050 4053 finally:
4051 4054 other.close()
4052 4055 return ret
4053 4056
4054 4057 @command('^push',
4055 4058 [('f', 'force', None, _('force push')),
4056 4059 ('r', 'rev', [],
4057 4060 _('a changeset intended to be included in the destination'),
4058 4061 _('REV')),
4059 4062 ('B', 'bookmark', [], _("bookmark to push"), _('BOOKMARK')),
4060 4063 ('b', 'branch', [],
4061 4064 _('a specific branch you would like to push'), _('BRANCH')),
4062 4065 ('', 'new-branch', False, _('allow pushing a new branch')),
4063 4066 ('', 'pushvars', [], _('variables that can be sent to server (ADVANCED)')),
4064 4067 ] + remoteopts,
4065 4068 _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]'))
4066 4069 def push(ui, repo, dest=None, **opts):
4067 4070 """push changes to the specified destination
4068 4071
4069 4072 Push changesets from the local repository to the specified
4070 4073 destination.
4071 4074
4072 4075 This operation is symmetrical to pull: it is identical to a pull
4073 4076 in the destination repository from the current one.
4074 4077
4075 4078 By default, push will not allow creation of new heads at the
4076 4079 destination, since multiple heads would make it unclear which head
4077 4080 to use. In this situation, it is recommended to pull and merge
4078 4081 before pushing.
4079 4082
4080 4083 Use --new-branch if you want to allow push to create a new named
4081 4084 branch that is not present at the destination. This allows you to
4082 4085 only create a new branch without forcing other changes.
4083 4086
4084 4087 .. note::
4085 4088
4086 4089 Extra care should be taken with the -f/--force option,
4087 4090 which will push all new heads on all branches, an action which will
4088 4091 almost always cause confusion for collaborators.
4089 4092
4090 4093 If -r/--rev is used, the specified revision and all its ancestors
4091 4094 will be pushed to the remote repository.
4092 4095
4093 4096 If -B/--bookmark is used, the specified bookmarked revision, its
4094 4097 ancestors, and the bookmark will be pushed to the remote
4095 4098 repository. Specifying ``.`` is equivalent to specifying the active
4096 4099 bookmark's name.
4097 4100
4098 4101 Please see :hg:`help urls` for important details about ``ssh://``
4099 4102 URLs. If DESTINATION is omitted, a default path will be used.
4100 4103
4101 4104 .. container:: verbose
4102 4105
4103 4106 The --pushvars option sends strings to the server that become
4104 4107 environment variables prepended with ``HG_USERVAR_``. For example,
4105 4108 ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with
4106 4109 ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment.
4107 4110
4108 4111 pushvars can provide for user-overridable hooks as well as set debug
4109 4112 levels. One example is having a hook that blocks commits containing
4110 4113 conflict markers, but enables the user to override the hook if the file
4111 4114 is using conflict markers for testing purposes or the file format has
4112 4115 strings that look like conflict markers.
4113 4116
4114 4117 By default, servers will ignore `--pushvars`. To enable it add the
4115 4118 following to your configuration file::
4116 4119
4117 4120 [push]
4118 4121 pushvars.server = true
4119 4122
4120 4123 Returns 0 if push was successful, 1 if nothing to push.
4121 4124 """
4122 4125
4123 4126 opts = pycompat.byteskwargs(opts)
4124 4127 if opts.get('bookmark'):
4125 4128 ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push')
4126 4129 for b in opts['bookmark']:
4127 4130 # translate -B options to -r so changesets get pushed
4128 4131 b = repo._bookmarks.expandname(b)
4129 4132 if b in repo._bookmarks:
4130 4133 opts.setdefault('rev', []).append(b)
4131 4134 else:
4132 4135 # if we try to push a deleted bookmark, translate it to null
4133 4136 # this lets simultaneous -r, -b options continue working
4134 4137 opts.setdefault('rev', []).append("null")
4135 4138
4136 4139 path = ui.paths.getpath(dest, default=('default-push', 'default'))
4137 4140 if not path:
4138 4141 raise error.Abort(_('default repository not configured!'),
4139 4142 hint=_("see 'hg help config.paths'"))
4140 4143 dest = path.pushloc or path.loc
4141 4144 branches = (path.branch, opts.get('branch') or [])
4142 4145 ui.status(_('pushing to %s\n') % util.hidepassword(dest))
4143 4146 revs, checkout = hg.addbranchrevs(repo, repo, branches, opts.get('rev'))
4144 4147 other = hg.peer(repo, opts, dest)
4145 4148
4146 4149 if revs:
4147 4150 revs = [repo.lookup(r) for r in scmutil.revrange(repo, revs)]
4148 4151 if not revs:
4149 4152 raise error.Abort(_("specified revisions evaluate to an empty set"),
4150 4153 hint=_("use different revision arguments"))
4151 4154 elif path.pushrev:
4152 4155 # It doesn't make any sense to specify ancestor revisions. So limit
4153 4156 # to DAG heads to make discovery simpler.
4154 4157 expr = revsetlang.formatspec('heads(%r)', path.pushrev)
4155 4158 revs = scmutil.revrange(repo, [expr])
4156 4159 revs = [repo[rev].node() for rev in revs]
4157 4160 if not revs:
4158 4161 raise error.Abort(_('default push revset for path evaluates to an '
4159 4162 'empty set'))
4160 4163
4161 4164 repo._subtoppath = dest
4162 4165 try:
4163 4166 # push subrepos depth-first for coherent ordering
4164 4167 c = repo['']
4165 4168 subs = c.substate # only repos that are committed
4166 4169 for s in sorted(subs):
4167 4170 result = c.sub(s).push(opts)
4168 4171 if result == 0:
4169 4172 return not result
4170 4173 finally:
4171 4174 del repo._subtoppath
4172 4175
4173 4176 opargs = dict(opts.get('opargs', {})) # copy opargs since we may mutate it
4174 4177 opargs.setdefault('pushvars', []).extend(opts.get('pushvars', []))
4175 4178
4176 4179 pushop = exchange.push(repo, other, opts.get('force'), revs=revs,
4177 4180 newbranch=opts.get('new_branch'),
4178 4181 bookmarks=opts.get('bookmark', ()),
4179 4182 opargs=opargs)
4180 4183
4181 4184 result = not pushop.cgresult
4182 4185
4183 4186 if pushop.bkresult is not None:
4184 4187 if pushop.bkresult == 2:
4185 4188 result = 2
4186 4189 elif not result and pushop.bkresult:
4187 4190 result = 2
4188 4191
4189 4192 return result
4190 4193
4191 4194 @command('recover', [])
4192 4195 def recover(ui, repo):
4193 4196 """roll back an interrupted transaction
4194 4197
4195 4198 Recover from an interrupted commit or pull.
4196 4199
4197 4200 This command tries to fix the repository status after an
4198 4201 interrupted operation. It should only be necessary when Mercurial
4199 4202 suggests it.
4200 4203
4201 4204 Returns 0 if successful, 1 if nothing to recover or verify fails.
4202 4205 """
4203 4206 if repo.recover():
4204 4207 return hg.verify(repo)
4205 4208 return 1
4206 4209
4207 4210 @command('^remove|rm',
4208 4211 [('A', 'after', None, _('record delete for missing files')),
4209 4212 ('f', 'force', None,
4210 4213 _('forget added files, delete modified files')),
4211 4214 ] + subrepoopts + walkopts,
4212 4215 _('[OPTION]... FILE...'),
4213 4216 inferrepo=True)
4214 4217 def remove(ui, repo, *pats, **opts):
4215 4218 """remove the specified files on the next commit
4216 4219
4217 4220 Schedule the indicated files for removal from the current branch.
4218 4221
4219 4222 This command schedules the files to be removed at the next commit.
4220 4223 To undo a remove before that, see :hg:`revert`. To undo added
4221 4224 files, see :hg:`forget`.
4222 4225
4223 4226 .. container:: verbose
4224 4227
4225 4228 -A/--after can be used to remove only files that have already
4226 4229 been deleted, -f/--force can be used to force deletion, and -Af
4227 4230 can be used to remove files from the next revision without
4228 4231 deleting them from the working directory.
4229 4232
4230 4233 The following table details the behavior of remove for different
4231 4234 file states (columns) and option combinations (rows). The file
4232 4235 states are Added [A], Clean [C], Modified [M] and Missing [!]
4233 4236 (as reported by :hg:`status`). The actions are Warn, Remove
4234 4237 (from branch) and Delete (from disk):
4235 4238
4236 4239 ========= == == == ==
4237 4240 opt/state A C M !
4238 4241 ========= == == == ==
4239 4242 none W RD W R
4240 4243 -f R RD RD R
4241 4244 -A W W W R
4242 4245 -Af R R R R
4243 4246 ========= == == == ==
4244 4247
4245 4248 .. note::
4246 4249
4247 4250 :hg:`remove` never deletes files in Added [A] state from the
4248 4251 working directory, not even if ``--force`` is specified.
4249 4252
4250 4253 Returns 0 on success, 1 if any warnings encountered.
4251 4254 """
4252 4255
4253 4256 opts = pycompat.byteskwargs(opts)
4254 4257 after, force = opts.get('after'), opts.get('force')
4255 4258 if not pats and not after:
4256 4259 raise error.Abort(_('no files specified'))
4257 4260
4258 4261 m = scmutil.match(repo[None], pats, opts)
4259 4262 subrepos = opts.get('subrepos')
4260 4263 return cmdutil.remove(ui, repo, m, "", after, force, subrepos)
4261 4264
4262 4265 @command('rename|move|mv',
4263 4266 [('A', 'after', None, _('record a rename that has already occurred')),
4264 4267 ('f', 'force', None, _('forcibly copy over an existing managed file')),
4265 4268 ] + walkopts + dryrunopts,
4266 4269 _('[OPTION]... SOURCE... DEST'))
4267 4270 def rename(ui, repo, *pats, **opts):
4268 4271 """rename files; equivalent of copy + remove
4269 4272
4270 4273 Mark dest as copies of sources; mark sources for deletion. If dest
4271 4274 is a directory, copies are put in that directory. If dest is a
4272 4275 file, there can only be one source.
4273 4276
4274 4277 By default, this command copies the contents of files as they
4275 4278 exist in the working directory. If invoked with -A/--after, the
4276 4279 operation is recorded, but no copying is performed.
4277 4280
4278 4281 This command takes effect at the next commit. To undo a rename
4279 4282 before that, see :hg:`revert`.
4280 4283
4281 4284 Returns 0 on success, 1 if errors are encountered.
4282 4285 """
4283 4286 opts = pycompat.byteskwargs(opts)
4284 4287 with repo.wlock(False):
4285 4288 return cmdutil.copy(ui, repo, pats, opts, rename=True)
4286 4289
4287 4290 @command('resolve',
4288 4291 [('a', 'all', None, _('select all unresolved files')),
4289 4292 ('l', 'list', None, _('list state of files needing merge')),
4290 4293 ('m', 'mark', None, _('mark files as resolved')),
4291 4294 ('u', 'unmark', None, _('mark files as unresolved')),
4292 4295 ('n', 'no-status', None, _('hide status prefix'))]
4293 4296 + mergetoolopts + walkopts + formatteropts,
4294 4297 _('[OPTION]... [FILE]...'),
4295 4298 inferrepo=True)
4296 4299 def resolve(ui, repo, *pats, **opts):
4297 4300 """redo merges or set/view the merge status of files
4298 4301
4299 4302 Merges with unresolved conflicts are often the result of
4300 4303 non-interactive merging using the ``internal:merge`` configuration
4301 4304 setting, or a command-line merge tool like ``diff3``. The resolve
4302 4305 command is used to manage the files involved in a merge, after
4303 4306 :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the
4304 4307 working directory must have two parents). See :hg:`help
4305 4308 merge-tools` for information on configuring merge tools.
4306 4309
4307 4310 The resolve command can be used in the following ways:
4308 4311
4309 4312 - :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified
4310 4313 files, discarding any previous merge attempts. Re-merging is not
4311 4314 performed for files already marked as resolved. Use ``--all/-a``
4312 4315 to select all unresolved files. ``--tool`` can be used to specify
4313 4316 the merge tool used for the given files. It overrides the HGMERGE
4314 4317 environment variable and your configuration files. Previous file
4315 4318 contents are saved with a ``.orig`` suffix.
4316 4319
4317 4320 - :hg:`resolve -m [FILE]`: mark a file as having been resolved
4318 4321 (e.g. after having manually fixed-up the files). The default is
4319 4322 to mark all unresolved files.
4320 4323
4321 4324 - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The
4322 4325 default is to mark all resolved files.
4323 4326
4324 4327 - :hg:`resolve -l`: list files which had or still have conflicts.
4325 4328 In the printed list, ``U`` = unresolved and ``R`` = resolved.
4326 4329 You can use ``set:unresolved()`` or ``set:resolved()`` to filter
4327 4330 the list. See :hg:`help filesets` for details.
4328 4331
4329 4332 .. note::
4330 4333
4331 4334 Mercurial will not let you commit files with unresolved merge
4332 4335 conflicts. You must use :hg:`resolve -m ...` before you can
4333 4336 commit after a conflicting merge.
4334 4337
4335 4338 Returns 0 on success, 1 if any files fail a resolve attempt.
4336 4339 """
4337 4340
4338 4341 opts = pycompat.byteskwargs(opts)
4339 4342 flaglist = 'all mark unmark list no_status'.split()
4340 4343 all, mark, unmark, show, nostatus = \
4341 4344 [opts.get(o) for o in flaglist]
4342 4345
4343 4346 if (show and (mark or unmark)) or (mark and unmark):
4344 4347 raise error.Abort(_("too many options specified"))
4345 4348 if pats and all:
4346 4349 raise error.Abort(_("can't specify --all and patterns"))
4347 4350 if not (all or pats or show or mark or unmark):
4348 4351 raise error.Abort(_('no files or directories specified'),
4349 4352 hint=('use --all to re-merge all unresolved files'))
4350 4353
4351 4354 if show:
4352 4355 ui.pager('resolve')
4353 4356 fm = ui.formatter('resolve', opts)
4354 4357 ms = mergemod.mergestate.read(repo)
4355 4358 m = scmutil.match(repo[None], pats, opts)
4356 4359
4357 4360 # Labels and keys based on merge state. Unresolved path conflicts show
4358 4361 # as 'P'. Resolved path conflicts show as 'R', the same as normal
4359 4362 # resolved conflicts.
4360 4363 mergestateinfo = {
4361 4364 'u': ('resolve.unresolved', 'U'),
4362 4365 'r': ('resolve.resolved', 'R'),
4363 4366 'pu': ('resolve.unresolved', 'P'),
4364 4367 'pr': ('resolve.resolved', 'R'),
4365 4368 'd': ('resolve.driverresolved', 'D'),
4366 4369 }
4367 4370
4368 4371 for f in ms:
4369 4372 if not m(f):
4370 4373 continue
4371 4374
4372 4375 label, key = mergestateinfo[ms[f]]
4373 4376 fm.startitem()
4374 4377 fm.condwrite(not nostatus, 'status', '%s ', key, label=label)
4375 4378 fm.write('path', '%s\n', f, label=label)
4376 4379 fm.end()
4377 4380 return 0
4378 4381
4379 4382 with repo.wlock():
4380 4383 ms = mergemod.mergestate.read(repo)
4381 4384
4382 4385 if not (ms.active() or repo.dirstate.p2() != nullid):
4383 4386 raise error.Abort(
4384 4387 _('resolve command not applicable when not merging'))
4385 4388
4386 4389 wctx = repo[None]
4387 4390
4388 4391 if ms.mergedriver and ms.mdstate() == 'u':
4389 4392 proceed = mergemod.driverpreprocess(repo, ms, wctx)
4390 4393 ms.commit()
4391 4394 # allow mark and unmark to go through
4392 4395 if not mark and not unmark and not proceed:
4393 4396 return 1
4394 4397
4395 4398 m = scmutil.match(wctx, pats, opts)
4396 4399 ret = 0
4397 4400 didwork = False
4398 4401 runconclude = False
4399 4402
4400 4403 tocomplete = []
4401 4404 for f in ms:
4402 4405 if not m(f):
4403 4406 continue
4404 4407
4405 4408 didwork = True
4406 4409
4407 4410 # don't let driver-resolved files be marked, and run the conclude
4408 4411 # step if asked to resolve
4409 4412 if ms[f] == "d":
4410 4413 exact = m.exact(f)
4411 4414 if mark:
4412 4415 if exact:
4413 4416 ui.warn(_('not marking %s as it is driver-resolved\n')
4414 4417 % f)
4415 4418 elif unmark:
4416 4419 if exact:
4417 4420 ui.warn(_('not unmarking %s as it is driver-resolved\n')
4418 4421 % f)
4419 4422 else:
4420 4423 runconclude = True
4421 4424 continue
4422 4425
4423 4426 # path conflicts must be resolved manually
4424 4427 if ms[f] in ("pu", "pr"):
4425 4428 if mark:
4426 4429 ms.mark(f, "pr")
4427 4430 elif unmark:
4428 4431 ms.mark(f, "pu")
4429 4432 elif ms[f] == "pu":
4430 4433 ui.warn(_('%s: path conflict must be resolved manually\n')
4431 4434 % f)
4432 4435 continue
4433 4436
4434 4437 if mark:
4435 4438 ms.mark(f, "r")
4436 4439 elif unmark:
4437 4440 ms.mark(f, "u")
4438 4441 else:
4439 4442 # backup pre-resolve (merge uses .orig for its own purposes)
4440 4443 a = repo.wjoin(f)
4441 4444 try:
4442 4445 util.copyfile(a, a + ".resolve")
4443 4446 except (IOError, OSError) as inst:
4444 4447 if inst.errno != errno.ENOENT:
4445 4448 raise
4446 4449
4447 4450 try:
4448 4451 # preresolve file
4449 4452 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
4450 4453 'resolve')
4451 4454 complete, r = ms.preresolve(f, wctx)
4452 4455 if not complete:
4453 4456 tocomplete.append(f)
4454 4457 elif r:
4455 4458 ret = 1
4456 4459 finally:
4457 4460 ui.setconfig('ui', 'forcemerge', '', 'resolve')
4458 4461 ms.commit()
4459 4462
4460 4463 # replace filemerge's .orig file with our resolve file, but only
4461 4464 # for merges that are complete
4462 4465 if complete:
4463 4466 try:
4464 4467 util.rename(a + ".resolve",
4465 4468 scmutil.origpath(ui, repo, a))
4466 4469 except OSError as inst:
4467 4470 if inst.errno != errno.ENOENT:
4468 4471 raise
4469 4472
4470 4473 for f in tocomplete:
4471 4474 try:
4472 4475 # resolve file
4473 4476 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
4474 4477 'resolve')
4475 4478 r = ms.resolve(f, wctx)
4476 4479 if r:
4477 4480 ret = 1
4478 4481 finally:
4479 4482 ui.setconfig('ui', 'forcemerge', '', 'resolve')
4480 4483 ms.commit()
4481 4484
4482 4485 # replace filemerge's .orig file with our resolve file
4483 4486 a = repo.wjoin(f)
4484 4487 try:
4485 4488 util.rename(a + ".resolve", scmutil.origpath(ui, repo, a))
4486 4489 except OSError as inst:
4487 4490 if inst.errno != errno.ENOENT:
4488 4491 raise
4489 4492
4490 4493 ms.commit()
4491 4494 ms.recordactions()
4492 4495
4493 4496 if not didwork and pats:
4494 4497 hint = None
4495 4498 if not any([p for p in pats if p.find(':') >= 0]):
4496 4499 pats = ['path:%s' % p for p in pats]
4497 4500 m = scmutil.match(wctx, pats, opts)
4498 4501 for f in ms:
4499 4502 if not m(f):
4500 4503 continue
4501 4504 flags = ''.join(['-%s ' % o[0] for o in flaglist
4502 4505 if opts.get(o)])
4503 4506 hint = _("(try: hg resolve %s%s)\n") % (
4504 4507 flags,
4505 4508 ' '.join(pats))
4506 4509 break
4507 4510 ui.warn(_("arguments do not match paths that need resolving\n"))
4508 4511 if hint:
4509 4512 ui.warn(hint)
4510 4513 elif ms.mergedriver and ms.mdstate() != 's':
4511 4514 # run conclude step when either a driver-resolved file is requested
4512 4515 # or there are no driver-resolved files
4513 4516 # we can't use 'ret' to determine whether any files are unresolved
4514 4517 # because we might not have tried to resolve some
4515 4518 if ((runconclude or not list(ms.driverresolved()))
4516 4519 and not list(ms.unresolved())):
4517 4520 proceed = mergemod.driverconclude(repo, ms, wctx)
4518 4521 ms.commit()
4519 4522 if not proceed:
4520 4523 return 1
4521 4524
4522 4525 # Nudge users into finishing an unfinished operation
4523 4526 unresolvedf = list(ms.unresolved())
4524 4527 driverresolvedf = list(ms.driverresolved())
4525 4528 if not unresolvedf and not driverresolvedf:
4526 4529 ui.status(_('(no more unresolved files)\n'))
4527 4530 cmdutil.checkafterresolved(repo)
4528 4531 elif not unresolvedf:
4529 4532 ui.status(_('(no more unresolved files -- '
4530 4533 'run "hg resolve --all" to conclude)\n'))
4531 4534
4532 4535 return ret
4533 4536
4534 4537 @command('revert',
4535 4538 [('a', 'all', None, _('revert all changes when no arguments given')),
4536 4539 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
4537 4540 ('r', 'rev', '', _('revert to the specified revision'), _('REV')),
4538 4541 ('C', 'no-backup', None, _('do not save backup copies of files')),
4539 4542 ('i', 'interactive', None, _('interactively select the changes')),
4540 4543 ] + walkopts + dryrunopts,
4541 4544 _('[OPTION]... [-r REV] [NAME]...'))
4542 4545 def revert(ui, repo, *pats, **opts):
4543 4546 """restore files to their checkout state
4544 4547
4545 4548 .. note::
4546 4549
4547 4550 To check out earlier revisions, you should use :hg:`update REV`.
4548 4551 To cancel an uncommitted merge (and lose your changes),
4549 4552 use :hg:`update --clean .`.
4550 4553
4551 4554 With no revision specified, revert the specified files or directories
4552 4555 to the contents they had in the parent of the working directory.
4553 4556 This restores the contents of files to an unmodified
4554 4557 state and unschedules adds, removes, copies, and renames. If the
4555 4558 working directory has two parents, you must explicitly specify a
4556 4559 revision.
4557 4560
4558 4561 Using the -r/--rev or -d/--date options, revert the given files or
4559 4562 directories to their states as of a specific revision. Because
4560 4563 revert does not change the working directory parents, this will
4561 4564 cause these files to appear modified. This can be helpful to "back
4562 4565 out" some or all of an earlier change. See :hg:`backout` for a
4563 4566 related method.
4564 4567
4565 4568 Modified files are saved with a .orig suffix before reverting.
4566 4569 To disable these backups, use --no-backup. It is possible to store
4567 4570 the backup files in a custom directory relative to the root of the
4568 4571 repository by setting the ``ui.origbackuppath`` configuration
4569 4572 option.
4570 4573
4571 4574 See :hg:`help dates` for a list of formats valid for -d/--date.
4572 4575
4573 4576 See :hg:`help backout` for a way to reverse the effect of an
4574 4577 earlier changeset.
4575 4578
4576 4579 Returns 0 on success.
4577 4580 """
4578 4581
4579 4582 opts = pycompat.byteskwargs(opts)
4580 4583 if opts.get("date"):
4581 4584 if opts.get("rev"):
4582 4585 raise error.Abort(_("you can't specify a revision and a date"))
4583 4586 opts["rev"] = cmdutil.finddate(ui, repo, opts["date"])
4584 4587
4585 4588 parent, p2 = repo.dirstate.parents()
4586 4589 if not opts.get('rev') and p2 != nullid:
4587 4590 # revert after merge is a trap for new users (issue2915)
4588 4591 raise error.Abort(_('uncommitted merge with no revision specified'),
4589 4592 hint=_("use 'hg update' or see 'hg help revert'"))
4590 4593
4591 4594 rev = opts.get('rev')
4592 4595 if rev:
4593 4596 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
4594 4597 ctx = scmutil.revsingle(repo, rev)
4595 4598
4596 4599 if (not (pats or opts.get('include') or opts.get('exclude') or
4597 4600 opts.get('all') or opts.get('interactive'))):
4598 4601 msg = _("no files or directories specified")
4599 4602 if p2 != nullid:
4600 4603 hint = _("uncommitted merge, use --all to discard all changes,"
4601 4604 " or 'hg update -C .' to abort the merge")
4602 4605 raise error.Abort(msg, hint=hint)
4603 4606 dirty = any(repo.status())
4604 4607 node = ctx.node()
4605 4608 if node != parent:
4606 4609 if dirty:
4607 4610 hint = _("uncommitted changes, use --all to discard all"
4608 4611 " changes, or 'hg update %s' to update") % ctx.rev()
4609 4612 else:
4610 4613 hint = _("use --all to revert all files,"
4611 4614 " or 'hg update %s' to update") % ctx.rev()
4612 4615 elif dirty:
4613 4616 hint = _("uncommitted changes, use --all to discard all changes")
4614 4617 else:
4615 4618 hint = _("use --all to revert all files")
4616 4619 raise error.Abort(msg, hint=hint)
4617 4620
4618 4621 return cmdutil.revert(ui, repo, ctx, (parent, p2), *pats,
4619 4622 **pycompat.strkwargs(opts))
4620 4623
4621 4624 @command('rollback', dryrunopts +
4622 4625 [('f', 'force', False, _('ignore safety measures'))])
4623 4626 def rollback(ui, repo, **opts):
4624 4627 """roll back the last transaction (DANGEROUS) (DEPRECATED)
4625 4628
4626 4629 Please use :hg:`commit --amend` instead of rollback to correct
4627 4630 mistakes in the last commit.
4628 4631
4629 4632 This command should be used with care. There is only one level of
4630 4633 rollback, and there is no way to undo a rollback. It will also
4631 4634 restore the dirstate at the time of the last transaction, losing
4632 4635 any dirstate changes since that time. This command does not alter
4633 4636 the working directory.
4634 4637
4635 4638 Transactions are used to encapsulate the effects of all commands
4636 4639 that create new changesets or propagate existing changesets into a
4637 4640 repository.
4638 4641
4639 4642 .. container:: verbose
4640 4643
4641 4644 For example, the following commands are transactional, and their
4642 4645 effects can be rolled back:
4643 4646
4644 4647 - commit
4645 4648 - import
4646 4649 - pull
4647 4650 - push (with this repository as the destination)
4648 4651 - unbundle
4649 4652
4650 4653 To avoid permanent data loss, rollback will refuse to rollback a
4651 4654 commit transaction if it isn't checked out. Use --force to
4652 4655 override this protection.
4653 4656
4654 4657 The rollback command can be entirely disabled by setting the
4655 4658 ``ui.rollback`` configuration setting to false. If you're here
4656 4659 because you want to use rollback and it's disabled, you can
4657 4660 re-enable the command by setting ``ui.rollback`` to true.
4658 4661
4659 4662 This command is not intended for use on public repositories. Once
4660 4663 changes are visible for pull by other users, rolling a transaction
4661 4664 back locally is ineffective (someone else may already have pulled
4662 4665 the changes). Furthermore, a race is possible with readers of the
4663 4666 repository; for example an in-progress pull from the repository
4664 4667 may fail if a rollback is performed.
4665 4668
4666 4669 Returns 0 on success, 1 if no rollback data is available.
4667 4670 """
4668 4671 if not ui.configbool('ui', 'rollback'):
4669 4672 raise error.Abort(_('rollback is disabled because it is unsafe'),
4670 4673 hint=('see `hg help -v rollback` for information'))
4671 4674 return repo.rollback(dryrun=opts.get(r'dry_run'),
4672 4675 force=opts.get(r'force'))
4673 4676
4674 4677 @command('root', [], cmdtype=readonly)
4675 4678 def root(ui, repo):
4676 4679 """print the root (top) of the current working directory
4677 4680
4678 4681 Print the root directory of the current repository.
4679 4682
4680 4683 Returns 0 on success.
4681 4684 """
4682 4685 ui.write(repo.root + "\n")
4683 4686
4684 4687 @command('^serve',
4685 4688 [('A', 'accesslog', '', _('name of access log file to write to'),
4686 4689 _('FILE')),
4687 4690 ('d', 'daemon', None, _('run server in background')),
4688 4691 ('', 'daemon-postexec', [], _('used internally by daemon mode')),
4689 4692 ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
4690 4693 # use string type, then we can check if something was passed
4691 4694 ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),
4692 4695 ('a', 'address', '', _('address to listen on (default: all interfaces)'),
4693 4696 _('ADDR')),
4694 4697 ('', 'prefix', '', _('prefix path to serve from (default: server root)'),
4695 4698 _('PREFIX')),
4696 4699 ('n', 'name', '',
4697 4700 _('name to show in web pages (default: working directory)'), _('NAME')),
4698 4701 ('', 'web-conf', '',
4699 4702 _("name of the hgweb config file (see 'hg help hgweb')"), _('FILE')),
4700 4703 ('', 'webdir-conf', '', _('name of the hgweb config file (DEPRECATED)'),
4701 4704 _('FILE')),
4702 4705 ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')),
4703 4706 ('', 'stdio', None, _('for remote clients (ADVANCED)')),
4704 4707 ('', 'cmdserver', '', _('for remote clients (ADVANCED)'), _('MODE')),
4705 4708 ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')),
4706 4709 ('', 'style', '', _('template style to use'), _('STYLE')),
4707 4710 ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
4708 4711 ('', 'certificate', '', _('SSL certificate file'), _('FILE'))]
4709 4712 + subrepoopts,
4710 4713 _('[OPTION]...'),
4711 4714 optionalrepo=True)
4712 4715 def serve(ui, repo, **opts):
4713 4716 """start stand-alone webserver
4714 4717
4715 4718 Start a local HTTP repository browser and pull server. You can use
4716 4719 this for ad-hoc sharing and browsing of repositories. It is
4717 4720 recommended to use a real web server to serve a repository for
4718 4721 longer periods of time.
4719 4722
4720 4723 Please note that the server does not implement access control.
4721 4724 This means that, by default, anybody can read from the server and
4722 4725 nobody can write to it by default. Set the ``web.allow-push``
4723 4726 option to ``*`` to allow everybody to push to the server. You
4724 4727 should use a real web server if you need to authenticate users.
4725 4728
4726 4729 By default, the server logs accesses to stdout and errors to
4727 4730 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
4728 4731 files.
4729 4732
4730 4733 To have the server choose a free port number to listen on, specify
4731 4734 a port number of 0; in this case, the server will print the port
4732 4735 number it uses.
4733 4736
4734 4737 Returns 0 on success.
4735 4738 """
4736 4739
4737 4740 opts = pycompat.byteskwargs(opts)
4738 4741 if opts["stdio"] and opts["cmdserver"]:
4739 4742 raise error.Abort(_("cannot use --stdio with --cmdserver"))
4740 4743
4741 4744 if opts["stdio"]:
4742 4745 if repo is None:
4743 4746 raise error.RepoError(_("there is no Mercurial repository here"
4744 4747 " (.hg not found)"))
4745 4748 s = sshserver.sshserver(ui, repo)
4746 4749 s.serve_forever()
4747 4750
4748 4751 service = server.createservice(ui, repo, opts)
4749 4752 return server.runservice(opts, initfn=service.init, runfn=service.run)
4750 4753
4751 4754 @command('^status|st',
4752 4755 [('A', 'all', None, _('show status of all files')),
4753 4756 ('m', 'modified', None, _('show only modified files')),
4754 4757 ('a', 'added', None, _('show only added files')),
4755 4758 ('r', 'removed', None, _('show only removed files')),
4756 4759 ('d', 'deleted', None, _('show only deleted (but tracked) files')),
4757 4760 ('c', 'clean', None, _('show only files without changes')),
4758 4761 ('u', 'unknown', None, _('show only unknown (not tracked) files')),
4759 4762 ('i', 'ignored', None, _('show only ignored files')),
4760 4763 ('n', 'no-status', None, _('hide status prefix')),
4761 4764 ('t', 'terse', '', _('show the terse output (EXPERIMENTAL)')),
4762 4765 ('C', 'copies', None, _('show source of copied files')),
4763 4766 ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
4764 4767 ('', 'rev', [], _('show difference from revision'), _('REV')),
4765 4768 ('', 'change', '', _('list the changed files of a revision'), _('REV')),
4766 4769 ] + walkopts + subrepoopts + formatteropts,
4767 4770 _('[OPTION]... [FILE]...'),
4768 4771 inferrepo=True, cmdtype=readonly)
4769 4772 def status(ui, repo, *pats, **opts):
4770 4773 """show changed files in the working directory
4771 4774
4772 4775 Show status of files in the repository. If names are given, only
4773 4776 files that match are shown. Files that are clean or ignored or
4774 4777 the source of a copy/move operation, are not listed unless
4775 4778 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
4776 4779 Unless options described with "show only ..." are given, the
4777 4780 options -mardu are used.
4778 4781
4779 4782 Option -q/--quiet hides untracked (unknown and ignored) files
4780 4783 unless explicitly requested with -u/--unknown or -i/--ignored.
4781 4784
4782 4785 .. note::
4783 4786
4784 4787 :hg:`status` may appear to disagree with diff if permissions have
4785 4788 changed or a merge has occurred. The standard diff format does
4786 4789 not report permission changes and diff only reports changes
4787 4790 relative to one merge parent.
4788 4791
4789 4792 If one revision is given, it is used as the base revision.
4790 4793 If two revisions are given, the differences between them are
4791 4794 shown. The --change option can also be used as a shortcut to list
4792 4795 the changed files of a revision from its first parent.
4793 4796
4794 4797 The codes used to show the status of files are::
4795 4798
4796 4799 M = modified
4797 4800 A = added
4798 4801 R = removed
4799 4802 C = clean
4800 4803 ! = missing (deleted by non-hg command, but still tracked)
4801 4804 ? = not tracked
4802 4805 I = ignored
4803 4806 = origin of the previous file (with --copies)
4804 4807
4805 4808 .. container:: verbose
4806 4809
4807 4810 The -t/--terse option abbreviates the output by showing only the directory
4808 4811 name if all the files in it share the same status. The option takes an
4809 4812 argument indicating the statuses to abbreviate: 'm' for 'modified', 'a'
4810 4813 for 'added', 'r' for 'removed', 'd' for 'deleted', 'u' for 'unknown', 'i'
4811 4814 for 'ignored' and 'c' for clean.
4812 4815
4813 4816 It abbreviates only those statuses which are passed. Note that clean and
4814 4817 ignored files are not displayed with '--terse ic' unless the -c/--clean
4815 4818 and -i/--ignored options are also used.
4816 4819
4817 4820 The -v/--verbose option shows information when the repository is in an
4818 4821 unfinished merge, shelve, rebase state etc. You can have this behavior
4819 4822 turned on by default by enabling the ``commands.status.verbose`` option.
4820 4823
4821 4824 You can skip displaying some of these states by setting
4822 4825 ``commands.status.skipstates`` to one or more of: 'bisect', 'graft',
4823 4826 'histedit', 'merge', 'rebase', or 'unshelve'.
4824 4827
4825 4828 Examples:
4826 4829
4827 4830 - show changes in the working directory relative to a
4828 4831 changeset::
4829 4832
4830 4833 hg status --rev 9353
4831 4834
4832 4835 - show changes in the working directory relative to the
4833 4836 current directory (see :hg:`help patterns` for more information)::
4834 4837
4835 4838 hg status re:
4836 4839
4837 4840 - show all changes including copies in an existing changeset::
4838 4841
4839 4842 hg status --copies --change 9353
4840 4843
4841 4844 - get a NUL separated list of added files, suitable for xargs::
4842 4845
4843 4846 hg status -an0
4844 4847
4845 4848 - show more information about the repository status, abbreviating
4846 4849 added, removed, modified, deleted, and untracked paths::
4847 4850
4848 4851 hg status -v -t mardu
4849 4852
4850 4853 Returns 0 on success.
4851 4854
4852 4855 """
4853 4856
4854 4857 opts = pycompat.byteskwargs(opts)
4855 4858 revs = opts.get('rev')
4856 4859 change = opts.get('change')
4857 4860 terse = opts.get('terse')
4858 4861
4859 4862 if revs and change:
4860 4863 msg = _('cannot specify --rev and --change at the same time')
4861 4864 raise error.Abort(msg)
4862 4865 elif revs and terse:
4863 4866 msg = _('cannot use --terse with --rev')
4864 4867 raise error.Abort(msg)
4865 4868 elif change:
4866 4869 repo = scmutil.unhidehashlikerevs(repo, [change], 'nowarn')
4867 4870 node2 = scmutil.revsingle(repo, change, None).node()
4868 4871 node1 = repo[node2].p1().node()
4869 4872 else:
4870 4873 repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn')
4871 4874 node1, node2 = scmutil.revpair(repo, revs)
4872 4875
4873 4876 if pats or ui.configbool('commands', 'status.relative'):
4874 4877 cwd = repo.getcwd()
4875 4878 else:
4876 4879 cwd = ''
4877 4880
4878 4881 if opts.get('print0'):
4879 4882 end = '\0'
4880 4883 else:
4881 4884 end = '\n'
4882 4885 copy = {}
4883 4886 states = 'modified added removed deleted unknown ignored clean'.split()
4884 4887 show = [k for k in states if opts.get(k)]
4885 4888 if opts.get('all'):
4886 4889 show += ui.quiet and (states[:4] + ['clean']) or states
4887 4890
4888 4891 if not show:
4889 4892 if ui.quiet:
4890 4893 show = states[:4]
4891 4894 else:
4892 4895 show = states[:5]
4893 4896
4894 4897 m = scmutil.match(repo[node2], pats, opts)
4895 4898 if terse:
4896 4899 # we need to compute clean and unknown to terse
4897 4900 stat = repo.status(node1, node2, m,
4898 4901 'ignored' in show or 'i' in terse,
4899 4902 True, True, opts.get('subrepos'))
4900 4903
4901 4904 stat = cmdutil.tersedir(stat, terse)
4902 4905 else:
4903 4906 stat = repo.status(node1, node2, m,
4904 4907 'ignored' in show, 'clean' in show,
4905 4908 'unknown' in show, opts.get('subrepos'))
4906 4909
4907 4910 changestates = zip(states, pycompat.iterbytestr('MAR!?IC'), stat)
4908 4911
4909 4912 if (opts.get('all') or opts.get('copies')
4910 4913 or ui.configbool('ui', 'statuscopies')) and not opts.get('no_status'):
4911 4914 copy = copies.pathcopies(repo[node1], repo[node2], m)
4912 4915
4913 4916 ui.pager('status')
4914 4917 fm = ui.formatter('status', opts)
4915 4918 fmt = '%s' + end
4916 4919 showchar = not opts.get('no_status')
4917 4920
4918 4921 for state, char, files in changestates:
4919 4922 if state in show:
4920 4923 label = 'status.' + state
4921 4924 for f in files:
4922 4925 fm.startitem()
4923 4926 fm.condwrite(showchar, 'status', '%s ', char, label=label)
4924 4927 fm.write('path', fmt, repo.pathto(f, cwd), label=label)
4925 4928 if f in copy:
4926 4929 fm.write("copy", ' %s' + end, repo.pathto(copy[f], cwd),
4927 4930 label='status.copied')
4928 4931
4929 4932 if ((ui.verbose or ui.configbool('commands', 'status.verbose'))
4930 4933 and not ui.plain()):
4931 4934 cmdutil.morestatus(repo, fm)
4932 4935 fm.end()
4933 4936
4934 4937 @command('^summary|sum',
4935 4938 [('', 'remote', None, _('check for push and pull'))],
4936 4939 '[--remote]', cmdtype=readonly)
4937 4940 def summary(ui, repo, **opts):
4938 4941 """summarize working directory state
4939 4942
4940 4943 This generates a brief summary of the working directory state,
4941 4944 including parents, branch, commit status, phase and available updates.
4942 4945
4943 4946 With the --remote option, this will check the default paths for
4944 4947 incoming and outgoing changes. This can be time-consuming.
4945 4948
4946 4949 Returns 0 on success.
4947 4950 """
4948 4951
4949 4952 opts = pycompat.byteskwargs(opts)
4950 4953 ui.pager('summary')
4951 4954 ctx = repo[None]
4952 4955 parents = ctx.parents()
4953 4956 pnode = parents[0].node()
4954 4957 marks = []
4955 4958
4956 4959 ms = None
4957 4960 try:
4958 4961 ms = mergemod.mergestate.read(repo)
4959 4962 except error.UnsupportedMergeRecords as e:
4960 4963 s = ' '.join(e.recordtypes)
4961 4964 ui.warn(
4962 4965 _('warning: merge state has unsupported record types: %s\n') % s)
4963 4966 unresolved = []
4964 4967 else:
4965 4968 unresolved = list(ms.unresolved())
4966 4969
4967 4970 for p in parents:
4968 4971 # label with log.changeset (instead of log.parent) since this
4969 4972 # shows a working directory parent *changeset*:
4970 4973 # i18n: column positioning for "hg summary"
4971 4974 ui.write(_('parent: %d:%s ') % (p.rev(), p),
4972 4975 label=cmdutil._changesetlabels(p))
4973 4976 ui.write(' '.join(p.tags()), label='log.tag')
4974 4977 if p.bookmarks():
4975 4978 marks.extend(p.bookmarks())
4976 4979 if p.rev() == -1:
4977 4980 if not len(repo):
4978 4981 ui.write(_(' (empty repository)'))
4979 4982 else:
4980 4983 ui.write(_(' (no revision checked out)'))
4981 4984 if p.obsolete():
4982 4985 ui.write(_(' (obsolete)'))
4983 4986 if p.isunstable():
4984 4987 instabilities = (ui.label(instability, 'trouble.%s' % instability)
4985 4988 for instability in p.instabilities())
4986 4989 ui.write(' ('
4987 4990 + ', '.join(instabilities)
4988 4991 + ')')
4989 4992 ui.write('\n')
4990 4993 if p.description():
4991 4994 ui.status(' ' + p.description().splitlines()[0].strip() + '\n',
4992 4995 label='log.summary')
4993 4996
4994 4997 branch = ctx.branch()
4995 4998 bheads = repo.branchheads(branch)
4996 4999 # i18n: column positioning for "hg summary"
4997 5000 m = _('branch: %s\n') % branch
4998 5001 if branch != 'default':
4999 5002 ui.write(m, label='log.branch')
5000 5003 else:
5001 5004 ui.status(m, label='log.branch')
5002 5005
5003 5006 if marks:
5004 5007 active = repo._activebookmark
5005 5008 # i18n: column positioning for "hg summary"
5006 5009 ui.write(_('bookmarks:'), label='log.bookmark')
5007 5010 if active is not None:
5008 5011 if active in marks:
5009 5012 ui.write(' *' + active, label=bookmarks.activebookmarklabel)
5010 5013 marks.remove(active)
5011 5014 else:
5012 5015 ui.write(' [%s]' % active, label=bookmarks.activebookmarklabel)
5013 5016 for m in marks:
5014 5017 ui.write(' ' + m, label='log.bookmark')
5015 5018 ui.write('\n', label='log.bookmark')
5016 5019
5017 5020 status = repo.status(unknown=True)
5018 5021
5019 5022 c = repo.dirstate.copies()
5020 5023 copied, renamed = [], []
5021 5024 for d, s in c.iteritems():
5022 5025 if s in status.removed:
5023 5026 status.removed.remove(s)
5024 5027 renamed.append(d)
5025 5028 else:
5026 5029 copied.append(d)
5027 5030 if d in status.added:
5028 5031 status.added.remove(d)
5029 5032
5030 5033 subs = [s for s in ctx.substate if ctx.sub(s).dirty()]
5031 5034
5032 5035 labels = [(ui.label(_('%d modified'), 'status.modified'), status.modified),
5033 5036 (ui.label(_('%d added'), 'status.added'), status.added),
5034 5037 (ui.label(_('%d removed'), 'status.removed'), status.removed),
5035 5038 (ui.label(_('%d renamed'), 'status.copied'), renamed),
5036 5039 (ui.label(_('%d copied'), 'status.copied'), copied),
5037 5040 (ui.label(_('%d deleted'), 'status.deleted'), status.deleted),
5038 5041 (ui.label(_('%d unknown'), 'status.unknown'), status.unknown),
5039 5042 (ui.label(_('%d unresolved'), 'resolve.unresolved'), unresolved),
5040 5043 (ui.label(_('%d subrepos'), 'status.modified'), subs)]
5041 5044 t = []
5042 5045 for l, s in labels:
5043 5046 if s:
5044 5047 t.append(l % len(s))
5045 5048
5046 5049 t = ', '.join(t)
5047 5050 cleanworkdir = False
5048 5051
5049 5052 if repo.vfs.exists('graftstate'):
5050 5053 t += _(' (graft in progress)')
5051 5054 if repo.vfs.exists('updatestate'):
5052 5055 t += _(' (interrupted update)')
5053 5056 elif len(parents) > 1:
5054 5057 t += _(' (merge)')
5055 5058 elif branch != parents[0].branch():
5056 5059 t += _(' (new branch)')
5057 5060 elif (parents[0].closesbranch() and
5058 5061 pnode in repo.branchheads(branch, closed=True)):
5059 5062 t += _(' (head closed)')
5060 5063 elif not (status.modified or status.added or status.removed or renamed or
5061 5064 copied or subs):
5062 5065 t += _(' (clean)')
5063 5066 cleanworkdir = True
5064 5067 elif pnode not in bheads:
5065 5068 t += _(' (new branch head)')
5066 5069
5067 5070 if parents:
5068 5071 pendingphase = max(p.phase() for p in parents)
5069 5072 else:
5070 5073 pendingphase = phases.public
5071 5074
5072 5075 if pendingphase > phases.newcommitphase(ui):
5073 5076 t += ' (%s)' % phases.phasenames[pendingphase]
5074 5077
5075 5078 if cleanworkdir:
5076 5079 # i18n: column positioning for "hg summary"
5077 5080 ui.status(_('commit: %s\n') % t.strip())
5078 5081 else:
5079 5082 # i18n: column positioning for "hg summary"
5080 5083 ui.write(_('commit: %s\n') % t.strip())
5081 5084
5082 5085 # all ancestors of branch heads - all ancestors of parent = new csets
5083 5086 new = len(repo.changelog.findmissing([pctx.node() for pctx in parents],
5084 5087 bheads))
5085 5088
5086 5089 if new == 0:
5087 5090 # i18n: column positioning for "hg summary"
5088 5091 ui.status(_('update: (current)\n'))
5089 5092 elif pnode not in bheads:
5090 5093 # i18n: column positioning for "hg summary"
5091 5094 ui.write(_('update: %d new changesets (update)\n') % new)
5092 5095 else:
5093 5096 # i18n: column positioning for "hg summary"
5094 5097 ui.write(_('update: %d new changesets, %d branch heads (merge)\n') %
5095 5098 (new, len(bheads)))
5096 5099
5097 5100 t = []
5098 5101 draft = len(repo.revs('draft()'))
5099 5102 if draft:
5100 5103 t.append(_('%d draft') % draft)
5101 5104 secret = len(repo.revs('secret()'))
5102 5105 if secret:
5103 5106 t.append(_('%d secret') % secret)
5104 5107
5105 5108 if draft or secret:
5106 5109 ui.status(_('phases: %s\n') % ', '.join(t))
5107 5110
5108 5111 if obsolete.isenabled(repo, obsolete.createmarkersopt):
5109 5112 for trouble in ("orphan", "contentdivergent", "phasedivergent"):
5110 5113 numtrouble = len(repo.revs(trouble + "()"))
5111 5114 # We write all the possibilities to ease translation
5112 5115 troublemsg = {
5113 5116 "orphan": _("orphan: %d changesets"),
5114 5117 "contentdivergent": _("content-divergent: %d changesets"),
5115 5118 "phasedivergent": _("phase-divergent: %d changesets"),
5116 5119 }
5117 5120 if numtrouble > 0:
5118 5121 ui.status(troublemsg[trouble] % numtrouble + "\n")
5119 5122
5120 5123 cmdutil.summaryhooks(ui, repo)
5121 5124
5122 5125 if opts.get('remote'):
5123 5126 needsincoming, needsoutgoing = True, True
5124 5127 else:
5125 5128 needsincoming, needsoutgoing = False, False
5126 5129 for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
5127 5130 if i:
5128 5131 needsincoming = True
5129 5132 if o:
5130 5133 needsoutgoing = True
5131 5134 if not needsincoming and not needsoutgoing:
5132 5135 return
5133 5136
5134 5137 def getincoming():
5135 5138 source, branches = hg.parseurl(ui.expandpath('default'))
5136 5139 sbranch = branches[0]
5137 5140 try:
5138 5141 other = hg.peer(repo, {}, source)
5139 5142 except error.RepoError:
5140 5143 if opts.get('remote'):
5141 5144 raise
5142 5145 return source, sbranch, None, None, None
5143 5146 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
5144 5147 if revs:
5145 5148 revs = [other.lookup(rev) for rev in revs]
5146 5149 ui.debug('comparing with %s\n' % util.hidepassword(source))
5147 5150 repo.ui.pushbuffer()
5148 5151 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
5149 5152 repo.ui.popbuffer()
5150 5153 return source, sbranch, other, commoninc, commoninc[1]
5151 5154
5152 5155 if needsincoming:
5153 5156 source, sbranch, sother, commoninc, incoming = getincoming()
5154 5157 else:
5155 5158 source = sbranch = sother = commoninc = incoming = None
5156 5159
5157 5160 def getoutgoing():
5158 5161 dest, branches = hg.parseurl(ui.expandpath('default-push', 'default'))
5159 5162 dbranch = branches[0]
5160 5163 revs, checkout = hg.addbranchrevs(repo, repo, branches, None)
5161 5164 if source != dest:
5162 5165 try:
5163 5166 dother = hg.peer(repo, {}, dest)
5164 5167 except error.RepoError:
5165 5168 if opts.get('remote'):
5166 5169 raise
5167 5170 return dest, dbranch, None, None
5168 5171 ui.debug('comparing with %s\n' % util.hidepassword(dest))
5169 5172 elif sother is None:
5170 5173 # there is no explicit destination peer, but source one is invalid
5171 5174 return dest, dbranch, None, None
5172 5175 else:
5173 5176 dother = sother
5174 5177 if (source != dest or (sbranch is not None and sbranch != dbranch)):
5175 5178 common = None
5176 5179 else:
5177 5180 common = commoninc
5178 5181 if revs:
5179 5182 revs = [repo.lookup(rev) for rev in revs]
5180 5183 repo.ui.pushbuffer()
5181 5184 outgoing = discovery.findcommonoutgoing(repo, dother, onlyheads=revs,
5182 5185 commoninc=common)
5183 5186 repo.ui.popbuffer()
5184 5187 return dest, dbranch, dother, outgoing
5185 5188
5186 5189 if needsoutgoing:
5187 5190 dest, dbranch, dother, outgoing = getoutgoing()
5188 5191 else:
5189 5192 dest = dbranch = dother = outgoing = None
5190 5193
5191 5194 if opts.get('remote'):
5192 5195 t = []
5193 5196 if incoming:
5194 5197 t.append(_('1 or more incoming'))
5195 5198 o = outgoing.missing
5196 5199 if o:
5197 5200 t.append(_('%d outgoing') % len(o))
5198 5201 other = dother or sother
5199 5202 if 'bookmarks' in other.listkeys('namespaces'):
5200 5203 counts = bookmarks.summary(repo, other)
5201 5204 if counts[0] > 0:
5202 5205 t.append(_('%d incoming bookmarks') % counts[0])
5203 5206 if counts[1] > 0:
5204 5207 t.append(_('%d outgoing bookmarks') % counts[1])
5205 5208
5206 5209 if t:
5207 5210 # i18n: column positioning for "hg summary"
5208 5211 ui.write(_('remote: %s\n') % (', '.join(t)))
5209 5212 else:
5210 5213 # i18n: column positioning for "hg summary"
5211 5214 ui.status(_('remote: (synced)\n'))
5212 5215
5213 5216 cmdutil.summaryremotehooks(ui, repo, opts,
5214 5217 ((source, sbranch, sother, commoninc),
5215 5218 (dest, dbranch, dother, outgoing)))
5216 5219
5217 5220 @command('tag',
5218 5221 [('f', 'force', None, _('force tag')),
5219 5222 ('l', 'local', None, _('make the tag local')),
5220 5223 ('r', 'rev', '', _('revision to tag'), _('REV')),
5221 5224 ('', 'remove', None, _('remove a tag')),
5222 5225 # -l/--local is already there, commitopts cannot be used
5223 5226 ('e', 'edit', None, _('invoke editor on commit messages')),
5224 5227 ('m', 'message', '', _('use text as commit message'), _('TEXT')),
5225 5228 ] + commitopts2,
5226 5229 _('[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...'))
5227 5230 def tag(ui, repo, name1, *names, **opts):
5228 5231 """add one or more tags for the current or given revision
5229 5232
5230 5233 Name a particular revision using <name>.
5231 5234
5232 5235 Tags are used to name particular revisions of the repository and are
5233 5236 very useful to compare different revisions, to go back to significant
5234 5237 earlier versions or to mark branch points as releases, etc. Changing
5235 5238 an existing tag is normally disallowed; use -f/--force to override.
5236 5239
5237 5240 If no revision is given, the parent of the working directory is
5238 5241 used.
5239 5242
5240 5243 To facilitate version control, distribution, and merging of tags,
5241 5244 they are stored as a file named ".hgtags" which is managed similarly
5242 5245 to other project files and can be hand-edited if necessary. This
5243 5246 also means that tagging creates a new commit. The file
5244 5247 ".hg/localtags" is used for local tags (not shared among
5245 5248 repositories).
5246 5249
5247 5250 Tag commits are usually made at the head of a branch. If the parent
5248 5251 of the working directory is not a branch head, :hg:`tag` aborts; use
5249 5252 -f/--force to force the tag commit to be based on a non-head
5250 5253 changeset.
5251 5254
5252 5255 See :hg:`help dates` for a list of formats valid for -d/--date.
5253 5256
5254 5257 Since tag names have priority over branch names during revision
5255 5258 lookup, using an existing branch name as a tag name is discouraged.
5256 5259
5257 5260 Returns 0 on success.
5258 5261 """
5259 5262 opts = pycompat.byteskwargs(opts)
5260 5263 wlock = lock = None
5261 5264 try:
5262 5265 wlock = repo.wlock()
5263 5266 lock = repo.lock()
5264 5267 rev_ = "."
5265 5268 names = [t.strip() for t in (name1,) + names]
5266 5269 if len(names) != len(set(names)):
5267 5270 raise error.Abort(_('tag names must be unique'))
5268 5271 for n in names:
5269 5272 scmutil.checknewlabel(repo, n, 'tag')
5270 5273 if not n:
5271 5274 raise error.Abort(_('tag names cannot consist entirely of '
5272 5275 'whitespace'))
5273 5276 if opts.get('rev') and opts.get('remove'):
5274 5277 raise error.Abort(_("--rev and --remove are incompatible"))
5275 5278 if opts.get('rev'):
5276 5279 rev_ = opts['rev']
5277 5280 message = opts.get('message')
5278 5281 if opts.get('remove'):
5279 5282 if opts.get('local'):
5280 5283 expectedtype = 'local'
5281 5284 else:
5282 5285 expectedtype = 'global'
5283 5286
5284 5287 for n in names:
5285 5288 if not repo.tagtype(n):
5286 5289 raise error.Abort(_("tag '%s' does not exist") % n)
5287 5290 if repo.tagtype(n) != expectedtype:
5288 5291 if expectedtype == 'global':
5289 5292 raise error.Abort(_("tag '%s' is not a global tag") % n)
5290 5293 else:
5291 5294 raise error.Abort(_("tag '%s' is not a local tag") % n)
5292 5295 rev_ = 'null'
5293 5296 if not message:
5294 5297 # we don't translate commit messages
5295 5298 message = 'Removed tag %s' % ', '.join(names)
5296 5299 elif not opts.get('force'):
5297 5300 for n in names:
5298 5301 if n in repo.tags():
5299 5302 raise error.Abort(_("tag '%s' already exists "
5300 5303 "(use -f to force)") % n)
5301 5304 if not opts.get('local'):
5302 5305 p1, p2 = repo.dirstate.parents()
5303 5306 if p2 != nullid:
5304 5307 raise error.Abort(_('uncommitted merge'))
5305 5308 bheads = repo.branchheads()
5306 5309 if not opts.get('force') and bheads and p1 not in bheads:
5307 5310 raise error.Abort(_('working directory is not at a branch head '
5308 5311 '(use -f to force)'))
5309 5312 r = scmutil.revsingle(repo, rev_).node()
5310 5313
5311 5314 if not message:
5312 5315 # we don't translate commit messages
5313 5316 message = ('Added tag %s for changeset %s' %
5314 5317 (', '.join(names), short(r)))
5315 5318
5316 5319 date = opts.get('date')
5317 5320 if date:
5318 5321 date = util.parsedate(date)
5319 5322
5320 5323 if opts.get('remove'):
5321 5324 editform = 'tag.remove'
5322 5325 else:
5323 5326 editform = 'tag.add'
5324 5327 editor = cmdutil.getcommiteditor(editform=editform,
5325 5328 **pycompat.strkwargs(opts))
5326 5329
5327 5330 # don't allow tagging the null rev
5328 5331 if (not opts.get('remove') and
5329 5332 scmutil.revsingle(repo, rev_).rev() == nullrev):
5330 5333 raise error.Abort(_("cannot tag null revision"))
5331 5334
5332 5335 tagsmod.tag(repo, names, r, message, opts.get('local'),
5333 5336 opts.get('user'), date, editor=editor)
5334 5337 finally:
5335 5338 release(lock, wlock)
5336 5339
5337 5340 @command('tags', formatteropts, '', cmdtype=readonly)
5338 5341 def tags(ui, repo, **opts):
5339 5342 """list repository tags
5340 5343
5341 5344 This lists both regular and local tags. When the -v/--verbose
5342 5345 switch is used, a third column "local" is printed for local tags.
5343 5346 When the -q/--quiet switch is used, only the tag name is printed.
5344 5347
5345 5348 Returns 0 on success.
5346 5349 """
5347 5350
5348 5351 opts = pycompat.byteskwargs(opts)
5349 5352 ui.pager('tags')
5350 5353 fm = ui.formatter('tags', opts)
5351 5354 hexfunc = fm.hexfunc
5352 5355 tagtype = ""
5353 5356
5354 5357 for t, n in reversed(repo.tagslist()):
5355 5358 hn = hexfunc(n)
5356 5359 label = 'tags.normal'
5357 5360 tagtype = ''
5358 5361 if repo.tagtype(t) == 'local':
5359 5362 label = 'tags.local'
5360 5363 tagtype = 'local'
5361 5364
5362 5365 fm.startitem()
5363 5366 fm.write('tag', '%s', t, label=label)
5364 5367 fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
5365 5368 fm.condwrite(not ui.quiet, 'rev node', fmt,
5366 5369 repo.changelog.rev(n), hn, label=label)
5367 5370 fm.condwrite(ui.verbose and tagtype, 'type', ' %s',
5368 5371 tagtype, label=label)
5369 5372 fm.plain('\n')
5370 5373 fm.end()
5371 5374
5372 5375 @command('tip',
5373 5376 [('p', 'patch', None, _('show patch')),
5374 5377 ('g', 'git', None, _('use git extended diff format')),
5375 5378 ] + templateopts,
5376 5379 _('[-p] [-g]'))
5377 5380 def tip(ui, repo, **opts):
5378 5381 """show the tip revision (DEPRECATED)
5379 5382
5380 5383 The tip revision (usually just called the tip) is the changeset
5381 5384 most recently added to the repository (and therefore the most
5382 5385 recently changed head).
5383 5386
5384 5387 If you have just made a commit, that commit will be the tip. If
5385 5388 you have just pulled changes from another repository, the tip of
5386 5389 that repository becomes the current tip. The "tip" tag is special
5387 5390 and cannot be renamed or assigned to a different changeset.
5388 5391
5389 5392 This command is deprecated, please use :hg:`heads` instead.
5390 5393
5391 5394 Returns 0 on success.
5392 5395 """
5393 5396 opts = pycompat.byteskwargs(opts)
5394 5397 displayer = cmdutil.show_changeset(ui, repo, opts)
5395 5398 displayer.show(repo['tip'])
5396 5399 displayer.close()
5397 5400
5398 5401 @command('unbundle',
5399 5402 [('u', 'update', None,
5400 5403 _('update to new branch head if changesets were unbundled'))],
5401 5404 _('[-u] FILE...'))
5402 5405 def unbundle(ui, repo, fname1, *fnames, **opts):
5403 5406 """apply one or more bundle files
5404 5407
5405 5408 Apply one or more bundle files generated by :hg:`bundle`.
5406 5409
5407 5410 Returns 0 on success, 1 if an update has unresolved files.
5408 5411 """
5409 5412 fnames = (fname1,) + fnames
5410 5413
5411 5414 with repo.lock():
5412 5415 for fname in fnames:
5413 5416 f = hg.openpath(ui, fname)
5414 5417 gen = exchange.readbundle(ui, f, fname)
5415 5418 if isinstance(gen, streamclone.streamcloneapplier):
5416 5419 raise error.Abort(
5417 5420 _('packed bundles cannot be applied with '
5418 5421 '"hg unbundle"'),
5419 5422 hint=_('use "hg debugapplystreamclonebundle"'))
5420 5423 url = 'bundle:' + fname
5421 5424 try:
5422 5425 txnname = 'unbundle'
5423 5426 if not isinstance(gen, bundle2.unbundle20):
5424 5427 txnname = 'unbundle\n%s' % util.hidepassword(url)
5425 5428 with repo.transaction(txnname) as tr:
5426 5429 op = bundle2.applybundle(repo, gen, tr, source='unbundle',
5427 5430 url=url)
5428 5431 except error.BundleUnknownFeatureError as exc:
5429 5432 raise error.Abort(
5430 5433 _('%s: unknown bundle feature, %s') % (fname, exc),
5431 5434 hint=_("see https://mercurial-scm.org/"
5432 5435 "wiki/BundleFeature for more "
5433 5436 "information"))
5434 5437 modheads = bundle2.combinechangegroupresults(op)
5435 5438
5436 5439 return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)
5437 5440
5438 5441 @command('^update|up|checkout|co',
5439 5442 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
5440 5443 ('c', 'check', None, _('require clean working directory')),
5441 5444 ('m', 'merge', None, _('merge uncommitted changes')),
5442 5445 ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
5443 5446 ('r', 'rev', '', _('revision'), _('REV'))
5444 5447 ] + mergetoolopts,
5445 5448 _('[-C|-c|-m] [-d DATE] [[-r] REV]'))
5446 5449 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False,
5447 5450 merge=None, tool=None):
5448 5451 """update working directory (or switch revisions)
5449 5452
5450 5453 Update the repository's working directory to the specified
5451 5454 changeset. If no changeset is specified, update to the tip of the
5452 5455 current named branch and move the active bookmark (see :hg:`help
5453 5456 bookmarks`).
5454 5457
5455 5458 Update sets the working directory's parent revision to the specified
5456 5459 changeset (see :hg:`help parents`).
5457 5460
5458 5461 If the changeset is not a descendant or ancestor of the working
5459 5462 directory's parent and there are uncommitted changes, the update is
5460 5463 aborted. With the -c/--check option, the working directory is checked
5461 5464 for uncommitted changes; if none are found, the working directory is
5462 5465 updated to the specified changeset.
5463 5466
5464 5467 .. container:: verbose
5465 5468
5466 5469 The -C/--clean, -c/--check, and -m/--merge options control what
5467 5470 happens if the working directory contains uncommitted changes.
5468 5471 At most of one of them can be specified.
5469 5472
5470 5473 1. If no option is specified, and if
5471 5474 the requested changeset is an ancestor or descendant of
5472 5475 the working directory's parent, the uncommitted changes
5473 5476 are merged into the requested changeset and the merged
5474 5477 result is left uncommitted. If the requested changeset is
5475 5478 not an ancestor or descendant (that is, it is on another
5476 5479 branch), the update is aborted and the uncommitted changes
5477 5480 are preserved.
5478 5481
5479 5482 2. With the -m/--merge option, the update is allowed even if the
5480 5483 requested changeset is not an ancestor or descendant of
5481 5484 the working directory's parent.
5482 5485
5483 5486 3. With the -c/--check option, the update is aborted and the
5484 5487 uncommitted changes are preserved.
5485 5488
5486 5489 4. With the -C/--clean option, uncommitted changes are discarded and
5487 5490 the working directory is updated to the requested changeset.
5488 5491
5489 5492 To cancel an uncommitted merge (and lose your changes), use
5490 5493 :hg:`update --clean .`.
5491 5494
5492 5495 Use null as the changeset to remove the working directory (like
5493 5496 :hg:`clone -U`).
5494 5497
5495 5498 If you want to revert just one file to an older revision, use
5496 5499 :hg:`revert [-r REV] NAME`.
5497 5500
5498 5501 See :hg:`help dates` for a list of formats valid for -d/--date.
5499 5502
5500 5503 Returns 0 on success, 1 if there are unresolved files.
5501 5504 """
5502 5505 if rev and node:
5503 5506 raise error.Abort(_("please specify just one revision"))
5504 5507
5505 5508 if ui.configbool('commands', 'update.requiredest'):
5506 5509 if not node and not rev and not date:
5507 5510 raise error.Abort(_('you must specify a destination'),
5508 5511 hint=_('for example: hg update ".::"'))
5509 5512
5510 5513 if rev is None or rev == '':
5511 5514 rev = node
5512 5515
5513 5516 if date and rev is not None:
5514 5517 raise error.Abort(_("you can't specify a revision and a date"))
5515 5518
5516 5519 if len([x for x in (clean, check, merge) if x]) > 1:
5517 5520 raise error.Abort(_("can only specify one of -C/--clean, -c/--check, "
5518 5521 "or -m/--merge"))
5519 5522
5520 5523 updatecheck = None
5521 5524 if check:
5522 5525 updatecheck = 'abort'
5523 5526 elif merge:
5524 5527 updatecheck = 'none'
5525 5528
5526 5529 with repo.wlock():
5527 5530 cmdutil.clearunfinished(repo)
5528 5531
5529 5532 if date:
5530 5533 rev = cmdutil.finddate(ui, repo, date)
5531 5534
5532 5535 # if we defined a bookmark, we have to remember the original name
5533 5536 brev = rev
5534 5537 repo = scmutil.unhidehashlikerevs(repo, [rev], 'nowarn')
5535 5538 ctx = scmutil.revsingle(repo, rev, rev)
5536 5539 rev = ctx.rev()
5537 5540 if ctx.hidden():
5538 5541 ui.warn(_("updating to a hidden changeset %s\n") % ctx.hex()[:12])
5539 5542
5540 5543 repo.ui.setconfig('ui', 'forcemerge', tool, 'update')
5541 5544
5542 5545 return hg.updatetotally(ui, repo, rev, brev, clean=clean,
5543 5546 updatecheck=updatecheck)
5544 5547
5545 5548 @command('verify', [])
5546 5549 def verify(ui, repo):
5547 5550 """verify the integrity of the repository
5548 5551
5549 5552 Verify the integrity of the current repository.
5550 5553
5551 5554 This will perform an extensive check of the repository's
5552 5555 integrity, validating the hashes and checksums of each entry in
5553 5556 the changelog, manifest, and tracked files, as well as the
5554 5557 integrity of their crosslinks and indices.
5555 5558
5556 5559 Please see https://mercurial-scm.org/wiki/RepositoryCorruption
5557 5560 for more information about recovery from corruption of the
5558 5561 repository.
5559 5562
5560 5563 Returns 0 on success, 1 if errors are encountered.
5561 5564 """
5562 5565 return hg.verify(repo)
5563 5566
5564 5567 @command('version', [] + formatteropts, norepo=True, cmdtype=readonly)
5565 5568 def version_(ui, **opts):
5566 5569 """output version and copyright information"""
5567 5570 opts = pycompat.byteskwargs(opts)
5568 5571 if ui.verbose:
5569 5572 ui.pager('version')
5570 5573 fm = ui.formatter("version", opts)
5571 5574 fm.startitem()
5572 5575 fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"),
5573 5576 util.version())
5574 5577 license = _(
5575 5578 "(see https://mercurial-scm.org for more information)\n"
5576 5579 "\nCopyright (C) 2005-2017 Matt Mackall and others\n"
5577 5580 "This is free software; see the source for copying conditions. "
5578 5581 "There is NO\nwarranty; "
5579 5582 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
5580 5583 )
5581 5584 if not ui.quiet:
5582 5585 fm.plain(license)
5583 5586
5584 5587 if ui.verbose:
5585 5588 fm.plain(_("\nEnabled extensions:\n\n"))
5586 5589 # format names and versions into columns
5587 5590 names = []
5588 5591 vers = []
5589 5592 isinternals = []
5590 5593 for name, module in extensions.extensions():
5591 5594 names.append(name)
5592 5595 vers.append(extensions.moduleversion(module) or None)
5593 5596 isinternals.append(extensions.ismoduleinternal(module))
5594 5597 fn = fm.nested("extensions")
5595 5598 if names:
5596 5599 namefmt = " %%-%ds " % max(len(n) for n in names)
5597 5600 places = [_("external"), _("internal")]
5598 5601 for n, v, p in zip(names, vers, isinternals):
5599 5602 fn.startitem()
5600 5603 fn.condwrite(ui.verbose, "name", namefmt, n)
5601 5604 if ui.verbose:
5602 5605 fn.plain("%s " % places[p])
5603 5606 fn.data(bundled=p)
5604 5607 fn.condwrite(ui.verbose and v, "ver", "%s", v)
5605 5608 if ui.verbose:
5606 5609 fn.plain("\n")
5607 5610 fn.end()
5608 5611 fm.end()
5609 5612
5610 5613 def loadcmdtable(ui, name, cmdtable):
5611 5614 """Load command functions from specified cmdtable
5612 5615 """
5613 5616 overrides = [cmd for cmd in cmdtable if cmd in table]
5614 5617 if overrides:
5615 5618 ui.warn(_("extension '%s' overrides commands: %s\n")
5616 5619 % (name, " ".join(overrides)))
5617 5620 table.update(cmdtable)
@@ -1,178 +1,183 b''
1 1 Tests for access level on hidden commits by various commands on based of their
2 2 type.
3 3
4 4 Setting the required config to start this
5 5
6 6 $ cat >> $HGRCPATH <<EOF
7 7 > [experimental]
8 8 > evolution=createmarkers, allowunstable
9 9 > directaccess=True
10 10 > directaccess.revnums=True
11 11 > [extensions]
12 12 > amend =
13 13 > EOF
14 14
15 15 $ hg init repo
16 16 $ cd repo
17 17 $ for ch in a b c; do touch $ch; echo "foo" >> $ch; hg ci -Aqm "Added "$ch; done
18 18
19 19 $ hg log -G -T '{rev}:{node} {desc}' --hidden
20 20 @ 2:28ad74487de9599d00d81085be739c61fc340652 Added c
21 21 |
22 22 o 1:29becc82797a4bc11ec8880b58eaecd2ab3e7760 Added b
23 23 |
24 24 o 0:18d04c59bb5d2d4090ad9a5b59bd6274adb63add Added a
25 25
26 26 $ echo "bar" >> c
27 27 $ hg amend
28 28
29 29 $ hg log -G -T '{rev}:{node} {desc}' --hidden
30 30 @ 3:2443a0e664694756d8b435d06b6ad84f941b6fc0 Added c
31 31 |
32 32 | x 2:28ad74487de9599d00d81085be739c61fc340652 Added c
33 33 |/
34 34 o 1:29becc82797a4bc11ec8880b58eaecd2ab3e7760 Added b
35 35 |
36 36 o 0:18d04c59bb5d2d4090ad9a5b59bd6274adb63add Added a
37 37
38 38 Testing read only commands on the hidden revision
39 39
40 40 Testing with rev number
41 41
42 42 $ hg exp 2 --config experimental.directaccess.revnums=False
43 43 abort: hidden revision '2'!
44 44 (use --hidden to access hidden revisions)
45 45 [255]
46 46
47 47 $ hg exp 2
48 48 # HG changeset patch
49 49 # User test
50 50 # Date 0 0
51 51 # Thu Jan 01 00:00:00 1970 +0000
52 52 # Node ID 28ad74487de9599d00d81085be739c61fc340652
53 53 # Parent 29becc82797a4bc11ec8880b58eaecd2ab3e7760
54 54 Added c
55 55
56 56 diff -r 29becc82797a -r 28ad74487de9 c
57 57 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
58 58 +++ b/c Thu Jan 01 00:00:00 1970 +0000
59 59 @@ -0,0 +1,1 @@
60 60 +foo
61 61
62 62 $ hg log -r 2
63 63 changeset: 2:28ad74487de9
64 64 user: test
65 65 date: Thu Jan 01 00:00:00 1970 +0000
66 66 obsolete: rewritten using amend as 3:2443a0e66469
67 67 summary: Added c
68 68
69 69 $ hg identify -r 2
70 70 28ad74487de9
71 71
72 72 $ hg status --change 2
73 73 A c
74 74
75 75 $ hg status --change 2 --config experimental.directaccess.revnums=False
76 76 abort: hidden revision '2'!
77 77 (use --hidden to access hidden revisions)
78 78 [255]
79 79
80 80 $ hg diff -c 2
81 81 diff -r 29becc82797a -r 28ad74487de9 c
82 82 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83 83 +++ b/c Thu Jan 01 00:00:00 1970 +0000
84 84 @@ -0,0 +1,1 @@
85 85 +foo
86 86
87 87 Testing with hash
88 88
89 89 `hg export`
90 90
91 91 $ hg exp 28ad74
92 92 # HG changeset patch
93 93 # User test
94 94 # Date 0 0
95 95 # Thu Jan 01 00:00:00 1970 +0000
96 96 # Node ID 28ad74487de9599d00d81085be739c61fc340652
97 97 # Parent 29becc82797a4bc11ec8880b58eaecd2ab3e7760
98 98 Added c
99 99
100 100 diff -r 29becc82797a -r 28ad74487de9 c
101 101 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
102 102 +++ b/c Thu Jan 01 00:00:00 1970 +0000
103 103 @@ -0,0 +1,1 @@
104 104 +foo
105 105
106 106 `hg log`
107 107
108 108 $ hg log -r 28ad74
109 109 changeset: 2:28ad74487de9
110 110 user: test
111 111 date: Thu Jan 01 00:00:00 1970 +0000
112 112 obsolete: rewritten using amend as 3:2443a0e66469
113 113 summary: Added c
114 114
115 115 `hg cat`
116 116
117 117 $ hg cat -r 28ad74 c
118 118 foo
119 119
120 120 `hg diff`
121 121
122 122 $ hg diff -c 28ad74
123 123 diff -r 29becc82797a -r 28ad74487de9 c
124 124 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
125 125 +++ b/c Thu Jan 01 00:00:00 1970 +0000
126 126 @@ -0,0 +1,1 @@
127 127 +foo
128 128
129 129 `hg files`
130 130
131 131 $ hg files -r 28ad74
132 132 a
133 133 b
134 134 c
135 135
136 136 `hg identify`
137 137
138 138 $ hg identify -r 28ad74
139 139 28ad74487de9
140 140
141 `hg annotate`
142
143 $ hg annotate -r 28ad74 a
144 0: foo
145
141 146 `hg status`
142 147
143 148 $ hg status --change 28ad74
144 149 A c
145 150
146 151 `hg update`
147 152
148 153 $ hg up 28ad74
149 154 updating to a hidden changeset 28ad74487de9
150 155 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
151 156
152 157 $ hg up 3
153 158 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
154 159
155 160 `hg revert`
156 161
157 162 $ hg revert -r 28ad74 --all
158 163 reverting c
159 164
160 165 $ hg diff
161 166 diff -r 2443a0e66469 c
162 167 --- a/c Thu Jan 01 00:00:00 1970 +0000
163 168 +++ b/c Thu Jan 01 00:00:00 1970 +0000
164 169 @@ -1,2 +1,1 @@
165 170 foo
166 171 -bar
167 172
168 173 Commands with undefined cmdtype should not work right now
169 174
170 175 $ hg phase -r 28ad74
171 176 abort: hidden revision '28ad74'!
172 177 (use --hidden to access hidden revisions)
173 178 [255]
174 179
175 180 $ hg phase -r 2
176 181 abort: hidden revision '2'!
177 182 (use --hidden to access hidden revisions)
178 183 [255]
General Comments 0
You need to be logged in to leave comments. Login now