##// END OF EJS Templates
paths: use `list_paths` in `hg paths`...
marmoute -
r47795:9bfe3818 default draft
parent child Browse files
Show More
@@ -1,7946 +1,7940 b''
1 1 # commands.py - command processing for mercurial
2 2 #
3 3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import
9 9
10 10 import errno
11 11 import os
12 12 import re
13 13 import sys
14 14
15 15 from .i18n import _
16 16 from .node import (
17 17 hex,
18 18 nullrev,
19 19 short,
20 20 wdirrev,
21 21 )
22 22 from .pycompat import open
23 23 from . import (
24 24 archival,
25 25 bookmarks,
26 26 bundle2,
27 27 bundlecaches,
28 28 changegroup,
29 29 cmdutil,
30 30 copies,
31 31 debugcommands as debugcommandsmod,
32 32 destutil,
33 33 dirstateguard,
34 34 discovery,
35 35 encoding,
36 36 error,
37 37 exchange,
38 38 extensions,
39 39 filemerge,
40 40 formatter,
41 41 graphmod,
42 42 grep as grepmod,
43 43 hbisect,
44 44 help,
45 45 hg,
46 46 logcmdutil,
47 47 merge as mergemod,
48 48 mergestate as mergestatemod,
49 49 narrowspec,
50 50 obsolete,
51 51 obsutil,
52 52 patch,
53 53 phases,
54 54 pycompat,
55 55 rcutil,
56 56 registrar,
57 57 requirements,
58 58 revsetlang,
59 59 rewriteutil,
60 60 scmutil,
61 61 server,
62 62 shelve as shelvemod,
63 63 state as statemod,
64 64 streamclone,
65 65 tags as tagsmod,
66 66 ui as uimod,
67 67 util,
68 68 verify as verifymod,
69 69 vfs as vfsmod,
70 70 wireprotoserver,
71 71 )
72 72 from .utils import (
73 73 dateutil,
74 74 stringutil,
75 75 urlutil,
76 76 )
77 77
78 78 if pycompat.TYPE_CHECKING:
79 79 from typing import (
80 80 List,
81 81 )
82 82
83 83
84 84 table = {}
85 85 table.update(debugcommandsmod.command._table)
86 86
87 87 command = registrar.command(table)
88 88 INTENT_READONLY = registrar.INTENT_READONLY
89 89
90 90 # common command options
91 91
92 92 globalopts = [
93 93 (
94 94 b'R',
95 95 b'repository',
96 96 b'',
97 97 _(b'repository root directory or name of overlay bundle file'),
98 98 _(b'REPO'),
99 99 ),
100 100 (b'', b'cwd', b'', _(b'change working directory'), _(b'DIR')),
101 101 (
102 102 b'y',
103 103 b'noninteractive',
104 104 None,
105 105 _(
106 106 b'do not prompt, automatically pick the first choice for all prompts'
107 107 ),
108 108 ),
109 109 (b'q', b'quiet', None, _(b'suppress output')),
110 110 (b'v', b'verbose', None, _(b'enable additional output')),
111 111 (
112 112 b'',
113 113 b'color',
114 114 b'',
115 115 # i18n: 'always', 'auto', 'never', and 'debug' are keywords
116 116 # and should not be translated
117 117 _(b"when to colorize (boolean, always, auto, never, or debug)"),
118 118 _(b'TYPE'),
119 119 ),
120 120 (
121 121 b'',
122 122 b'config',
123 123 [],
124 124 _(b'set/override config option (use \'section.name=value\')'),
125 125 _(b'CONFIG'),
126 126 ),
127 127 (b'', b'debug', None, _(b'enable debugging output')),
128 128 (b'', b'debugger', None, _(b'start debugger')),
129 129 (
130 130 b'',
131 131 b'encoding',
132 132 encoding.encoding,
133 133 _(b'set the charset encoding'),
134 134 _(b'ENCODE'),
135 135 ),
136 136 (
137 137 b'',
138 138 b'encodingmode',
139 139 encoding.encodingmode,
140 140 _(b'set the charset encoding mode'),
141 141 _(b'MODE'),
142 142 ),
143 143 (b'', b'traceback', None, _(b'always print a traceback on exception')),
144 144 (b'', b'time', None, _(b'time how long the command takes')),
145 145 (b'', b'profile', None, _(b'print command execution profile')),
146 146 (b'', b'version', None, _(b'output version information and exit')),
147 147 (b'h', b'help', None, _(b'display help and exit')),
148 148 (b'', b'hidden', False, _(b'consider hidden changesets')),
149 149 (
150 150 b'',
151 151 b'pager',
152 152 b'auto',
153 153 _(b"when to paginate (boolean, always, auto, or never)"),
154 154 _(b'TYPE'),
155 155 ),
156 156 ]
157 157
158 158 dryrunopts = cmdutil.dryrunopts
159 159 remoteopts = cmdutil.remoteopts
160 160 walkopts = cmdutil.walkopts
161 161 commitopts = cmdutil.commitopts
162 162 commitopts2 = cmdutil.commitopts2
163 163 commitopts3 = cmdutil.commitopts3
164 164 formatteropts = cmdutil.formatteropts
165 165 templateopts = cmdutil.templateopts
166 166 logopts = cmdutil.logopts
167 167 diffopts = cmdutil.diffopts
168 168 diffwsopts = cmdutil.diffwsopts
169 169 diffopts2 = cmdutil.diffopts2
170 170 mergetoolopts = cmdutil.mergetoolopts
171 171 similarityopts = cmdutil.similarityopts
172 172 subrepoopts = cmdutil.subrepoopts
173 173 debugrevlogopts = cmdutil.debugrevlogopts
174 174
175 175 # Commands start here, listed alphabetically
176 176
177 177
178 178 @command(
179 179 b'abort',
180 180 dryrunopts,
181 181 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
182 182 helpbasic=True,
183 183 )
184 184 def abort(ui, repo, **opts):
185 185 """abort an unfinished operation (EXPERIMENTAL)
186 186
187 187 Aborts a multistep operation like graft, histedit, rebase, merge,
188 188 and unshelve if they are in an unfinished state.
189 189
190 190 use --dry-run/-n to dry run the command.
191 191 """
192 192 dryrun = opts.get('dry_run')
193 193 abortstate = cmdutil.getunfinishedstate(repo)
194 194 if not abortstate:
195 195 raise error.StateError(_(b'no operation in progress'))
196 196 if not abortstate.abortfunc:
197 197 raise error.InputError(
198 198 (
199 199 _(b"%s in progress but does not support 'hg abort'")
200 200 % (abortstate._opname)
201 201 ),
202 202 hint=abortstate.hint(),
203 203 )
204 204 if dryrun:
205 205 ui.status(
206 206 _(b'%s in progress, will be aborted\n') % (abortstate._opname)
207 207 )
208 208 return
209 209 return abortstate.abortfunc(ui, repo)
210 210
211 211
212 212 @command(
213 213 b'add',
214 214 walkopts + subrepoopts + dryrunopts,
215 215 _(b'[OPTION]... [FILE]...'),
216 216 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
217 217 helpbasic=True,
218 218 inferrepo=True,
219 219 )
220 220 def add(ui, repo, *pats, **opts):
221 221 """add the specified files on the next commit
222 222
223 223 Schedule files to be version controlled and added to the
224 224 repository.
225 225
226 226 The files will be added to the repository at the next commit. To
227 227 undo an add before that, see :hg:`forget`.
228 228
229 229 If no names are given, add all files to the repository (except
230 230 files matching ``.hgignore``).
231 231
232 232 .. container:: verbose
233 233
234 234 Examples:
235 235
236 236 - New (unknown) files are added
237 237 automatically by :hg:`add`::
238 238
239 239 $ ls
240 240 foo.c
241 241 $ hg status
242 242 ? foo.c
243 243 $ hg add
244 244 adding foo.c
245 245 $ hg status
246 246 A foo.c
247 247
248 248 - Specific files to be added can be specified::
249 249
250 250 $ ls
251 251 bar.c foo.c
252 252 $ hg status
253 253 ? bar.c
254 254 ? foo.c
255 255 $ hg add bar.c
256 256 $ hg status
257 257 A bar.c
258 258 ? foo.c
259 259
260 260 Returns 0 if all files are successfully added.
261 261 """
262 262
263 263 m = scmutil.match(repo[None], pats, pycompat.byteskwargs(opts))
264 264 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
265 265 rejected = cmdutil.add(ui, repo, m, b"", uipathfn, False, **opts)
266 266 return rejected and 1 or 0
267 267
268 268
269 269 @command(
270 270 b'addremove',
271 271 similarityopts + subrepoopts + walkopts + dryrunopts,
272 272 _(b'[OPTION]... [FILE]...'),
273 273 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
274 274 inferrepo=True,
275 275 )
276 276 def addremove(ui, repo, *pats, **opts):
277 277 """add all new files, delete all missing files
278 278
279 279 Add all new files and remove all missing files from the
280 280 repository.
281 281
282 282 Unless names are given, new files are ignored if they match any of
283 283 the patterns in ``.hgignore``. As with add, these changes take
284 284 effect at the next commit.
285 285
286 286 Use the -s/--similarity option to detect renamed files. This
287 287 option takes a percentage between 0 (disabled) and 100 (files must
288 288 be identical) as its parameter. With a parameter greater than 0,
289 289 this compares every removed file with every added file and records
290 290 those similar enough as renames. Detecting renamed files this way
291 291 can be expensive. After using this option, :hg:`status -C` can be
292 292 used to check which files were identified as moved or renamed. If
293 293 not specified, -s/--similarity defaults to 100 and only renames of
294 294 identical files are detected.
295 295
296 296 .. container:: verbose
297 297
298 298 Examples:
299 299
300 300 - A number of files (bar.c and foo.c) are new,
301 301 while foobar.c has been removed (without using :hg:`remove`)
302 302 from the repository::
303 303
304 304 $ ls
305 305 bar.c foo.c
306 306 $ hg status
307 307 ! foobar.c
308 308 ? bar.c
309 309 ? foo.c
310 310 $ hg addremove
311 311 adding bar.c
312 312 adding foo.c
313 313 removing foobar.c
314 314 $ hg status
315 315 A bar.c
316 316 A foo.c
317 317 R foobar.c
318 318
319 319 - A file foobar.c was moved to foo.c without using :hg:`rename`.
320 320 Afterwards, it was edited slightly::
321 321
322 322 $ ls
323 323 foo.c
324 324 $ hg status
325 325 ! foobar.c
326 326 ? foo.c
327 327 $ hg addremove --similarity 90
328 328 removing foobar.c
329 329 adding foo.c
330 330 recording removal of foobar.c as rename to foo.c (94% similar)
331 331 $ hg status -C
332 332 A foo.c
333 333 foobar.c
334 334 R foobar.c
335 335
336 336 Returns 0 if all files are successfully added.
337 337 """
338 338 opts = pycompat.byteskwargs(opts)
339 339 if not opts.get(b'similarity'):
340 340 opts[b'similarity'] = b'100'
341 341 matcher = scmutil.match(repo[None], pats, opts)
342 342 relative = scmutil.anypats(pats, opts)
343 343 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative)
344 344 return scmutil.addremove(repo, matcher, b"", uipathfn, opts)
345 345
346 346
347 347 @command(
348 348 b'annotate|blame',
349 349 [
350 350 (b'r', b'rev', b'', _(b'annotate the specified revision'), _(b'REV')),
351 351 (
352 352 b'',
353 353 b'follow',
354 354 None,
355 355 _(b'follow copies/renames and list the filename (DEPRECATED)'),
356 356 ),
357 357 (b'', b'no-follow', None, _(b"don't follow copies and renames")),
358 358 (b'a', b'text', None, _(b'treat all files as text')),
359 359 (b'u', b'user', None, _(b'list the author (long with -v)')),
360 360 (b'f', b'file', None, _(b'list the filename')),
361 361 (b'd', b'date', None, _(b'list the date (short with -q)')),
362 362 (b'n', b'number', None, _(b'list the revision number (default)')),
363 363 (b'c', b'changeset', None, _(b'list the changeset')),
364 364 (
365 365 b'l',
366 366 b'line-number',
367 367 None,
368 368 _(b'show line number at the first appearance'),
369 369 ),
370 370 (
371 371 b'',
372 372 b'skip',
373 373 [],
374 374 _(b'revset to not display (EXPERIMENTAL)'),
375 375 _(b'REV'),
376 376 ),
377 377 ]
378 378 + diffwsopts
379 379 + walkopts
380 380 + formatteropts,
381 381 _(b'[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
382 382 helpcategory=command.CATEGORY_FILE_CONTENTS,
383 383 helpbasic=True,
384 384 inferrepo=True,
385 385 )
386 386 def annotate(ui, repo, *pats, **opts):
387 387 """show changeset information by line for each file
388 388
389 389 List changes in files, showing the revision id responsible for
390 390 each line.
391 391
392 392 This command is useful for discovering when a change was made and
393 393 by whom.
394 394
395 395 If you include --file, --user, or --date, the revision number is
396 396 suppressed unless you also include --number.
397 397
398 398 Without the -a/--text option, annotate will avoid processing files
399 399 it detects as binary. With -a, annotate will annotate the file
400 400 anyway, although the results will probably be neither useful
401 401 nor desirable.
402 402
403 403 .. container:: verbose
404 404
405 405 Template:
406 406
407 407 The following keywords are supported in addition to the common template
408 408 keywords and functions. See also :hg:`help templates`.
409 409
410 410 :lines: List of lines with annotation data.
411 411 :path: String. Repository-absolute path of the specified file.
412 412
413 413 And each entry of ``{lines}`` provides the following sub-keywords in
414 414 addition to ``{date}``, ``{node}``, ``{rev}``, ``{user}``, etc.
415 415
416 416 :line: String. Line content.
417 417 :lineno: Integer. Line number at that revision.
418 418 :path: String. Repository-absolute path of the file at that revision.
419 419
420 420 See :hg:`help templates.operators` for the list expansion syntax.
421 421
422 422 Returns 0 on success.
423 423 """
424 424 opts = pycompat.byteskwargs(opts)
425 425 if not pats:
426 426 raise error.InputError(
427 427 _(b'at least one filename or pattern is required')
428 428 )
429 429
430 430 if opts.get(b'follow'):
431 431 # --follow is deprecated and now just an alias for -f/--file
432 432 # to mimic the behavior of Mercurial before version 1.5
433 433 opts[b'file'] = True
434 434
435 435 if (
436 436 not opts.get(b'user')
437 437 and not opts.get(b'changeset')
438 438 and not opts.get(b'date')
439 439 and not opts.get(b'file')
440 440 ):
441 441 opts[b'number'] = True
442 442
443 443 linenumber = opts.get(b'line_number') is not None
444 444 if (
445 445 linenumber
446 446 and (not opts.get(b'changeset'))
447 447 and (not opts.get(b'number'))
448 448 ):
449 449 raise error.InputError(_(b'at least one of -n/-c is required for -l'))
450 450
451 451 rev = opts.get(b'rev')
452 452 if rev:
453 453 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
454 454 ctx = scmutil.revsingle(repo, rev)
455 455
456 456 ui.pager(b'annotate')
457 457 rootfm = ui.formatter(b'annotate', opts)
458 458 if ui.debugflag:
459 459 shorthex = pycompat.identity
460 460 else:
461 461
462 462 def shorthex(h):
463 463 return h[:12]
464 464
465 465 if ui.quiet:
466 466 datefunc = dateutil.shortdate
467 467 else:
468 468 datefunc = dateutil.datestr
469 469 if ctx.rev() is None:
470 470 if opts.get(b'changeset'):
471 471 # omit "+" suffix which is appended to node hex
472 472 def formatrev(rev):
473 473 if rev == wdirrev:
474 474 return b'%d' % ctx.p1().rev()
475 475 else:
476 476 return b'%d' % rev
477 477
478 478 else:
479 479
480 480 def formatrev(rev):
481 481 if rev == wdirrev:
482 482 return b'%d+' % ctx.p1().rev()
483 483 else:
484 484 return b'%d ' % rev
485 485
486 486 def formathex(h):
487 487 if h == repo.nodeconstants.wdirhex:
488 488 return b'%s+' % shorthex(hex(ctx.p1().node()))
489 489 else:
490 490 return b'%s ' % shorthex(h)
491 491
492 492 else:
493 493 formatrev = b'%d'.__mod__
494 494 formathex = shorthex
495 495
496 496 opmap = [
497 497 (b'user', b' ', lambda x: x.fctx.user(), ui.shortuser),
498 498 (b'rev', b' ', lambda x: scmutil.intrev(x.fctx), formatrev),
499 499 (b'node', b' ', lambda x: hex(scmutil.binnode(x.fctx)), formathex),
500 500 (b'date', b' ', lambda x: x.fctx.date(), util.cachefunc(datefunc)),
501 501 (b'path', b' ', lambda x: x.fctx.path(), pycompat.bytestr),
502 502 (b'lineno', b':', lambda x: x.lineno, pycompat.bytestr),
503 503 ]
504 504 opnamemap = {
505 505 b'rev': b'number',
506 506 b'node': b'changeset',
507 507 b'path': b'file',
508 508 b'lineno': b'line_number',
509 509 }
510 510
511 511 if rootfm.isplain():
512 512
513 513 def makefunc(get, fmt):
514 514 return lambda x: fmt(get(x))
515 515
516 516 else:
517 517
518 518 def makefunc(get, fmt):
519 519 return get
520 520
521 521 datahint = rootfm.datahint()
522 522 funcmap = [
523 523 (makefunc(get, fmt), sep)
524 524 for fn, sep, get, fmt in opmap
525 525 if opts.get(opnamemap.get(fn, fn)) or fn in datahint
526 526 ]
527 527 funcmap[0] = (funcmap[0][0], b'') # no separator in front of first column
528 528 fields = b' '.join(
529 529 fn
530 530 for fn, sep, get, fmt in opmap
531 531 if opts.get(opnamemap.get(fn, fn)) or fn in datahint
532 532 )
533 533
534 534 def bad(x, y):
535 535 raise error.Abort(b"%s: %s" % (x, y))
536 536
537 537 m = scmutil.match(ctx, pats, opts, badfn=bad)
538 538
539 539 follow = not opts.get(b'no_follow')
540 540 diffopts = patch.difffeatureopts(
541 541 ui, opts, section=b'annotate', whitespace=True
542 542 )
543 543 skiprevs = opts.get(b'skip')
544 544 if skiprevs:
545 545 skiprevs = scmutil.revrange(repo, skiprevs)
546 546
547 547 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
548 548 for abs in ctx.walk(m):
549 549 fctx = ctx[abs]
550 550 rootfm.startitem()
551 551 rootfm.data(path=abs)
552 552 if not opts.get(b'text') and fctx.isbinary():
553 553 rootfm.plain(_(b"%s: binary file\n") % uipathfn(abs))
554 554 continue
555 555
556 556 fm = rootfm.nested(b'lines', tmpl=b'{rev}: {line}')
557 557 lines = fctx.annotate(
558 558 follow=follow, skiprevs=skiprevs, diffopts=diffopts
559 559 )
560 560 if not lines:
561 561 fm.end()
562 562 continue
563 563 formats = []
564 564 pieces = []
565 565
566 566 for f, sep in funcmap:
567 567 l = [f(n) for n in lines]
568 568 if fm.isplain():
569 569 sizes = [encoding.colwidth(x) for x in l]
570 570 ml = max(sizes)
571 571 formats.append([sep + b' ' * (ml - w) + b'%s' for w in sizes])
572 572 else:
573 573 formats.append([b'%s'] * len(l))
574 574 pieces.append(l)
575 575
576 576 for f, p, n in zip(zip(*formats), zip(*pieces), lines):
577 577 fm.startitem()
578 578 fm.context(fctx=n.fctx)
579 579 fm.write(fields, b"".join(f), *p)
580 580 if n.skip:
581 581 fmt = b"* %s"
582 582 else:
583 583 fmt = b": %s"
584 584 fm.write(b'line', fmt, n.text)
585 585
586 586 if not lines[-1].text.endswith(b'\n'):
587 587 fm.plain(b'\n')
588 588 fm.end()
589 589
590 590 rootfm.end()
591 591
592 592
593 593 @command(
594 594 b'archive',
595 595 [
596 596 (b'', b'no-decode', None, _(b'do not pass files through decoders')),
597 597 (
598 598 b'p',
599 599 b'prefix',
600 600 b'',
601 601 _(b'directory prefix for files in archive'),
602 602 _(b'PREFIX'),
603 603 ),
604 604 (b'r', b'rev', b'', _(b'revision to distribute'), _(b'REV')),
605 605 (b't', b'type', b'', _(b'type of distribution to create'), _(b'TYPE')),
606 606 ]
607 607 + subrepoopts
608 608 + walkopts,
609 609 _(b'[OPTION]... DEST'),
610 610 helpcategory=command.CATEGORY_IMPORT_EXPORT,
611 611 )
612 612 def archive(ui, repo, dest, **opts):
613 613 """create an unversioned archive of a repository revision
614 614
615 615 By default, the revision used is the parent of the working
616 616 directory; use -r/--rev to specify a different revision.
617 617
618 618 The archive type is automatically detected based on file
619 619 extension (to override, use -t/--type).
620 620
621 621 .. container:: verbose
622 622
623 623 Examples:
624 624
625 625 - create a zip file containing the 1.0 release::
626 626
627 627 hg archive -r 1.0 project-1.0.zip
628 628
629 629 - create a tarball excluding .hg files::
630 630
631 631 hg archive project.tar.gz -X ".hg*"
632 632
633 633 Valid types are:
634 634
635 635 :``files``: a directory full of files (default)
636 636 :``tar``: tar archive, uncompressed
637 637 :``tbz2``: tar archive, compressed using bzip2
638 638 :``tgz``: tar archive, compressed using gzip
639 639 :``txz``: tar archive, compressed using lzma (only in Python 3)
640 640 :``uzip``: zip archive, uncompressed
641 641 :``zip``: zip archive, compressed using deflate
642 642
643 643 The exact name of the destination archive or directory is given
644 644 using a format string; see :hg:`help export` for details.
645 645
646 646 Each member added to an archive file has a directory prefix
647 647 prepended. Use -p/--prefix to specify a format string for the
648 648 prefix. The default is the basename of the archive, with suffixes
649 649 removed.
650 650
651 651 Returns 0 on success.
652 652 """
653 653
654 654 opts = pycompat.byteskwargs(opts)
655 655 rev = opts.get(b'rev')
656 656 if rev:
657 657 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
658 658 ctx = scmutil.revsingle(repo, rev)
659 659 if not ctx:
660 660 raise error.InputError(
661 661 _(b'no working directory: please specify a revision')
662 662 )
663 663 node = ctx.node()
664 664 dest = cmdutil.makefilename(ctx, dest)
665 665 if os.path.realpath(dest) == repo.root:
666 666 raise error.InputError(_(b'repository root cannot be destination'))
667 667
668 668 kind = opts.get(b'type') or archival.guesskind(dest) or b'files'
669 669 prefix = opts.get(b'prefix')
670 670
671 671 if dest == b'-':
672 672 if kind == b'files':
673 673 raise error.InputError(_(b'cannot archive plain files to stdout'))
674 674 dest = cmdutil.makefileobj(ctx, dest)
675 675 if not prefix:
676 676 prefix = os.path.basename(repo.root) + b'-%h'
677 677
678 678 prefix = cmdutil.makefilename(ctx, prefix)
679 679 match = scmutil.match(ctx, [], opts)
680 680 archival.archive(
681 681 repo,
682 682 dest,
683 683 node,
684 684 kind,
685 685 not opts.get(b'no_decode'),
686 686 match,
687 687 prefix,
688 688 subrepos=opts.get(b'subrepos'),
689 689 )
690 690
691 691
692 692 @command(
693 693 b'backout',
694 694 [
695 695 (
696 696 b'',
697 697 b'merge',
698 698 None,
699 699 _(b'merge with old dirstate parent after backout'),
700 700 ),
701 701 (
702 702 b'',
703 703 b'commit',
704 704 None,
705 705 _(b'commit if no conflicts were encountered (DEPRECATED)'),
706 706 ),
707 707 (b'', b'no-commit', None, _(b'do not commit')),
708 708 (
709 709 b'',
710 710 b'parent',
711 711 b'',
712 712 _(b'parent to choose when backing out merge (DEPRECATED)'),
713 713 _(b'REV'),
714 714 ),
715 715 (b'r', b'rev', b'', _(b'revision to backout'), _(b'REV')),
716 716 (b'e', b'edit', False, _(b'invoke editor on commit messages')),
717 717 ]
718 718 + mergetoolopts
719 719 + walkopts
720 720 + commitopts
721 721 + commitopts2,
722 722 _(b'[OPTION]... [-r] REV'),
723 723 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
724 724 )
725 725 def backout(ui, repo, node=None, rev=None, **opts):
726 726 """reverse effect of earlier changeset
727 727
728 728 Prepare a new changeset with the effect of REV undone in the
729 729 current working directory. If no conflicts were encountered,
730 730 it will be committed immediately.
731 731
732 732 If REV is the parent of the working directory, then this new changeset
733 733 is committed automatically (unless --no-commit is specified).
734 734
735 735 .. note::
736 736
737 737 :hg:`backout` cannot be used to fix either an unwanted or
738 738 incorrect merge.
739 739
740 740 .. container:: verbose
741 741
742 742 Examples:
743 743
744 744 - Reverse the effect of the parent of the working directory.
745 745 This backout will be committed immediately::
746 746
747 747 hg backout -r .
748 748
749 749 - Reverse the effect of previous bad revision 23::
750 750
751 751 hg backout -r 23
752 752
753 753 - Reverse the effect of previous bad revision 23 and
754 754 leave changes uncommitted::
755 755
756 756 hg backout -r 23 --no-commit
757 757 hg commit -m "Backout revision 23"
758 758
759 759 By default, the pending changeset will have one parent,
760 760 maintaining a linear history. With --merge, the pending
761 761 changeset will instead have two parents: the old parent of the
762 762 working directory and a new child of REV that simply undoes REV.
763 763
764 764 Before version 1.7, the behavior without --merge was equivalent
765 765 to specifying --merge followed by :hg:`update --clean .` to
766 766 cancel the merge and leave the child of REV as a head to be
767 767 merged separately.
768 768
769 769 See :hg:`help dates` for a list of formats valid for -d/--date.
770 770
771 771 See :hg:`help revert` for a way to restore files to the state
772 772 of another revision.
773 773
774 774 Returns 0 on success, 1 if nothing to backout or there are unresolved
775 775 files.
776 776 """
777 777 with repo.wlock(), repo.lock():
778 778 return _dobackout(ui, repo, node, rev, **opts)
779 779
780 780
781 781 def _dobackout(ui, repo, node=None, rev=None, **opts):
782 782 cmdutil.check_incompatible_arguments(opts, 'no_commit', ['commit', 'merge'])
783 783 opts = pycompat.byteskwargs(opts)
784 784
785 785 if rev and node:
786 786 raise error.InputError(_(b"please specify just one revision"))
787 787
788 788 if not rev:
789 789 rev = node
790 790
791 791 if not rev:
792 792 raise error.InputError(_(b"please specify a revision to backout"))
793 793
794 794 date = opts.get(b'date')
795 795 if date:
796 796 opts[b'date'] = dateutil.parsedate(date)
797 797
798 798 cmdutil.checkunfinished(repo)
799 799 cmdutil.bailifchanged(repo)
800 800 ctx = scmutil.revsingle(repo, rev)
801 801 node = ctx.node()
802 802
803 803 op1, op2 = repo.dirstate.parents()
804 804 if not repo.changelog.isancestor(node, op1):
805 805 raise error.InputError(
806 806 _(b'cannot backout change that is not an ancestor')
807 807 )
808 808
809 809 p1, p2 = repo.changelog.parents(node)
810 810 if p1 == repo.nullid:
811 811 raise error.InputError(_(b'cannot backout a change with no parents'))
812 812 if p2 != repo.nullid:
813 813 if not opts.get(b'parent'):
814 814 raise error.InputError(_(b'cannot backout a merge changeset'))
815 815 p = repo.lookup(opts[b'parent'])
816 816 if p not in (p1, p2):
817 817 raise error.InputError(
818 818 _(b'%s is not a parent of %s') % (short(p), short(node))
819 819 )
820 820 parent = p
821 821 else:
822 822 if opts.get(b'parent'):
823 823 raise error.InputError(
824 824 _(b'cannot use --parent on non-merge changeset')
825 825 )
826 826 parent = p1
827 827
828 828 # the backout should appear on the same branch
829 829 branch = repo.dirstate.branch()
830 830 bheads = repo.branchheads(branch)
831 831 rctx = scmutil.revsingle(repo, hex(parent))
832 832 if not opts.get(b'merge') and op1 != node:
833 833 with dirstateguard.dirstateguard(repo, b'backout'):
834 834 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
835 835 with ui.configoverride(overrides, b'backout'):
836 836 stats = mergemod.back_out(ctx, parent=repo[parent])
837 837 repo.setparents(op1, op2)
838 838 hg._showstats(repo, stats)
839 839 if stats.unresolvedcount:
840 840 repo.ui.status(
841 841 _(b"use 'hg resolve' to retry unresolved file merges\n")
842 842 )
843 843 return 1
844 844 else:
845 845 hg.clean(repo, node, show_stats=False)
846 846 repo.dirstate.setbranch(branch)
847 847 cmdutil.revert(ui, repo, rctx)
848 848
849 849 if opts.get(b'no_commit'):
850 850 msg = _(b"changeset %s backed out, don't forget to commit.\n")
851 851 ui.status(msg % short(node))
852 852 return 0
853 853
854 854 def commitfunc(ui, repo, message, match, opts):
855 855 editform = b'backout'
856 856 e = cmdutil.getcommiteditor(
857 857 editform=editform, **pycompat.strkwargs(opts)
858 858 )
859 859 if not message:
860 860 # we don't translate commit messages
861 861 message = b"Backed out changeset %s" % short(node)
862 862 e = cmdutil.getcommiteditor(edit=True, editform=editform)
863 863 return repo.commit(
864 864 message, opts.get(b'user'), opts.get(b'date'), match, editor=e
865 865 )
866 866
867 867 # save to detect changes
868 868 tip = repo.changelog.tip()
869 869
870 870 newnode = cmdutil.commit(ui, repo, commitfunc, [], opts)
871 871 if not newnode:
872 872 ui.status(_(b"nothing changed\n"))
873 873 return 1
874 874 cmdutil.commitstatus(repo, newnode, branch, bheads, tip)
875 875
876 876 def nice(node):
877 877 return b'%d:%s' % (repo.changelog.rev(node), short(node))
878 878
879 879 ui.status(
880 880 _(b'changeset %s backs out changeset %s\n')
881 881 % (nice(newnode), nice(node))
882 882 )
883 883 if opts.get(b'merge') and op1 != node:
884 884 hg.clean(repo, op1, show_stats=False)
885 885 ui.status(_(b'merging with changeset %s\n') % nice(newnode))
886 886 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
887 887 with ui.configoverride(overrides, b'backout'):
888 888 return hg.merge(repo[b'tip'])
889 889 return 0
890 890
891 891
892 892 @command(
893 893 b'bisect',
894 894 [
895 895 (b'r', b'reset', False, _(b'reset bisect state')),
896 896 (b'g', b'good', False, _(b'mark changeset good')),
897 897 (b'b', b'bad', False, _(b'mark changeset bad')),
898 898 (b's', b'skip', False, _(b'skip testing changeset')),
899 899 (b'e', b'extend', False, _(b'extend the bisect range')),
900 900 (
901 901 b'c',
902 902 b'command',
903 903 b'',
904 904 _(b'use command to check changeset state'),
905 905 _(b'CMD'),
906 906 ),
907 907 (b'U', b'noupdate', False, _(b'do not update to target')),
908 908 ],
909 909 _(b"[-gbsr] [-U] [-c CMD] [REV]"),
910 910 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
911 911 )
912 912 def bisect(
913 913 ui,
914 914 repo,
915 915 positional_1=None,
916 916 positional_2=None,
917 917 command=None,
918 918 reset=None,
919 919 good=None,
920 920 bad=None,
921 921 skip=None,
922 922 extend=None,
923 923 noupdate=None,
924 924 ):
925 925 """subdivision search of changesets
926 926
927 927 This command helps to find changesets which introduce problems. To
928 928 use, mark the earliest changeset you know exhibits the problem as
929 929 bad, then mark the latest changeset which is free from the problem
930 930 as good. Bisect will update your working directory to a revision
931 931 for testing (unless the -U/--noupdate option is specified). Once
932 932 you have performed tests, mark the working directory as good or
933 933 bad, and bisect will either update to another candidate changeset
934 934 or announce that it has found the bad revision.
935 935
936 936 As a shortcut, you can also use the revision argument to mark a
937 937 revision as good or bad without checking it out first.
938 938
939 939 If you supply a command, it will be used for automatic bisection.
940 940 The environment variable HG_NODE will contain the ID of the
941 941 changeset being tested. The exit status of the command will be
942 942 used to mark revisions as good or bad: status 0 means good, 125
943 943 means to skip the revision, 127 (command not found) will abort the
944 944 bisection, and any other non-zero exit status means the revision
945 945 is bad.
946 946
947 947 .. container:: verbose
948 948
949 949 Some examples:
950 950
951 951 - start a bisection with known bad revision 34, and good revision 12::
952 952
953 953 hg bisect --bad 34
954 954 hg bisect --good 12
955 955
956 956 - advance the current bisection by marking current revision as good or
957 957 bad::
958 958
959 959 hg bisect --good
960 960 hg bisect --bad
961 961
962 962 - mark the current revision, or a known revision, to be skipped (e.g. if
963 963 that revision is not usable because of another issue)::
964 964
965 965 hg bisect --skip
966 966 hg bisect --skip 23
967 967
968 968 - skip all revisions that do not touch directories ``foo`` or ``bar``::
969 969
970 970 hg bisect --skip "!( file('path:foo') & file('path:bar') )"
971 971
972 972 - forget the current bisection::
973 973
974 974 hg bisect --reset
975 975
976 976 - use 'make && make tests' to automatically find the first broken
977 977 revision::
978 978
979 979 hg bisect --reset
980 980 hg bisect --bad 34
981 981 hg bisect --good 12
982 982 hg bisect --command "make && make tests"
983 983
984 984 - see all changesets whose states are already known in the current
985 985 bisection::
986 986
987 987 hg log -r "bisect(pruned)"
988 988
989 989 - see the changeset currently being bisected (especially useful
990 990 if running with -U/--noupdate)::
991 991
992 992 hg log -r "bisect(current)"
993 993
994 994 - see all changesets that took part in the current bisection::
995 995
996 996 hg log -r "bisect(range)"
997 997
998 998 - you can even get a nice graph::
999 999
1000 1000 hg log --graph -r "bisect(range)"
1001 1001
1002 1002 See :hg:`help revisions.bisect` for more about the `bisect()` predicate.
1003 1003
1004 1004 Returns 0 on success.
1005 1005 """
1006 1006 rev = []
1007 1007 # backward compatibility
1008 1008 if positional_1 in (b"good", b"bad", b"reset", b"init"):
1009 1009 ui.warn(_(b"(use of 'hg bisect <cmd>' is deprecated)\n"))
1010 1010 cmd = positional_1
1011 1011 rev.append(positional_2)
1012 1012 if cmd == b"good":
1013 1013 good = True
1014 1014 elif cmd == b"bad":
1015 1015 bad = True
1016 1016 else:
1017 1017 reset = True
1018 1018 elif positional_2:
1019 1019 raise error.InputError(_(b'incompatible arguments'))
1020 1020 elif positional_1 is not None:
1021 1021 rev.append(positional_1)
1022 1022
1023 1023 incompatibles = {
1024 1024 b'--bad': bad,
1025 1025 b'--command': bool(command),
1026 1026 b'--extend': extend,
1027 1027 b'--good': good,
1028 1028 b'--reset': reset,
1029 1029 b'--skip': skip,
1030 1030 }
1031 1031
1032 1032 enabled = [x for x in incompatibles if incompatibles[x]]
1033 1033
1034 1034 if len(enabled) > 1:
1035 1035 raise error.InputError(
1036 1036 _(b'%s and %s are incompatible') % tuple(sorted(enabled)[0:2])
1037 1037 )
1038 1038
1039 1039 if reset:
1040 1040 hbisect.resetstate(repo)
1041 1041 return
1042 1042
1043 1043 state = hbisect.load_state(repo)
1044 1044
1045 1045 if rev:
1046 1046 nodes = [repo[i].node() for i in scmutil.revrange(repo, rev)]
1047 1047 else:
1048 1048 nodes = [repo.lookup(b'.')]
1049 1049
1050 1050 # update state
1051 1051 if good or bad or skip:
1052 1052 if good:
1053 1053 state[b'good'] += nodes
1054 1054 elif bad:
1055 1055 state[b'bad'] += nodes
1056 1056 elif skip:
1057 1057 state[b'skip'] += nodes
1058 1058 hbisect.save_state(repo, state)
1059 1059 if not (state[b'good'] and state[b'bad']):
1060 1060 return
1061 1061
1062 1062 def mayupdate(repo, node, show_stats=True):
1063 1063 """common used update sequence"""
1064 1064 if noupdate:
1065 1065 return
1066 1066 cmdutil.checkunfinished(repo)
1067 1067 cmdutil.bailifchanged(repo)
1068 1068 return hg.clean(repo, node, show_stats=show_stats)
1069 1069
1070 1070 displayer = logcmdutil.changesetdisplayer(ui, repo, {})
1071 1071
1072 1072 if command:
1073 1073 changesets = 1
1074 1074 if noupdate:
1075 1075 try:
1076 1076 node = state[b'current'][0]
1077 1077 except LookupError:
1078 1078 raise error.StateError(
1079 1079 _(
1080 1080 b'current bisect revision is unknown - '
1081 1081 b'start a new bisect to fix'
1082 1082 )
1083 1083 )
1084 1084 else:
1085 1085 node, p2 = repo.dirstate.parents()
1086 1086 if p2 != repo.nullid:
1087 1087 raise error.StateError(_(b'current bisect revision is a merge'))
1088 1088 if rev:
1089 1089 if not nodes:
1090 1090 raise error.Abort(_(b'empty revision set'))
1091 1091 node = repo[nodes[-1]].node()
1092 1092 with hbisect.restore_state(repo, state, node):
1093 1093 while changesets:
1094 1094 # update state
1095 1095 state[b'current'] = [node]
1096 1096 hbisect.save_state(repo, state)
1097 1097 status = ui.system(
1098 1098 command,
1099 1099 environ={b'HG_NODE': hex(node)},
1100 1100 blockedtag=b'bisect_check',
1101 1101 )
1102 1102 if status == 125:
1103 1103 transition = b"skip"
1104 1104 elif status == 0:
1105 1105 transition = b"good"
1106 1106 # status < 0 means process was killed
1107 1107 elif status == 127:
1108 1108 raise error.Abort(_(b"failed to execute %s") % command)
1109 1109 elif status < 0:
1110 1110 raise error.Abort(_(b"%s killed") % command)
1111 1111 else:
1112 1112 transition = b"bad"
1113 1113 state[transition].append(node)
1114 1114 ctx = repo[node]
1115 1115 summary = cmdutil.format_changeset_summary(ui, ctx, b'bisect')
1116 1116 ui.status(_(b'changeset %s: %s\n') % (summary, transition))
1117 1117 hbisect.checkstate(state)
1118 1118 # bisect
1119 1119 nodes, changesets, bgood = hbisect.bisect(repo, state)
1120 1120 # update to next check
1121 1121 node = nodes[0]
1122 1122 mayupdate(repo, node, show_stats=False)
1123 1123 hbisect.printresult(ui, repo, state, displayer, nodes, bgood)
1124 1124 return
1125 1125
1126 1126 hbisect.checkstate(state)
1127 1127
1128 1128 # actually bisect
1129 1129 nodes, changesets, good = hbisect.bisect(repo, state)
1130 1130 if extend:
1131 1131 if not changesets:
1132 1132 extendctx = hbisect.extendrange(repo, state, nodes, good)
1133 1133 if extendctx is not None:
1134 1134 ui.write(
1135 1135 _(b"Extending search to changeset %s\n")
1136 1136 % cmdutil.format_changeset_summary(ui, extendctx, b'bisect')
1137 1137 )
1138 1138 state[b'current'] = [extendctx.node()]
1139 1139 hbisect.save_state(repo, state)
1140 1140 return mayupdate(repo, extendctx.node())
1141 1141 raise error.StateError(_(b"nothing to extend"))
1142 1142
1143 1143 if changesets == 0:
1144 1144 hbisect.printresult(ui, repo, state, displayer, nodes, good)
1145 1145 else:
1146 1146 assert len(nodes) == 1 # only a single node can be tested next
1147 1147 node = nodes[0]
1148 1148 # compute the approximate number of remaining tests
1149 1149 tests, size = 0, 2
1150 1150 while size <= changesets:
1151 1151 tests, size = tests + 1, size * 2
1152 1152 rev = repo.changelog.rev(node)
1153 1153 summary = cmdutil.format_changeset_summary(ui, repo[rev], b'bisect')
1154 1154 ui.write(
1155 1155 _(
1156 1156 b"Testing changeset %s "
1157 1157 b"(%d changesets remaining, ~%d tests)\n"
1158 1158 )
1159 1159 % (summary, changesets, tests)
1160 1160 )
1161 1161 state[b'current'] = [node]
1162 1162 hbisect.save_state(repo, state)
1163 1163 return mayupdate(repo, node)
1164 1164
1165 1165
1166 1166 @command(
1167 1167 b'bookmarks|bookmark',
1168 1168 [
1169 1169 (b'f', b'force', False, _(b'force')),
1170 1170 (b'r', b'rev', b'', _(b'revision for bookmark action'), _(b'REV')),
1171 1171 (b'd', b'delete', False, _(b'delete a given bookmark')),
1172 1172 (b'm', b'rename', b'', _(b'rename a given bookmark'), _(b'OLD')),
1173 1173 (b'i', b'inactive', False, _(b'mark a bookmark inactive')),
1174 1174 (b'l', b'list', False, _(b'list existing bookmarks')),
1175 1175 ]
1176 1176 + formatteropts,
1177 1177 _(b'hg bookmarks [OPTIONS]... [NAME]...'),
1178 1178 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
1179 1179 )
1180 1180 def bookmark(ui, repo, *names, **opts):
1181 1181 """create a new bookmark or list existing bookmarks
1182 1182
1183 1183 Bookmarks are labels on changesets to help track lines of development.
1184 1184 Bookmarks are unversioned and can be moved, renamed and deleted.
1185 1185 Deleting or moving a bookmark has no effect on the associated changesets.
1186 1186
1187 1187 Creating or updating to a bookmark causes it to be marked as 'active'.
1188 1188 The active bookmark is indicated with a '*'.
1189 1189 When a commit is made, the active bookmark will advance to the new commit.
1190 1190 A plain :hg:`update` will also advance an active bookmark, if possible.
1191 1191 Updating away from a bookmark will cause it to be deactivated.
1192 1192
1193 1193 Bookmarks can be pushed and pulled between repositories (see
1194 1194 :hg:`help push` and :hg:`help pull`). If a shared bookmark has
1195 1195 diverged, a new 'divergent bookmark' of the form 'name@path' will
1196 1196 be created. Using :hg:`merge` will resolve the divergence.
1197 1197
1198 1198 Specifying bookmark as '.' to -m/-d/-l options is equivalent to specifying
1199 1199 the active bookmark's name.
1200 1200
1201 1201 A bookmark named '@' has the special property that :hg:`clone` will
1202 1202 check it out by default if it exists.
1203 1203
1204 1204 .. container:: verbose
1205 1205
1206 1206 Template:
1207 1207
1208 1208 The following keywords are supported in addition to the common template
1209 1209 keywords and functions such as ``{bookmark}``. See also
1210 1210 :hg:`help templates`.
1211 1211
1212 1212 :active: Boolean. True if the bookmark is active.
1213 1213
1214 1214 Examples:
1215 1215
1216 1216 - create an active bookmark for a new line of development::
1217 1217
1218 1218 hg book new-feature
1219 1219
1220 1220 - create an inactive bookmark as a place marker::
1221 1221
1222 1222 hg book -i reviewed
1223 1223
1224 1224 - create an inactive bookmark on another changeset::
1225 1225
1226 1226 hg book -r .^ tested
1227 1227
1228 1228 - rename bookmark turkey to dinner::
1229 1229
1230 1230 hg book -m turkey dinner
1231 1231
1232 1232 - move the '@' bookmark from another branch::
1233 1233
1234 1234 hg book -f @
1235 1235
1236 1236 - print only the active bookmark name::
1237 1237
1238 1238 hg book -ql .
1239 1239 """
1240 1240 opts = pycompat.byteskwargs(opts)
1241 1241 force = opts.get(b'force')
1242 1242 rev = opts.get(b'rev')
1243 1243 inactive = opts.get(b'inactive') # meaning add/rename to inactive bookmark
1244 1244
1245 1245 action = cmdutil.check_at_most_one_arg(opts, b'delete', b'rename', b'list')
1246 1246 if action:
1247 1247 cmdutil.check_incompatible_arguments(opts, action, [b'rev'])
1248 1248 elif names or rev:
1249 1249 action = b'add'
1250 1250 elif inactive:
1251 1251 action = b'inactive' # meaning deactivate
1252 1252 else:
1253 1253 action = b'list'
1254 1254
1255 1255 cmdutil.check_incompatible_arguments(
1256 1256 opts, b'inactive', [b'delete', b'list']
1257 1257 )
1258 1258 if not names and action in {b'add', b'delete'}:
1259 1259 raise error.InputError(_(b"bookmark name required"))
1260 1260
1261 1261 if action in {b'add', b'delete', b'rename', b'inactive'}:
1262 1262 with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
1263 1263 if action == b'delete':
1264 1264 names = pycompat.maplist(repo._bookmarks.expandname, names)
1265 1265 bookmarks.delete(repo, tr, names)
1266 1266 elif action == b'rename':
1267 1267 if not names:
1268 1268 raise error.InputError(_(b"new bookmark name required"))
1269 1269 elif len(names) > 1:
1270 1270 raise error.InputError(
1271 1271 _(b"only one new bookmark name allowed")
1272 1272 )
1273 1273 oldname = repo._bookmarks.expandname(opts[b'rename'])
1274 1274 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
1275 1275 elif action == b'add':
1276 1276 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
1277 1277 elif action == b'inactive':
1278 1278 if len(repo._bookmarks) == 0:
1279 1279 ui.status(_(b"no bookmarks set\n"))
1280 1280 elif not repo._activebookmark:
1281 1281 ui.status(_(b"no active bookmark\n"))
1282 1282 else:
1283 1283 bookmarks.deactivate(repo)
1284 1284 elif action == b'list':
1285 1285 names = pycompat.maplist(repo._bookmarks.expandname, names)
1286 1286 with ui.formatter(b'bookmarks', opts) as fm:
1287 1287 bookmarks.printbookmarks(ui, repo, fm, names)
1288 1288 else:
1289 1289 raise error.ProgrammingError(b'invalid action: %s' % action)
1290 1290
1291 1291
1292 1292 @command(
1293 1293 b'branch',
1294 1294 [
1295 1295 (
1296 1296 b'f',
1297 1297 b'force',
1298 1298 None,
1299 1299 _(b'set branch name even if it shadows an existing branch'),
1300 1300 ),
1301 1301 (b'C', b'clean', None, _(b'reset branch name to parent branch name')),
1302 1302 (
1303 1303 b'r',
1304 1304 b'rev',
1305 1305 [],
1306 1306 _(b'change branches of the given revs (EXPERIMENTAL)'),
1307 1307 ),
1308 1308 ],
1309 1309 _(b'[-fC] [NAME]'),
1310 1310 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
1311 1311 )
1312 1312 def branch(ui, repo, label=None, **opts):
1313 1313 """set or show the current branch name
1314 1314
1315 1315 .. note::
1316 1316
1317 1317 Branch names are permanent and global. Use :hg:`bookmark` to create a
1318 1318 light-weight bookmark instead. See :hg:`help glossary` for more
1319 1319 information about named branches and bookmarks.
1320 1320
1321 1321 With no argument, show the current branch name. With one argument,
1322 1322 set the working directory branch name (the branch will not exist
1323 1323 in the repository until the next commit). Standard practice
1324 1324 recommends that primary development take place on the 'default'
1325 1325 branch.
1326 1326
1327 1327 Unless -f/--force is specified, branch will not let you set a
1328 1328 branch name that already exists.
1329 1329
1330 1330 Use -C/--clean to reset the working directory branch to that of
1331 1331 the parent of the working directory, negating a previous branch
1332 1332 change.
1333 1333
1334 1334 Use the command :hg:`update` to switch to an existing branch. Use
1335 1335 :hg:`commit --close-branch` to mark this branch head as closed.
1336 1336 When all heads of a branch are closed, the branch will be
1337 1337 considered closed.
1338 1338
1339 1339 Returns 0 on success.
1340 1340 """
1341 1341 opts = pycompat.byteskwargs(opts)
1342 1342 revs = opts.get(b'rev')
1343 1343 if label:
1344 1344 label = label.strip()
1345 1345
1346 1346 if not opts.get(b'clean') and not label:
1347 1347 if revs:
1348 1348 raise error.InputError(
1349 1349 _(b"no branch name specified for the revisions")
1350 1350 )
1351 1351 ui.write(b"%s\n" % repo.dirstate.branch())
1352 1352 return
1353 1353
1354 1354 with repo.wlock():
1355 1355 if opts.get(b'clean'):
1356 1356 label = repo[b'.'].branch()
1357 1357 repo.dirstate.setbranch(label)
1358 1358 ui.status(_(b'reset working directory to branch %s\n') % label)
1359 1359 elif label:
1360 1360
1361 1361 scmutil.checknewlabel(repo, label, b'branch')
1362 1362 if revs:
1363 1363 return cmdutil.changebranch(ui, repo, revs, label, opts)
1364 1364
1365 1365 if not opts.get(b'force') and label in repo.branchmap():
1366 1366 if label not in [p.branch() for p in repo[None].parents()]:
1367 1367 raise error.InputError(
1368 1368 _(b'a branch of the same name already exists'),
1369 1369 # i18n: "it" refers to an existing branch
1370 1370 hint=_(b"use 'hg update' to switch to it"),
1371 1371 )
1372 1372
1373 1373 repo.dirstate.setbranch(label)
1374 1374 ui.status(_(b'marked working directory as branch %s\n') % label)
1375 1375
1376 1376 # find any open named branches aside from default
1377 1377 for n, h, t, c in repo.branchmap().iterbranches():
1378 1378 if n != b"default" and not c:
1379 1379 return 0
1380 1380 ui.status(
1381 1381 _(
1382 1382 b'(branches are permanent and global, '
1383 1383 b'did you want a bookmark?)\n'
1384 1384 )
1385 1385 )
1386 1386
1387 1387
1388 1388 @command(
1389 1389 b'branches',
1390 1390 [
1391 1391 (
1392 1392 b'a',
1393 1393 b'active',
1394 1394 False,
1395 1395 _(b'show only branches that have unmerged heads (DEPRECATED)'),
1396 1396 ),
1397 1397 (b'c', b'closed', False, _(b'show normal and closed branches')),
1398 1398 (b'r', b'rev', [], _(b'show branch name(s) of the given rev')),
1399 1399 ]
1400 1400 + formatteropts,
1401 1401 _(b'[-c]'),
1402 1402 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
1403 1403 intents={INTENT_READONLY},
1404 1404 )
1405 1405 def branches(ui, repo, active=False, closed=False, **opts):
1406 1406 """list repository named branches
1407 1407
1408 1408 List the repository's named branches, indicating which ones are
1409 1409 inactive. If -c/--closed is specified, also list branches which have
1410 1410 been marked closed (see :hg:`commit --close-branch`).
1411 1411
1412 1412 Use the command :hg:`update` to switch to an existing branch.
1413 1413
1414 1414 .. container:: verbose
1415 1415
1416 1416 Template:
1417 1417
1418 1418 The following keywords are supported in addition to the common template
1419 1419 keywords and functions such as ``{branch}``. See also
1420 1420 :hg:`help templates`.
1421 1421
1422 1422 :active: Boolean. True if the branch is active.
1423 1423 :closed: Boolean. True if the branch is closed.
1424 1424 :current: Boolean. True if it is the current branch.
1425 1425
1426 1426 Returns 0.
1427 1427 """
1428 1428
1429 1429 opts = pycompat.byteskwargs(opts)
1430 1430 revs = opts.get(b'rev')
1431 1431 selectedbranches = None
1432 1432 if revs:
1433 1433 revs = scmutil.revrange(repo, revs)
1434 1434 getbi = repo.revbranchcache().branchinfo
1435 1435 selectedbranches = {getbi(r)[0] for r in revs}
1436 1436
1437 1437 ui.pager(b'branches')
1438 1438 fm = ui.formatter(b'branches', opts)
1439 1439 hexfunc = fm.hexfunc
1440 1440
1441 1441 allheads = set(repo.heads())
1442 1442 branches = []
1443 1443 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1444 1444 if selectedbranches is not None and tag not in selectedbranches:
1445 1445 continue
1446 1446 isactive = False
1447 1447 if not isclosed:
1448 1448 openheads = set(repo.branchmap().iteropen(heads))
1449 1449 isactive = bool(openheads & allheads)
1450 1450 branches.append((tag, repo[tip], isactive, not isclosed))
1451 1451 branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), reverse=True)
1452 1452
1453 1453 for tag, ctx, isactive, isopen in branches:
1454 1454 if active and not isactive:
1455 1455 continue
1456 1456 if isactive:
1457 1457 label = b'branches.active'
1458 1458 notice = b''
1459 1459 elif not isopen:
1460 1460 if not closed:
1461 1461 continue
1462 1462 label = b'branches.closed'
1463 1463 notice = _(b' (closed)')
1464 1464 else:
1465 1465 label = b'branches.inactive'
1466 1466 notice = _(b' (inactive)')
1467 1467 current = tag == repo.dirstate.branch()
1468 1468 if current:
1469 1469 label = b'branches.current'
1470 1470
1471 1471 fm.startitem()
1472 1472 fm.write(b'branch', b'%s', tag, label=label)
1473 1473 rev = ctx.rev()
1474 1474 padsize = max(31 - len(b"%d" % rev) - encoding.colwidth(tag), 0)
1475 1475 fmt = b' ' * padsize + b' %d:%s'
1476 1476 fm.condwrite(
1477 1477 not ui.quiet,
1478 1478 b'rev node',
1479 1479 fmt,
1480 1480 rev,
1481 1481 hexfunc(ctx.node()),
1482 1482 label=b'log.changeset changeset.%s' % ctx.phasestr(),
1483 1483 )
1484 1484 fm.context(ctx=ctx)
1485 1485 fm.data(active=isactive, closed=not isopen, current=current)
1486 1486 if not ui.quiet:
1487 1487 fm.plain(notice)
1488 1488 fm.plain(b'\n')
1489 1489 fm.end()
1490 1490
1491 1491
1492 1492 @command(
1493 1493 b'bundle',
1494 1494 [
1495 1495 (
1496 1496 b'f',
1497 1497 b'force',
1498 1498 None,
1499 1499 _(b'run even when the destination is unrelated'),
1500 1500 ),
1501 1501 (
1502 1502 b'r',
1503 1503 b'rev',
1504 1504 [],
1505 1505 _(b'a changeset intended to be added to the destination'),
1506 1506 _(b'REV'),
1507 1507 ),
1508 1508 (
1509 1509 b'b',
1510 1510 b'branch',
1511 1511 [],
1512 1512 _(b'a specific branch you would like to bundle'),
1513 1513 _(b'BRANCH'),
1514 1514 ),
1515 1515 (
1516 1516 b'',
1517 1517 b'base',
1518 1518 [],
1519 1519 _(b'a base changeset assumed to be available at the destination'),
1520 1520 _(b'REV'),
1521 1521 ),
1522 1522 (b'a', b'all', None, _(b'bundle all changesets in the repository')),
1523 1523 (
1524 1524 b't',
1525 1525 b'type',
1526 1526 b'bzip2',
1527 1527 _(b'bundle compression type to use'),
1528 1528 _(b'TYPE'),
1529 1529 ),
1530 1530 ]
1531 1531 + remoteopts,
1532 1532 _(b'[-f] [-t BUNDLESPEC] [-a] [-r REV]... [--base REV]... FILE [DEST]...'),
1533 1533 helpcategory=command.CATEGORY_IMPORT_EXPORT,
1534 1534 )
1535 1535 def bundle(ui, repo, fname, *dests, **opts):
1536 1536 """create a bundle file
1537 1537
1538 1538 Generate a bundle file containing data to be transferred to another
1539 1539 repository.
1540 1540
1541 1541 To create a bundle containing all changesets, use -a/--all
1542 1542 (or --base null). Otherwise, hg assumes the destination will have
1543 1543 all the nodes you specify with --base parameters. Otherwise, hg
1544 1544 will assume the repository has all the nodes in destination, or
1545 1545 default-push/default if no destination is specified, where destination
1546 1546 is the repositories you provide through DEST option.
1547 1547
1548 1548 You can change bundle format with the -t/--type option. See
1549 1549 :hg:`help bundlespec` for documentation on this format. By default,
1550 1550 the most appropriate format is used and compression defaults to
1551 1551 bzip2.
1552 1552
1553 1553 The bundle file can then be transferred using conventional means
1554 1554 and applied to another repository with the unbundle or pull
1555 1555 command. This is useful when direct push and pull are not
1556 1556 available or when exporting an entire repository is undesirable.
1557 1557
1558 1558 Applying bundles preserves all changeset contents including
1559 1559 permissions, copy/rename information, and revision history.
1560 1560
1561 1561 Returns 0 on success, 1 if no changes found.
1562 1562 """
1563 1563 opts = pycompat.byteskwargs(opts)
1564 1564 revs = None
1565 1565 if b'rev' in opts:
1566 1566 revstrings = opts[b'rev']
1567 1567 revs = scmutil.revrange(repo, revstrings)
1568 1568 if revstrings and not revs:
1569 1569 raise error.InputError(_(b'no commits to bundle'))
1570 1570
1571 1571 bundletype = opts.get(b'type', b'bzip2').lower()
1572 1572 try:
1573 1573 bundlespec = bundlecaches.parsebundlespec(
1574 1574 repo, bundletype, strict=False
1575 1575 )
1576 1576 except error.UnsupportedBundleSpecification as e:
1577 1577 raise error.InputError(
1578 1578 pycompat.bytestr(e),
1579 1579 hint=_(b"see 'hg help bundlespec' for supported values for --type"),
1580 1580 )
1581 1581 cgversion = bundlespec.contentopts[b"cg.version"]
1582 1582
1583 1583 # Packed bundles are a pseudo bundle format for now.
1584 1584 if cgversion == b's1':
1585 1585 raise error.InputError(
1586 1586 _(b'packed bundles cannot be produced by "hg bundle"'),
1587 1587 hint=_(b"use 'hg debugcreatestreamclonebundle'"),
1588 1588 )
1589 1589
1590 1590 if opts.get(b'all'):
1591 1591 if dests:
1592 1592 raise error.InputError(
1593 1593 _(b"--all is incompatible with specifying destinations")
1594 1594 )
1595 1595 if opts.get(b'base'):
1596 1596 ui.warn(_(b"ignoring --base because --all was specified\n"))
1597 1597 base = [nullrev]
1598 1598 else:
1599 1599 base = scmutil.revrange(repo, opts.get(b'base'))
1600 1600 if cgversion not in changegroup.supportedoutgoingversions(repo):
1601 1601 raise error.Abort(
1602 1602 _(b"repository does not support bundle version %s") % cgversion
1603 1603 )
1604 1604
1605 1605 if base:
1606 1606 if dests:
1607 1607 raise error.InputError(
1608 1608 _(b"--base is incompatible with specifying destinations")
1609 1609 )
1610 1610 common = [repo[rev].node() for rev in base]
1611 1611 heads = [repo[r].node() for r in revs] if revs else None
1612 1612 outgoing = discovery.outgoing(repo, common, heads)
1613 1613 missing = outgoing.missing
1614 1614 excluded = outgoing.excluded
1615 1615 else:
1616 1616 missing = set()
1617 1617 excluded = set()
1618 1618 for path in urlutil.get_push_paths(repo, ui, dests):
1619 1619 other = hg.peer(repo, opts, path.rawloc)
1620 1620 if revs is not None:
1621 1621 hex_revs = [repo[r].hex() for r in revs]
1622 1622 else:
1623 1623 hex_revs = None
1624 1624 branches = (path.branch, [])
1625 1625 head_revs, checkout = hg.addbranchrevs(
1626 1626 repo, repo, branches, hex_revs
1627 1627 )
1628 1628 heads = (
1629 1629 head_revs
1630 1630 and pycompat.maplist(repo.lookup, head_revs)
1631 1631 or head_revs
1632 1632 )
1633 1633 outgoing = discovery.findcommonoutgoing(
1634 1634 repo,
1635 1635 other,
1636 1636 onlyheads=heads,
1637 1637 force=opts.get(b'force'),
1638 1638 portable=True,
1639 1639 )
1640 1640 missing.update(outgoing.missing)
1641 1641 excluded.update(outgoing.excluded)
1642 1642
1643 1643 if not missing:
1644 1644 scmutil.nochangesfound(ui, repo, not base and excluded)
1645 1645 return 1
1646 1646
1647 1647 if heads:
1648 1648 outgoing = discovery.outgoing(
1649 1649 repo, missingroots=missing, ancestorsof=heads
1650 1650 )
1651 1651 else:
1652 1652 outgoing = discovery.outgoing(repo, missingroots=missing)
1653 1653 outgoing.excluded = sorted(excluded)
1654 1654
1655 1655 if cgversion == b'01': # bundle1
1656 1656 bversion = b'HG10' + bundlespec.wirecompression
1657 1657 bcompression = None
1658 1658 elif cgversion in (b'02', b'03'):
1659 1659 bversion = b'HG20'
1660 1660 bcompression = bundlespec.wirecompression
1661 1661 else:
1662 1662 raise error.ProgrammingError(
1663 1663 b'bundle: unexpected changegroup version %s' % cgversion
1664 1664 )
1665 1665
1666 1666 # TODO compression options should be derived from bundlespec parsing.
1667 1667 # This is a temporary hack to allow adjusting bundle compression
1668 1668 # level without a) formalizing the bundlespec changes to declare it
1669 1669 # b) introducing a command flag.
1670 1670 compopts = {}
1671 1671 complevel = ui.configint(
1672 1672 b'experimental', b'bundlecomplevel.' + bundlespec.compression
1673 1673 )
1674 1674 if complevel is None:
1675 1675 complevel = ui.configint(b'experimental', b'bundlecomplevel')
1676 1676 if complevel is not None:
1677 1677 compopts[b'level'] = complevel
1678 1678
1679 1679 compthreads = ui.configint(
1680 1680 b'experimental', b'bundlecompthreads.' + bundlespec.compression
1681 1681 )
1682 1682 if compthreads is None:
1683 1683 compthreads = ui.configint(b'experimental', b'bundlecompthreads')
1684 1684 if compthreads is not None:
1685 1685 compopts[b'threads'] = compthreads
1686 1686
1687 1687 # Bundling of obsmarker and phases is optional as not all clients
1688 1688 # support the necessary features.
1689 1689 cfg = ui.configbool
1690 1690 contentopts = {
1691 1691 b'obsolescence': cfg(b'experimental', b'evolution.bundle-obsmarker'),
1692 1692 b'obsolescence-mandatory': cfg(
1693 1693 b'experimental', b'evolution.bundle-obsmarker:mandatory'
1694 1694 ),
1695 1695 b'phases': cfg(b'experimental', b'bundle-phases'),
1696 1696 }
1697 1697 bundlespec.contentopts.update(contentopts)
1698 1698
1699 1699 bundle2.writenewbundle(
1700 1700 ui,
1701 1701 repo,
1702 1702 b'bundle',
1703 1703 fname,
1704 1704 bversion,
1705 1705 outgoing,
1706 1706 bundlespec.contentopts,
1707 1707 compression=bcompression,
1708 1708 compopts=compopts,
1709 1709 )
1710 1710
1711 1711
1712 1712 @command(
1713 1713 b'cat',
1714 1714 [
1715 1715 (
1716 1716 b'o',
1717 1717 b'output',
1718 1718 b'',
1719 1719 _(b'print output to file with formatted name'),
1720 1720 _(b'FORMAT'),
1721 1721 ),
1722 1722 (b'r', b'rev', b'', _(b'print the given revision'), _(b'REV')),
1723 1723 (b'', b'decode', None, _(b'apply any matching decode filter')),
1724 1724 ]
1725 1725 + walkopts
1726 1726 + formatteropts,
1727 1727 _(b'[OPTION]... FILE...'),
1728 1728 helpcategory=command.CATEGORY_FILE_CONTENTS,
1729 1729 inferrepo=True,
1730 1730 intents={INTENT_READONLY},
1731 1731 )
1732 1732 def cat(ui, repo, file1, *pats, **opts):
1733 1733 """output the current or given revision of files
1734 1734
1735 1735 Print the specified files as they were at the given revision. If
1736 1736 no revision is given, the parent of the working directory is used.
1737 1737
1738 1738 Output may be to a file, in which case the name of the file is
1739 1739 given using a template string. See :hg:`help templates`. In addition
1740 1740 to the common template keywords, the following formatting rules are
1741 1741 supported:
1742 1742
1743 1743 :``%%``: literal "%" character
1744 1744 :``%s``: basename of file being printed
1745 1745 :``%d``: dirname of file being printed, or '.' if in repository root
1746 1746 :``%p``: root-relative path name of file being printed
1747 1747 :``%H``: changeset hash (40 hexadecimal digits)
1748 1748 :``%R``: changeset revision number
1749 1749 :``%h``: short-form changeset hash (12 hexadecimal digits)
1750 1750 :``%r``: zero-padded changeset revision number
1751 1751 :``%b``: basename of the exporting repository
1752 1752 :``\\``: literal "\\" character
1753 1753
1754 1754 .. container:: verbose
1755 1755
1756 1756 Template:
1757 1757
1758 1758 The following keywords are supported in addition to the common template
1759 1759 keywords and functions. See also :hg:`help templates`.
1760 1760
1761 1761 :data: String. File content.
1762 1762 :path: String. Repository-absolute path of the file.
1763 1763
1764 1764 Returns 0 on success.
1765 1765 """
1766 1766 opts = pycompat.byteskwargs(opts)
1767 1767 rev = opts.get(b'rev')
1768 1768 if rev:
1769 1769 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
1770 1770 ctx = scmutil.revsingle(repo, rev)
1771 1771 m = scmutil.match(ctx, (file1,) + pats, opts)
1772 1772 fntemplate = opts.pop(b'output', b'')
1773 1773 if cmdutil.isstdiofilename(fntemplate):
1774 1774 fntemplate = b''
1775 1775
1776 1776 if fntemplate:
1777 1777 fm = formatter.nullformatter(ui, b'cat', opts)
1778 1778 else:
1779 1779 ui.pager(b'cat')
1780 1780 fm = ui.formatter(b'cat', opts)
1781 1781 with fm:
1782 1782 return cmdutil.cat(
1783 1783 ui, repo, ctx, m, fm, fntemplate, b'', **pycompat.strkwargs(opts)
1784 1784 )
1785 1785
1786 1786
1787 1787 @command(
1788 1788 b'clone',
1789 1789 [
1790 1790 (
1791 1791 b'U',
1792 1792 b'noupdate',
1793 1793 None,
1794 1794 _(
1795 1795 b'the clone will include an empty working '
1796 1796 b'directory (only a repository)'
1797 1797 ),
1798 1798 ),
1799 1799 (
1800 1800 b'u',
1801 1801 b'updaterev',
1802 1802 b'',
1803 1803 _(b'revision, tag, or branch to check out'),
1804 1804 _(b'REV'),
1805 1805 ),
1806 1806 (
1807 1807 b'r',
1808 1808 b'rev',
1809 1809 [],
1810 1810 _(
1811 1811 b'do not clone everything, but include this changeset'
1812 1812 b' and its ancestors'
1813 1813 ),
1814 1814 _(b'REV'),
1815 1815 ),
1816 1816 (
1817 1817 b'b',
1818 1818 b'branch',
1819 1819 [],
1820 1820 _(
1821 1821 b'do not clone everything, but include this branch\'s'
1822 1822 b' changesets and their ancestors'
1823 1823 ),
1824 1824 _(b'BRANCH'),
1825 1825 ),
1826 1826 (b'', b'pull', None, _(b'use pull protocol to copy metadata')),
1827 1827 (b'', b'uncompressed', None, _(b'an alias to --stream (DEPRECATED)')),
1828 1828 (b'', b'stream', None, _(b'clone with minimal data processing')),
1829 1829 ]
1830 1830 + remoteopts,
1831 1831 _(b'[OPTION]... SOURCE [DEST]'),
1832 1832 helpcategory=command.CATEGORY_REPO_CREATION,
1833 1833 helpbasic=True,
1834 1834 norepo=True,
1835 1835 )
1836 1836 def clone(ui, source, dest=None, **opts):
1837 1837 """make a copy of an existing repository
1838 1838
1839 1839 Create a copy of an existing repository in a new directory.
1840 1840
1841 1841 If no destination directory name is specified, it defaults to the
1842 1842 basename of the source.
1843 1843
1844 1844 The location of the source is added to the new repository's
1845 1845 ``.hg/hgrc`` file, as the default to be used for future pulls.
1846 1846
1847 1847 Only local paths and ``ssh://`` URLs are supported as
1848 1848 destinations. For ``ssh://`` destinations, no working directory or
1849 1849 ``.hg/hgrc`` will be created on the remote side.
1850 1850
1851 1851 If the source repository has a bookmark called '@' set, that
1852 1852 revision will be checked out in the new repository by default.
1853 1853
1854 1854 To check out a particular version, use -u/--update, or
1855 1855 -U/--noupdate to create a clone with no working directory.
1856 1856
1857 1857 To pull only a subset of changesets, specify one or more revisions
1858 1858 identifiers with -r/--rev or branches with -b/--branch. The
1859 1859 resulting clone will contain only the specified changesets and
1860 1860 their ancestors. These options (or 'clone src#rev dest') imply
1861 1861 --pull, even for local source repositories.
1862 1862
1863 1863 In normal clone mode, the remote normalizes repository data into a common
1864 1864 exchange format and the receiving end translates this data into its local
1865 1865 storage format. --stream activates a different clone mode that essentially
1866 1866 copies repository files from the remote with minimal data processing. This
1867 1867 significantly reduces the CPU cost of a clone both remotely and locally.
1868 1868 However, it often increases the transferred data size by 30-40%. This can
1869 1869 result in substantially faster clones where I/O throughput is plentiful,
1870 1870 especially for larger repositories. A side-effect of --stream clones is
1871 1871 that storage settings and requirements on the remote are applied locally:
1872 1872 a modern client may inherit legacy or inefficient storage used by the
1873 1873 remote or a legacy Mercurial client may not be able to clone from a
1874 1874 modern Mercurial remote.
1875 1875
1876 1876 .. note::
1877 1877
1878 1878 Specifying a tag will include the tagged changeset but not the
1879 1879 changeset containing the tag.
1880 1880
1881 1881 .. container:: verbose
1882 1882
1883 1883 For efficiency, hardlinks are used for cloning whenever the
1884 1884 source and destination are on the same filesystem (note this
1885 1885 applies only to the repository data, not to the working
1886 1886 directory). Some filesystems, such as AFS, implement hardlinking
1887 1887 incorrectly, but do not report errors. In these cases, use the
1888 1888 --pull option to avoid hardlinking.
1889 1889
1890 1890 Mercurial will update the working directory to the first applicable
1891 1891 revision from this list:
1892 1892
1893 1893 a) null if -U or the source repository has no changesets
1894 1894 b) if -u . and the source repository is local, the first parent of
1895 1895 the source repository's working directory
1896 1896 c) the changeset specified with -u (if a branch name, this means the
1897 1897 latest head of that branch)
1898 1898 d) the changeset specified with -r
1899 1899 e) the tipmost head specified with -b
1900 1900 f) the tipmost head specified with the url#branch source syntax
1901 1901 g) the revision marked with the '@' bookmark, if present
1902 1902 h) the tipmost head of the default branch
1903 1903 i) tip
1904 1904
1905 1905 When cloning from servers that support it, Mercurial may fetch
1906 1906 pre-generated data from a server-advertised URL or inline from the
1907 1907 same stream. When this is done, hooks operating on incoming changesets
1908 1908 and changegroups may fire more than once, once for each pre-generated
1909 1909 bundle and as well as for any additional remaining data. In addition,
1910 1910 if an error occurs, the repository may be rolled back to a partial
1911 1911 clone. This behavior may change in future releases.
1912 1912 See :hg:`help -e clonebundles` for more.
1913 1913
1914 1914 Examples:
1915 1915
1916 1916 - clone a remote repository to a new directory named hg/::
1917 1917
1918 1918 hg clone https://www.mercurial-scm.org/repo/hg/
1919 1919
1920 1920 - create a lightweight local clone::
1921 1921
1922 1922 hg clone project/ project-feature/
1923 1923
1924 1924 - clone from an absolute path on an ssh server (note double-slash)::
1925 1925
1926 1926 hg clone ssh://user@server//home/projects/alpha/
1927 1927
1928 1928 - do a streaming clone while checking out a specified version::
1929 1929
1930 1930 hg clone --stream http://server/repo -u 1.5
1931 1931
1932 1932 - create a repository without changesets after a particular revision::
1933 1933
1934 1934 hg clone -r 04e544 experimental/ good/
1935 1935
1936 1936 - clone (and track) a particular named branch::
1937 1937
1938 1938 hg clone https://www.mercurial-scm.org/repo/hg/#stable
1939 1939
1940 1940 See :hg:`help urls` for details on specifying URLs.
1941 1941
1942 1942 Returns 0 on success.
1943 1943 """
1944 1944 opts = pycompat.byteskwargs(opts)
1945 1945 cmdutil.check_at_most_one_arg(opts, b'noupdate', b'updaterev')
1946 1946
1947 1947 # --include/--exclude can come from narrow or sparse.
1948 1948 includepats, excludepats = None, None
1949 1949
1950 1950 # hg.clone() differentiates between None and an empty set. So make sure
1951 1951 # patterns are sets if narrow is requested without patterns.
1952 1952 if opts.get(b'narrow'):
1953 1953 includepats = set()
1954 1954 excludepats = set()
1955 1955
1956 1956 if opts.get(b'include'):
1957 1957 includepats = narrowspec.parsepatterns(opts.get(b'include'))
1958 1958 if opts.get(b'exclude'):
1959 1959 excludepats = narrowspec.parsepatterns(opts.get(b'exclude'))
1960 1960
1961 1961 r = hg.clone(
1962 1962 ui,
1963 1963 opts,
1964 1964 source,
1965 1965 dest,
1966 1966 pull=opts.get(b'pull'),
1967 1967 stream=opts.get(b'stream') or opts.get(b'uncompressed'),
1968 1968 revs=opts.get(b'rev'),
1969 1969 update=opts.get(b'updaterev') or not opts.get(b'noupdate'),
1970 1970 branch=opts.get(b'branch'),
1971 1971 shareopts=opts.get(b'shareopts'),
1972 1972 storeincludepats=includepats,
1973 1973 storeexcludepats=excludepats,
1974 1974 depth=opts.get(b'depth') or None,
1975 1975 )
1976 1976
1977 1977 return r is None
1978 1978
1979 1979
1980 1980 @command(
1981 1981 b'commit|ci',
1982 1982 [
1983 1983 (
1984 1984 b'A',
1985 1985 b'addremove',
1986 1986 None,
1987 1987 _(b'mark new/missing files as added/removed before committing'),
1988 1988 ),
1989 1989 (b'', b'close-branch', None, _(b'mark a branch head as closed')),
1990 1990 (b'', b'amend', None, _(b'amend the parent of the working directory')),
1991 1991 (b's', b'secret', None, _(b'use the secret phase for committing')),
1992 1992 (b'e', b'edit', None, _(b'invoke editor on commit messages')),
1993 1993 (
1994 1994 b'',
1995 1995 b'force-close-branch',
1996 1996 None,
1997 1997 _(b'forcibly close branch from a non-head changeset (ADVANCED)'),
1998 1998 ),
1999 1999 (b'i', b'interactive', None, _(b'use interactive mode')),
2000 2000 ]
2001 2001 + walkopts
2002 2002 + commitopts
2003 2003 + commitopts2
2004 2004 + subrepoopts,
2005 2005 _(b'[OPTION]... [FILE]...'),
2006 2006 helpcategory=command.CATEGORY_COMMITTING,
2007 2007 helpbasic=True,
2008 2008 inferrepo=True,
2009 2009 )
2010 2010 def commit(ui, repo, *pats, **opts):
2011 2011 """commit the specified files or all outstanding changes
2012 2012
2013 2013 Commit changes to the given files into the repository. Unlike a
2014 2014 centralized SCM, this operation is a local operation. See
2015 2015 :hg:`push` for a way to actively distribute your changes.
2016 2016
2017 2017 If a list of files is omitted, all changes reported by :hg:`status`
2018 2018 will be committed.
2019 2019
2020 2020 If you are committing the result of a merge, do not provide any
2021 2021 filenames or -I/-X filters.
2022 2022
2023 2023 If no commit message is specified, Mercurial starts your
2024 2024 configured editor where you can enter a message. In case your
2025 2025 commit fails, you will find a backup of your message in
2026 2026 ``.hg/last-message.txt``.
2027 2027
2028 2028 The --close-branch flag can be used to mark the current branch
2029 2029 head closed. When all heads of a branch are closed, the branch
2030 2030 will be considered closed and no longer listed.
2031 2031
2032 2032 The --amend flag can be used to amend the parent of the
2033 2033 working directory with a new commit that contains the changes
2034 2034 in the parent in addition to those currently reported by :hg:`status`,
2035 2035 if there are any. The old commit is stored in a backup bundle in
2036 2036 ``.hg/strip-backup`` (see :hg:`help bundle` and :hg:`help unbundle`
2037 2037 on how to restore it).
2038 2038
2039 2039 Message, user and date are taken from the amended commit unless
2040 2040 specified. When a message isn't specified on the command line,
2041 2041 the editor will open with the message of the amended commit.
2042 2042
2043 2043 It is not possible to amend public changesets (see :hg:`help phases`)
2044 2044 or changesets that have children.
2045 2045
2046 2046 See :hg:`help dates` for a list of formats valid for -d/--date.
2047 2047
2048 2048 Returns 0 on success, 1 if nothing changed.
2049 2049
2050 2050 .. container:: verbose
2051 2051
2052 2052 Examples:
2053 2053
2054 2054 - commit all files ending in .py::
2055 2055
2056 2056 hg commit --include "set:**.py"
2057 2057
2058 2058 - commit all non-binary files::
2059 2059
2060 2060 hg commit --exclude "set:binary()"
2061 2061
2062 2062 - amend the current commit and set the date to now::
2063 2063
2064 2064 hg commit --amend --date now
2065 2065 """
2066 2066 with repo.wlock(), repo.lock():
2067 2067 return _docommit(ui, repo, *pats, **opts)
2068 2068
2069 2069
2070 2070 def _docommit(ui, repo, *pats, **opts):
2071 2071 if opts.get('interactive'):
2072 2072 opts.pop('interactive')
2073 2073 ret = cmdutil.dorecord(
2074 2074 ui, repo, commit, None, False, cmdutil.recordfilter, *pats, **opts
2075 2075 )
2076 2076 # ret can be 0 (no changes to record) or the value returned by
2077 2077 # commit(), 1 if nothing changed or None on success.
2078 2078 return 1 if ret == 0 else ret
2079 2079
2080 2080 opts = pycompat.byteskwargs(opts)
2081 2081 if opts.get(b'subrepos'):
2082 2082 cmdutil.check_incompatible_arguments(opts, b'subrepos', [b'amend'])
2083 2083 # Let --subrepos on the command line override config setting.
2084 2084 ui.setconfig(b'ui', b'commitsubrepos', True, b'commit')
2085 2085
2086 2086 cmdutil.checkunfinished(repo, commit=True)
2087 2087
2088 2088 branch = repo[None].branch()
2089 2089 bheads = repo.branchheads(branch)
2090 2090 tip = repo.changelog.tip()
2091 2091
2092 2092 extra = {}
2093 2093 if opts.get(b'close_branch') or opts.get(b'force_close_branch'):
2094 2094 extra[b'close'] = b'1'
2095 2095
2096 2096 if repo[b'.'].closesbranch():
2097 2097 raise error.InputError(
2098 2098 _(b'current revision is already a branch closing head')
2099 2099 )
2100 2100 elif not bheads:
2101 2101 raise error.InputError(
2102 2102 _(b'branch "%s" has no heads to close') % branch
2103 2103 )
2104 2104 elif (
2105 2105 branch == repo[b'.'].branch()
2106 2106 and repo[b'.'].node() not in bheads
2107 2107 and not opts.get(b'force_close_branch')
2108 2108 ):
2109 2109 hint = _(
2110 2110 b'use --force-close-branch to close branch from a non-head'
2111 2111 b' changeset'
2112 2112 )
2113 2113 raise error.InputError(_(b'can only close branch heads'), hint=hint)
2114 2114 elif opts.get(b'amend'):
2115 2115 if (
2116 2116 repo[b'.'].p1().branch() != branch
2117 2117 and repo[b'.'].p2().branch() != branch
2118 2118 ):
2119 2119 raise error.InputError(_(b'can only close branch heads'))
2120 2120
2121 2121 if opts.get(b'amend'):
2122 2122 if ui.configbool(b'ui', b'commitsubrepos'):
2123 2123 raise error.InputError(
2124 2124 _(b'cannot amend with ui.commitsubrepos enabled')
2125 2125 )
2126 2126
2127 2127 old = repo[b'.']
2128 2128 rewriteutil.precheck(repo, [old.rev()], b'amend')
2129 2129
2130 2130 # Currently histedit gets confused if an amend happens while histedit
2131 2131 # is in progress. Since we have a checkunfinished command, we are
2132 2132 # temporarily honoring it.
2133 2133 #
2134 2134 # Note: eventually this guard will be removed. Please do not expect
2135 2135 # this behavior to remain.
2136 2136 if not obsolete.isenabled(repo, obsolete.createmarkersopt):
2137 2137 cmdutil.checkunfinished(repo)
2138 2138
2139 2139 node = cmdutil.amend(ui, repo, old, extra, pats, opts)
2140 2140 if node == old.node():
2141 2141 ui.status(_(b"nothing changed\n"))
2142 2142 return 1
2143 2143 else:
2144 2144
2145 2145 def commitfunc(ui, repo, message, match, opts):
2146 2146 overrides = {}
2147 2147 if opts.get(b'secret'):
2148 2148 overrides[(b'phases', b'new-commit')] = b'secret'
2149 2149
2150 2150 baseui = repo.baseui
2151 2151 with baseui.configoverride(overrides, b'commit'):
2152 2152 with ui.configoverride(overrides, b'commit'):
2153 2153 editform = cmdutil.mergeeditform(
2154 2154 repo[None], b'commit.normal'
2155 2155 )
2156 2156 editor = cmdutil.getcommiteditor(
2157 2157 editform=editform, **pycompat.strkwargs(opts)
2158 2158 )
2159 2159 return repo.commit(
2160 2160 message,
2161 2161 opts.get(b'user'),
2162 2162 opts.get(b'date'),
2163 2163 match,
2164 2164 editor=editor,
2165 2165 extra=extra,
2166 2166 )
2167 2167
2168 2168 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
2169 2169
2170 2170 if not node:
2171 2171 stat = cmdutil.postcommitstatus(repo, pats, opts)
2172 2172 if stat.deleted:
2173 2173 ui.status(
2174 2174 _(
2175 2175 b"nothing changed (%d missing files, see "
2176 2176 b"'hg status')\n"
2177 2177 )
2178 2178 % len(stat.deleted)
2179 2179 )
2180 2180 else:
2181 2181 ui.status(_(b"nothing changed\n"))
2182 2182 return 1
2183 2183
2184 2184 cmdutil.commitstatus(repo, node, branch, bheads, tip, opts)
2185 2185
2186 2186 if not ui.quiet and ui.configbool(b'commands', b'commit.post-status'):
2187 2187 status(
2188 2188 ui,
2189 2189 repo,
2190 2190 modified=True,
2191 2191 added=True,
2192 2192 removed=True,
2193 2193 deleted=True,
2194 2194 unknown=True,
2195 2195 subrepos=opts.get(b'subrepos'),
2196 2196 )
2197 2197
2198 2198
2199 2199 @command(
2200 2200 b'config|showconfig|debugconfig',
2201 2201 [
2202 2202 (b'u', b'untrusted', None, _(b'show untrusted configuration options')),
2203 2203 (b'e', b'edit', None, _(b'edit user config')),
2204 2204 (b'l', b'local', None, _(b'edit repository config')),
2205 2205 (
2206 2206 b'',
2207 2207 b'shared',
2208 2208 None,
2209 2209 _(b'edit shared source repository config (EXPERIMENTAL)'),
2210 2210 ),
2211 2211 (b'', b'non-shared', None, _(b'edit non shared config (EXPERIMENTAL)')),
2212 2212 (b'g', b'global', None, _(b'edit global config')),
2213 2213 ]
2214 2214 + formatteropts,
2215 2215 _(b'[-u] [NAME]...'),
2216 2216 helpcategory=command.CATEGORY_HELP,
2217 2217 optionalrepo=True,
2218 2218 intents={INTENT_READONLY},
2219 2219 )
2220 2220 def config(ui, repo, *values, **opts):
2221 2221 """show combined config settings from all hgrc files
2222 2222
2223 2223 With no arguments, print names and values of all config items.
2224 2224
2225 2225 With one argument of the form section.name, print just the value
2226 2226 of that config item.
2227 2227
2228 2228 With multiple arguments, print names and values of all config
2229 2229 items with matching section names or section.names.
2230 2230
2231 2231 With --edit, start an editor on the user-level config file. With
2232 2232 --global, edit the system-wide config file. With --local, edit the
2233 2233 repository-level config file.
2234 2234
2235 2235 With --debug, the source (filename and line number) is printed
2236 2236 for each config item.
2237 2237
2238 2238 See :hg:`help config` for more information about config files.
2239 2239
2240 2240 .. container:: verbose
2241 2241
2242 2242 --non-shared flag is used to edit `.hg/hgrc-not-shared` config file.
2243 2243 This file is not shared across shares when in share-safe mode.
2244 2244
2245 2245 Template:
2246 2246
2247 2247 The following keywords are supported. See also :hg:`help templates`.
2248 2248
2249 2249 :name: String. Config name.
2250 2250 :source: String. Filename and line number where the item is defined.
2251 2251 :value: String. Config value.
2252 2252
2253 2253 The --shared flag can be used to edit the config file of shared source
2254 2254 repository. It only works when you have shared using the experimental
2255 2255 share safe feature.
2256 2256
2257 2257 Returns 0 on success, 1 if NAME does not exist.
2258 2258
2259 2259 """
2260 2260
2261 2261 opts = pycompat.byteskwargs(opts)
2262 2262 editopts = (b'edit', b'local', b'global', b'shared', b'non_shared')
2263 2263 if any(opts.get(o) for o in editopts):
2264 2264 cmdutil.check_at_most_one_arg(opts, *editopts[1:])
2265 2265 if opts.get(b'local'):
2266 2266 if not repo:
2267 2267 raise error.InputError(
2268 2268 _(b"can't use --local outside a repository")
2269 2269 )
2270 2270 paths = [repo.vfs.join(b'hgrc')]
2271 2271 elif opts.get(b'global'):
2272 2272 paths = rcutil.systemrcpath()
2273 2273 elif opts.get(b'shared'):
2274 2274 if not repo.shared():
2275 2275 raise error.InputError(
2276 2276 _(b"repository is not shared; can't use --shared")
2277 2277 )
2278 2278 if requirements.SHARESAFE_REQUIREMENT not in repo.requirements:
2279 2279 raise error.InputError(
2280 2280 _(
2281 2281 b"share safe feature not enabled; "
2282 2282 b"unable to edit shared source repository config"
2283 2283 )
2284 2284 )
2285 2285 paths = [vfsmod.vfs(repo.sharedpath).join(b'hgrc')]
2286 2286 elif opts.get(b'non_shared'):
2287 2287 paths = [repo.vfs.join(b'hgrc-not-shared')]
2288 2288 else:
2289 2289 paths = rcutil.userrcpath()
2290 2290
2291 2291 for f in paths:
2292 2292 if os.path.exists(f):
2293 2293 break
2294 2294 else:
2295 2295 if opts.get(b'global'):
2296 2296 samplehgrc = uimod.samplehgrcs[b'global']
2297 2297 elif opts.get(b'local'):
2298 2298 samplehgrc = uimod.samplehgrcs[b'local']
2299 2299 else:
2300 2300 samplehgrc = uimod.samplehgrcs[b'user']
2301 2301
2302 2302 f = paths[0]
2303 2303 fp = open(f, b"wb")
2304 2304 fp.write(util.tonativeeol(samplehgrc))
2305 2305 fp.close()
2306 2306
2307 2307 editor = ui.geteditor()
2308 2308 ui.system(
2309 2309 b"%s \"%s\"" % (editor, f),
2310 2310 onerr=error.InputError,
2311 2311 errprefix=_(b"edit failed"),
2312 2312 blockedtag=b'config_edit',
2313 2313 )
2314 2314 return
2315 2315 ui.pager(b'config')
2316 2316 fm = ui.formatter(b'config', opts)
2317 2317 for t, f in rcutil.rccomponents():
2318 2318 if t == b'path':
2319 2319 ui.debug(b'read config from: %s\n' % f)
2320 2320 elif t == b'resource':
2321 2321 ui.debug(b'read config from: resource:%s.%s\n' % (f[0], f[1]))
2322 2322 elif t == b'items':
2323 2323 # Don't print anything for 'items'.
2324 2324 pass
2325 2325 else:
2326 2326 raise error.ProgrammingError(b'unknown rctype: %s' % t)
2327 2327 untrusted = bool(opts.get(b'untrusted'))
2328 2328
2329 2329 selsections = selentries = []
2330 2330 if values:
2331 2331 selsections = [v for v in values if b'.' not in v]
2332 2332 selentries = [v for v in values if b'.' in v]
2333 2333 uniquesel = len(selentries) == 1 and not selsections
2334 2334 selsections = set(selsections)
2335 2335 selentries = set(selentries)
2336 2336
2337 2337 matched = False
2338 2338 for section, name, value in ui.walkconfig(untrusted=untrusted):
2339 2339 source = ui.configsource(section, name, untrusted)
2340 2340 value = pycompat.bytestr(value)
2341 2341 defaultvalue = ui.configdefault(section, name)
2342 2342 if fm.isplain():
2343 2343 source = source or b'none'
2344 2344 value = value.replace(b'\n', b'\\n')
2345 2345 entryname = section + b'.' + name
2346 2346 if values and not (section in selsections or entryname in selentries):
2347 2347 continue
2348 2348 fm.startitem()
2349 2349 fm.condwrite(ui.debugflag, b'source', b'%s: ', source)
2350 2350 if uniquesel:
2351 2351 fm.data(name=entryname)
2352 2352 fm.write(b'value', b'%s\n', value)
2353 2353 else:
2354 2354 fm.write(b'name value', b'%s=%s\n', entryname, value)
2355 2355 if formatter.isprintable(defaultvalue):
2356 2356 fm.data(defaultvalue=defaultvalue)
2357 2357 elif isinstance(defaultvalue, list) and all(
2358 2358 formatter.isprintable(e) for e in defaultvalue
2359 2359 ):
2360 2360 fm.data(defaultvalue=fm.formatlist(defaultvalue, name=b'value'))
2361 2361 # TODO: no idea how to process unsupported defaultvalue types
2362 2362 matched = True
2363 2363 fm.end()
2364 2364 if matched:
2365 2365 return 0
2366 2366 return 1
2367 2367
2368 2368
2369 2369 @command(
2370 2370 b'continue',
2371 2371 dryrunopts,
2372 2372 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
2373 2373 helpbasic=True,
2374 2374 )
2375 2375 def continuecmd(ui, repo, **opts):
2376 2376 """resumes an interrupted operation (EXPERIMENTAL)
2377 2377
2378 2378 Finishes a multistep operation like graft, histedit, rebase, merge,
2379 2379 and unshelve if they are in an interrupted state.
2380 2380
2381 2381 use --dry-run/-n to dry run the command.
2382 2382 """
2383 2383 dryrun = opts.get('dry_run')
2384 2384 contstate = cmdutil.getunfinishedstate(repo)
2385 2385 if not contstate:
2386 2386 raise error.StateError(_(b'no operation in progress'))
2387 2387 if not contstate.continuefunc:
2388 2388 raise error.StateError(
2389 2389 (
2390 2390 _(b"%s in progress but does not support 'hg continue'")
2391 2391 % (contstate._opname)
2392 2392 ),
2393 2393 hint=contstate.continuemsg(),
2394 2394 )
2395 2395 if dryrun:
2396 2396 ui.status(_(b'%s in progress, will be resumed\n') % (contstate._opname))
2397 2397 return
2398 2398 return contstate.continuefunc(ui, repo)
2399 2399
2400 2400
2401 2401 @command(
2402 2402 b'copy|cp',
2403 2403 [
2404 2404 (b'', b'forget', None, _(b'unmark a destination file as copied')),
2405 2405 (b'A', b'after', None, _(b'record a copy that has already occurred')),
2406 2406 (
2407 2407 b'',
2408 2408 b'at-rev',
2409 2409 b'',
2410 2410 _(b'(un)mark copies in the given revision (EXPERIMENTAL)'),
2411 2411 _(b'REV'),
2412 2412 ),
2413 2413 (
2414 2414 b'f',
2415 2415 b'force',
2416 2416 None,
2417 2417 _(b'forcibly copy over an existing managed file'),
2418 2418 ),
2419 2419 ]
2420 2420 + walkopts
2421 2421 + dryrunopts,
2422 2422 _(b'[OPTION]... (SOURCE... DEST | --forget DEST...)'),
2423 2423 helpcategory=command.CATEGORY_FILE_CONTENTS,
2424 2424 )
2425 2425 def copy(ui, repo, *pats, **opts):
2426 2426 """mark files as copied for the next commit
2427 2427
2428 2428 Mark dest as having copies of source files. If dest is a
2429 2429 directory, copies are put in that directory. If dest is a file,
2430 2430 the source must be a single file.
2431 2431
2432 2432 By default, this command copies the contents of files as they
2433 2433 exist in the working directory. If invoked with -A/--after, the
2434 2434 operation is recorded, but no copying is performed.
2435 2435
2436 2436 To undo marking a destination file as copied, use --forget. With that
2437 2437 option, all given (positional) arguments are unmarked as copies. The
2438 2438 destination file(s) will be left in place (still tracked). Note that
2439 2439 :hg:`copy --forget` behaves the same way as :hg:`rename --forget`.
2440 2440
2441 2441 This command takes effect with the next commit by default.
2442 2442
2443 2443 Returns 0 on success, 1 if errors are encountered.
2444 2444 """
2445 2445 opts = pycompat.byteskwargs(opts)
2446 2446 with repo.wlock():
2447 2447 return cmdutil.copy(ui, repo, pats, opts)
2448 2448
2449 2449
2450 2450 @command(
2451 2451 b'debugcommands',
2452 2452 [],
2453 2453 _(b'[COMMAND]'),
2454 2454 helpcategory=command.CATEGORY_HELP,
2455 2455 norepo=True,
2456 2456 )
2457 2457 def debugcommands(ui, cmd=b'', *args):
2458 2458 """list all available commands and options"""
2459 2459 for cmd, vals in sorted(pycompat.iteritems(table)):
2460 2460 cmd = cmd.split(b'|')[0]
2461 2461 opts = b', '.join([i[1] for i in vals[1]])
2462 2462 ui.write(b'%s: %s\n' % (cmd, opts))
2463 2463
2464 2464
2465 2465 @command(
2466 2466 b'debugcomplete',
2467 2467 [(b'o', b'options', None, _(b'show the command options'))],
2468 2468 _(b'[-o] CMD'),
2469 2469 helpcategory=command.CATEGORY_HELP,
2470 2470 norepo=True,
2471 2471 )
2472 2472 def debugcomplete(ui, cmd=b'', **opts):
2473 2473 """returns the completion list associated with the given command"""
2474 2474
2475 2475 if opts.get('options'):
2476 2476 options = []
2477 2477 otables = [globalopts]
2478 2478 if cmd:
2479 2479 aliases, entry = cmdutil.findcmd(cmd, table, False)
2480 2480 otables.append(entry[1])
2481 2481 for t in otables:
2482 2482 for o in t:
2483 2483 if b"(DEPRECATED)" in o[3]:
2484 2484 continue
2485 2485 if o[0]:
2486 2486 options.append(b'-%s' % o[0])
2487 2487 options.append(b'--%s' % o[1])
2488 2488 ui.write(b"%s\n" % b"\n".join(options))
2489 2489 return
2490 2490
2491 2491 cmdlist, unused_allcmds = cmdutil.findpossible(cmd, table)
2492 2492 if ui.verbose:
2493 2493 cmdlist = [b' '.join(c[0]) for c in cmdlist.values()]
2494 2494 ui.write(b"%s\n" % b"\n".join(sorted(cmdlist)))
2495 2495
2496 2496
2497 2497 @command(
2498 2498 b'diff',
2499 2499 [
2500 2500 (b'r', b'rev', [], _(b'revision (DEPRECATED)'), _(b'REV')),
2501 2501 (b'', b'from', b'', _(b'revision to diff from'), _(b'REV1')),
2502 2502 (b'', b'to', b'', _(b'revision to diff to'), _(b'REV2')),
2503 2503 (b'c', b'change', b'', _(b'change made by revision'), _(b'REV')),
2504 2504 ]
2505 2505 + diffopts
2506 2506 + diffopts2
2507 2507 + walkopts
2508 2508 + subrepoopts,
2509 2509 _(b'[OPTION]... ([-c REV] | [--from REV1] [--to REV2]) [FILE]...'),
2510 2510 helpcategory=command.CATEGORY_FILE_CONTENTS,
2511 2511 helpbasic=True,
2512 2512 inferrepo=True,
2513 2513 intents={INTENT_READONLY},
2514 2514 )
2515 2515 def diff(ui, repo, *pats, **opts):
2516 2516 """diff repository (or selected files)
2517 2517
2518 2518 Show differences between revisions for the specified files.
2519 2519
2520 2520 Differences between files are shown using the unified diff format.
2521 2521
2522 2522 .. note::
2523 2523
2524 2524 :hg:`diff` may generate unexpected results for merges, as it will
2525 2525 default to comparing against the working directory's first
2526 2526 parent changeset if no revisions are specified.
2527 2527
2528 2528 By default, the working directory files are compared to its first parent. To
2529 2529 see the differences from another revision, use --from. To see the difference
2530 2530 to another revision, use --to. For example, :hg:`diff --from .^` will show
2531 2531 the differences from the working copy's grandparent to the working copy,
2532 2532 :hg:`diff --to .` will show the diff from the working copy to its parent
2533 2533 (i.e. the reverse of the default), and :hg:`diff --from 1.0 --to 1.2` will
2534 2534 show the diff between those two revisions.
2535 2535
2536 2536 Alternatively you can specify -c/--change with a revision to see the changes
2537 2537 in that changeset relative to its first parent (i.e. :hg:`diff -c 42` is
2538 2538 equivalent to :hg:`diff --from 42^ --to 42`)
2539 2539
2540 2540 Without the -a/--text option, diff will avoid generating diffs of
2541 2541 files it detects as binary. With -a, diff will generate a diff
2542 2542 anyway, probably with undesirable results.
2543 2543
2544 2544 Use the -g/--git option to generate diffs in the git extended diff
2545 2545 format. For more information, read :hg:`help diffs`.
2546 2546
2547 2547 .. container:: verbose
2548 2548
2549 2549 Examples:
2550 2550
2551 2551 - compare a file in the current working directory to its parent::
2552 2552
2553 2553 hg diff foo.c
2554 2554
2555 2555 - compare two historical versions of a directory, with rename info::
2556 2556
2557 2557 hg diff --git --from 1.0 --to 1.2 lib/
2558 2558
2559 2559 - get change stats relative to the last change on some date::
2560 2560
2561 2561 hg diff --stat --from "date('may 2')"
2562 2562
2563 2563 - diff all newly-added files that contain a keyword::
2564 2564
2565 2565 hg diff "set:added() and grep(GNU)"
2566 2566
2567 2567 - compare a revision and its parents::
2568 2568
2569 2569 hg diff -c 9353 # compare against first parent
2570 2570 hg diff --from 9353^ --to 9353 # same using revset syntax
2571 2571 hg diff --from 9353^2 --to 9353 # compare against the second parent
2572 2572
2573 2573 Returns 0 on success.
2574 2574 """
2575 2575
2576 2576 cmdutil.check_at_most_one_arg(opts, 'rev', 'change')
2577 2577 opts = pycompat.byteskwargs(opts)
2578 2578 revs = opts.get(b'rev')
2579 2579 change = opts.get(b'change')
2580 2580 from_rev = opts.get(b'from')
2581 2581 to_rev = opts.get(b'to')
2582 2582 stat = opts.get(b'stat')
2583 2583 reverse = opts.get(b'reverse')
2584 2584
2585 2585 cmdutil.check_incompatible_arguments(opts, b'from', [b'rev', b'change'])
2586 2586 cmdutil.check_incompatible_arguments(opts, b'to', [b'rev', b'change'])
2587 2587 if change:
2588 2588 repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn')
2589 2589 ctx2 = scmutil.revsingle(repo, change, None)
2590 2590 ctx1 = logcmdutil.diff_parent(ctx2)
2591 2591 elif from_rev or to_rev:
2592 2592 repo = scmutil.unhidehashlikerevs(
2593 2593 repo, [from_rev] + [to_rev], b'nowarn'
2594 2594 )
2595 2595 ctx1 = scmutil.revsingle(repo, from_rev, None)
2596 2596 ctx2 = scmutil.revsingle(repo, to_rev, None)
2597 2597 else:
2598 2598 repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn')
2599 2599 ctx1, ctx2 = scmutil.revpair(repo, revs)
2600 2600
2601 2601 if reverse:
2602 2602 ctxleft = ctx2
2603 2603 ctxright = ctx1
2604 2604 else:
2605 2605 ctxleft = ctx1
2606 2606 ctxright = ctx2
2607 2607
2608 2608 diffopts = patch.diffallopts(ui, opts)
2609 2609 m = scmutil.match(ctx2, pats, opts)
2610 2610 m = repo.narrowmatch(m)
2611 2611 ui.pager(b'diff')
2612 2612 logcmdutil.diffordiffstat(
2613 2613 ui,
2614 2614 repo,
2615 2615 diffopts,
2616 2616 ctxleft,
2617 2617 ctxright,
2618 2618 m,
2619 2619 stat=stat,
2620 2620 listsubrepos=opts.get(b'subrepos'),
2621 2621 root=opts.get(b'root'),
2622 2622 )
2623 2623
2624 2624
2625 2625 @command(
2626 2626 b'export',
2627 2627 [
2628 2628 (
2629 2629 b'B',
2630 2630 b'bookmark',
2631 2631 b'',
2632 2632 _(b'export changes only reachable by given bookmark'),
2633 2633 _(b'BOOKMARK'),
2634 2634 ),
2635 2635 (
2636 2636 b'o',
2637 2637 b'output',
2638 2638 b'',
2639 2639 _(b'print output to file with formatted name'),
2640 2640 _(b'FORMAT'),
2641 2641 ),
2642 2642 (b'', b'switch-parent', None, _(b'diff against the second parent')),
2643 2643 (b'r', b'rev', [], _(b'revisions to export'), _(b'REV')),
2644 2644 ]
2645 2645 + diffopts
2646 2646 + formatteropts,
2647 2647 _(b'[OPTION]... [-o OUTFILESPEC] [-r] [REV]...'),
2648 2648 helpcategory=command.CATEGORY_IMPORT_EXPORT,
2649 2649 helpbasic=True,
2650 2650 intents={INTENT_READONLY},
2651 2651 )
2652 2652 def export(ui, repo, *changesets, **opts):
2653 2653 """dump the header and diffs for one or more changesets
2654 2654
2655 2655 Print the changeset header and diffs for one or more revisions.
2656 2656 If no revision is given, the parent of the working directory is used.
2657 2657
2658 2658 The information shown in the changeset header is: author, date,
2659 2659 branch name (if non-default), changeset hash, parent(s) and commit
2660 2660 comment.
2661 2661
2662 2662 .. note::
2663 2663
2664 2664 :hg:`export` may generate unexpected diff output for merge
2665 2665 changesets, as it will compare the merge changeset against its
2666 2666 first parent only.
2667 2667
2668 2668 Output may be to a file, in which case the name of the file is
2669 2669 given using a template string. See :hg:`help templates`. In addition
2670 2670 to the common template keywords, the following formatting rules are
2671 2671 supported:
2672 2672
2673 2673 :``%%``: literal "%" character
2674 2674 :``%H``: changeset hash (40 hexadecimal digits)
2675 2675 :``%N``: number of patches being generated
2676 2676 :``%R``: changeset revision number
2677 2677 :``%b``: basename of the exporting repository
2678 2678 :``%h``: short-form changeset hash (12 hexadecimal digits)
2679 2679 :``%m``: first line of the commit message (only alphanumeric characters)
2680 2680 :``%n``: zero-padded sequence number, starting at 1
2681 2681 :``%r``: zero-padded changeset revision number
2682 2682 :``\\``: literal "\\" character
2683 2683
2684 2684 Without the -a/--text option, export will avoid generating diffs
2685 2685 of files it detects as binary. With -a, export will generate a
2686 2686 diff anyway, probably with undesirable results.
2687 2687
2688 2688 With -B/--bookmark changesets reachable by the given bookmark are
2689 2689 selected.
2690 2690
2691 2691 Use the -g/--git option to generate diffs in the git extended diff
2692 2692 format. See :hg:`help diffs` for more information.
2693 2693
2694 2694 With the --switch-parent option, the diff will be against the
2695 2695 second parent. It can be useful to review a merge.
2696 2696
2697 2697 .. container:: verbose
2698 2698
2699 2699 Template:
2700 2700
2701 2701 The following keywords are supported in addition to the common template
2702 2702 keywords and functions. See also :hg:`help templates`.
2703 2703
2704 2704 :diff: String. Diff content.
2705 2705 :parents: List of strings. Parent nodes of the changeset.
2706 2706
2707 2707 Examples:
2708 2708
2709 2709 - use export and import to transplant a bugfix to the current
2710 2710 branch::
2711 2711
2712 2712 hg export -r 9353 | hg import -
2713 2713
2714 2714 - export all the changesets between two revisions to a file with
2715 2715 rename information::
2716 2716
2717 2717 hg export --git -r 123:150 > changes.txt
2718 2718
2719 2719 - split outgoing changes into a series of patches with
2720 2720 descriptive names::
2721 2721
2722 2722 hg export -r "outgoing()" -o "%n-%m.patch"
2723 2723
2724 2724 Returns 0 on success.
2725 2725 """
2726 2726 opts = pycompat.byteskwargs(opts)
2727 2727 bookmark = opts.get(b'bookmark')
2728 2728 changesets += tuple(opts.get(b'rev', []))
2729 2729
2730 2730 cmdutil.check_at_most_one_arg(opts, b'rev', b'bookmark')
2731 2731
2732 2732 if bookmark:
2733 2733 if bookmark not in repo._bookmarks:
2734 2734 raise error.InputError(_(b"bookmark '%s' not found") % bookmark)
2735 2735
2736 2736 revs = scmutil.bookmarkrevs(repo, bookmark)
2737 2737 else:
2738 2738 if not changesets:
2739 2739 changesets = [b'.']
2740 2740
2741 2741 repo = scmutil.unhidehashlikerevs(repo, changesets, b'nowarn')
2742 2742 revs = scmutil.revrange(repo, changesets)
2743 2743
2744 2744 if not revs:
2745 2745 raise error.InputError(_(b"export requires at least one changeset"))
2746 2746 if len(revs) > 1:
2747 2747 ui.note(_(b'exporting patches:\n'))
2748 2748 else:
2749 2749 ui.note(_(b'exporting patch:\n'))
2750 2750
2751 2751 fntemplate = opts.get(b'output')
2752 2752 if cmdutil.isstdiofilename(fntemplate):
2753 2753 fntemplate = b''
2754 2754
2755 2755 if fntemplate:
2756 2756 fm = formatter.nullformatter(ui, b'export', opts)
2757 2757 else:
2758 2758 ui.pager(b'export')
2759 2759 fm = ui.formatter(b'export', opts)
2760 2760 with fm:
2761 2761 cmdutil.export(
2762 2762 repo,
2763 2763 revs,
2764 2764 fm,
2765 2765 fntemplate=fntemplate,
2766 2766 switch_parent=opts.get(b'switch_parent'),
2767 2767 opts=patch.diffallopts(ui, opts),
2768 2768 )
2769 2769
2770 2770
2771 2771 @command(
2772 2772 b'files',
2773 2773 [
2774 2774 (
2775 2775 b'r',
2776 2776 b'rev',
2777 2777 b'',
2778 2778 _(b'search the repository as it is in REV'),
2779 2779 _(b'REV'),
2780 2780 ),
2781 2781 (
2782 2782 b'0',
2783 2783 b'print0',
2784 2784 None,
2785 2785 _(b'end filenames with NUL, for use with xargs'),
2786 2786 ),
2787 2787 ]
2788 2788 + walkopts
2789 2789 + formatteropts
2790 2790 + subrepoopts,
2791 2791 _(b'[OPTION]... [FILE]...'),
2792 2792 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
2793 2793 intents={INTENT_READONLY},
2794 2794 )
2795 2795 def files(ui, repo, *pats, **opts):
2796 2796 """list tracked files
2797 2797
2798 2798 Print files under Mercurial control in the working directory or
2799 2799 specified revision for given files (excluding removed files).
2800 2800 Files can be specified as filenames or filesets.
2801 2801
2802 2802 If no files are given to match, this command prints the names
2803 2803 of all files under Mercurial control.
2804 2804
2805 2805 .. container:: verbose
2806 2806
2807 2807 Template:
2808 2808
2809 2809 The following keywords are supported in addition to the common template
2810 2810 keywords and functions. See also :hg:`help templates`.
2811 2811
2812 2812 :flags: String. Character denoting file's symlink and executable bits.
2813 2813 :path: String. Repository-absolute path of the file.
2814 2814 :size: Integer. Size of the file in bytes.
2815 2815
2816 2816 Examples:
2817 2817
2818 2818 - list all files under the current directory::
2819 2819
2820 2820 hg files .
2821 2821
2822 2822 - shows sizes and flags for current revision::
2823 2823
2824 2824 hg files -vr .
2825 2825
2826 2826 - list all files named README::
2827 2827
2828 2828 hg files -I "**/README"
2829 2829
2830 2830 - list all binary files::
2831 2831
2832 2832 hg files "set:binary()"
2833 2833
2834 2834 - find files containing a regular expression::
2835 2835
2836 2836 hg files "set:grep('bob')"
2837 2837
2838 2838 - search tracked file contents with xargs and grep::
2839 2839
2840 2840 hg files -0 | xargs -0 grep foo
2841 2841
2842 2842 See :hg:`help patterns` and :hg:`help filesets` for more information
2843 2843 on specifying file patterns.
2844 2844
2845 2845 Returns 0 if a match is found, 1 otherwise.
2846 2846
2847 2847 """
2848 2848
2849 2849 opts = pycompat.byteskwargs(opts)
2850 2850 rev = opts.get(b'rev')
2851 2851 if rev:
2852 2852 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
2853 2853 ctx = scmutil.revsingle(repo, rev, None)
2854 2854
2855 2855 end = b'\n'
2856 2856 if opts.get(b'print0'):
2857 2857 end = b'\0'
2858 2858 fmt = b'%s' + end
2859 2859
2860 2860 m = scmutil.match(ctx, pats, opts)
2861 2861 ui.pager(b'files')
2862 2862 uipathfn = scmutil.getuipathfn(ctx.repo(), legacyrelativevalue=True)
2863 2863 with ui.formatter(b'files', opts) as fm:
2864 2864 return cmdutil.files(
2865 2865 ui, ctx, m, uipathfn, fm, fmt, opts.get(b'subrepos')
2866 2866 )
2867 2867
2868 2868
2869 2869 @command(
2870 2870 b'forget',
2871 2871 [
2872 2872 (b'i', b'interactive', None, _(b'use interactive mode')),
2873 2873 ]
2874 2874 + walkopts
2875 2875 + dryrunopts,
2876 2876 _(b'[OPTION]... FILE...'),
2877 2877 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
2878 2878 helpbasic=True,
2879 2879 inferrepo=True,
2880 2880 )
2881 2881 def forget(ui, repo, *pats, **opts):
2882 2882 """forget the specified files on the next commit
2883 2883
2884 2884 Mark the specified files so they will no longer be tracked
2885 2885 after the next commit.
2886 2886
2887 2887 This only removes files from the current branch, not from the
2888 2888 entire project history, and it does not delete them from the
2889 2889 working directory.
2890 2890
2891 2891 To delete the file from the working directory, see :hg:`remove`.
2892 2892
2893 2893 To undo a forget before the next commit, see :hg:`add`.
2894 2894
2895 2895 .. container:: verbose
2896 2896
2897 2897 Examples:
2898 2898
2899 2899 - forget newly-added binary files::
2900 2900
2901 2901 hg forget "set:added() and binary()"
2902 2902
2903 2903 - forget files that would be excluded by .hgignore::
2904 2904
2905 2905 hg forget "set:hgignore()"
2906 2906
2907 2907 Returns 0 on success.
2908 2908 """
2909 2909
2910 2910 opts = pycompat.byteskwargs(opts)
2911 2911 if not pats:
2912 2912 raise error.InputError(_(b'no files specified'))
2913 2913
2914 2914 m = scmutil.match(repo[None], pats, opts)
2915 2915 dryrun, interactive = opts.get(b'dry_run'), opts.get(b'interactive')
2916 2916 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
2917 2917 rejected = cmdutil.forget(
2918 2918 ui,
2919 2919 repo,
2920 2920 m,
2921 2921 prefix=b"",
2922 2922 uipathfn=uipathfn,
2923 2923 explicitonly=False,
2924 2924 dryrun=dryrun,
2925 2925 interactive=interactive,
2926 2926 )[0]
2927 2927 return rejected and 1 or 0
2928 2928
2929 2929
2930 2930 @command(
2931 2931 b'graft',
2932 2932 [
2933 2933 (b'r', b'rev', [], _(b'revisions to graft'), _(b'REV')),
2934 2934 (
2935 2935 b'',
2936 2936 b'base',
2937 2937 b'',
2938 2938 _(b'base revision when doing the graft merge (ADVANCED)'),
2939 2939 _(b'REV'),
2940 2940 ),
2941 2941 (b'c', b'continue', False, _(b'resume interrupted graft')),
2942 2942 (b'', b'stop', False, _(b'stop interrupted graft')),
2943 2943 (b'', b'abort', False, _(b'abort interrupted graft')),
2944 2944 (b'e', b'edit', False, _(b'invoke editor on commit messages')),
2945 2945 (b'', b'log', None, _(b'append graft info to log message')),
2946 2946 (
2947 2947 b'',
2948 2948 b'no-commit',
2949 2949 None,
2950 2950 _(b"don't commit, just apply the changes in working directory"),
2951 2951 ),
2952 2952 (b'f', b'force', False, _(b'force graft')),
2953 2953 (
2954 2954 b'D',
2955 2955 b'currentdate',
2956 2956 False,
2957 2957 _(b'record the current date as commit date'),
2958 2958 ),
2959 2959 (
2960 2960 b'U',
2961 2961 b'currentuser',
2962 2962 False,
2963 2963 _(b'record the current user as committer'),
2964 2964 ),
2965 2965 ]
2966 2966 + commitopts2
2967 2967 + mergetoolopts
2968 2968 + dryrunopts,
2969 2969 _(b'[OPTION]... [-r REV]... REV...'),
2970 2970 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
2971 2971 )
2972 2972 def graft(ui, repo, *revs, **opts):
2973 2973 """copy changes from other branches onto the current branch
2974 2974
2975 2975 This command uses Mercurial's merge logic to copy individual
2976 2976 changes from other branches without merging branches in the
2977 2977 history graph. This is sometimes known as 'backporting' or
2978 2978 'cherry-picking'. By default, graft will copy user, date, and
2979 2979 description from the source changesets.
2980 2980
2981 2981 Changesets that are ancestors of the current revision, that have
2982 2982 already been grafted, or that are merges will be skipped.
2983 2983
2984 2984 If --log is specified, log messages will have a comment appended
2985 2985 of the form::
2986 2986
2987 2987 (grafted from CHANGESETHASH)
2988 2988
2989 2989 If --force is specified, revisions will be grafted even if they
2990 2990 are already ancestors of, or have been grafted to, the destination.
2991 2991 This is useful when the revisions have since been backed out.
2992 2992
2993 2993 If a graft merge results in conflicts, the graft process is
2994 2994 interrupted so that the current merge can be manually resolved.
2995 2995 Once all conflicts are addressed, the graft process can be
2996 2996 continued with the -c/--continue option.
2997 2997
2998 2998 The -c/--continue option reapplies all the earlier options.
2999 2999
3000 3000 .. container:: verbose
3001 3001
3002 3002 The --base option exposes more of how graft internally uses merge with a
3003 3003 custom base revision. --base can be used to specify another ancestor than
3004 3004 the first and only parent.
3005 3005
3006 3006 The command::
3007 3007
3008 3008 hg graft -r 345 --base 234
3009 3009
3010 3010 is thus pretty much the same as::
3011 3011
3012 3012 hg diff --from 234 --to 345 | hg import
3013 3013
3014 3014 but using merge to resolve conflicts and track moved files.
3015 3015
3016 3016 The result of a merge can thus be backported as a single commit by
3017 3017 specifying one of the merge parents as base, and thus effectively
3018 3018 grafting the changes from the other side.
3019 3019
3020 3020 It is also possible to collapse multiple changesets and clean up history
3021 3021 by specifying another ancestor as base, much like rebase --collapse
3022 3022 --keep.
3023 3023
3024 3024 The commit message can be tweaked after the fact using commit --amend .
3025 3025
3026 3026 For using non-ancestors as the base to backout changes, see the backout
3027 3027 command and the hidden --parent option.
3028 3028
3029 3029 .. container:: verbose
3030 3030
3031 3031 Examples:
3032 3032
3033 3033 - copy a single change to the stable branch and edit its description::
3034 3034
3035 3035 hg update stable
3036 3036 hg graft --edit 9393
3037 3037
3038 3038 - graft a range of changesets with one exception, updating dates::
3039 3039
3040 3040 hg graft -D "2085::2093 and not 2091"
3041 3041
3042 3042 - continue a graft after resolving conflicts::
3043 3043
3044 3044 hg graft -c
3045 3045
3046 3046 - show the source of a grafted changeset::
3047 3047
3048 3048 hg log --debug -r .
3049 3049
3050 3050 - show revisions sorted by date::
3051 3051
3052 3052 hg log -r "sort(all(), date)"
3053 3053
3054 3054 - backport the result of a merge as a single commit::
3055 3055
3056 3056 hg graft -r 123 --base 123^
3057 3057
3058 3058 - land a feature branch as one changeset::
3059 3059
3060 3060 hg up -cr default
3061 3061 hg graft -r featureX --base "ancestor('featureX', 'default')"
3062 3062
3063 3063 See :hg:`help revisions` for more about specifying revisions.
3064 3064
3065 3065 Returns 0 on successful completion, 1 if there are unresolved files.
3066 3066 """
3067 3067 with repo.wlock():
3068 3068 return _dograft(ui, repo, *revs, **opts)
3069 3069
3070 3070
3071 3071 def _dograft(ui, repo, *revs, **opts):
3072 3072 opts = pycompat.byteskwargs(opts)
3073 3073 if revs and opts.get(b'rev'):
3074 3074 ui.warn(
3075 3075 _(
3076 3076 b'warning: inconsistent use of --rev might give unexpected '
3077 3077 b'revision ordering!\n'
3078 3078 )
3079 3079 )
3080 3080
3081 3081 revs = list(revs)
3082 3082 revs.extend(opts.get(b'rev'))
3083 3083 # a dict of data to be stored in state file
3084 3084 statedata = {}
3085 3085 # list of new nodes created by ongoing graft
3086 3086 statedata[b'newnodes'] = []
3087 3087
3088 3088 cmdutil.resolvecommitoptions(ui, opts)
3089 3089
3090 3090 editor = cmdutil.getcommiteditor(
3091 3091 editform=b'graft', **pycompat.strkwargs(opts)
3092 3092 )
3093 3093
3094 3094 cmdutil.check_at_most_one_arg(opts, b'abort', b'stop', b'continue')
3095 3095
3096 3096 cont = False
3097 3097 if opts.get(b'no_commit'):
3098 3098 cmdutil.check_incompatible_arguments(
3099 3099 opts,
3100 3100 b'no_commit',
3101 3101 [b'edit', b'currentuser', b'currentdate', b'log'],
3102 3102 )
3103 3103
3104 3104 graftstate = statemod.cmdstate(repo, b'graftstate')
3105 3105
3106 3106 if opts.get(b'stop'):
3107 3107 cmdutil.check_incompatible_arguments(
3108 3108 opts,
3109 3109 b'stop',
3110 3110 [
3111 3111 b'edit',
3112 3112 b'log',
3113 3113 b'user',
3114 3114 b'date',
3115 3115 b'currentdate',
3116 3116 b'currentuser',
3117 3117 b'rev',
3118 3118 ],
3119 3119 )
3120 3120 return _stopgraft(ui, repo, graftstate)
3121 3121 elif opts.get(b'abort'):
3122 3122 cmdutil.check_incompatible_arguments(
3123 3123 opts,
3124 3124 b'abort',
3125 3125 [
3126 3126 b'edit',
3127 3127 b'log',
3128 3128 b'user',
3129 3129 b'date',
3130 3130 b'currentdate',
3131 3131 b'currentuser',
3132 3132 b'rev',
3133 3133 ],
3134 3134 )
3135 3135 return cmdutil.abortgraft(ui, repo, graftstate)
3136 3136 elif opts.get(b'continue'):
3137 3137 cont = True
3138 3138 if revs:
3139 3139 raise error.InputError(_(b"can't specify --continue and revisions"))
3140 3140 # read in unfinished revisions
3141 3141 if graftstate.exists():
3142 3142 statedata = cmdutil.readgraftstate(repo, graftstate)
3143 3143 if statedata.get(b'date'):
3144 3144 opts[b'date'] = statedata[b'date']
3145 3145 if statedata.get(b'user'):
3146 3146 opts[b'user'] = statedata[b'user']
3147 3147 if statedata.get(b'log'):
3148 3148 opts[b'log'] = True
3149 3149 if statedata.get(b'no_commit'):
3150 3150 opts[b'no_commit'] = statedata.get(b'no_commit')
3151 3151 if statedata.get(b'base'):
3152 3152 opts[b'base'] = statedata.get(b'base')
3153 3153 nodes = statedata[b'nodes']
3154 3154 revs = [repo[node].rev() for node in nodes]
3155 3155 else:
3156 3156 cmdutil.wrongtooltocontinue(repo, _(b'graft'))
3157 3157 else:
3158 3158 if not revs:
3159 3159 raise error.InputError(_(b'no revisions specified'))
3160 3160 cmdutil.checkunfinished(repo)
3161 3161 cmdutil.bailifchanged(repo)
3162 3162 revs = scmutil.revrange(repo, revs)
3163 3163
3164 3164 skipped = set()
3165 3165 basectx = None
3166 3166 if opts.get(b'base'):
3167 3167 basectx = scmutil.revsingle(repo, opts[b'base'], None)
3168 3168 if basectx is None:
3169 3169 # check for merges
3170 3170 for rev in repo.revs(b'%ld and merge()', revs):
3171 3171 ui.warn(_(b'skipping ungraftable merge revision %d\n') % rev)
3172 3172 skipped.add(rev)
3173 3173 revs = [r for r in revs if r not in skipped]
3174 3174 if not revs:
3175 3175 return -1
3176 3176 if basectx is not None and len(revs) != 1:
3177 3177 raise error.InputError(_(b'only one revision allowed with --base '))
3178 3178
3179 3179 # Don't check in the --continue case, in effect retaining --force across
3180 3180 # --continues. That's because without --force, any revisions we decided to
3181 3181 # skip would have been filtered out here, so they wouldn't have made their
3182 3182 # way to the graftstate. With --force, any revisions we would have otherwise
3183 3183 # skipped would not have been filtered out, and if they hadn't been applied
3184 3184 # already, they'd have been in the graftstate.
3185 3185 if not (cont or opts.get(b'force')) and basectx is None:
3186 3186 # check for ancestors of dest branch
3187 3187 ancestors = repo.revs(b'%ld & (::.)', revs)
3188 3188 for rev in ancestors:
3189 3189 ui.warn(_(b'skipping ancestor revision %d:%s\n') % (rev, repo[rev]))
3190 3190
3191 3191 revs = [r for r in revs if r not in ancestors]
3192 3192
3193 3193 if not revs:
3194 3194 return -1
3195 3195
3196 3196 # analyze revs for earlier grafts
3197 3197 ids = {}
3198 3198 for ctx in repo.set(b"%ld", revs):
3199 3199 ids[ctx.hex()] = ctx.rev()
3200 3200 n = ctx.extra().get(b'source')
3201 3201 if n:
3202 3202 ids[n] = ctx.rev()
3203 3203
3204 3204 # check ancestors for earlier grafts
3205 3205 ui.debug(b'scanning for duplicate grafts\n')
3206 3206
3207 3207 # The only changesets we can be sure doesn't contain grafts of any
3208 3208 # revs, are the ones that are common ancestors of *all* revs:
3209 3209 for rev in repo.revs(b'only(%d,ancestor(%ld))', repo[b'.'].rev(), revs):
3210 3210 ctx = repo[rev]
3211 3211 n = ctx.extra().get(b'source')
3212 3212 if n in ids:
3213 3213 try:
3214 3214 r = repo[n].rev()
3215 3215 except error.RepoLookupError:
3216 3216 r = None
3217 3217 if r in revs:
3218 3218 ui.warn(
3219 3219 _(
3220 3220 b'skipping revision %d:%s '
3221 3221 b'(already grafted to %d:%s)\n'
3222 3222 )
3223 3223 % (r, repo[r], rev, ctx)
3224 3224 )
3225 3225 revs.remove(r)
3226 3226 elif ids[n] in revs:
3227 3227 if r is None:
3228 3228 ui.warn(
3229 3229 _(
3230 3230 b'skipping already grafted revision %d:%s '
3231 3231 b'(%d:%s also has unknown origin %s)\n'
3232 3232 )
3233 3233 % (ids[n], repo[ids[n]], rev, ctx, n[:12])
3234 3234 )
3235 3235 else:
3236 3236 ui.warn(
3237 3237 _(
3238 3238 b'skipping already grafted revision %d:%s '
3239 3239 b'(%d:%s also has origin %d:%s)\n'
3240 3240 )
3241 3241 % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])
3242 3242 )
3243 3243 revs.remove(ids[n])
3244 3244 elif ctx.hex() in ids:
3245 3245 r = ids[ctx.hex()]
3246 3246 if r in revs:
3247 3247 ui.warn(
3248 3248 _(
3249 3249 b'skipping already grafted revision %d:%s '
3250 3250 b'(was grafted from %d:%s)\n'
3251 3251 )
3252 3252 % (r, repo[r], rev, ctx)
3253 3253 )
3254 3254 revs.remove(r)
3255 3255 if not revs:
3256 3256 return -1
3257 3257
3258 3258 if opts.get(b'no_commit'):
3259 3259 statedata[b'no_commit'] = True
3260 3260 if opts.get(b'base'):
3261 3261 statedata[b'base'] = opts[b'base']
3262 3262 for pos, ctx in enumerate(repo.set(b"%ld", revs)):
3263 3263 desc = b'%d:%s "%s"' % (
3264 3264 ctx.rev(),
3265 3265 ctx,
3266 3266 ctx.description().split(b'\n', 1)[0],
3267 3267 )
3268 3268 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
3269 3269 if names:
3270 3270 desc += b' (%s)' % b' '.join(names)
3271 3271 ui.status(_(b'grafting %s\n') % desc)
3272 3272 if opts.get(b'dry_run'):
3273 3273 continue
3274 3274
3275 3275 source = ctx.extra().get(b'source')
3276 3276 extra = {}
3277 3277 if source:
3278 3278 extra[b'source'] = source
3279 3279 extra[b'intermediate-source'] = ctx.hex()
3280 3280 else:
3281 3281 extra[b'source'] = ctx.hex()
3282 3282 user = ctx.user()
3283 3283 if opts.get(b'user'):
3284 3284 user = opts[b'user']
3285 3285 statedata[b'user'] = user
3286 3286 date = ctx.date()
3287 3287 if opts.get(b'date'):
3288 3288 date = opts[b'date']
3289 3289 statedata[b'date'] = date
3290 3290 message = ctx.description()
3291 3291 if opts.get(b'log'):
3292 3292 message += b'\n(grafted from %s)' % ctx.hex()
3293 3293 statedata[b'log'] = True
3294 3294
3295 3295 # we don't merge the first commit when continuing
3296 3296 if not cont:
3297 3297 # perform the graft merge with p1(rev) as 'ancestor'
3298 3298 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
3299 3299 base = ctx.p1() if basectx is None else basectx
3300 3300 with ui.configoverride(overrides, b'graft'):
3301 3301 stats = mergemod.graft(repo, ctx, base, [b'local', b'graft'])
3302 3302 # report any conflicts
3303 3303 if stats.unresolvedcount > 0:
3304 3304 # write out state for --continue
3305 3305 nodes = [repo[rev].hex() for rev in revs[pos:]]
3306 3306 statedata[b'nodes'] = nodes
3307 3307 stateversion = 1
3308 3308 graftstate.save(stateversion, statedata)
3309 3309 ui.error(_(b"abort: unresolved conflicts, can't continue\n"))
3310 3310 ui.error(_(b"(use 'hg resolve' and 'hg graft --continue')\n"))
3311 3311 return 1
3312 3312 else:
3313 3313 cont = False
3314 3314
3315 3315 # commit if --no-commit is false
3316 3316 if not opts.get(b'no_commit'):
3317 3317 node = repo.commit(
3318 3318 text=message, user=user, date=date, extra=extra, editor=editor
3319 3319 )
3320 3320 if node is None:
3321 3321 ui.warn(
3322 3322 _(b'note: graft of %d:%s created no changes to commit\n')
3323 3323 % (ctx.rev(), ctx)
3324 3324 )
3325 3325 # checking that newnodes exist because old state files won't have it
3326 3326 elif statedata.get(b'newnodes') is not None:
3327 3327 nn = statedata[b'newnodes'] # type: List[bytes]
3328 3328 nn.append(node)
3329 3329
3330 3330 # remove state when we complete successfully
3331 3331 if not opts.get(b'dry_run'):
3332 3332 graftstate.delete()
3333 3333
3334 3334 return 0
3335 3335
3336 3336
3337 3337 def _stopgraft(ui, repo, graftstate):
3338 3338 """stop the interrupted graft"""
3339 3339 if not graftstate.exists():
3340 3340 raise error.StateError(_(b"no interrupted graft found"))
3341 3341 pctx = repo[b'.']
3342 3342 mergemod.clean_update(pctx)
3343 3343 graftstate.delete()
3344 3344 ui.status(_(b"stopped the interrupted graft\n"))
3345 3345 ui.status(_(b"working directory is now at %s\n") % pctx.hex()[:12])
3346 3346 return 0
3347 3347
3348 3348
3349 3349 statemod.addunfinished(
3350 3350 b'graft',
3351 3351 fname=b'graftstate',
3352 3352 clearable=True,
3353 3353 stopflag=True,
3354 3354 continueflag=True,
3355 3355 abortfunc=cmdutil.hgabortgraft,
3356 3356 cmdhint=_(b"use 'hg graft --continue' or 'hg graft --stop' to stop"),
3357 3357 )
3358 3358
3359 3359
3360 3360 @command(
3361 3361 b'grep',
3362 3362 [
3363 3363 (b'0', b'print0', None, _(b'end fields with NUL')),
3364 3364 (b'', b'all', None, _(b'an alias to --diff (DEPRECATED)')),
3365 3365 (
3366 3366 b'',
3367 3367 b'diff',
3368 3368 None,
3369 3369 _(
3370 3370 b'search revision differences for when the pattern was added '
3371 3371 b'or removed'
3372 3372 ),
3373 3373 ),
3374 3374 (b'a', b'text', None, _(b'treat all files as text')),
3375 3375 (
3376 3376 b'f',
3377 3377 b'follow',
3378 3378 None,
3379 3379 _(
3380 3380 b'follow changeset history,'
3381 3381 b' or file history across copies and renames'
3382 3382 ),
3383 3383 ),
3384 3384 (b'i', b'ignore-case', None, _(b'ignore case when matching')),
3385 3385 (
3386 3386 b'l',
3387 3387 b'files-with-matches',
3388 3388 None,
3389 3389 _(b'print only filenames and revisions that match'),
3390 3390 ),
3391 3391 (b'n', b'line-number', None, _(b'print matching line numbers')),
3392 3392 (
3393 3393 b'r',
3394 3394 b'rev',
3395 3395 [],
3396 3396 _(b'search files changed within revision range'),
3397 3397 _(b'REV'),
3398 3398 ),
3399 3399 (
3400 3400 b'',
3401 3401 b'all-files',
3402 3402 None,
3403 3403 _(
3404 3404 b'include all files in the changeset while grepping (DEPRECATED)'
3405 3405 ),
3406 3406 ),
3407 3407 (b'u', b'user', None, _(b'list the author (long with -v)')),
3408 3408 (b'd', b'date', None, _(b'list the date (short with -q)')),
3409 3409 ]
3410 3410 + formatteropts
3411 3411 + walkopts,
3412 3412 _(b'[--diff] [OPTION]... PATTERN [FILE]...'),
3413 3413 helpcategory=command.CATEGORY_FILE_CONTENTS,
3414 3414 inferrepo=True,
3415 3415 intents={INTENT_READONLY},
3416 3416 )
3417 3417 def grep(ui, repo, pattern, *pats, **opts):
3418 3418 """search for a pattern in specified files
3419 3419
3420 3420 Search the working directory or revision history for a regular
3421 3421 expression in the specified files for the entire repository.
3422 3422
3423 3423 By default, grep searches the repository files in the working
3424 3424 directory and prints the files where it finds a match. To specify
3425 3425 historical revisions instead of the working directory, use the
3426 3426 --rev flag.
3427 3427
3428 3428 To search instead historical revision differences that contains a
3429 3429 change in match status ("-" for a match that becomes a non-match,
3430 3430 or "+" for a non-match that becomes a match), use the --diff flag.
3431 3431
3432 3432 PATTERN can be any Python (roughly Perl-compatible) regular
3433 3433 expression.
3434 3434
3435 3435 If no FILEs are specified and the --rev flag isn't supplied, all
3436 3436 files in the working directory are searched. When using the --rev
3437 3437 flag and specifying FILEs, use the --follow argument to also
3438 3438 follow the specified FILEs across renames and copies.
3439 3439
3440 3440 .. container:: verbose
3441 3441
3442 3442 Template:
3443 3443
3444 3444 The following keywords are supported in addition to the common template
3445 3445 keywords and functions. See also :hg:`help templates`.
3446 3446
3447 3447 :change: String. Character denoting insertion ``+`` or removal ``-``.
3448 3448 Available if ``--diff`` is specified.
3449 3449 :lineno: Integer. Line number of the match.
3450 3450 :path: String. Repository-absolute path of the file.
3451 3451 :texts: List of text chunks.
3452 3452
3453 3453 And each entry of ``{texts}`` provides the following sub-keywords.
3454 3454
3455 3455 :matched: Boolean. True if the chunk matches the specified pattern.
3456 3456 :text: String. Chunk content.
3457 3457
3458 3458 See :hg:`help templates.operators` for the list expansion syntax.
3459 3459
3460 3460 Returns 0 if a match is found, 1 otherwise.
3461 3461
3462 3462 """
3463 3463 cmdutil.check_incompatible_arguments(opts, 'all_files', ['all', 'diff'])
3464 3464 opts = pycompat.byteskwargs(opts)
3465 3465 diff = opts.get(b'all') or opts.get(b'diff')
3466 3466 follow = opts.get(b'follow')
3467 3467 if opts.get(b'all_files') is None and not diff:
3468 3468 opts[b'all_files'] = True
3469 3469 plaingrep = (
3470 3470 opts.get(b'all_files')
3471 3471 and not opts.get(b'rev')
3472 3472 and not opts.get(b'follow')
3473 3473 )
3474 3474 all_files = opts.get(b'all_files')
3475 3475 if plaingrep:
3476 3476 opts[b'rev'] = [b'wdir()']
3477 3477
3478 3478 reflags = re.M
3479 3479 if opts.get(b'ignore_case'):
3480 3480 reflags |= re.I
3481 3481 try:
3482 3482 regexp = util.re.compile(pattern, reflags)
3483 3483 except re.error as inst:
3484 3484 ui.warn(
3485 3485 _(b"grep: invalid match pattern: %s\n")
3486 3486 % stringutil.forcebytestr(inst)
3487 3487 )
3488 3488 return 1
3489 3489 sep, eol = b':', b'\n'
3490 3490 if opts.get(b'print0'):
3491 3491 sep = eol = b'\0'
3492 3492
3493 3493 searcher = grepmod.grepsearcher(
3494 3494 ui, repo, regexp, all_files=all_files, diff=diff, follow=follow
3495 3495 )
3496 3496
3497 3497 getfile = searcher._getfile
3498 3498
3499 3499 uipathfn = scmutil.getuipathfn(repo)
3500 3500
3501 3501 def display(fm, fn, ctx, pstates, states):
3502 3502 rev = scmutil.intrev(ctx)
3503 3503 if fm.isplain():
3504 3504 formatuser = ui.shortuser
3505 3505 else:
3506 3506 formatuser = pycompat.bytestr
3507 3507 if ui.quiet:
3508 3508 datefmt = b'%Y-%m-%d'
3509 3509 else:
3510 3510 datefmt = b'%a %b %d %H:%M:%S %Y %1%2'
3511 3511 found = False
3512 3512
3513 3513 @util.cachefunc
3514 3514 def binary():
3515 3515 flog = getfile(fn)
3516 3516 try:
3517 3517 return stringutil.binary(flog.read(ctx.filenode(fn)))
3518 3518 except error.WdirUnsupported:
3519 3519 return ctx[fn].isbinary()
3520 3520
3521 3521 fieldnamemap = {b'linenumber': b'lineno'}
3522 3522 if diff:
3523 3523 iter = grepmod.difflinestates(pstates, states)
3524 3524 else:
3525 3525 iter = [(b'', l) for l in states]
3526 3526 for change, l in iter:
3527 3527 fm.startitem()
3528 3528 fm.context(ctx=ctx)
3529 3529 fm.data(node=fm.hexfunc(scmutil.binnode(ctx)), path=fn)
3530 3530 fm.plain(uipathfn(fn), label=b'grep.filename')
3531 3531
3532 3532 cols = [
3533 3533 (b'rev', b'%d', rev, not plaingrep, b''),
3534 3534 (
3535 3535 b'linenumber',
3536 3536 b'%d',
3537 3537 l.linenum,
3538 3538 opts.get(b'line_number'),
3539 3539 b'',
3540 3540 ),
3541 3541 ]
3542 3542 if diff:
3543 3543 cols.append(
3544 3544 (
3545 3545 b'change',
3546 3546 b'%s',
3547 3547 change,
3548 3548 True,
3549 3549 b'grep.inserted '
3550 3550 if change == b'+'
3551 3551 else b'grep.deleted ',
3552 3552 )
3553 3553 )
3554 3554 cols.extend(
3555 3555 [
3556 3556 (
3557 3557 b'user',
3558 3558 b'%s',
3559 3559 formatuser(ctx.user()),
3560 3560 opts.get(b'user'),
3561 3561 b'',
3562 3562 ),
3563 3563 (
3564 3564 b'date',
3565 3565 b'%s',
3566 3566 fm.formatdate(ctx.date(), datefmt),
3567 3567 opts.get(b'date'),
3568 3568 b'',
3569 3569 ),
3570 3570 ]
3571 3571 )
3572 3572 for name, fmt, data, cond, extra_label in cols:
3573 3573 if cond:
3574 3574 fm.plain(sep, label=b'grep.sep')
3575 3575 field = fieldnamemap.get(name, name)
3576 3576 label = extra_label + (b'grep.%s' % name)
3577 3577 fm.condwrite(cond, field, fmt, data, label=label)
3578 3578 if not opts.get(b'files_with_matches'):
3579 3579 fm.plain(sep, label=b'grep.sep')
3580 3580 if not opts.get(b'text') and binary():
3581 3581 fm.plain(_(b" Binary file matches"))
3582 3582 else:
3583 3583 displaymatches(fm.nested(b'texts', tmpl=b'{text}'), l)
3584 3584 fm.plain(eol)
3585 3585 found = True
3586 3586 if opts.get(b'files_with_matches'):
3587 3587 break
3588 3588 return found
3589 3589
3590 3590 def displaymatches(fm, l):
3591 3591 p = 0
3592 3592 for s, e in l.findpos(regexp):
3593 3593 if p < s:
3594 3594 fm.startitem()
3595 3595 fm.write(b'text', b'%s', l.line[p:s])
3596 3596 fm.data(matched=False)
3597 3597 fm.startitem()
3598 3598 fm.write(b'text', b'%s', l.line[s:e], label=b'grep.match')
3599 3599 fm.data(matched=True)
3600 3600 p = e
3601 3601 if p < len(l.line):
3602 3602 fm.startitem()
3603 3603 fm.write(b'text', b'%s', l.line[p:])
3604 3604 fm.data(matched=False)
3605 3605 fm.end()
3606 3606
3607 3607 found = False
3608 3608
3609 3609 wopts = logcmdutil.walkopts(
3610 3610 pats=pats,
3611 3611 opts=opts,
3612 3612 revspec=opts[b'rev'],
3613 3613 include_pats=opts[b'include'],
3614 3614 exclude_pats=opts[b'exclude'],
3615 3615 follow=follow,
3616 3616 force_changelog_traversal=all_files,
3617 3617 filter_revisions_by_pats=not all_files,
3618 3618 )
3619 3619 revs, makefilematcher = logcmdutil.makewalker(repo, wopts)
3620 3620
3621 3621 ui.pager(b'grep')
3622 3622 fm = ui.formatter(b'grep', opts)
3623 3623 for fn, ctx, pstates, states in searcher.searchfiles(revs, makefilematcher):
3624 3624 r = display(fm, fn, ctx, pstates, states)
3625 3625 found = found or r
3626 3626 if r and not diff and not all_files:
3627 3627 searcher.skipfile(fn, ctx.rev())
3628 3628 fm.end()
3629 3629
3630 3630 return not found
3631 3631
3632 3632
3633 3633 @command(
3634 3634 b'heads',
3635 3635 [
3636 3636 (
3637 3637 b'r',
3638 3638 b'rev',
3639 3639 b'',
3640 3640 _(b'show only heads which are descendants of STARTREV'),
3641 3641 _(b'STARTREV'),
3642 3642 ),
3643 3643 (b't', b'topo', False, _(b'show topological heads only')),
3644 3644 (
3645 3645 b'a',
3646 3646 b'active',
3647 3647 False,
3648 3648 _(b'show active branchheads only (DEPRECATED)'),
3649 3649 ),
3650 3650 (b'c', b'closed', False, _(b'show normal and closed branch heads')),
3651 3651 ]
3652 3652 + templateopts,
3653 3653 _(b'[-ct] [-r STARTREV] [REV]...'),
3654 3654 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
3655 3655 intents={INTENT_READONLY},
3656 3656 )
3657 3657 def heads(ui, repo, *branchrevs, **opts):
3658 3658 """show branch heads
3659 3659
3660 3660 With no arguments, show all open branch heads in the repository.
3661 3661 Branch heads are changesets that have no descendants on the
3662 3662 same branch. They are where development generally takes place and
3663 3663 are the usual targets for update and merge operations.
3664 3664
3665 3665 If one or more REVs are given, only open branch heads on the
3666 3666 branches associated with the specified changesets are shown. This
3667 3667 means that you can use :hg:`heads .` to see the heads on the
3668 3668 currently checked-out branch.
3669 3669
3670 3670 If -c/--closed is specified, also show branch heads marked closed
3671 3671 (see :hg:`commit --close-branch`).
3672 3672
3673 3673 If STARTREV is specified, only those heads that are descendants of
3674 3674 STARTREV will be displayed.
3675 3675
3676 3676 If -t/--topo is specified, named branch mechanics will be ignored and only
3677 3677 topological heads (changesets with no children) will be shown.
3678 3678
3679 3679 Returns 0 if matching heads are found, 1 if not.
3680 3680 """
3681 3681
3682 3682 opts = pycompat.byteskwargs(opts)
3683 3683 start = None
3684 3684 rev = opts.get(b'rev')
3685 3685 if rev:
3686 3686 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
3687 3687 start = scmutil.revsingle(repo, rev, None).node()
3688 3688
3689 3689 if opts.get(b'topo'):
3690 3690 heads = [repo[h] for h in repo.heads(start)]
3691 3691 else:
3692 3692 heads = []
3693 3693 for branch in repo.branchmap():
3694 3694 heads += repo.branchheads(branch, start, opts.get(b'closed'))
3695 3695 heads = [repo[h] for h in heads]
3696 3696
3697 3697 if branchrevs:
3698 3698 branches = {
3699 3699 repo[r].branch() for r in scmutil.revrange(repo, branchrevs)
3700 3700 }
3701 3701 heads = [h for h in heads if h.branch() in branches]
3702 3702
3703 3703 if opts.get(b'active') and branchrevs:
3704 3704 dagheads = repo.heads(start)
3705 3705 heads = [h for h in heads if h.node() in dagheads]
3706 3706
3707 3707 if branchrevs:
3708 3708 haveheads = {h.branch() for h in heads}
3709 3709 if branches - haveheads:
3710 3710 headless = b', '.join(b for b in branches - haveheads)
3711 3711 msg = _(b'no open branch heads found on branches %s')
3712 3712 if opts.get(b'rev'):
3713 3713 msg += _(b' (started at %s)') % opts[b'rev']
3714 3714 ui.warn((msg + b'\n') % headless)
3715 3715
3716 3716 if not heads:
3717 3717 return 1
3718 3718
3719 3719 ui.pager(b'heads')
3720 3720 heads = sorted(heads, key=lambda x: -(x.rev()))
3721 3721 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
3722 3722 for ctx in heads:
3723 3723 displayer.show(ctx)
3724 3724 displayer.close()
3725 3725
3726 3726
3727 3727 @command(
3728 3728 b'help',
3729 3729 [
3730 3730 (b'e', b'extension', None, _(b'show only help for extensions')),
3731 3731 (b'c', b'command', None, _(b'show only help for commands')),
3732 3732 (b'k', b'keyword', None, _(b'show topics matching keyword')),
3733 3733 (
3734 3734 b's',
3735 3735 b'system',
3736 3736 [],
3737 3737 _(b'show help for specific platform(s)'),
3738 3738 _(b'PLATFORM'),
3739 3739 ),
3740 3740 ],
3741 3741 _(b'[-eck] [-s PLATFORM] [TOPIC]'),
3742 3742 helpcategory=command.CATEGORY_HELP,
3743 3743 norepo=True,
3744 3744 intents={INTENT_READONLY},
3745 3745 )
3746 3746 def help_(ui, name=None, **opts):
3747 3747 """show help for a given topic or a help overview
3748 3748
3749 3749 With no arguments, print a list of commands with short help messages.
3750 3750
3751 3751 Given a topic, extension, or command name, print help for that
3752 3752 topic.
3753 3753
3754 3754 Returns 0 if successful.
3755 3755 """
3756 3756
3757 3757 keep = opts.get('system') or []
3758 3758 if len(keep) == 0:
3759 3759 if pycompat.sysplatform.startswith(b'win'):
3760 3760 keep.append(b'windows')
3761 3761 elif pycompat.sysplatform == b'OpenVMS':
3762 3762 keep.append(b'vms')
3763 3763 elif pycompat.sysplatform == b'plan9':
3764 3764 keep.append(b'plan9')
3765 3765 else:
3766 3766 keep.append(b'unix')
3767 3767 keep.append(pycompat.sysplatform.lower())
3768 3768 if ui.verbose:
3769 3769 keep.append(b'verbose')
3770 3770
3771 3771 commands = sys.modules[__name__]
3772 3772 formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts)
3773 3773 ui.pager(b'help')
3774 3774 ui.write(formatted)
3775 3775
3776 3776
3777 3777 @command(
3778 3778 b'identify|id',
3779 3779 [
3780 3780 (b'r', b'rev', b'', _(b'identify the specified revision'), _(b'REV')),
3781 3781 (b'n', b'num', None, _(b'show local revision number')),
3782 3782 (b'i', b'id', None, _(b'show global revision id')),
3783 3783 (b'b', b'branch', None, _(b'show branch')),
3784 3784 (b't', b'tags', None, _(b'show tags')),
3785 3785 (b'B', b'bookmarks', None, _(b'show bookmarks')),
3786 3786 ]
3787 3787 + remoteopts
3788 3788 + formatteropts,
3789 3789 _(b'[-nibtB] [-r REV] [SOURCE]'),
3790 3790 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
3791 3791 optionalrepo=True,
3792 3792 intents={INTENT_READONLY},
3793 3793 )
3794 3794 def identify(
3795 3795 ui,
3796 3796 repo,
3797 3797 source=None,
3798 3798 rev=None,
3799 3799 num=None,
3800 3800 id=None,
3801 3801 branch=None,
3802 3802 tags=None,
3803 3803 bookmarks=None,
3804 3804 **opts
3805 3805 ):
3806 3806 """identify the working directory or specified revision
3807 3807
3808 3808 Print a summary identifying the repository state at REV using one or
3809 3809 two parent hash identifiers, followed by a "+" if the working
3810 3810 directory has uncommitted changes, the branch name (if not default),
3811 3811 a list of tags, and a list of bookmarks.
3812 3812
3813 3813 When REV is not given, print a summary of the current state of the
3814 3814 repository including the working directory. Specify -r. to get information
3815 3815 of the working directory parent without scanning uncommitted changes.
3816 3816
3817 3817 Specifying a path to a repository root or Mercurial bundle will
3818 3818 cause lookup to operate on that repository/bundle.
3819 3819
3820 3820 .. container:: verbose
3821 3821
3822 3822 Template:
3823 3823
3824 3824 The following keywords are supported in addition to the common template
3825 3825 keywords and functions. See also :hg:`help templates`.
3826 3826
3827 3827 :dirty: String. Character ``+`` denoting if the working directory has
3828 3828 uncommitted changes.
3829 3829 :id: String. One or two nodes, optionally followed by ``+``.
3830 3830 :parents: List of strings. Parent nodes of the changeset.
3831 3831
3832 3832 Examples:
3833 3833
3834 3834 - generate a build identifier for the working directory::
3835 3835
3836 3836 hg id --id > build-id.dat
3837 3837
3838 3838 - find the revision corresponding to a tag::
3839 3839
3840 3840 hg id -n -r 1.3
3841 3841
3842 3842 - check the most recent revision of a remote repository::
3843 3843
3844 3844 hg id -r tip https://www.mercurial-scm.org/repo/hg/
3845 3845
3846 3846 See :hg:`log` for generating more information about specific revisions,
3847 3847 including full hash identifiers.
3848 3848
3849 3849 Returns 0 if successful.
3850 3850 """
3851 3851
3852 3852 opts = pycompat.byteskwargs(opts)
3853 3853 if not repo and not source:
3854 3854 raise error.InputError(
3855 3855 _(b"there is no Mercurial repository here (.hg not found)")
3856 3856 )
3857 3857
3858 3858 default = not (num or id or branch or tags or bookmarks)
3859 3859 output = []
3860 3860 revs = []
3861 3861
3862 3862 peer = None
3863 3863 try:
3864 3864 if source:
3865 3865 source, branches = urlutil.get_unique_pull_path(
3866 3866 b'identify', repo, ui, source
3867 3867 )
3868 3868 # only pass ui when no repo
3869 3869 peer = hg.peer(repo or ui, opts, source)
3870 3870 repo = peer.local()
3871 3871 revs, checkout = hg.addbranchrevs(repo, peer, branches, None)
3872 3872
3873 3873 fm = ui.formatter(b'identify', opts)
3874 3874 fm.startitem()
3875 3875
3876 3876 if not repo:
3877 3877 if num or branch or tags:
3878 3878 raise error.InputError(
3879 3879 _(b"can't query remote revision number, branch, or tags")
3880 3880 )
3881 3881 if not rev and revs:
3882 3882 rev = revs[0]
3883 3883 if not rev:
3884 3884 rev = b"tip"
3885 3885
3886 3886 remoterev = peer.lookup(rev)
3887 3887 hexrev = fm.hexfunc(remoterev)
3888 3888 if default or id:
3889 3889 output = [hexrev]
3890 3890 fm.data(id=hexrev)
3891 3891
3892 3892 @util.cachefunc
3893 3893 def getbms():
3894 3894 bms = []
3895 3895
3896 3896 if b'bookmarks' in peer.listkeys(b'namespaces'):
3897 3897 hexremoterev = hex(remoterev)
3898 3898 bms = [
3899 3899 bm
3900 3900 for bm, bmr in pycompat.iteritems(
3901 3901 peer.listkeys(b'bookmarks')
3902 3902 )
3903 3903 if bmr == hexremoterev
3904 3904 ]
3905 3905
3906 3906 return sorted(bms)
3907 3907
3908 3908 if fm.isplain():
3909 3909 if bookmarks:
3910 3910 output.extend(getbms())
3911 3911 elif default and not ui.quiet:
3912 3912 # multiple bookmarks for a single parent separated by '/'
3913 3913 bm = b'/'.join(getbms())
3914 3914 if bm:
3915 3915 output.append(bm)
3916 3916 else:
3917 3917 fm.data(node=hex(remoterev))
3918 3918 if bookmarks or b'bookmarks' in fm.datahint():
3919 3919 fm.data(bookmarks=fm.formatlist(getbms(), name=b'bookmark'))
3920 3920 else:
3921 3921 if rev:
3922 3922 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
3923 3923 ctx = scmutil.revsingle(repo, rev, None)
3924 3924
3925 3925 if ctx.rev() is None:
3926 3926 ctx = repo[None]
3927 3927 parents = ctx.parents()
3928 3928 taglist = []
3929 3929 for p in parents:
3930 3930 taglist.extend(p.tags())
3931 3931
3932 3932 dirty = b""
3933 3933 if ctx.dirty(missing=True, merge=False, branch=False):
3934 3934 dirty = b'+'
3935 3935 fm.data(dirty=dirty)
3936 3936
3937 3937 hexoutput = [fm.hexfunc(p.node()) for p in parents]
3938 3938 if default or id:
3939 3939 output = [b"%s%s" % (b'+'.join(hexoutput), dirty)]
3940 3940 fm.data(id=b"%s%s" % (b'+'.join(hexoutput), dirty))
3941 3941
3942 3942 if num:
3943 3943 numoutput = [b"%d" % p.rev() for p in parents]
3944 3944 output.append(b"%s%s" % (b'+'.join(numoutput), dirty))
3945 3945
3946 3946 fm.data(
3947 3947 parents=fm.formatlist(
3948 3948 [fm.hexfunc(p.node()) for p in parents], name=b'node'
3949 3949 )
3950 3950 )
3951 3951 else:
3952 3952 hexoutput = fm.hexfunc(ctx.node())
3953 3953 if default or id:
3954 3954 output = [hexoutput]
3955 3955 fm.data(id=hexoutput)
3956 3956
3957 3957 if num:
3958 3958 output.append(pycompat.bytestr(ctx.rev()))
3959 3959 taglist = ctx.tags()
3960 3960
3961 3961 if default and not ui.quiet:
3962 3962 b = ctx.branch()
3963 3963 if b != b'default':
3964 3964 output.append(b"(%s)" % b)
3965 3965
3966 3966 # multiple tags for a single parent separated by '/'
3967 3967 t = b'/'.join(taglist)
3968 3968 if t:
3969 3969 output.append(t)
3970 3970
3971 3971 # multiple bookmarks for a single parent separated by '/'
3972 3972 bm = b'/'.join(ctx.bookmarks())
3973 3973 if bm:
3974 3974 output.append(bm)
3975 3975 else:
3976 3976 if branch:
3977 3977 output.append(ctx.branch())
3978 3978
3979 3979 if tags:
3980 3980 output.extend(taglist)
3981 3981
3982 3982 if bookmarks:
3983 3983 output.extend(ctx.bookmarks())
3984 3984
3985 3985 fm.data(node=ctx.hex())
3986 3986 fm.data(branch=ctx.branch())
3987 3987 fm.data(tags=fm.formatlist(taglist, name=b'tag', sep=b':'))
3988 3988 fm.data(bookmarks=fm.formatlist(ctx.bookmarks(), name=b'bookmark'))
3989 3989 fm.context(ctx=ctx)
3990 3990
3991 3991 fm.plain(b"%s\n" % b' '.join(output))
3992 3992 fm.end()
3993 3993 finally:
3994 3994 if peer:
3995 3995 peer.close()
3996 3996
3997 3997
3998 3998 @command(
3999 3999 b'import|patch',
4000 4000 [
4001 4001 (
4002 4002 b'p',
4003 4003 b'strip',
4004 4004 1,
4005 4005 _(
4006 4006 b'directory strip option for patch. This has the same '
4007 4007 b'meaning as the corresponding patch option'
4008 4008 ),
4009 4009 _(b'NUM'),
4010 4010 ),
4011 4011 (b'b', b'base', b'', _(b'base path (DEPRECATED)'), _(b'PATH')),
4012 4012 (b'', b'secret', None, _(b'use the secret phase for committing')),
4013 4013 (b'e', b'edit', False, _(b'invoke editor on commit messages')),
4014 4014 (
4015 4015 b'f',
4016 4016 b'force',
4017 4017 None,
4018 4018 _(b'skip check for outstanding uncommitted changes (DEPRECATED)'),
4019 4019 ),
4020 4020 (
4021 4021 b'',
4022 4022 b'no-commit',
4023 4023 None,
4024 4024 _(b"don't commit, just update the working directory"),
4025 4025 ),
4026 4026 (
4027 4027 b'',
4028 4028 b'bypass',
4029 4029 None,
4030 4030 _(b"apply patch without touching the working directory"),
4031 4031 ),
4032 4032 (b'', b'partial', None, _(b'commit even if some hunks fail')),
4033 4033 (b'', b'exact', None, _(b'abort if patch would apply lossily')),
4034 4034 (b'', b'prefix', b'', _(b'apply patch to subdirectory'), _(b'DIR')),
4035 4035 (
4036 4036 b'',
4037 4037 b'import-branch',
4038 4038 None,
4039 4039 _(b'use any branch information in patch (implied by --exact)'),
4040 4040 ),
4041 4041 ]
4042 4042 + commitopts
4043 4043 + commitopts2
4044 4044 + similarityopts,
4045 4045 _(b'[OPTION]... PATCH...'),
4046 4046 helpcategory=command.CATEGORY_IMPORT_EXPORT,
4047 4047 )
4048 4048 def import_(ui, repo, patch1=None, *patches, **opts):
4049 4049 """import an ordered set of patches
4050 4050
4051 4051 Import a list of patches and commit them individually (unless
4052 4052 --no-commit is specified).
4053 4053
4054 4054 To read a patch from standard input (stdin), use "-" as the patch
4055 4055 name. If a URL is specified, the patch will be downloaded from
4056 4056 there.
4057 4057
4058 4058 Import first applies changes to the working directory (unless
4059 4059 --bypass is specified), import will abort if there are outstanding
4060 4060 changes.
4061 4061
4062 4062 Use --bypass to apply and commit patches directly to the
4063 4063 repository, without affecting the working directory. Without
4064 4064 --exact, patches will be applied on top of the working directory
4065 4065 parent revision.
4066 4066
4067 4067 You can import a patch straight from a mail message. Even patches
4068 4068 as attachments work (to use the body part, it must have type
4069 4069 text/plain or text/x-patch). From and Subject headers of email
4070 4070 message are used as default committer and commit message. All
4071 4071 text/plain body parts before first diff are added to the commit
4072 4072 message.
4073 4073
4074 4074 If the imported patch was generated by :hg:`export`, user and
4075 4075 description from patch override values from message headers and
4076 4076 body. Values given on command line with -m/--message and -u/--user
4077 4077 override these.
4078 4078
4079 4079 If --exact is specified, import will set the working directory to
4080 4080 the parent of each patch before applying it, and will abort if the
4081 4081 resulting changeset has a different ID than the one recorded in
4082 4082 the patch. This will guard against various ways that portable
4083 4083 patch formats and mail systems might fail to transfer Mercurial
4084 4084 data or metadata. See :hg:`bundle` for lossless transmission.
4085 4085
4086 4086 Use --partial to ensure a changeset will be created from the patch
4087 4087 even if some hunks fail to apply. Hunks that fail to apply will be
4088 4088 written to a <target-file>.rej file. Conflicts can then be resolved
4089 4089 by hand before :hg:`commit --amend` is run to update the created
4090 4090 changeset. This flag exists to let people import patches that
4091 4091 partially apply without losing the associated metadata (author,
4092 4092 date, description, ...).
4093 4093
4094 4094 .. note::
4095 4095
4096 4096 When no hunks apply cleanly, :hg:`import --partial` will create
4097 4097 an empty changeset, importing only the patch metadata.
4098 4098
4099 4099 With -s/--similarity, hg will attempt to discover renames and
4100 4100 copies in the patch in the same way as :hg:`addremove`.
4101 4101
4102 4102 It is possible to use external patch programs to perform the patch
4103 4103 by setting the ``ui.patch`` configuration option. For the default
4104 4104 internal tool, the fuzz can also be configured via ``patch.fuzz``.
4105 4105 See :hg:`help config` for more information about configuration
4106 4106 files and how to use these options.
4107 4107
4108 4108 See :hg:`help dates` for a list of formats valid for -d/--date.
4109 4109
4110 4110 .. container:: verbose
4111 4111
4112 4112 Examples:
4113 4113
4114 4114 - import a traditional patch from a website and detect renames::
4115 4115
4116 4116 hg import -s 80 http://example.com/bugfix.patch
4117 4117
4118 4118 - import a changeset from an hgweb server::
4119 4119
4120 4120 hg import https://www.mercurial-scm.org/repo/hg/rev/5ca8c111e9aa
4121 4121
4122 4122 - import all the patches in an Unix-style mbox::
4123 4123
4124 4124 hg import incoming-patches.mbox
4125 4125
4126 4126 - import patches from stdin::
4127 4127
4128 4128 hg import -
4129 4129
4130 4130 - attempt to exactly restore an exported changeset (not always
4131 4131 possible)::
4132 4132
4133 4133 hg import --exact proposed-fix.patch
4134 4134
4135 4135 - use an external tool to apply a patch which is too fuzzy for
4136 4136 the default internal tool.
4137 4137
4138 4138 hg import --config ui.patch="patch --merge" fuzzy.patch
4139 4139
4140 4140 - change the default fuzzing from 2 to a less strict 7
4141 4141
4142 4142 hg import --config ui.fuzz=7 fuzz.patch
4143 4143
4144 4144 Returns 0 on success, 1 on partial success (see --partial).
4145 4145 """
4146 4146
4147 4147 cmdutil.check_incompatible_arguments(
4148 4148 opts, 'no_commit', ['bypass', 'secret']
4149 4149 )
4150 4150 cmdutil.check_incompatible_arguments(opts, 'exact', ['edit', 'prefix'])
4151 4151 opts = pycompat.byteskwargs(opts)
4152 4152 if not patch1:
4153 4153 raise error.InputError(_(b'need at least one patch to import'))
4154 4154
4155 4155 patches = (patch1,) + patches
4156 4156
4157 4157 date = opts.get(b'date')
4158 4158 if date:
4159 4159 opts[b'date'] = dateutil.parsedate(date)
4160 4160
4161 4161 exact = opts.get(b'exact')
4162 4162 update = not opts.get(b'bypass')
4163 4163 try:
4164 4164 sim = float(opts.get(b'similarity') or 0)
4165 4165 except ValueError:
4166 4166 raise error.InputError(_(b'similarity must be a number'))
4167 4167 if sim < 0 or sim > 100:
4168 4168 raise error.InputError(_(b'similarity must be between 0 and 100'))
4169 4169 if sim and not update:
4170 4170 raise error.InputError(_(b'cannot use --similarity with --bypass'))
4171 4171
4172 4172 base = opts[b"base"]
4173 4173 msgs = []
4174 4174 ret = 0
4175 4175
4176 4176 with repo.wlock():
4177 4177 if update:
4178 4178 cmdutil.checkunfinished(repo)
4179 4179 if exact or not opts.get(b'force'):
4180 4180 cmdutil.bailifchanged(repo)
4181 4181
4182 4182 if not opts.get(b'no_commit'):
4183 4183 lock = repo.lock
4184 4184 tr = lambda: repo.transaction(b'import')
4185 4185 dsguard = util.nullcontextmanager
4186 4186 else:
4187 4187 lock = util.nullcontextmanager
4188 4188 tr = util.nullcontextmanager
4189 4189 dsguard = lambda: dirstateguard.dirstateguard(repo, b'import')
4190 4190 with lock(), tr(), dsguard():
4191 4191 parents = repo[None].parents()
4192 4192 for patchurl in patches:
4193 4193 if patchurl == b'-':
4194 4194 ui.status(_(b'applying patch from stdin\n'))
4195 4195 patchfile = ui.fin
4196 4196 patchurl = b'stdin' # for error message
4197 4197 else:
4198 4198 patchurl = os.path.join(base, patchurl)
4199 4199 ui.status(_(b'applying %s\n') % patchurl)
4200 4200 patchfile = hg.openpath(ui, patchurl, sendaccept=False)
4201 4201
4202 4202 haspatch = False
4203 4203 for hunk in patch.split(patchfile):
4204 4204 with patch.extract(ui, hunk) as patchdata:
4205 4205 msg, node, rej = cmdutil.tryimportone(
4206 4206 ui, repo, patchdata, parents, opts, msgs, hg.clean
4207 4207 )
4208 4208 if msg:
4209 4209 haspatch = True
4210 4210 ui.note(msg + b'\n')
4211 4211 if update or exact:
4212 4212 parents = repo[None].parents()
4213 4213 else:
4214 4214 parents = [repo[node]]
4215 4215 if rej:
4216 4216 ui.write_err(_(b"patch applied partially\n"))
4217 4217 ui.write_err(
4218 4218 _(
4219 4219 b"(fix the .rej files and run "
4220 4220 b"`hg commit --amend`)\n"
4221 4221 )
4222 4222 )
4223 4223 ret = 1
4224 4224 break
4225 4225
4226 4226 if not haspatch:
4227 4227 raise error.InputError(_(b'%s: no diffs found') % patchurl)
4228 4228
4229 4229 if msgs:
4230 4230 repo.savecommitmessage(b'\n* * *\n'.join(msgs))
4231 4231 return ret
4232 4232
4233 4233
4234 4234 @command(
4235 4235 b'incoming|in',
4236 4236 [
4237 4237 (
4238 4238 b'f',
4239 4239 b'force',
4240 4240 None,
4241 4241 _(b'run even if remote repository is unrelated'),
4242 4242 ),
4243 4243 (b'n', b'newest-first', None, _(b'show newest record first')),
4244 4244 (b'', b'bundle', b'', _(b'file to store the bundles into'), _(b'FILE')),
4245 4245 (
4246 4246 b'r',
4247 4247 b'rev',
4248 4248 [],
4249 4249 _(b'a remote changeset intended to be added'),
4250 4250 _(b'REV'),
4251 4251 ),
4252 4252 (b'B', b'bookmarks', False, _(b"compare bookmarks")),
4253 4253 (
4254 4254 b'b',
4255 4255 b'branch',
4256 4256 [],
4257 4257 _(b'a specific branch you would like to pull'),
4258 4258 _(b'BRANCH'),
4259 4259 ),
4260 4260 ]
4261 4261 + logopts
4262 4262 + remoteopts
4263 4263 + subrepoopts,
4264 4264 _(b'[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]'),
4265 4265 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
4266 4266 )
4267 4267 def incoming(ui, repo, source=b"default", **opts):
4268 4268 """show new changesets found in source
4269 4269
4270 4270 Show new changesets found in the specified path/URL or the default
4271 4271 pull location. These are the changesets that would have been pulled
4272 4272 by :hg:`pull` at the time you issued this command.
4273 4273
4274 4274 See pull for valid source format details.
4275 4275
4276 4276 .. container:: verbose
4277 4277
4278 4278 With -B/--bookmarks, the result of bookmark comparison between
4279 4279 local and remote repositories is displayed. With -v/--verbose,
4280 4280 status is also displayed for each bookmark like below::
4281 4281
4282 4282 BM1 01234567890a added
4283 4283 BM2 1234567890ab advanced
4284 4284 BM3 234567890abc diverged
4285 4285 BM4 34567890abcd changed
4286 4286
4287 4287 The action taken locally when pulling depends on the
4288 4288 status of each bookmark:
4289 4289
4290 4290 :``added``: pull will create it
4291 4291 :``advanced``: pull will update it
4292 4292 :``diverged``: pull will create a divergent bookmark
4293 4293 :``changed``: result depends on remote changesets
4294 4294
4295 4295 From the point of view of pulling behavior, bookmark
4296 4296 existing only in the remote repository are treated as ``added``,
4297 4297 even if it is in fact locally deleted.
4298 4298
4299 4299 .. container:: verbose
4300 4300
4301 4301 For remote repository, using --bundle avoids downloading the
4302 4302 changesets twice if the incoming is followed by a pull.
4303 4303
4304 4304 Examples:
4305 4305
4306 4306 - show incoming changes with patches and full description::
4307 4307
4308 4308 hg incoming -vp
4309 4309
4310 4310 - show incoming changes excluding merges, store a bundle::
4311 4311
4312 4312 hg in -vpM --bundle incoming.hg
4313 4313 hg pull incoming.hg
4314 4314
4315 4315 - briefly list changes inside a bundle::
4316 4316
4317 4317 hg in changes.hg -T "{desc|firstline}\\n"
4318 4318
4319 4319 Returns 0 if there are incoming changes, 1 otherwise.
4320 4320 """
4321 4321 opts = pycompat.byteskwargs(opts)
4322 4322 if opts.get(b'graph'):
4323 4323 logcmdutil.checkunsupportedgraphflags([], opts)
4324 4324
4325 4325 def display(other, chlist, displayer):
4326 4326 revdag = logcmdutil.graphrevs(other, chlist, opts)
4327 4327 logcmdutil.displaygraph(
4328 4328 ui, repo, revdag, displayer, graphmod.asciiedges
4329 4329 )
4330 4330
4331 4331 hg._incoming(display, lambda: 1, ui, repo, source, opts, buffered=True)
4332 4332 return 0
4333 4333
4334 4334 cmdutil.check_incompatible_arguments(opts, b'subrepos', [b'bundle'])
4335 4335
4336 4336 if opts.get(b'bookmarks'):
4337 4337 srcs = urlutil.get_pull_paths(repo, ui, [source], opts.get(b'branch'))
4338 4338 for source, branches in srcs:
4339 4339 other = hg.peer(repo, opts, source)
4340 4340 try:
4341 4341 if b'bookmarks' not in other.listkeys(b'namespaces'):
4342 4342 ui.warn(_(b"remote doesn't support bookmarks\n"))
4343 4343 return 0
4344 4344 ui.pager(b'incoming')
4345 4345 ui.status(
4346 4346 _(b'comparing with %s\n') % urlutil.hidepassword(source)
4347 4347 )
4348 4348 return bookmarks.incoming(ui, repo, other)
4349 4349 finally:
4350 4350 other.close()
4351 4351
4352 4352 return hg.incoming(ui, repo, source, opts)
4353 4353
4354 4354
4355 4355 @command(
4356 4356 b'init',
4357 4357 remoteopts,
4358 4358 _(b'[-e CMD] [--remotecmd CMD] [DEST]'),
4359 4359 helpcategory=command.CATEGORY_REPO_CREATION,
4360 4360 helpbasic=True,
4361 4361 norepo=True,
4362 4362 )
4363 4363 def init(ui, dest=b".", **opts):
4364 4364 """create a new repository in the given directory
4365 4365
4366 4366 Initialize a new repository in the given directory. If the given
4367 4367 directory does not exist, it will be created.
4368 4368
4369 4369 If no directory is given, the current directory is used.
4370 4370
4371 4371 It is possible to specify an ``ssh://`` URL as the destination.
4372 4372 See :hg:`help urls` for more information.
4373 4373
4374 4374 Returns 0 on success.
4375 4375 """
4376 4376 opts = pycompat.byteskwargs(opts)
4377 4377 path = urlutil.get_clone_path(ui, dest)[1]
4378 4378 peer = hg.peer(ui, opts, path, create=True)
4379 4379 peer.close()
4380 4380
4381 4381
4382 4382 @command(
4383 4383 b'locate',
4384 4384 [
4385 4385 (
4386 4386 b'r',
4387 4387 b'rev',
4388 4388 b'',
4389 4389 _(b'search the repository as it is in REV'),
4390 4390 _(b'REV'),
4391 4391 ),
4392 4392 (
4393 4393 b'0',
4394 4394 b'print0',
4395 4395 None,
4396 4396 _(b'end filenames with NUL, for use with xargs'),
4397 4397 ),
4398 4398 (
4399 4399 b'f',
4400 4400 b'fullpath',
4401 4401 None,
4402 4402 _(b'print complete paths from the filesystem root'),
4403 4403 ),
4404 4404 ]
4405 4405 + walkopts,
4406 4406 _(b'[OPTION]... [PATTERN]...'),
4407 4407 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
4408 4408 )
4409 4409 def locate(ui, repo, *pats, **opts):
4410 4410 """locate files matching specific patterns (DEPRECATED)
4411 4411
4412 4412 Print files under Mercurial control in the working directory whose
4413 4413 names match the given patterns.
4414 4414
4415 4415 By default, this command searches all directories in the working
4416 4416 directory. To search just the current directory and its
4417 4417 subdirectories, use "--include .".
4418 4418
4419 4419 If no patterns are given to match, this command prints the names
4420 4420 of all files under Mercurial control in the working directory.
4421 4421
4422 4422 If you want to feed the output of this command into the "xargs"
4423 4423 command, use the -0 option to both this command and "xargs". This
4424 4424 will avoid the problem of "xargs" treating single filenames that
4425 4425 contain whitespace as multiple filenames.
4426 4426
4427 4427 See :hg:`help files` for a more versatile command.
4428 4428
4429 4429 Returns 0 if a match is found, 1 otherwise.
4430 4430 """
4431 4431 opts = pycompat.byteskwargs(opts)
4432 4432 if opts.get(b'print0'):
4433 4433 end = b'\0'
4434 4434 else:
4435 4435 end = b'\n'
4436 4436 ctx = scmutil.revsingle(repo, opts.get(b'rev'), None)
4437 4437
4438 4438 ret = 1
4439 4439 m = scmutil.match(
4440 4440 ctx, pats, opts, default=b'relglob', badfn=lambda x, y: False
4441 4441 )
4442 4442
4443 4443 ui.pager(b'locate')
4444 4444 if ctx.rev() is None:
4445 4445 # When run on the working copy, "locate" includes removed files, so
4446 4446 # we get the list of files from the dirstate.
4447 4447 filesgen = sorted(repo.dirstate.matches(m))
4448 4448 else:
4449 4449 filesgen = ctx.matches(m)
4450 4450 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=bool(pats))
4451 4451 for abs in filesgen:
4452 4452 if opts.get(b'fullpath'):
4453 4453 ui.write(repo.wjoin(abs), end)
4454 4454 else:
4455 4455 ui.write(uipathfn(abs), end)
4456 4456 ret = 0
4457 4457
4458 4458 return ret
4459 4459
4460 4460
4461 4461 @command(
4462 4462 b'log|history',
4463 4463 [
4464 4464 (
4465 4465 b'f',
4466 4466 b'follow',
4467 4467 None,
4468 4468 _(
4469 4469 b'follow changeset history, or file history across copies and renames'
4470 4470 ),
4471 4471 ),
4472 4472 (
4473 4473 b'',
4474 4474 b'follow-first',
4475 4475 None,
4476 4476 _(b'only follow the first parent of merge changesets (DEPRECATED)'),
4477 4477 ),
4478 4478 (
4479 4479 b'd',
4480 4480 b'date',
4481 4481 b'',
4482 4482 _(b'show revisions matching date spec'),
4483 4483 _(b'DATE'),
4484 4484 ),
4485 4485 (b'C', b'copies', None, _(b'show copied files')),
4486 4486 (
4487 4487 b'k',
4488 4488 b'keyword',
4489 4489 [],
4490 4490 _(b'do case-insensitive search for a given text'),
4491 4491 _(b'TEXT'),
4492 4492 ),
4493 4493 (
4494 4494 b'r',
4495 4495 b'rev',
4496 4496 [],
4497 4497 _(b'revisions to select or follow from'),
4498 4498 _(b'REV'),
4499 4499 ),
4500 4500 (
4501 4501 b'L',
4502 4502 b'line-range',
4503 4503 [],
4504 4504 _(b'follow line range of specified file (EXPERIMENTAL)'),
4505 4505 _(b'FILE,RANGE'),
4506 4506 ),
4507 4507 (
4508 4508 b'',
4509 4509 b'removed',
4510 4510 None,
4511 4511 _(b'include revisions where files were removed'),
4512 4512 ),
4513 4513 (
4514 4514 b'm',
4515 4515 b'only-merges',
4516 4516 None,
4517 4517 _(b'show only merges (DEPRECATED) (use -r "merge()" instead)'),
4518 4518 ),
4519 4519 (b'u', b'user', [], _(b'revisions committed by user'), _(b'USER')),
4520 4520 (
4521 4521 b'',
4522 4522 b'only-branch',
4523 4523 [],
4524 4524 _(
4525 4525 b'show only changesets within the given named branch (DEPRECATED)'
4526 4526 ),
4527 4527 _(b'BRANCH'),
4528 4528 ),
4529 4529 (
4530 4530 b'b',
4531 4531 b'branch',
4532 4532 [],
4533 4533 _(b'show changesets within the given named branch'),
4534 4534 _(b'BRANCH'),
4535 4535 ),
4536 4536 (
4537 4537 b'B',
4538 4538 b'bookmark',
4539 4539 [],
4540 4540 _(b"show changesets within the given bookmark"),
4541 4541 _(b'BOOKMARK'),
4542 4542 ),
4543 4543 (
4544 4544 b'P',
4545 4545 b'prune',
4546 4546 [],
4547 4547 _(b'do not display revision or any of its ancestors'),
4548 4548 _(b'REV'),
4549 4549 ),
4550 4550 ]
4551 4551 + logopts
4552 4552 + walkopts,
4553 4553 _(b'[OPTION]... [FILE]'),
4554 4554 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
4555 4555 helpbasic=True,
4556 4556 inferrepo=True,
4557 4557 intents={INTENT_READONLY},
4558 4558 )
4559 4559 def log(ui, repo, *pats, **opts):
4560 4560 """show revision history of entire repository or files
4561 4561
4562 4562 Print the revision history of the specified files or the entire
4563 4563 project.
4564 4564
4565 4565 If no revision range is specified, the default is ``tip:0`` unless
4566 4566 --follow is set.
4567 4567
4568 4568 File history is shown without following rename or copy history of
4569 4569 files. Use -f/--follow with a filename to follow history across
4570 4570 renames and copies. --follow without a filename will only show
4571 4571 ancestors of the starting revisions. The starting revisions can be
4572 4572 specified by -r/--rev, which default to the working directory parent.
4573 4573
4574 4574 By default this command prints revision number and changeset id,
4575 4575 tags, non-trivial parents, user, date and time, and a summary for
4576 4576 each commit. When the -v/--verbose switch is used, the list of
4577 4577 changed files and full commit message are shown.
4578 4578
4579 4579 With --graph the revisions are shown as an ASCII art DAG with the most
4580 4580 recent changeset at the top.
4581 4581 'o' is a changeset, '@' is a working directory parent, '%' is a changeset
4582 4582 involved in an unresolved merge conflict, '_' closes a branch,
4583 4583 'x' is obsolete, '*' is unstable, and '+' represents a fork where the
4584 4584 changeset from the lines below is a parent of the 'o' merge on the same
4585 4585 line.
4586 4586 Paths in the DAG are represented with '|', '/' and so forth. ':' in place
4587 4587 of a '|' indicates one or more revisions in a path are omitted.
4588 4588
4589 4589 .. container:: verbose
4590 4590
4591 4591 Use -L/--line-range FILE,M:N options to follow the history of lines
4592 4592 from M to N in FILE. With -p/--patch only diff hunks affecting
4593 4593 specified line range will be shown. This option requires --follow;
4594 4594 it can be specified multiple times. Currently, this option is not
4595 4595 compatible with --graph. This option is experimental.
4596 4596
4597 4597 .. note::
4598 4598
4599 4599 :hg:`log --patch` may generate unexpected diff output for merge
4600 4600 changesets, as it will only compare the merge changeset against
4601 4601 its first parent. Also, only files different from BOTH parents
4602 4602 will appear in files:.
4603 4603
4604 4604 .. note::
4605 4605
4606 4606 For performance reasons, :hg:`log FILE` may omit duplicate changes
4607 4607 made on branches and will not show removals or mode changes. To
4608 4608 see all such changes, use the --removed switch.
4609 4609
4610 4610 .. container:: verbose
4611 4611
4612 4612 .. note::
4613 4613
4614 4614 The history resulting from -L/--line-range options depends on diff
4615 4615 options; for instance if white-spaces are ignored, respective changes
4616 4616 with only white-spaces in specified line range will not be listed.
4617 4617
4618 4618 .. container:: verbose
4619 4619
4620 4620 Some examples:
4621 4621
4622 4622 - changesets with full descriptions and file lists::
4623 4623
4624 4624 hg log -v
4625 4625
4626 4626 - changesets ancestral to the working directory::
4627 4627
4628 4628 hg log -f
4629 4629
4630 4630 - last 10 commits on the current branch::
4631 4631
4632 4632 hg log -l 10 -b .
4633 4633
4634 4634 - changesets showing all modifications of a file, including removals::
4635 4635
4636 4636 hg log --removed file.c
4637 4637
4638 4638 - all changesets that touch a directory, with diffs, excluding merges::
4639 4639
4640 4640 hg log -Mp lib/
4641 4641
4642 4642 - all revision numbers that match a keyword::
4643 4643
4644 4644 hg log -k bug --template "{rev}\\n"
4645 4645
4646 4646 - the full hash identifier of the working directory parent::
4647 4647
4648 4648 hg log -r . --template "{node}\\n"
4649 4649
4650 4650 - list available log templates::
4651 4651
4652 4652 hg log -T list
4653 4653
4654 4654 - check if a given changeset is included in a tagged release::
4655 4655
4656 4656 hg log -r "a21ccf and ancestor(1.9)"
4657 4657
4658 4658 - find all changesets by some user in a date range::
4659 4659
4660 4660 hg log -k alice -d "may 2008 to jul 2008"
4661 4661
4662 4662 - summary of all changesets after the last tag::
4663 4663
4664 4664 hg log -r "last(tagged())::" --template "{desc|firstline}\\n"
4665 4665
4666 4666 - changesets touching lines 13 to 23 for file.c::
4667 4667
4668 4668 hg log -L file.c,13:23
4669 4669
4670 4670 - changesets touching lines 13 to 23 for file.c and lines 2 to 6 of
4671 4671 main.c with patch::
4672 4672
4673 4673 hg log -L file.c,13:23 -L main.c,2:6 -p
4674 4674
4675 4675 See :hg:`help dates` for a list of formats valid for -d/--date.
4676 4676
4677 4677 See :hg:`help revisions` for more about specifying and ordering
4678 4678 revisions.
4679 4679
4680 4680 See :hg:`help templates` for more about pre-packaged styles and
4681 4681 specifying custom templates. The default template used by the log
4682 4682 command can be customized via the ``command-templates.log`` configuration
4683 4683 setting.
4684 4684
4685 4685 Returns 0 on success.
4686 4686
4687 4687 """
4688 4688 opts = pycompat.byteskwargs(opts)
4689 4689 linerange = opts.get(b'line_range')
4690 4690
4691 4691 if linerange and not opts.get(b'follow'):
4692 4692 raise error.InputError(_(b'--line-range requires --follow'))
4693 4693
4694 4694 if linerange and pats:
4695 4695 # TODO: take pats as patterns with no line-range filter
4696 4696 raise error.InputError(
4697 4697 _(b'FILE arguments are not compatible with --line-range option')
4698 4698 )
4699 4699
4700 4700 repo = scmutil.unhidehashlikerevs(repo, opts.get(b'rev'), b'nowarn')
4701 4701 walk_opts = logcmdutil.parseopts(ui, pats, opts)
4702 4702 revs, differ = logcmdutil.getrevs(repo, walk_opts)
4703 4703 if linerange:
4704 4704 # TODO: should follow file history from logcmdutil._initialrevs(),
4705 4705 # then filter the result by logcmdutil._makerevset() and --limit
4706 4706 revs, differ = logcmdutil.getlinerangerevs(repo, revs, opts)
4707 4707
4708 4708 getcopies = None
4709 4709 if opts.get(b'copies'):
4710 4710 endrev = None
4711 4711 if revs:
4712 4712 endrev = revs.max() + 1
4713 4713 getcopies = scmutil.getcopiesfn(repo, endrev=endrev)
4714 4714
4715 4715 ui.pager(b'log')
4716 4716 displayer = logcmdutil.changesetdisplayer(
4717 4717 ui, repo, opts, differ, buffered=True
4718 4718 )
4719 4719 if opts.get(b'graph'):
4720 4720 displayfn = logcmdutil.displaygraphrevs
4721 4721 else:
4722 4722 displayfn = logcmdutil.displayrevs
4723 4723 displayfn(ui, repo, revs, displayer, getcopies)
4724 4724
4725 4725
4726 4726 @command(
4727 4727 b'manifest',
4728 4728 [
4729 4729 (b'r', b'rev', b'', _(b'revision to display'), _(b'REV')),
4730 4730 (b'', b'all', False, _(b"list files from all revisions")),
4731 4731 ]
4732 4732 + formatteropts,
4733 4733 _(b'[-r REV]'),
4734 4734 helpcategory=command.CATEGORY_MAINTENANCE,
4735 4735 intents={INTENT_READONLY},
4736 4736 )
4737 4737 def manifest(ui, repo, node=None, rev=None, **opts):
4738 4738 """output the current or given revision of the project manifest
4739 4739
4740 4740 Print a list of version controlled files for the given revision.
4741 4741 If no revision is given, the first parent of the working directory
4742 4742 is used, or the null revision if no revision is checked out.
4743 4743
4744 4744 With -v, print file permissions, symlink and executable bits.
4745 4745 With --debug, print file revision hashes.
4746 4746
4747 4747 If option --all is specified, the list of all files from all revisions
4748 4748 is printed. This includes deleted and renamed files.
4749 4749
4750 4750 Returns 0 on success.
4751 4751 """
4752 4752 opts = pycompat.byteskwargs(opts)
4753 4753 fm = ui.formatter(b'manifest', opts)
4754 4754
4755 4755 if opts.get(b'all'):
4756 4756 if rev or node:
4757 4757 raise error.InputError(_(b"can't specify a revision with --all"))
4758 4758
4759 4759 res = set()
4760 4760 for rev in repo:
4761 4761 ctx = repo[rev]
4762 4762 res |= set(ctx.files())
4763 4763
4764 4764 ui.pager(b'manifest')
4765 4765 for f in sorted(res):
4766 4766 fm.startitem()
4767 4767 fm.write(b"path", b'%s\n', f)
4768 4768 fm.end()
4769 4769 return
4770 4770
4771 4771 if rev and node:
4772 4772 raise error.InputError(_(b"please specify just one revision"))
4773 4773
4774 4774 if not node:
4775 4775 node = rev
4776 4776
4777 4777 char = {b'l': b'@', b'x': b'*', b'': b'', b't': b'd'}
4778 4778 mode = {b'l': b'644', b'x': b'755', b'': b'644', b't': b'755'}
4779 4779 if node:
4780 4780 repo = scmutil.unhidehashlikerevs(repo, [node], b'nowarn')
4781 4781 ctx = scmutil.revsingle(repo, node)
4782 4782 mf = ctx.manifest()
4783 4783 ui.pager(b'manifest')
4784 4784 for f in ctx:
4785 4785 fm.startitem()
4786 4786 fm.context(ctx=ctx)
4787 4787 fl = ctx[f].flags()
4788 4788 fm.condwrite(ui.debugflag, b'hash', b'%s ', hex(mf[f]))
4789 4789 fm.condwrite(ui.verbose, b'mode type', b'%s %1s ', mode[fl], char[fl])
4790 4790 fm.write(b'path', b'%s\n', f)
4791 4791 fm.end()
4792 4792
4793 4793
4794 4794 @command(
4795 4795 b'merge',
4796 4796 [
4797 4797 (
4798 4798 b'f',
4799 4799 b'force',
4800 4800 None,
4801 4801 _(b'force a merge including outstanding changes (DEPRECATED)'),
4802 4802 ),
4803 4803 (b'r', b'rev', b'', _(b'revision to merge'), _(b'REV')),
4804 4804 (
4805 4805 b'P',
4806 4806 b'preview',
4807 4807 None,
4808 4808 _(b'review revisions to merge (no merge is performed)'),
4809 4809 ),
4810 4810 (b'', b'abort', None, _(b'abort the ongoing merge')),
4811 4811 ]
4812 4812 + mergetoolopts,
4813 4813 _(b'[-P] [[-r] REV]'),
4814 4814 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
4815 4815 helpbasic=True,
4816 4816 )
4817 4817 def merge(ui, repo, node=None, **opts):
4818 4818 """merge another revision into working directory
4819 4819
4820 4820 The current working directory is updated with all changes made in
4821 4821 the requested revision since the last common predecessor revision.
4822 4822
4823 4823 Files that changed between either parent are marked as changed for
4824 4824 the next commit and a commit must be performed before any further
4825 4825 updates to the repository are allowed. The next commit will have
4826 4826 two parents.
4827 4827
4828 4828 ``--tool`` can be used to specify the merge tool used for file
4829 4829 merges. It overrides the HGMERGE environment variable and your
4830 4830 configuration files. See :hg:`help merge-tools` for options.
4831 4831
4832 4832 If no revision is specified, the working directory's parent is a
4833 4833 head revision, and the current branch contains exactly one other
4834 4834 head, the other head is merged with by default. Otherwise, an
4835 4835 explicit revision with which to merge must be provided.
4836 4836
4837 4837 See :hg:`help resolve` for information on handling file conflicts.
4838 4838
4839 4839 To undo an uncommitted merge, use :hg:`merge --abort` which
4840 4840 will check out a clean copy of the original merge parent, losing
4841 4841 all changes.
4842 4842
4843 4843 Returns 0 on success, 1 if there are unresolved files.
4844 4844 """
4845 4845
4846 4846 opts = pycompat.byteskwargs(opts)
4847 4847 abort = opts.get(b'abort')
4848 4848 if abort and repo.dirstate.p2() == repo.nullid:
4849 4849 cmdutil.wrongtooltocontinue(repo, _(b'merge'))
4850 4850 cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview'])
4851 4851 if abort:
4852 4852 state = cmdutil.getunfinishedstate(repo)
4853 4853 if state and state._opname != b'merge':
4854 4854 raise error.StateError(
4855 4855 _(b'cannot abort merge with %s in progress') % (state._opname),
4856 4856 hint=state.hint(),
4857 4857 )
4858 4858 if node:
4859 4859 raise error.InputError(_(b"cannot specify a node with --abort"))
4860 4860 return hg.abortmerge(repo.ui, repo)
4861 4861
4862 4862 if opts.get(b'rev') and node:
4863 4863 raise error.InputError(_(b"please specify just one revision"))
4864 4864 if not node:
4865 4865 node = opts.get(b'rev')
4866 4866
4867 4867 if node:
4868 4868 ctx = scmutil.revsingle(repo, node)
4869 4869 else:
4870 4870 if ui.configbool(b'commands', b'merge.require-rev'):
4871 4871 raise error.InputError(
4872 4872 _(
4873 4873 b'configuration requires specifying revision to merge '
4874 4874 b'with'
4875 4875 )
4876 4876 )
4877 4877 ctx = repo[destutil.destmerge(repo)]
4878 4878
4879 4879 if ctx.node() is None:
4880 4880 raise error.InputError(
4881 4881 _(b'merging with the working copy has no effect')
4882 4882 )
4883 4883
4884 4884 if opts.get(b'preview'):
4885 4885 # find nodes that are ancestors of p2 but not of p1
4886 4886 p1 = repo[b'.'].node()
4887 4887 p2 = ctx.node()
4888 4888 nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
4889 4889
4890 4890 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
4891 4891 for node in nodes:
4892 4892 displayer.show(repo[node])
4893 4893 displayer.close()
4894 4894 return 0
4895 4895
4896 4896 # ui.forcemerge is an internal variable, do not document
4897 4897 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
4898 4898 with ui.configoverride(overrides, b'merge'):
4899 4899 force = opts.get(b'force')
4900 4900 labels = [b'working copy', b'merge rev']
4901 4901 return hg.merge(ctx, force=force, labels=labels)
4902 4902
4903 4903
4904 4904 statemod.addunfinished(
4905 4905 b'merge',
4906 4906 fname=None,
4907 4907 clearable=True,
4908 4908 allowcommit=True,
4909 4909 cmdmsg=_(b'outstanding uncommitted merge'),
4910 4910 abortfunc=hg.abortmerge,
4911 4911 statushint=_(
4912 4912 b'To continue: hg commit\nTo abort: hg merge --abort'
4913 4913 ),
4914 4914 cmdhint=_(b"use 'hg commit' or 'hg merge --abort'"),
4915 4915 )
4916 4916
4917 4917
4918 4918 @command(
4919 4919 b'outgoing|out',
4920 4920 [
4921 4921 (
4922 4922 b'f',
4923 4923 b'force',
4924 4924 None,
4925 4925 _(b'run even when the destination is unrelated'),
4926 4926 ),
4927 4927 (
4928 4928 b'r',
4929 4929 b'rev',
4930 4930 [],
4931 4931 _(b'a changeset intended to be included in the destination'),
4932 4932 _(b'REV'),
4933 4933 ),
4934 4934 (b'n', b'newest-first', None, _(b'show newest record first')),
4935 4935 (b'B', b'bookmarks', False, _(b'compare bookmarks')),
4936 4936 (
4937 4937 b'b',
4938 4938 b'branch',
4939 4939 [],
4940 4940 _(b'a specific branch you would like to push'),
4941 4941 _(b'BRANCH'),
4942 4942 ),
4943 4943 ]
4944 4944 + logopts
4945 4945 + remoteopts
4946 4946 + subrepoopts,
4947 4947 _(b'[-M] [-p] [-n] [-f] [-r REV]... [DEST]...'),
4948 4948 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
4949 4949 )
4950 4950 def outgoing(ui, repo, *dests, **opts):
4951 4951 """show changesets not found in the destination
4952 4952
4953 4953 Show changesets not found in the specified destination repository
4954 4954 or the default push location. These are the changesets that would
4955 4955 be pushed if a push was requested.
4956 4956
4957 4957 See pull for details of valid destination formats.
4958 4958
4959 4959 .. container:: verbose
4960 4960
4961 4961 With -B/--bookmarks, the result of bookmark comparison between
4962 4962 local and remote repositories is displayed. With -v/--verbose,
4963 4963 status is also displayed for each bookmark like below::
4964 4964
4965 4965 BM1 01234567890a added
4966 4966 BM2 deleted
4967 4967 BM3 234567890abc advanced
4968 4968 BM4 34567890abcd diverged
4969 4969 BM5 4567890abcde changed
4970 4970
4971 4971 The action taken when pushing depends on the
4972 4972 status of each bookmark:
4973 4973
4974 4974 :``added``: push with ``-B`` will create it
4975 4975 :``deleted``: push with ``-B`` will delete it
4976 4976 :``advanced``: push will update it
4977 4977 :``diverged``: push with ``-B`` will update it
4978 4978 :``changed``: push with ``-B`` will update it
4979 4979
4980 4980 From the point of view of pushing behavior, bookmarks
4981 4981 existing only in the remote repository are treated as
4982 4982 ``deleted``, even if it is in fact added remotely.
4983 4983
4984 4984 Returns 0 if there are outgoing changes, 1 otherwise.
4985 4985 """
4986 4986 opts = pycompat.byteskwargs(opts)
4987 4987 if opts.get(b'bookmarks'):
4988 4988 for path in urlutil.get_push_paths(repo, ui, dests):
4989 4989 dest = path.pushloc or path.loc
4990 4990 other = hg.peer(repo, opts, dest)
4991 4991 try:
4992 4992 if b'bookmarks' not in other.listkeys(b'namespaces'):
4993 4993 ui.warn(_(b"remote doesn't support bookmarks\n"))
4994 4994 return 0
4995 4995 ui.status(
4996 4996 _(b'comparing with %s\n') % urlutil.hidepassword(dest)
4997 4997 )
4998 4998 ui.pager(b'outgoing')
4999 4999 return bookmarks.outgoing(ui, repo, other)
5000 5000 finally:
5001 5001 other.close()
5002 5002
5003 5003 return hg.outgoing(ui, repo, dests, opts)
5004 5004
5005 5005
5006 5006 @command(
5007 5007 b'parents',
5008 5008 [
5009 5009 (
5010 5010 b'r',
5011 5011 b'rev',
5012 5012 b'',
5013 5013 _(b'show parents of the specified revision'),
5014 5014 _(b'REV'),
5015 5015 ),
5016 5016 ]
5017 5017 + templateopts,
5018 5018 _(b'[-r REV] [FILE]'),
5019 5019 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
5020 5020 inferrepo=True,
5021 5021 )
5022 5022 def parents(ui, repo, file_=None, **opts):
5023 5023 """show the parents of the working directory or revision (DEPRECATED)
5024 5024
5025 5025 Print the working directory's parent revisions. If a revision is
5026 5026 given via -r/--rev, the parent of that revision will be printed.
5027 5027 If a file argument is given, the revision in which the file was
5028 5028 last changed (before the working directory revision or the
5029 5029 argument to --rev if given) is printed.
5030 5030
5031 5031 This command is equivalent to::
5032 5032
5033 5033 hg log -r "p1()+p2()" or
5034 5034 hg log -r "p1(REV)+p2(REV)" or
5035 5035 hg log -r "max(::p1() and file(FILE))+max(::p2() and file(FILE))" or
5036 5036 hg log -r "max(::p1(REV) and file(FILE))+max(::p2(REV) and file(FILE))"
5037 5037
5038 5038 See :hg:`summary` and :hg:`help revsets` for related information.
5039 5039
5040 5040 Returns 0 on success.
5041 5041 """
5042 5042
5043 5043 opts = pycompat.byteskwargs(opts)
5044 5044 rev = opts.get(b'rev')
5045 5045 if rev:
5046 5046 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
5047 5047 ctx = scmutil.revsingle(repo, rev, None)
5048 5048
5049 5049 if file_:
5050 5050 m = scmutil.match(ctx, (file_,), opts)
5051 5051 if m.anypats() or len(m.files()) != 1:
5052 5052 raise error.InputError(_(b'can only specify an explicit filename'))
5053 5053 file_ = m.files()[0]
5054 5054 filenodes = []
5055 5055 for cp in ctx.parents():
5056 5056 if not cp:
5057 5057 continue
5058 5058 try:
5059 5059 filenodes.append(cp.filenode(file_))
5060 5060 except error.LookupError:
5061 5061 pass
5062 5062 if not filenodes:
5063 5063 raise error.InputError(_(b"'%s' not found in manifest") % file_)
5064 5064 p = []
5065 5065 for fn in filenodes:
5066 5066 fctx = repo.filectx(file_, fileid=fn)
5067 5067 p.append(fctx.node())
5068 5068 else:
5069 5069 p = [cp.node() for cp in ctx.parents()]
5070 5070
5071 5071 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
5072 5072 for n in p:
5073 5073 if n != repo.nullid:
5074 5074 displayer.show(repo[n])
5075 5075 displayer.close()
5076 5076
5077 5077
5078 5078 @command(
5079 5079 b'paths',
5080 5080 formatteropts,
5081 5081 _(b'[NAME]'),
5082 5082 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
5083 5083 optionalrepo=True,
5084 5084 intents={INTENT_READONLY},
5085 5085 )
5086 5086 def paths(ui, repo, search=None, **opts):
5087 5087 """show aliases for remote repositories
5088 5088
5089 5089 Show definition of symbolic path name NAME. If no name is given,
5090 5090 show definition of all available names.
5091 5091
5092 5092 Option -q/--quiet suppresses all output when searching for NAME
5093 5093 and shows only the path names when listing all definitions.
5094 5094
5095 5095 Path names are defined in the [paths] section of your
5096 5096 configuration file and in ``/etc/mercurial/hgrc``. If run inside a
5097 5097 repository, ``.hg/hgrc`` is used, too.
5098 5098
5099 5099 The path names ``default`` and ``default-push`` have a special
5100 5100 meaning. When performing a push or pull operation, they are used
5101 5101 as fallbacks if no location is specified on the command-line.
5102 5102 When ``default-push`` is set, it will be used for push and
5103 5103 ``default`` will be used for pull; otherwise ``default`` is used
5104 5104 as the fallback for both. When cloning a repository, the clone
5105 5105 source is written as ``default`` in ``.hg/hgrc``.
5106 5106
5107 5107 .. note::
5108 5108
5109 5109 ``default`` and ``default-push`` apply to all inbound (e.g.
5110 5110 :hg:`incoming`) and outbound (e.g. :hg:`outgoing`, :hg:`email`
5111 5111 and :hg:`bundle`) operations.
5112 5112
5113 5113 See :hg:`help urls` for more information.
5114 5114
5115 5115 .. container:: verbose
5116 5116
5117 5117 Template:
5118 5118
5119 5119 The following keywords are supported. See also :hg:`help templates`.
5120 5120
5121 5121 :name: String. Symbolic name of the path alias.
5122 5122 :pushurl: String. URL for push operations.
5123 5123 :url: String. URL or directory path for the other operations.
5124 5124
5125 5125 Returns 0 on success.
5126 5126 """
5127 5127
5128 5128 opts = pycompat.byteskwargs(opts)
5129
5130 pathitems = urlutil.list_paths(ui, search)
5129 5131 ui.pager(b'paths')
5130 if search:
5131 pathitems = [
5132 (name, path)
5133 for name, path in pycompat.iteritems(ui.paths)
5134 if name == search
5135 ]
5136 else:
5137 pathitems = sorted(pycompat.iteritems(ui.paths))
5138 5132
5139 5133 fm = ui.formatter(b'paths', opts)
5140 5134 if fm.isplain():
5141 5135 hidepassword = urlutil.hidepassword
5142 5136 else:
5143 5137 hidepassword = bytes
5144 5138 if ui.quiet:
5145 5139 namefmt = b'%s\n'
5146 5140 else:
5147 5141 namefmt = b'%s = '
5148 5142 showsubopts = not search and not ui.quiet
5149 5143
5150 5144 for name, path in pathitems:
5151 5145 fm.startitem()
5152 5146 fm.condwrite(not search, b'name', namefmt, name)
5153 5147 fm.condwrite(not ui.quiet, b'url', b'%s\n', hidepassword(path.rawloc))
5154 5148 for subopt, value in sorted(path.suboptions.items()):
5155 5149 assert subopt not in (b'name', b'url')
5156 5150 if showsubopts:
5157 5151 fm.plain(b'%s:%s = ' % (name, subopt))
5158 5152 fm.condwrite(showsubopts, subopt, b'%s\n', value)
5159 5153
5160 5154 fm.end()
5161 5155
5162 5156 if search and not pathitems:
5163 5157 if not ui.quiet:
5164 5158 ui.warn(_(b"not found!\n"))
5165 5159 return 1
5166 5160 else:
5167 5161 return 0
5168 5162
5169 5163
5170 5164 @command(
5171 5165 b'phase',
5172 5166 [
5173 5167 (b'p', b'public', False, _(b'set changeset phase to public')),
5174 5168 (b'd', b'draft', False, _(b'set changeset phase to draft')),
5175 5169 (b's', b'secret', False, _(b'set changeset phase to secret')),
5176 5170 (b'f', b'force', False, _(b'allow to move boundary backward')),
5177 5171 (b'r', b'rev', [], _(b'target revision'), _(b'REV')),
5178 5172 ],
5179 5173 _(b'[-p|-d|-s] [-f] [-r] [REV...]'),
5180 5174 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
5181 5175 )
5182 5176 def phase(ui, repo, *revs, **opts):
5183 5177 """set or show the current phase name
5184 5178
5185 5179 With no argument, show the phase name of the current revision(s).
5186 5180
5187 5181 With one of -p/--public, -d/--draft or -s/--secret, change the
5188 5182 phase value of the specified revisions.
5189 5183
5190 5184 Unless -f/--force is specified, :hg:`phase` won't move changesets from a
5191 5185 lower phase to a higher phase. Phases are ordered as follows::
5192 5186
5193 5187 public < draft < secret
5194 5188
5195 5189 Returns 0 on success, 1 if some phases could not be changed.
5196 5190
5197 5191 (For more information about the phases concept, see :hg:`help phases`.)
5198 5192 """
5199 5193 opts = pycompat.byteskwargs(opts)
5200 5194 # search for a unique phase argument
5201 5195 targetphase = None
5202 5196 for idx, name in enumerate(phases.cmdphasenames):
5203 5197 if opts[name]:
5204 5198 if targetphase is not None:
5205 5199 raise error.InputError(_(b'only one phase can be specified'))
5206 5200 targetphase = idx
5207 5201
5208 5202 # look for specified revision
5209 5203 revs = list(revs)
5210 5204 revs.extend(opts[b'rev'])
5211 5205 if not revs:
5212 5206 # display both parents as the second parent phase can influence
5213 5207 # the phase of a merge commit
5214 5208 revs = [c.rev() for c in repo[None].parents()]
5215 5209
5216 5210 revs = scmutil.revrange(repo, revs)
5217 5211
5218 5212 ret = 0
5219 5213 if targetphase is None:
5220 5214 # display
5221 5215 for r in revs:
5222 5216 ctx = repo[r]
5223 5217 ui.write(b'%i: %s\n' % (ctx.rev(), ctx.phasestr()))
5224 5218 else:
5225 5219 with repo.lock(), repo.transaction(b"phase") as tr:
5226 5220 # set phase
5227 5221 if not revs:
5228 5222 raise error.InputError(_(b'empty revision set'))
5229 5223 nodes = [repo[r].node() for r in revs]
5230 5224 # moving revision from public to draft may hide them
5231 5225 # We have to check result on an unfiltered repository
5232 5226 unfi = repo.unfiltered()
5233 5227 getphase = unfi._phasecache.phase
5234 5228 olddata = [getphase(unfi, r) for r in unfi]
5235 5229 phases.advanceboundary(repo, tr, targetphase, nodes)
5236 5230 if opts[b'force']:
5237 5231 phases.retractboundary(repo, tr, targetphase, nodes)
5238 5232 getphase = unfi._phasecache.phase
5239 5233 newdata = [getphase(unfi, r) for r in unfi]
5240 5234 changes = sum(newdata[r] != olddata[r] for r in unfi)
5241 5235 cl = unfi.changelog
5242 5236 rejected = [n for n in nodes if newdata[cl.rev(n)] < targetphase]
5243 5237 if rejected:
5244 5238 ui.warn(
5245 5239 _(
5246 5240 b'cannot move %i changesets to a higher '
5247 5241 b'phase, use --force\n'
5248 5242 )
5249 5243 % len(rejected)
5250 5244 )
5251 5245 ret = 1
5252 5246 if changes:
5253 5247 msg = _(b'phase changed for %i changesets\n') % changes
5254 5248 if ret:
5255 5249 ui.status(msg)
5256 5250 else:
5257 5251 ui.note(msg)
5258 5252 else:
5259 5253 ui.warn(_(b'no phases changed\n'))
5260 5254 return ret
5261 5255
5262 5256
5263 5257 def postincoming(ui, repo, modheads, optupdate, checkout, brev):
5264 5258 """Run after a changegroup has been added via pull/unbundle
5265 5259
5266 5260 This takes arguments below:
5267 5261
5268 5262 :modheads: change of heads by pull/unbundle
5269 5263 :optupdate: updating working directory is needed or not
5270 5264 :checkout: update destination revision (or None to default destination)
5271 5265 :brev: a name, which might be a bookmark to be activated after updating
5272 5266
5273 5267 return True if update raise any conflict, False otherwise.
5274 5268 """
5275 5269 if modheads == 0:
5276 5270 return False
5277 5271 if optupdate:
5278 5272 try:
5279 5273 return hg.updatetotally(ui, repo, checkout, brev)
5280 5274 except error.UpdateAbort as inst:
5281 5275 msg = _(b"not updating: %s") % stringutil.forcebytestr(inst)
5282 5276 hint = inst.hint
5283 5277 raise error.UpdateAbort(msg, hint=hint)
5284 5278 if modheads is not None and modheads > 1:
5285 5279 currentbranchheads = len(repo.branchheads())
5286 5280 if currentbranchheads == modheads:
5287 5281 ui.status(
5288 5282 _(b"(run 'hg heads' to see heads, 'hg merge' to merge)\n")
5289 5283 )
5290 5284 elif currentbranchheads > 1:
5291 5285 ui.status(
5292 5286 _(b"(run 'hg heads .' to see heads, 'hg merge' to merge)\n")
5293 5287 )
5294 5288 else:
5295 5289 ui.status(_(b"(run 'hg heads' to see heads)\n"))
5296 5290 elif not ui.configbool(b'commands', b'update.requiredest'):
5297 5291 ui.status(_(b"(run 'hg update' to get a working copy)\n"))
5298 5292 return False
5299 5293
5300 5294
5301 5295 @command(
5302 5296 b'pull',
5303 5297 [
5304 5298 (
5305 5299 b'u',
5306 5300 b'update',
5307 5301 None,
5308 5302 _(b'update to new branch head if new descendants were pulled'),
5309 5303 ),
5310 5304 (
5311 5305 b'f',
5312 5306 b'force',
5313 5307 None,
5314 5308 _(b'run even when remote repository is unrelated'),
5315 5309 ),
5316 5310 (
5317 5311 b'',
5318 5312 b'confirm',
5319 5313 None,
5320 5314 _(b'confirm pull before applying changes'),
5321 5315 ),
5322 5316 (
5323 5317 b'r',
5324 5318 b'rev',
5325 5319 [],
5326 5320 _(b'a remote changeset intended to be added'),
5327 5321 _(b'REV'),
5328 5322 ),
5329 5323 (b'B', b'bookmark', [], _(b"bookmark to pull"), _(b'BOOKMARK')),
5330 5324 (
5331 5325 b'b',
5332 5326 b'branch',
5333 5327 [],
5334 5328 _(b'a specific branch you would like to pull'),
5335 5329 _(b'BRANCH'),
5336 5330 ),
5337 5331 ]
5338 5332 + remoteopts,
5339 5333 _(b'[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]...'),
5340 5334 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
5341 5335 helpbasic=True,
5342 5336 )
5343 5337 def pull(ui, repo, *sources, **opts):
5344 5338 """pull changes from the specified source
5345 5339
5346 5340 Pull changes from a remote repository to a local one.
5347 5341
5348 5342 This finds all changes from the repository at the specified path
5349 5343 or URL and adds them to a local repository (the current one unless
5350 5344 -R is specified). By default, this does not update the copy of the
5351 5345 project in the working directory.
5352 5346
5353 5347 When cloning from servers that support it, Mercurial may fetch
5354 5348 pre-generated data. When this is done, hooks operating on incoming
5355 5349 changesets and changegroups may fire more than once, once for each
5356 5350 pre-generated bundle and as well as for any additional remaining
5357 5351 data. See :hg:`help -e clonebundles` for more.
5358 5352
5359 5353 Use :hg:`incoming` if you want to see what would have been added
5360 5354 by a pull at the time you issued this command. If you then decide
5361 5355 to add those changes to the repository, you should use :hg:`pull
5362 5356 -r X` where ``X`` is the last changeset listed by :hg:`incoming`.
5363 5357
5364 5358 If SOURCE is omitted, the 'default' path will be used.
5365 5359 See :hg:`help urls` for more information.
5366 5360
5367 5361 If multiple sources are specified, they will be pulled sequentially as if
5368 5362 the command was run multiple time. If --update is specify and the command
5369 5363 will stop at the first failed --update.
5370 5364
5371 5365 Specifying bookmark as ``.`` is equivalent to specifying the active
5372 5366 bookmark's name.
5373 5367
5374 5368 Returns 0 on success, 1 if an update had unresolved files.
5375 5369 """
5376 5370
5377 5371 opts = pycompat.byteskwargs(opts)
5378 5372 if ui.configbool(b'commands', b'update.requiredest') and opts.get(
5379 5373 b'update'
5380 5374 ):
5381 5375 msg = _(b'update destination required by configuration')
5382 5376 hint = _(b'use hg pull followed by hg update DEST')
5383 5377 raise error.InputError(msg, hint=hint)
5384 5378
5385 5379 sources = urlutil.get_pull_paths(repo, ui, sources, opts.get(b'branch'))
5386 5380 for source, branches in sources:
5387 5381 ui.status(_(b'pulling from %s\n') % urlutil.hidepassword(source))
5388 5382 ui.flush()
5389 5383 other = hg.peer(repo, opts, source)
5390 5384 update_conflict = None
5391 5385 try:
5392 5386 revs, checkout = hg.addbranchrevs(
5393 5387 repo, other, branches, opts.get(b'rev')
5394 5388 )
5395 5389
5396 5390 pullopargs = {}
5397 5391
5398 5392 nodes = None
5399 5393 if opts.get(b'bookmark') or revs:
5400 5394 # The list of bookmark used here is the same used to actually update
5401 5395 # the bookmark names, to avoid the race from issue 4689 and we do
5402 5396 # all lookup and bookmark queries in one go so they see the same
5403 5397 # version of the server state (issue 4700).
5404 5398 nodes = []
5405 5399 fnodes = []
5406 5400 revs = revs or []
5407 5401 if revs and not other.capable(b'lookup'):
5408 5402 err = _(
5409 5403 b"other repository doesn't support revision lookup, "
5410 5404 b"so a rev cannot be specified."
5411 5405 )
5412 5406 raise error.Abort(err)
5413 5407 with other.commandexecutor() as e:
5414 5408 fremotebookmarks = e.callcommand(
5415 5409 b'listkeys', {b'namespace': b'bookmarks'}
5416 5410 )
5417 5411 for r in revs:
5418 5412 fnodes.append(e.callcommand(b'lookup', {b'key': r}))
5419 5413 remotebookmarks = fremotebookmarks.result()
5420 5414 remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks)
5421 5415 pullopargs[b'remotebookmarks'] = remotebookmarks
5422 5416 for b in opts.get(b'bookmark', []):
5423 5417 b = repo._bookmarks.expandname(b)
5424 5418 if b not in remotebookmarks:
5425 5419 raise error.InputError(
5426 5420 _(b'remote bookmark %s not found!') % b
5427 5421 )
5428 5422 nodes.append(remotebookmarks[b])
5429 5423 for i, rev in enumerate(revs):
5430 5424 node = fnodes[i].result()
5431 5425 nodes.append(node)
5432 5426 if rev == checkout:
5433 5427 checkout = node
5434 5428
5435 5429 wlock = util.nullcontextmanager()
5436 5430 if opts.get(b'update'):
5437 5431 wlock = repo.wlock()
5438 5432 with wlock:
5439 5433 pullopargs.update(opts.get(b'opargs', {}))
5440 5434 modheads = exchange.pull(
5441 5435 repo,
5442 5436 other,
5443 5437 heads=nodes,
5444 5438 force=opts.get(b'force'),
5445 5439 bookmarks=opts.get(b'bookmark', ()),
5446 5440 opargs=pullopargs,
5447 5441 confirm=opts.get(b'confirm'),
5448 5442 ).cgresult
5449 5443
5450 5444 # brev is a name, which might be a bookmark to be activated at
5451 5445 # the end of the update. In other words, it is an explicit
5452 5446 # destination of the update
5453 5447 brev = None
5454 5448
5455 5449 if checkout:
5456 5450 checkout = repo.unfiltered().changelog.rev(checkout)
5457 5451
5458 5452 # order below depends on implementation of
5459 5453 # hg.addbranchrevs(). opts['bookmark'] is ignored,
5460 5454 # because 'checkout' is determined without it.
5461 5455 if opts.get(b'rev'):
5462 5456 brev = opts[b'rev'][0]
5463 5457 elif opts.get(b'branch'):
5464 5458 brev = opts[b'branch'][0]
5465 5459 else:
5466 5460 brev = branches[0]
5467 5461 repo._subtoppath = source
5468 5462 try:
5469 5463 update_conflict = postincoming(
5470 5464 ui, repo, modheads, opts.get(b'update'), checkout, brev
5471 5465 )
5472 5466 except error.FilteredRepoLookupError as exc:
5473 5467 msg = _(b'cannot update to target: %s') % exc.args[0]
5474 5468 exc.args = (msg,) + exc.args[1:]
5475 5469 raise
5476 5470 finally:
5477 5471 del repo._subtoppath
5478 5472
5479 5473 finally:
5480 5474 other.close()
5481 5475 # skip the remaining pull source if they are some conflict.
5482 5476 if update_conflict:
5483 5477 break
5484 5478 if update_conflict:
5485 5479 return 1
5486 5480 else:
5487 5481 return 0
5488 5482
5489 5483
5490 5484 @command(
5491 5485 b'purge|clean',
5492 5486 [
5493 5487 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
5494 5488 (b'', b'all', None, _(b'purge ignored files too')),
5495 5489 (b'i', b'ignored', None, _(b'purge only ignored files')),
5496 5490 (b'', b'dirs', None, _(b'purge empty directories')),
5497 5491 (b'', b'files', None, _(b'purge files')),
5498 5492 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
5499 5493 (
5500 5494 b'0',
5501 5495 b'print0',
5502 5496 None,
5503 5497 _(
5504 5498 b'end filenames with NUL, for use with xargs'
5505 5499 b' (implies -p/--print)'
5506 5500 ),
5507 5501 ),
5508 5502 (b'', b'confirm', None, _(b'ask before permanently deleting files')),
5509 5503 ]
5510 5504 + cmdutil.walkopts,
5511 5505 _(b'hg purge [OPTION]... [DIR]...'),
5512 5506 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
5513 5507 )
5514 5508 def purge(ui, repo, *dirs, **opts):
5515 5509 """removes files not tracked by Mercurial
5516 5510
5517 5511 Delete files not known to Mercurial. This is useful to test local
5518 5512 and uncommitted changes in an otherwise-clean source tree.
5519 5513
5520 5514 This means that purge will delete the following by default:
5521 5515
5522 5516 - Unknown files: files marked with "?" by :hg:`status`
5523 5517 - Empty directories: in fact Mercurial ignores directories unless
5524 5518 they contain files under source control management
5525 5519
5526 5520 But it will leave untouched:
5527 5521
5528 5522 - Modified and unmodified tracked files
5529 5523 - Ignored files (unless -i or --all is specified)
5530 5524 - New files added to the repository (with :hg:`add`)
5531 5525
5532 5526 The --files and --dirs options can be used to direct purge to delete
5533 5527 only files, only directories, or both. If neither option is given,
5534 5528 both will be deleted.
5535 5529
5536 5530 If directories are given on the command line, only files in these
5537 5531 directories are considered.
5538 5532
5539 5533 Be careful with purge, as you could irreversibly delete some files
5540 5534 you forgot to add to the repository. If you only want to print the
5541 5535 list of files that this program would delete, use the --print
5542 5536 option.
5543 5537 """
5544 5538 opts = pycompat.byteskwargs(opts)
5545 5539 cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
5546 5540
5547 5541 act = not opts.get(b'print')
5548 5542 eol = b'\n'
5549 5543 if opts.get(b'print0'):
5550 5544 eol = b'\0'
5551 5545 act = False # --print0 implies --print
5552 5546 if opts.get(b'all', False):
5553 5547 ignored = True
5554 5548 unknown = True
5555 5549 else:
5556 5550 ignored = opts.get(b'ignored', False)
5557 5551 unknown = not ignored
5558 5552
5559 5553 removefiles = opts.get(b'files')
5560 5554 removedirs = opts.get(b'dirs')
5561 5555 confirm = opts.get(b'confirm')
5562 5556 if confirm is None:
5563 5557 try:
5564 5558 extensions.find(b'purge')
5565 5559 confirm = False
5566 5560 except KeyError:
5567 5561 confirm = True
5568 5562
5569 5563 if not removefiles and not removedirs:
5570 5564 removefiles = True
5571 5565 removedirs = True
5572 5566
5573 5567 match = scmutil.match(repo[None], dirs, opts)
5574 5568
5575 5569 paths = mergemod.purge(
5576 5570 repo,
5577 5571 match,
5578 5572 unknown=unknown,
5579 5573 ignored=ignored,
5580 5574 removeemptydirs=removedirs,
5581 5575 removefiles=removefiles,
5582 5576 abortonerror=opts.get(b'abort_on_err'),
5583 5577 noop=not act,
5584 5578 confirm=confirm,
5585 5579 )
5586 5580
5587 5581 for path in paths:
5588 5582 if not act:
5589 5583 ui.write(b'%s%s' % (path, eol))
5590 5584
5591 5585
5592 5586 @command(
5593 5587 b'push',
5594 5588 [
5595 5589 (b'f', b'force', None, _(b'force push')),
5596 5590 (
5597 5591 b'r',
5598 5592 b'rev',
5599 5593 [],
5600 5594 _(b'a changeset intended to be included in the destination'),
5601 5595 _(b'REV'),
5602 5596 ),
5603 5597 (b'B', b'bookmark', [], _(b"bookmark to push"), _(b'BOOKMARK')),
5604 5598 (b'', b'all-bookmarks', None, _(b"push all bookmarks (EXPERIMENTAL)")),
5605 5599 (
5606 5600 b'b',
5607 5601 b'branch',
5608 5602 [],
5609 5603 _(b'a specific branch you would like to push'),
5610 5604 _(b'BRANCH'),
5611 5605 ),
5612 5606 (b'', b'new-branch', False, _(b'allow pushing a new branch')),
5613 5607 (
5614 5608 b'',
5615 5609 b'pushvars',
5616 5610 [],
5617 5611 _(b'variables that can be sent to server (ADVANCED)'),
5618 5612 ),
5619 5613 (
5620 5614 b'',
5621 5615 b'publish',
5622 5616 False,
5623 5617 _(b'push the changeset as public (EXPERIMENTAL)'),
5624 5618 ),
5625 5619 ]
5626 5620 + remoteopts,
5627 5621 _(b'[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]...'),
5628 5622 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
5629 5623 helpbasic=True,
5630 5624 )
5631 5625 def push(ui, repo, *dests, **opts):
5632 5626 """push changes to the specified destination
5633 5627
5634 5628 Push changesets from the local repository to the specified
5635 5629 destination.
5636 5630
5637 5631 This operation is symmetrical to pull: it is identical to a pull
5638 5632 in the destination repository from the current one.
5639 5633
5640 5634 By default, push will not allow creation of new heads at the
5641 5635 destination, since multiple heads would make it unclear which head
5642 5636 to use. In this situation, it is recommended to pull and merge
5643 5637 before pushing.
5644 5638
5645 5639 Use --new-branch if you want to allow push to create a new named
5646 5640 branch that is not present at the destination. This allows you to
5647 5641 only create a new branch without forcing other changes.
5648 5642
5649 5643 .. note::
5650 5644
5651 5645 Extra care should be taken with the -f/--force option,
5652 5646 which will push all new heads on all branches, an action which will
5653 5647 almost always cause confusion for collaborators.
5654 5648
5655 5649 If -r/--rev is used, the specified revision and all its ancestors
5656 5650 will be pushed to the remote repository.
5657 5651
5658 5652 If -B/--bookmark is used, the specified bookmarked revision, its
5659 5653 ancestors, and the bookmark will be pushed to the remote
5660 5654 repository. Specifying ``.`` is equivalent to specifying the active
5661 5655 bookmark's name. Use the --all-bookmarks option for pushing all
5662 5656 current bookmarks.
5663 5657
5664 5658 Please see :hg:`help urls` for important details about ``ssh://``
5665 5659 URLs. If DESTINATION is omitted, a default path will be used.
5666 5660
5667 5661 When passed multiple destinations, push will process them one after the
5668 5662 other, but stop should an error occur.
5669 5663
5670 5664 .. container:: verbose
5671 5665
5672 5666 The --pushvars option sends strings to the server that become
5673 5667 environment variables prepended with ``HG_USERVAR_``. For example,
5674 5668 ``--pushvars ENABLE_FEATURE=true``, provides the server side hooks with
5675 5669 ``HG_USERVAR_ENABLE_FEATURE=true`` as part of their environment.
5676 5670
5677 5671 pushvars can provide for user-overridable hooks as well as set debug
5678 5672 levels. One example is having a hook that blocks commits containing
5679 5673 conflict markers, but enables the user to override the hook if the file
5680 5674 is using conflict markers for testing purposes or the file format has
5681 5675 strings that look like conflict markers.
5682 5676
5683 5677 By default, servers will ignore `--pushvars`. To enable it add the
5684 5678 following to your configuration file::
5685 5679
5686 5680 [push]
5687 5681 pushvars.server = true
5688 5682
5689 5683 Returns 0 if push was successful, 1 if nothing to push.
5690 5684 """
5691 5685
5692 5686 opts = pycompat.byteskwargs(opts)
5693 5687
5694 5688 if opts.get(b'all_bookmarks'):
5695 5689 cmdutil.check_incompatible_arguments(
5696 5690 opts,
5697 5691 b'all_bookmarks',
5698 5692 [b'bookmark', b'rev'],
5699 5693 )
5700 5694 opts[b'bookmark'] = list(repo._bookmarks)
5701 5695
5702 5696 if opts.get(b'bookmark'):
5703 5697 ui.setconfig(b'bookmarks', b'pushing', opts[b'bookmark'], b'push')
5704 5698 for b in opts[b'bookmark']:
5705 5699 # translate -B options to -r so changesets get pushed
5706 5700 b = repo._bookmarks.expandname(b)
5707 5701 if b in repo._bookmarks:
5708 5702 opts.setdefault(b'rev', []).append(b)
5709 5703 else:
5710 5704 # if we try to push a deleted bookmark, translate it to null
5711 5705 # this lets simultaneous -r, -b options continue working
5712 5706 opts.setdefault(b'rev', []).append(b"null")
5713 5707
5714 5708 some_pushed = False
5715 5709 result = 0
5716 5710 for path in urlutil.get_push_paths(repo, ui, dests):
5717 5711 dest = path.pushloc or path.loc
5718 5712 branches = (path.branch, opts.get(b'branch') or [])
5719 5713 ui.status(_(b'pushing to %s\n') % urlutil.hidepassword(dest))
5720 5714 revs, checkout = hg.addbranchrevs(
5721 5715 repo, repo, branches, opts.get(b'rev')
5722 5716 )
5723 5717 other = hg.peer(repo, opts, dest)
5724 5718
5725 5719 try:
5726 5720 if revs:
5727 5721 revs = [repo[r].node() for r in scmutil.revrange(repo, revs)]
5728 5722 if not revs:
5729 5723 raise error.InputError(
5730 5724 _(b"specified revisions evaluate to an empty set"),
5731 5725 hint=_(b"use different revision arguments"),
5732 5726 )
5733 5727 elif path.pushrev:
5734 5728 # It doesn't make any sense to specify ancestor revisions. So limit
5735 5729 # to DAG heads to make discovery simpler.
5736 5730 expr = revsetlang.formatspec(b'heads(%r)', path.pushrev)
5737 5731 revs = scmutil.revrange(repo, [expr])
5738 5732 revs = [repo[rev].node() for rev in revs]
5739 5733 if not revs:
5740 5734 raise error.InputError(
5741 5735 _(
5742 5736 b'default push revset for path evaluates to an empty set'
5743 5737 )
5744 5738 )
5745 5739 elif ui.configbool(b'commands', b'push.require-revs'):
5746 5740 raise error.InputError(
5747 5741 _(b'no revisions specified to push'),
5748 5742 hint=_(b'did you mean "hg push -r ."?'),
5749 5743 )
5750 5744
5751 5745 repo._subtoppath = dest
5752 5746 try:
5753 5747 # push subrepos depth-first for coherent ordering
5754 5748 c = repo[b'.']
5755 5749 subs = c.substate # only repos that are committed
5756 5750 for s in sorted(subs):
5757 5751 sub_result = c.sub(s).push(opts)
5758 5752 if sub_result == 0:
5759 5753 return 1
5760 5754 finally:
5761 5755 del repo._subtoppath
5762 5756
5763 5757 opargs = dict(
5764 5758 opts.get(b'opargs', {})
5765 5759 ) # copy opargs since we may mutate it
5766 5760 opargs.setdefault(b'pushvars', []).extend(opts.get(b'pushvars', []))
5767 5761
5768 5762 pushop = exchange.push(
5769 5763 repo,
5770 5764 other,
5771 5765 opts.get(b'force'),
5772 5766 revs=revs,
5773 5767 newbranch=opts.get(b'new_branch'),
5774 5768 bookmarks=opts.get(b'bookmark', ()),
5775 5769 publish=opts.get(b'publish'),
5776 5770 opargs=opargs,
5777 5771 )
5778 5772
5779 5773 if pushop.cgresult == 0:
5780 5774 result = 1
5781 5775 elif pushop.cgresult is not None:
5782 5776 some_pushed = True
5783 5777
5784 5778 if pushop.bkresult is not None:
5785 5779 if pushop.bkresult == 2:
5786 5780 result = 2
5787 5781 elif not result and pushop.bkresult:
5788 5782 result = 2
5789 5783
5790 5784 if result:
5791 5785 break
5792 5786
5793 5787 finally:
5794 5788 other.close()
5795 5789 if result == 0 and not some_pushed:
5796 5790 result = 1
5797 5791 return result
5798 5792
5799 5793
5800 5794 @command(
5801 5795 b'recover',
5802 5796 [
5803 5797 (b'', b'verify', False, b"run `hg verify` after successful recover"),
5804 5798 ],
5805 5799 helpcategory=command.CATEGORY_MAINTENANCE,
5806 5800 )
5807 5801 def recover(ui, repo, **opts):
5808 5802 """roll back an interrupted transaction
5809 5803
5810 5804 Recover from an interrupted commit or pull.
5811 5805
5812 5806 This command tries to fix the repository status after an
5813 5807 interrupted operation. It should only be necessary when Mercurial
5814 5808 suggests it.
5815 5809
5816 5810 Returns 0 if successful, 1 if nothing to recover or verify fails.
5817 5811 """
5818 5812 ret = repo.recover()
5819 5813 if ret:
5820 5814 if opts['verify']:
5821 5815 return hg.verify(repo)
5822 5816 else:
5823 5817 msg = _(
5824 5818 b"(verify step skipped, run `hg verify` to check your "
5825 5819 b"repository content)\n"
5826 5820 )
5827 5821 ui.warn(msg)
5828 5822 return 0
5829 5823 return 1
5830 5824
5831 5825
5832 5826 @command(
5833 5827 b'remove|rm',
5834 5828 [
5835 5829 (b'A', b'after', None, _(b'record delete for missing files')),
5836 5830 (b'f', b'force', None, _(b'forget added files, delete modified files')),
5837 5831 ]
5838 5832 + subrepoopts
5839 5833 + walkopts
5840 5834 + dryrunopts,
5841 5835 _(b'[OPTION]... FILE...'),
5842 5836 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
5843 5837 helpbasic=True,
5844 5838 inferrepo=True,
5845 5839 )
5846 5840 def remove(ui, repo, *pats, **opts):
5847 5841 """remove the specified files on the next commit
5848 5842
5849 5843 Schedule the indicated files for removal from the current branch.
5850 5844
5851 5845 This command schedules the files to be removed at the next commit.
5852 5846 To undo a remove before that, see :hg:`revert`. To undo added
5853 5847 files, see :hg:`forget`.
5854 5848
5855 5849 .. container:: verbose
5856 5850
5857 5851 -A/--after can be used to remove only files that have already
5858 5852 been deleted, -f/--force can be used to force deletion, and -Af
5859 5853 can be used to remove files from the next revision without
5860 5854 deleting them from the working directory.
5861 5855
5862 5856 The following table details the behavior of remove for different
5863 5857 file states (columns) and option combinations (rows). The file
5864 5858 states are Added [A], Clean [C], Modified [M] and Missing [!]
5865 5859 (as reported by :hg:`status`). The actions are Warn, Remove
5866 5860 (from branch) and Delete (from disk):
5867 5861
5868 5862 ========= == == == ==
5869 5863 opt/state A C M !
5870 5864 ========= == == == ==
5871 5865 none W RD W R
5872 5866 -f R RD RD R
5873 5867 -A W W W R
5874 5868 -Af R R R R
5875 5869 ========= == == == ==
5876 5870
5877 5871 .. note::
5878 5872
5879 5873 :hg:`remove` never deletes files in Added [A] state from the
5880 5874 working directory, not even if ``--force`` is specified.
5881 5875
5882 5876 Returns 0 on success, 1 if any warnings encountered.
5883 5877 """
5884 5878
5885 5879 opts = pycompat.byteskwargs(opts)
5886 5880 after, force = opts.get(b'after'), opts.get(b'force')
5887 5881 dryrun = opts.get(b'dry_run')
5888 5882 if not pats and not after:
5889 5883 raise error.InputError(_(b'no files specified'))
5890 5884
5891 5885 m = scmutil.match(repo[None], pats, opts)
5892 5886 subrepos = opts.get(b'subrepos')
5893 5887 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
5894 5888 return cmdutil.remove(
5895 5889 ui, repo, m, b"", uipathfn, after, force, subrepos, dryrun=dryrun
5896 5890 )
5897 5891
5898 5892
5899 5893 @command(
5900 5894 b'rename|move|mv',
5901 5895 [
5902 5896 (b'', b'forget', None, _(b'unmark a destination file as renamed')),
5903 5897 (b'A', b'after', None, _(b'record a rename that has already occurred')),
5904 5898 (
5905 5899 b'',
5906 5900 b'at-rev',
5907 5901 b'',
5908 5902 _(b'(un)mark renames in the given revision (EXPERIMENTAL)'),
5909 5903 _(b'REV'),
5910 5904 ),
5911 5905 (
5912 5906 b'f',
5913 5907 b'force',
5914 5908 None,
5915 5909 _(b'forcibly move over an existing managed file'),
5916 5910 ),
5917 5911 ]
5918 5912 + walkopts
5919 5913 + dryrunopts,
5920 5914 _(b'[OPTION]... SOURCE... DEST'),
5921 5915 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
5922 5916 )
5923 5917 def rename(ui, repo, *pats, **opts):
5924 5918 """rename files; equivalent of copy + remove
5925 5919
5926 5920 Mark dest as copies of sources; mark sources for deletion. If dest
5927 5921 is a directory, copies are put in that directory. If dest is a
5928 5922 file, there can only be one source.
5929 5923
5930 5924 By default, this command copies the contents of files as they
5931 5925 exist in the working directory. If invoked with -A/--after, the
5932 5926 operation is recorded, but no copying is performed.
5933 5927
5934 5928 To undo marking a destination file as renamed, use --forget. With that
5935 5929 option, all given (positional) arguments are unmarked as renames. The
5936 5930 destination file(s) will be left in place (still tracked). The source
5937 5931 file(s) will not be restored. Note that :hg:`rename --forget` behaves
5938 5932 the same way as :hg:`copy --forget`.
5939 5933
5940 5934 This command takes effect with the next commit by default.
5941 5935
5942 5936 Returns 0 on success, 1 if errors are encountered.
5943 5937 """
5944 5938 opts = pycompat.byteskwargs(opts)
5945 5939 with repo.wlock():
5946 5940 return cmdutil.copy(ui, repo, pats, opts, rename=True)
5947 5941
5948 5942
5949 5943 @command(
5950 5944 b'resolve',
5951 5945 [
5952 5946 (b'a', b'all', None, _(b'select all unresolved files')),
5953 5947 (b'l', b'list', None, _(b'list state of files needing merge')),
5954 5948 (b'm', b'mark', None, _(b'mark files as resolved')),
5955 5949 (b'u', b'unmark', None, _(b'mark files as unresolved')),
5956 5950 (b'n', b'no-status', None, _(b'hide status prefix')),
5957 5951 (b'', b're-merge', None, _(b're-merge files')),
5958 5952 ]
5959 5953 + mergetoolopts
5960 5954 + walkopts
5961 5955 + formatteropts,
5962 5956 _(b'[OPTION]... [FILE]...'),
5963 5957 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
5964 5958 inferrepo=True,
5965 5959 )
5966 5960 def resolve(ui, repo, *pats, **opts):
5967 5961 """redo merges or set/view the merge status of files
5968 5962
5969 5963 Merges with unresolved conflicts are often the result of
5970 5964 non-interactive merging using the ``internal:merge`` configuration
5971 5965 setting, or a command-line merge tool like ``diff3``. The resolve
5972 5966 command is used to manage the files involved in a merge, after
5973 5967 :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the
5974 5968 working directory must have two parents). See :hg:`help
5975 5969 merge-tools` for information on configuring merge tools.
5976 5970
5977 5971 The resolve command can be used in the following ways:
5978 5972
5979 5973 - :hg:`resolve [--re-merge] [--tool TOOL] FILE...`: attempt to re-merge
5980 5974 the specified files, discarding any previous merge attempts. Re-merging
5981 5975 is not performed for files already marked as resolved. Use ``--all/-a``
5982 5976 to select all unresolved files. ``--tool`` can be used to specify
5983 5977 the merge tool used for the given files. It overrides the HGMERGE
5984 5978 environment variable and your configuration files. Previous file
5985 5979 contents are saved with a ``.orig`` suffix.
5986 5980
5987 5981 - :hg:`resolve -m [FILE]`: mark a file as having been resolved
5988 5982 (e.g. after having manually fixed-up the files). The default is
5989 5983 to mark all unresolved files.
5990 5984
5991 5985 - :hg:`resolve -u [FILE]...`: mark a file as unresolved. The
5992 5986 default is to mark all resolved files.
5993 5987
5994 5988 - :hg:`resolve -l`: list files which had or still have conflicts.
5995 5989 In the printed list, ``U`` = unresolved and ``R`` = resolved.
5996 5990 You can use ``set:unresolved()`` or ``set:resolved()`` to filter
5997 5991 the list. See :hg:`help filesets` for details.
5998 5992
5999 5993 .. note::
6000 5994
6001 5995 Mercurial will not let you commit files with unresolved merge
6002 5996 conflicts. You must use :hg:`resolve -m ...` before you can
6003 5997 commit after a conflicting merge.
6004 5998
6005 5999 .. container:: verbose
6006 6000
6007 6001 Template:
6008 6002
6009 6003 The following keywords are supported in addition to the common template
6010 6004 keywords and functions. See also :hg:`help templates`.
6011 6005
6012 6006 :mergestatus: String. Character denoting merge conflicts, ``U`` or ``R``.
6013 6007 :path: String. Repository-absolute path of the file.
6014 6008
6015 6009 Returns 0 on success, 1 if any files fail a resolve attempt.
6016 6010 """
6017 6011
6018 6012 opts = pycompat.byteskwargs(opts)
6019 6013 confirm = ui.configbool(b'commands', b'resolve.confirm')
6020 6014 flaglist = b'all mark unmark list no_status re_merge'.split()
6021 6015 all, mark, unmark, show, nostatus, remerge = [opts.get(o) for o in flaglist]
6022 6016
6023 6017 actioncount = len(list(filter(None, [show, mark, unmark, remerge])))
6024 6018 if actioncount > 1:
6025 6019 raise error.InputError(_(b"too many actions specified"))
6026 6020 elif actioncount == 0 and ui.configbool(
6027 6021 b'commands', b'resolve.explicit-re-merge'
6028 6022 ):
6029 6023 hint = _(b'use --mark, --unmark, --list or --re-merge')
6030 6024 raise error.InputError(_(b'no action specified'), hint=hint)
6031 6025 if pats and all:
6032 6026 raise error.InputError(_(b"can't specify --all and patterns"))
6033 6027 if not (all or pats or show or mark or unmark):
6034 6028 raise error.InputError(
6035 6029 _(b'no files or directories specified'),
6036 6030 hint=b'use --all to re-merge all unresolved files',
6037 6031 )
6038 6032
6039 6033 if confirm:
6040 6034 if all:
6041 6035 if ui.promptchoice(
6042 6036 _(b're-merge all unresolved files (yn)?$$ &Yes $$ &No')
6043 6037 ):
6044 6038 raise error.CanceledError(_(b'user quit'))
6045 6039 if mark and not pats:
6046 6040 if ui.promptchoice(
6047 6041 _(
6048 6042 b'mark all unresolved files as resolved (yn)?'
6049 6043 b'$$ &Yes $$ &No'
6050 6044 )
6051 6045 ):
6052 6046 raise error.CanceledError(_(b'user quit'))
6053 6047 if unmark and not pats:
6054 6048 if ui.promptchoice(
6055 6049 _(
6056 6050 b'mark all resolved files as unresolved (yn)?'
6057 6051 b'$$ &Yes $$ &No'
6058 6052 )
6059 6053 ):
6060 6054 raise error.CanceledError(_(b'user quit'))
6061 6055
6062 6056 uipathfn = scmutil.getuipathfn(repo)
6063 6057
6064 6058 if show:
6065 6059 ui.pager(b'resolve')
6066 6060 fm = ui.formatter(b'resolve', opts)
6067 6061 ms = mergestatemod.mergestate.read(repo)
6068 6062 wctx = repo[None]
6069 6063 m = scmutil.match(wctx, pats, opts)
6070 6064
6071 6065 # Labels and keys based on merge state. Unresolved path conflicts show
6072 6066 # as 'P'. Resolved path conflicts show as 'R', the same as normal
6073 6067 # resolved conflicts.
6074 6068 mergestateinfo = {
6075 6069 mergestatemod.MERGE_RECORD_UNRESOLVED: (
6076 6070 b'resolve.unresolved',
6077 6071 b'U',
6078 6072 ),
6079 6073 mergestatemod.MERGE_RECORD_RESOLVED: (b'resolve.resolved', b'R'),
6080 6074 mergestatemod.MERGE_RECORD_UNRESOLVED_PATH: (
6081 6075 b'resolve.unresolved',
6082 6076 b'P',
6083 6077 ),
6084 6078 mergestatemod.MERGE_RECORD_RESOLVED_PATH: (
6085 6079 b'resolve.resolved',
6086 6080 b'R',
6087 6081 ),
6088 6082 }
6089 6083
6090 6084 for f in ms:
6091 6085 if not m(f):
6092 6086 continue
6093 6087
6094 6088 label, key = mergestateinfo[ms[f]]
6095 6089 fm.startitem()
6096 6090 fm.context(ctx=wctx)
6097 6091 fm.condwrite(not nostatus, b'mergestatus', b'%s ', key, label=label)
6098 6092 fm.data(path=f)
6099 6093 fm.plain(b'%s\n' % uipathfn(f), label=label)
6100 6094 fm.end()
6101 6095 return 0
6102 6096
6103 6097 with repo.wlock():
6104 6098 ms = mergestatemod.mergestate.read(repo)
6105 6099
6106 6100 if not (ms.active() or repo.dirstate.p2() != repo.nullid):
6107 6101 raise error.StateError(
6108 6102 _(b'resolve command not applicable when not merging')
6109 6103 )
6110 6104
6111 6105 wctx = repo[None]
6112 6106 m = scmutil.match(wctx, pats, opts)
6113 6107 ret = 0
6114 6108 didwork = False
6115 6109
6116 6110 tocomplete = []
6117 6111 hasconflictmarkers = []
6118 6112 if mark:
6119 6113 markcheck = ui.config(b'commands', b'resolve.mark-check')
6120 6114 if markcheck not in [b'warn', b'abort']:
6121 6115 # Treat all invalid / unrecognized values as 'none'.
6122 6116 markcheck = False
6123 6117 for f in ms:
6124 6118 if not m(f):
6125 6119 continue
6126 6120
6127 6121 didwork = True
6128 6122
6129 6123 # path conflicts must be resolved manually
6130 6124 if ms[f] in (
6131 6125 mergestatemod.MERGE_RECORD_UNRESOLVED_PATH,
6132 6126 mergestatemod.MERGE_RECORD_RESOLVED_PATH,
6133 6127 ):
6134 6128 if mark:
6135 6129 ms.mark(f, mergestatemod.MERGE_RECORD_RESOLVED_PATH)
6136 6130 elif unmark:
6137 6131 ms.mark(f, mergestatemod.MERGE_RECORD_UNRESOLVED_PATH)
6138 6132 elif ms[f] == mergestatemod.MERGE_RECORD_UNRESOLVED_PATH:
6139 6133 ui.warn(
6140 6134 _(b'%s: path conflict must be resolved manually\n')
6141 6135 % uipathfn(f)
6142 6136 )
6143 6137 continue
6144 6138
6145 6139 if mark:
6146 6140 if markcheck:
6147 6141 fdata = repo.wvfs.tryread(f)
6148 6142 if (
6149 6143 filemerge.hasconflictmarkers(fdata)
6150 6144 and ms[f] != mergestatemod.MERGE_RECORD_RESOLVED
6151 6145 ):
6152 6146 hasconflictmarkers.append(f)
6153 6147 ms.mark(f, mergestatemod.MERGE_RECORD_RESOLVED)
6154 6148 elif unmark:
6155 6149 ms.mark(f, mergestatemod.MERGE_RECORD_UNRESOLVED)
6156 6150 else:
6157 6151 # backup pre-resolve (merge uses .orig for its own purposes)
6158 6152 a = repo.wjoin(f)
6159 6153 try:
6160 6154 util.copyfile(a, a + b".resolve")
6161 6155 except (IOError, OSError) as inst:
6162 6156 if inst.errno != errno.ENOENT:
6163 6157 raise
6164 6158
6165 6159 try:
6166 6160 # preresolve file
6167 6161 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
6168 6162 with ui.configoverride(overrides, b'resolve'):
6169 6163 complete, r = ms.preresolve(f, wctx)
6170 6164 if not complete:
6171 6165 tocomplete.append(f)
6172 6166 elif r:
6173 6167 ret = 1
6174 6168 finally:
6175 6169 ms.commit()
6176 6170
6177 6171 # replace filemerge's .orig file with our resolve file, but only
6178 6172 # for merges that are complete
6179 6173 if complete:
6180 6174 try:
6181 6175 util.rename(
6182 6176 a + b".resolve", scmutil.backuppath(ui, repo, f)
6183 6177 )
6184 6178 except OSError as inst:
6185 6179 if inst.errno != errno.ENOENT:
6186 6180 raise
6187 6181
6188 6182 if hasconflictmarkers:
6189 6183 ui.warn(
6190 6184 _(
6191 6185 b'warning: the following files still have conflict '
6192 6186 b'markers:\n'
6193 6187 )
6194 6188 + b''.join(
6195 6189 b' ' + uipathfn(f) + b'\n' for f in hasconflictmarkers
6196 6190 )
6197 6191 )
6198 6192 if markcheck == b'abort' and not all and not pats:
6199 6193 raise error.StateError(
6200 6194 _(b'conflict markers detected'),
6201 6195 hint=_(b'use --all to mark anyway'),
6202 6196 )
6203 6197
6204 6198 for f in tocomplete:
6205 6199 try:
6206 6200 # resolve file
6207 6201 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
6208 6202 with ui.configoverride(overrides, b'resolve'):
6209 6203 r = ms.resolve(f, wctx)
6210 6204 if r:
6211 6205 ret = 1
6212 6206 finally:
6213 6207 ms.commit()
6214 6208
6215 6209 # replace filemerge's .orig file with our resolve file
6216 6210 a = repo.wjoin(f)
6217 6211 try:
6218 6212 util.rename(a + b".resolve", scmutil.backuppath(ui, repo, f))
6219 6213 except OSError as inst:
6220 6214 if inst.errno != errno.ENOENT:
6221 6215 raise
6222 6216
6223 6217 ms.commit()
6224 6218 branchmerge = repo.dirstate.p2() != repo.nullid
6225 6219 mergestatemod.recordupdates(repo, ms.actions(), branchmerge, None)
6226 6220
6227 6221 if not didwork and pats:
6228 6222 hint = None
6229 6223 if not any([p for p in pats if p.find(b':') >= 0]):
6230 6224 pats = [b'path:%s' % p for p in pats]
6231 6225 m = scmutil.match(wctx, pats, opts)
6232 6226 for f in ms:
6233 6227 if not m(f):
6234 6228 continue
6235 6229
6236 6230 def flag(o):
6237 6231 if o == b're_merge':
6238 6232 return b'--re-merge '
6239 6233 return b'-%s ' % o[0:1]
6240 6234
6241 6235 flags = b''.join([flag(o) for o in flaglist if opts.get(o)])
6242 6236 hint = _(b"(try: hg resolve %s%s)\n") % (
6243 6237 flags,
6244 6238 b' '.join(pats),
6245 6239 )
6246 6240 break
6247 6241 ui.warn(_(b"arguments do not match paths that need resolving\n"))
6248 6242 if hint:
6249 6243 ui.warn(hint)
6250 6244
6251 6245 unresolvedf = ms.unresolvedcount()
6252 6246 if not unresolvedf:
6253 6247 ui.status(_(b'(no more unresolved files)\n'))
6254 6248 cmdutil.checkafterresolved(repo)
6255 6249
6256 6250 return ret
6257 6251
6258 6252
6259 6253 @command(
6260 6254 b'revert',
6261 6255 [
6262 6256 (b'a', b'all', None, _(b'revert all changes when no arguments given')),
6263 6257 (b'd', b'date', b'', _(b'tipmost revision matching date'), _(b'DATE')),
6264 6258 (b'r', b'rev', b'', _(b'revert to the specified revision'), _(b'REV')),
6265 6259 (b'C', b'no-backup', None, _(b'do not save backup copies of files')),
6266 6260 (b'i', b'interactive', None, _(b'interactively select the changes')),
6267 6261 ]
6268 6262 + walkopts
6269 6263 + dryrunopts,
6270 6264 _(b'[OPTION]... [-r REV] [NAME]...'),
6271 6265 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
6272 6266 )
6273 6267 def revert(ui, repo, *pats, **opts):
6274 6268 """restore files to their checkout state
6275 6269
6276 6270 .. note::
6277 6271
6278 6272 To check out earlier revisions, you should use :hg:`update REV`.
6279 6273 To cancel an uncommitted merge (and lose your changes),
6280 6274 use :hg:`merge --abort`.
6281 6275
6282 6276 With no revision specified, revert the specified files or directories
6283 6277 to the contents they had in the parent of the working directory.
6284 6278 This restores the contents of files to an unmodified
6285 6279 state and unschedules adds, removes, copies, and renames. If the
6286 6280 working directory has two parents, you must explicitly specify a
6287 6281 revision.
6288 6282
6289 6283 Using the -r/--rev or -d/--date options, revert the given files or
6290 6284 directories to their states as of a specific revision. Because
6291 6285 revert does not change the working directory parents, this will
6292 6286 cause these files to appear modified. This can be helpful to "back
6293 6287 out" some or all of an earlier change. See :hg:`backout` for a
6294 6288 related method.
6295 6289
6296 6290 Modified files are saved with a .orig suffix before reverting.
6297 6291 To disable these backups, use --no-backup. It is possible to store
6298 6292 the backup files in a custom directory relative to the root of the
6299 6293 repository by setting the ``ui.origbackuppath`` configuration
6300 6294 option.
6301 6295
6302 6296 See :hg:`help dates` for a list of formats valid for -d/--date.
6303 6297
6304 6298 See :hg:`help backout` for a way to reverse the effect of an
6305 6299 earlier changeset.
6306 6300
6307 6301 Returns 0 on success.
6308 6302 """
6309 6303
6310 6304 opts = pycompat.byteskwargs(opts)
6311 6305 if opts.get(b"date"):
6312 6306 cmdutil.check_incompatible_arguments(opts, b'date', [b'rev'])
6313 6307 opts[b"rev"] = cmdutil.finddate(ui, repo, opts[b"date"])
6314 6308
6315 6309 parent, p2 = repo.dirstate.parents()
6316 6310 if not opts.get(b'rev') and p2 != repo.nullid:
6317 6311 # revert after merge is a trap for new users (issue2915)
6318 6312 raise error.InputError(
6319 6313 _(b'uncommitted merge with no revision specified'),
6320 6314 hint=_(b"use 'hg update' or see 'hg help revert'"),
6321 6315 )
6322 6316
6323 6317 rev = opts.get(b'rev')
6324 6318 if rev:
6325 6319 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
6326 6320 ctx = scmutil.revsingle(repo, rev)
6327 6321
6328 6322 if not (
6329 6323 pats
6330 6324 or opts.get(b'include')
6331 6325 or opts.get(b'exclude')
6332 6326 or opts.get(b'all')
6333 6327 or opts.get(b'interactive')
6334 6328 ):
6335 6329 msg = _(b"no files or directories specified")
6336 6330 if p2 != repo.nullid:
6337 6331 hint = _(
6338 6332 b"uncommitted merge, use --all to discard all changes,"
6339 6333 b" or 'hg update -C .' to abort the merge"
6340 6334 )
6341 6335 raise error.InputError(msg, hint=hint)
6342 6336 dirty = any(repo.status())
6343 6337 node = ctx.node()
6344 6338 if node != parent:
6345 6339 if dirty:
6346 6340 hint = (
6347 6341 _(
6348 6342 b"uncommitted changes, use --all to discard all"
6349 6343 b" changes, or 'hg update %d' to update"
6350 6344 )
6351 6345 % ctx.rev()
6352 6346 )
6353 6347 else:
6354 6348 hint = (
6355 6349 _(
6356 6350 b"use --all to revert all files,"
6357 6351 b" or 'hg update %d' to update"
6358 6352 )
6359 6353 % ctx.rev()
6360 6354 )
6361 6355 elif dirty:
6362 6356 hint = _(b"uncommitted changes, use --all to discard all changes")
6363 6357 else:
6364 6358 hint = _(b"use --all to revert all files")
6365 6359 raise error.InputError(msg, hint=hint)
6366 6360
6367 6361 return cmdutil.revert(ui, repo, ctx, *pats, **pycompat.strkwargs(opts))
6368 6362
6369 6363
6370 6364 @command(
6371 6365 b'rollback',
6372 6366 dryrunopts + [(b'f', b'force', False, _(b'ignore safety measures'))],
6373 6367 helpcategory=command.CATEGORY_MAINTENANCE,
6374 6368 )
6375 6369 def rollback(ui, repo, **opts):
6376 6370 """roll back the last transaction (DANGEROUS) (DEPRECATED)
6377 6371
6378 6372 Please use :hg:`commit --amend` instead of rollback to correct
6379 6373 mistakes in the last commit.
6380 6374
6381 6375 This command should be used with care. There is only one level of
6382 6376 rollback, and there is no way to undo a rollback. It will also
6383 6377 restore the dirstate at the time of the last transaction, losing
6384 6378 any dirstate changes since that time. This command does not alter
6385 6379 the working directory.
6386 6380
6387 6381 Transactions are used to encapsulate the effects of all commands
6388 6382 that create new changesets or propagate existing changesets into a
6389 6383 repository.
6390 6384
6391 6385 .. container:: verbose
6392 6386
6393 6387 For example, the following commands are transactional, and their
6394 6388 effects can be rolled back:
6395 6389
6396 6390 - commit
6397 6391 - import
6398 6392 - pull
6399 6393 - push (with this repository as the destination)
6400 6394 - unbundle
6401 6395
6402 6396 To avoid permanent data loss, rollback will refuse to rollback a
6403 6397 commit transaction if it isn't checked out. Use --force to
6404 6398 override this protection.
6405 6399
6406 6400 The rollback command can be entirely disabled by setting the
6407 6401 ``ui.rollback`` configuration setting to false. If you're here
6408 6402 because you want to use rollback and it's disabled, you can
6409 6403 re-enable the command by setting ``ui.rollback`` to true.
6410 6404
6411 6405 This command is not intended for use on public repositories. Once
6412 6406 changes are visible for pull by other users, rolling a transaction
6413 6407 back locally is ineffective (someone else may already have pulled
6414 6408 the changes). Furthermore, a race is possible with readers of the
6415 6409 repository; for example an in-progress pull from the repository
6416 6410 may fail if a rollback is performed.
6417 6411
6418 6412 Returns 0 on success, 1 if no rollback data is available.
6419 6413 """
6420 6414 if not ui.configbool(b'ui', b'rollback'):
6421 6415 raise error.Abort(
6422 6416 _(b'rollback is disabled because it is unsafe'),
6423 6417 hint=b'see `hg help -v rollback` for information',
6424 6418 )
6425 6419 return repo.rollback(dryrun=opts.get('dry_run'), force=opts.get('force'))
6426 6420
6427 6421
6428 6422 @command(
6429 6423 b'root',
6430 6424 [] + formatteropts,
6431 6425 intents={INTENT_READONLY},
6432 6426 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
6433 6427 )
6434 6428 def root(ui, repo, **opts):
6435 6429 """print the root (top) of the current working directory
6436 6430
6437 6431 Print the root directory of the current repository.
6438 6432
6439 6433 .. container:: verbose
6440 6434
6441 6435 Template:
6442 6436
6443 6437 The following keywords are supported in addition to the common template
6444 6438 keywords and functions. See also :hg:`help templates`.
6445 6439
6446 6440 :hgpath: String. Path to the .hg directory.
6447 6441 :storepath: String. Path to the directory holding versioned data.
6448 6442
6449 6443 Returns 0 on success.
6450 6444 """
6451 6445 opts = pycompat.byteskwargs(opts)
6452 6446 with ui.formatter(b'root', opts) as fm:
6453 6447 fm.startitem()
6454 6448 fm.write(b'reporoot', b'%s\n', repo.root)
6455 6449 fm.data(hgpath=repo.path, storepath=repo.spath)
6456 6450
6457 6451
6458 6452 @command(
6459 6453 b'serve',
6460 6454 [
6461 6455 (
6462 6456 b'A',
6463 6457 b'accesslog',
6464 6458 b'',
6465 6459 _(b'name of access log file to write to'),
6466 6460 _(b'FILE'),
6467 6461 ),
6468 6462 (b'd', b'daemon', None, _(b'run server in background')),
6469 6463 (b'', b'daemon-postexec', [], _(b'used internally by daemon mode')),
6470 6464 (
6471 6465 b'E',
6472 6466 b'errorlog',
6473 6467 b'',
6474 6468 _(b'name of error log file to write to'),
6475 6469 _(b'FILE'),
6476 6470 ),
6477 6471 # use string type, then we can check if something was passed
6478 6472 (
6479 6473 b'p',
6480 6474 b'port',
6481 6475 b'',
6482 6476 _(b'port to listen on (default: 8000)'),
6483 6477 _(b'PORT'),
6484 6478 ),
6485 6479 (
6486 6480 b'a',
6487 6481 b'address',
6488 6482 b'',
6489 6483 _(b'address to listen on (default: all interfaces)'),
6490 6484 _(b'ADDR'),
6491 6485 ),
6492 6486 (
6493 6487 b'',
6494 6488 b'prefix',
6495 6489 b'',
6496 6490 _(b'prefix path to serve from (default: server root)'),
6497 6491 _(b'PREFIX'),
6498 6492 ),
6499 6493 (
6500 6494 b'n',
6501 6495 b'name',
6502 6496 b'',
6503 6497 _(b'name to show in web pages (default: working directory)'),
6504 6498 _(b'NAME'),
6505 6499 ),
6506 6500 (
6507 6501 b'',
6508 6502 b'web-conf',
6509 6503 b'',
6510 6504 _(b"name of the hgweb config file (see 'hg help hgweb')"),
6511 6505 _(b'FILE'),
6512 6506 ),
6513 6507 (
6514 6508 b'',
6515 6509 b'webdir-conf',
6516 6510 b'',
6517 6511 _(b'name of the hgweb config file (DEPRECATED)'),
6518 6512 _(b'FILE'),
6519 6513 ),
6520 6514 (
6521 6515 b'',
6522 6516 b'pid-file',
6523 6517 b'',
6524 6518 _(b'name of file to write process ID to'),
6525 6519 _(b'FILE'),
6526 6520 ),
6527 6521 (b'', b'stdio', None, _(b'for remote clients (ADVANCED)')),
6528 6522 (
6529 6523 b'',
6530 6524 b'cmdserver',
6531 6525 b'',
6532 6526 _(b'for remote clients (ADVANCED)'),
6533 6527 _(b'MODE'),
6534 6528 ),
6535 6529 (b't', b'templates', b'', _(b'web templates to use'), _(b'TEMPLATE')),
6536 6530 (b'', b'style', b'', _(b'template style to use'), _(b'STYLE')),
6537 6531 (b'6', b'ipv6', None, _(b'use IPv6 in addition to IPv4')),
6538 6532 (b'', b'certificate', b'', _(b'SSL certificate file'), _(b'FILE')),
6539 6533 (b'', b'print-url', None, _(b'start and print only the URL')),
6540 6534 ]
6541 6535 + subrepoopts,
6542 6536 _(b'[OPTION]...'),
6543 6537 helpcategory=command.CATEGORY_REMOTE_REPO_MANAGEMENT,
6544 6538 helpbasic=True,
6545 6539 optionalrepo=True,
6546 6540 )
6547 6541 def serve(ui, repo, **opts):
6548 6542 """start stand-alone webserver
6549 6543
6550 6544 Start a local HTTP repository browser and pull server. You can use
6551 6545 this for ad-hoc sharing and browsing of repositories. It is
6552 6546 recommended to use a real web server to serve a repository for
6553 6547 longer periods of time.
6554 6548
6555 6549 Please note that the server does not implement access control.
6556 6550 This means that, by default, anybody can read from the server and
6557 6551 nobody can write to it by default. Set the ``web.allow-push``
6558 6552 option to ``*`` to allow everybody to push to the server. You
6559 6553 should use a real web server if you need to authenticate users.
6560 6554
6561 6555 By default, the server logs accesses to stdout and errors to
6562 6556 stderr. Use the -A/--accesslog and -E/--errorlog options to log to
6563 6557 files.
6564 6558
6565 6559 To have the server choose a free port number to listen on, specify
6566 6560 a port number of 0; in this case, the server will print the port
6567 6561 number it uses.
6568 6562
6569 6563 Returns 0 on success.
6570 6564 """
6571 6565
6572 6566 cmdutil.check_incompatible_arguments(opts, 'stdio', ['cmdserver'])
6573 6567 opts = pycompat.byteskwargs(opts)
6574 6568 if opts[b"print_url"] and ui.verbose:
6575 6569 raise error.InputError(_(b"cannot use --print-url with --verbose"))
6576 6570
6577 6571 if opts[b"stdio"]:
6578 6572 if repo is None:
6579 6573 raise error.RepoError(
6580 6574 _(b"there is no Mercurial repository here (.hg not found)")
6581 6575 )
6582 6576 s = wireprotoserver.sshserver(ui, repo)
6583 6577 s.serve_forever()
6584 6578 return
6585 6579
6586 6580 service = server.createservice(ui, repo, opts)
6587 6581 return server.runservice(opts, initfn=service.init, runfn=service.run)
6588 6582
6589 6583
6590 6584 @command(
6591 6585 b'shelve',
6592 6586 [
6593 6587 (
6594 6588 b'A',
6595 6589 b'addremove',
6596 6590 None,
6597 6591 _(b'mark new/missing files as added/removed before shelving'),
6598 6592 ),
6599 6593 (b'u', b'unknown', None, _(b'store unknown files in the shelve')),
6600 6594 (b'', b'cleanup', None, _(b'delete all shelved changes')),
6601 6595 (
6602 6596 b'',
6603 6597 b'date',
6604 6598 b'',
6605 6599 _(b'shelve with the specified commit date'),
6606 6600 _(b'DATE'),
6607 6601 ),
6608 6602 (b'd', b'delete', None, _(b'delete the named shelved change(s)')),
6609 6603 (b'e', b'edit', False, _(b'invoke editor on commit messages')),
6610 6604 (
6611 6605 b'k',
6612 6606 b'keep',
6613 6607 False,
6614 6608 _(b'shelve, but keep changes in the working directory'),
6615 6609 ),
6616 6610 (b'l', b'list', None, _(b'list current shelves')),
6617 6611 (b'm', b'message', b'', _(b'use text as shelve message'), _(b'TEXT')),
6618 6612 (
6619 6613 b'n',
6620 6614 b'name',
6621 6615 b'',
6622 6616 _(b'use the given name for the shelved commit'),
6623 6617 _(b'NAME'),
6624 6618 ),
6625 6619 (
6626 6620 b'p',
6627 6621 b'patch',
6628 6622 None,
6629 6623 _(
6630 6624 b'output patches for changes (provide the names of the shelved '
6631 6625 b'changes as positional arguments)'
6632 6626 ),
6633 6627 ),
6634 6628 (b'i', b'interactive', None, _(b'interactive mode')),
6635 6629 (
6636 6630 b'',
6637 6631 b'stat',
6638 6632 None,
6639 6633 _(
6640 6634 b'output diffstat-style summary of changes (provide the names of '
6641 6635 b'the shelved changes as positional arguments)'
6642 6636 ),
6643 6637 ),
6644 6638 ]
6645 6639 + cmdutil.walkopts,
6646 6640 _(b'hg shelve [OPTION]... [FILE]...'),
6647 6641 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
6648 6642 )
6649 6643 def shelve(ui, repo, *pats, **opts):
6650 6644 """save and set aside changes from the working directory
6651 6645
6652 6646 Shelving takes files that "hg status" reports as not clean, saves
6653 6647 the modifications to a bundle (a shelved change), and reverts the
6654 6648 files so that their state in the working directory becomes clean.
6655 6649
6656 6650 To restore these changes to the working directory, using "hg
6657 6651 unshelve"; this will work even if you switch to a different
6658 6652 commit.
6659 6653
6660 6654 When no files are specified, "hg shelve" saves all not-clean
6661 6655 files. If specific files or directories are named, only changes to
6662 6656 those files are shelved.
6663 6657
6664 6658 In bare shelve (when no files are specified, without interactive,
6665 6659 include and exclude option), shelving remembers information if the
6666 6660 working directory was on newly created branch, in other words working
6667 6661 directory was on different branch than its first parent. In this
6668 6662 situation unshelving restores branch information to the working directory.
6669 6663
6670 6664 Each shelved change has a name that makes it easier to find later.
6671 6665 The name of a shelved change defaults to being based on the active
6672 6666 bookmark, or if there is no active bookmark, the current named
6673 6667 branch. To specify a different name, use ``--name``.
6674 6668
6675 6669 To see a list of existing shelved changes, use the ``--list``
6676 6670 option. For each shelved change, this will print its name, age,
6677 6671 and description; use ``--patch`` or ``--stat`` for more details.
6678 6672
6679 6673 To delete specific shelved changes, use ``--delete``. To delete
6680 6674 all shelved changes, use ``--cleanup``.
6681 6675 """
6682 6676 opts = pycompat.byteskwargs(opts)
6683 6677 allowables = [
6684 6678 (b'addremove', {b'create'}), # 'create' is pseudo action
6685 6679 (b'unknown', {b'create'}),
6686 6680 (b'cleanup', {b'cleanup'}),
6687 6681 # ('date', {'create'}), # ignored for passing '--date "0 0"' in tests
6688 6682 (b'delete', {b'delete'}),
6689 6683 (b'edit', {b'create'}),
6690 6684 (b'keep', {b'create'}),
6691 6685 (b'list', {b'list'}),
6692 6686 (b'message', {b'create'}),
6693 6687 (b'name', {b'create'}),
6694 6688 (b'patch', {b'patch', b'list'}),
6695 6689 (b'stat', {b'stat', b'list'}),
6696 6690 ]
6697 6691
6698 6692 def checkopt(opt):
6699 6693 if opts.get(opt):
6700 6694 for i, allowable in allowables:
6701 6695 if opts[i] and opt not in allowable:
6702 6696 raise error.InputError(
6703 6697 _(
6704 6698 b"options '--%s' and '--%s' may not be "
6705 6699 b"used together"
6706 6700 )
6707 6701 % (opt, i)
6708 6702 )
6709 6703 return True
6710 6704
6711 6705 if checkopt(b'cleanup'):
6712 6706 if pats:
6713 6707 raise error.InputError(
6714 6708 _(b"cannot specify names when using '--cleanup'")
6715 6709 )
6716 6710 return shelvemod.cleanupcmd(ui, repo)
6717 6711 elif checkopt(b'delete'):
6718 6712 return shelvemod.deletecmd(ui, repo, pats)
6719 6713 elif checkopt(b'list'):
6720 6714 return shelvemod.listcmd(ui, repo, pats, opts)
6721 6715 elif checkopt(b'patch') or checkopt(b'stat'):
6722 6716 return shelvemod.patchcmds(ui, repo, pats, opts)
6723 6717 else:
6724 6718 return shelvemod.createcmd(ui, repo, pats, opts)
6725 6719
6726 6720
6727 6721 _NOTTERSE = b'nothing'
6728 6722
6729 6723
6730 6724 @command(
6731 6725 b'status|st',
6732 6726 [
6733 6727 (b'A', b'all', None, _(b'show status of all files')),
6734 6728 (b'm', b'modified', None, _(b'show only modified files')),
6735 6729 (b'a', b'added', None, _(b'show only added files')),
6736 6730 (b'r', b'removed', None, _(b'show only removed files')),
6737 6731 (b'd', b'deleted', None, _(b'show only missing files')),
6738 6732 (b'c', b'clean', None, _(b'show only files without changes')),
6739 6733 (b'u', b'unknown', None, _(b'show only unknown (not tracked) files')),
6740 6734 (b'i', b'ignored', None, _(b'show only ignored files')),
6741 6735 (b'n', b'no-status', None, _(b'hide status prefix')),
6742 6736 (b't', b'terse', _NOTTERSE, _(b'show the terse output (EXPERIMENTAL)')),
6743 6737 (
6744 6738 b'C',
6745 6739 b'copies',
6746 6740 None,
6747 6741 _(b'show source of copied files (DEFAULT: ui.statuscopies)'),
6748 6742 ),
6749 6743 (
6750 6744 b'0',
6751 6745 b'print0',
6752 6746 None,
6753 6747 _(b'end filenames with NUL, for use with xargs'),
6754 6748 ),
6755 6749 (b'', b'rev', [], _(b'show difference from revision'), _(b'REV')),
6756 6750 (
6757 6751 b'',
6758 6752 b'change',
6759 6753 b'',
6760 6754 _(b'list the changed files of a revision'),
6761 6755 _(b'REV'),
6762 6756 ),
6763 6757 ]
6764 6758 + walkopts
6765 6759 + subrepoopts
6766 6760 + formatteropts,
6767 6761 _(b'[OPTION]... [FILE]...'),
6768 6762 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
6769 6763 helpbasic=True,
6770 6764 inferrepo=True,
6771 6765 intents={INTENT_READONLY},
6772 6766 )
6773 6767 def status(ui, repo, *pats, **opts):
6774 6768 """show changed files in the working directory
6775 6769
6776 6770 Show status of files in the repository. If names are given, only
6777 6771 files that match are shown. Files that are clean or ignored or
6778 6772 the source of a copy/move operation, are not listed unless
6779 6773 -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
6780 6774 Unless options described with "show only ..." are given, the
6781 6775 options -mardu are used.
6782 6776
6783 6777 Option -q/--quiet hides untracked (unknown and ignored) files
6784 6778 unless explicitly requested with -u/--unknown or -i/--ignored.
6785 6779
6786 6780 .. note::
6787 6781
6788 6782 :hg:`status` may appear to disagree with diff if permissions have
6789 6783 changed or a merge has occurred. The standard diff format does
6790 6784 not report permission changes and diff only reports changes
6791 6785 relative to one merge parent.
6792 6786
6793 6787 If one revision is given, it is used as the base revision.
6794 6788 If two revisions are given, the differences between them are
6795 6789 shown. The --change option can also be used as a shortcut to list
6796 6790 the changed files of a revision from its first parent.
6797 6791
6798 6792 The codes used to show the status of files are::
6799 6793
6800 6794 M = modified
6801 6795 A = added
6802 6796 R = removed
6803 6797 C = clean
6804 6798 ! = missing (deleted by non-hg command, but still tracked)
6805 6799 ? = not tracked
6806 6800 I = ignored
6807 6801 = origin of the previous file (with --copies)
6808 6802
6809 6803 .. container:: verbose
6810 6804
6811 6805 The -t/--terse option abbreviates the output by showing only the directory
6812 6806 name if all the files in it share the same status. The option takes an
6813 6807 argument indicating the statuses to abbreviate: 'm' for 'modified', 'a'
6814 6808 for 'added', 'r' for 'removed', 'd' for 'deleted', 'u' for 'unknown', 'i'
6815 6809 for 'ignored' and 'c' for clean.
6816 6810
6817 6811 It abbreviates only those statuses which are passed. Note that clean and
6818 6812 ignored files are not displayed with '--terse ic' unless the -c/--clean
6819 6813 and -i/--ignored options are also used.
6820 6814
6821 6815 The -v/--verbose option shows information when the repository is in an
6822 6816 unfinished merge, shelve, rebase state etc. You can have this behavior
6823 6817 turned on by default by enabling the ``commands.status.verbose`` option.
6824 6818
6825 6819 You can skip displaying some of these states by setting
6826 6820 ``commands.status.skipstates`` to one or more of: 'bisect', 'graft',
6827 6821 'histedit', 'merge', 'rebase', or 'unshelve'.
6828 6822
6829 6823 Template:
6830 6824
6831 6825 The following keywords are supported in addition to the common template
6832 6826 keywords and functions. See also :hg:`help templates`.
6833 6827
6834 6828 :path: String. Repository-absolute path of the file.
6835 6829 :source: String. Repository-absolute path of the file originated from.
6836 6830 Available if ``--copies`` is specified.
6837 6831 :status: String. Character denoting file's status.
6838 6832
6839 6833 Examples:
6840 6834
6841 6835 - show changes in the working directory relative to a
6842 6836 changeset::
6843 6837
6844 6838 hg status --rev 9353
6845 6839
6846 6840 - show changes in the working directory relative to the
6847 6841 current directory (see :hg:`help patterns` for more information)::
6848 6842
6849 6843 hg status re:
6850 6844
6851 6845 - show all changes including copies in an existing changeset::
6852 6846
6853 6847 hg status --copies --change 9353
6854 6848
6855 6849 - get a NUL separated list of added files, suitable for xargs::
6856 6850
6857 6851 hg status -an0
6858 6852
6859 6853 - show more information about the repository status, abbreviating
6860 6854 added, removed, modified, deleted, and untracked paths::
6861 6855
6862 6856 hg status -v -t mardu
6863 6857
6864 6858 Returns 0 on success.
6865 6859
6866 6860 """
6867 6861
6868 6862 cmdutil.check_at_most_one_arg(opts, 'rev', 'change')
6869 6863 opts = pycompat.byteskwargs(opts)
6870 6864 revs = opts.get(b'rev')
6871 6865 change = opts.get(b'change')
6872 6866 terse = opts.get(b'terse')
6873 6867 if terse is _NOTTERSE:
6874 6868 if revs:
6875 6869 terse = b''
6876 6870 else:
6877 6871 terse = ui.config(b'commands', b'status.terse')
6878 6872
6879 6873 if revs and terse:
6880 6874 msg = _(b'cannot use --terse with --rev')
6881 6875 raise error.InputError(msg)
6882 6876 elif change:
6883 6877 repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn')
6884 6878 ctx2 = scmutil.revsingle(repo, change, None)
6885 6879 ctx1 = ctx2.p1()
6886 6880 else:
6887 6881 repo = scmutil.unhidehashlikerevs(repo, revs, b'nowarn')
6888 6882 ctx1, ctx2 = scmutil.revpair(repo, revs)
6889 6883
6890 6884 forcerelativevalue = None
6891 6885 if ui.hasconfig(b'commands', b'status.relative'):
6892 6886 forcerelativevalue = ui.configbool(b'commands', b'status.relative')
6893 6887 uipathfn = scmutil.getuipathfn(
6894 6888 repo,
6895 6889 legacyrelativevalue=bool(pats),
6896 6890 forcerelativevalue=forcerelativevalue,
6897 6891 )
6898 6892
6899 6893 if opts.get(b'print0'):
6900 6894 end = b'\0'
6901 6895 else:
6902 6896 end = b'\n'
6903 6897 states = b'modified added removed deleted unknown ignored clean'.split()
6904 6898 show = [k for k in states if opts.get(k)]
6905 6899 if opts.get(b'all'):
6906 6900 show += ui.quiet and (states[:4] + [b'clean']) or states
6907 6901
6908 6902 if not show:
6909 6903 if ui.quiet:
6910 6904 show = states[:4]
6911 6905 else:
6912 6906 show = states[:5]
6913 6907
6914 6908 m = scmutil.match(ctx2, pats, opts)
6915 6909 if terse:
6916 6910 # we need to compute clean and unknown to terse
6917 6911 stat = repo.status(
6918 6912 ctx1.node(),
6919 6913 ctx2.node(),
6920 6914 m,
6921 6915 b'ignored' in show or b'i' in terse,
6922 6916 clean=True,
6923 6917 unknown=True,
6924 6918 listsubrepos=opts.get(b'subrepos'),
6925 6919 )
6926 6920
6927 6921 stat = cmdutil.tersedir(stat, terse)
6928 6922 else:
6929 6923 stat = repo.status(
6930 6924 ctx1.node(),
6931 6925 ctx2.node(),
6932 6926 m,
6933 6927 b'ignored' in show,
6934 6928 b'clean' in show,
6935 6929 b'unknown' in show,
6936 6930 opts.get(b'subrepos'),
6937 6931 )
6938 6932
6939 6933 changestates = zip(
6940 6934 states,
6941 6935 pycompat.iterbytestr(b'MAR!?IC'),
6942 6936 [getattr(stat, s.decode('utf8')) for s in states],
6943 6937 )
6944 6938
6945 6939 copy = {}
6946 6940 if (
6947 6941 opts.get(b'all')
6948 6942 or opts.get(b'copies')
6949 6943 or ui.configbool(b'ui', b'statuscopies')
6950 6944 ) and not opts.get(b'no_status'):
6951 6945 copy = copies.pathcopies(ctx1, ctx2, m)
6952 6946
6953 6947 morestatus = None
6954 6948 if (
6955 6949 (ui.verbose or ui.configbool(b'commands', b'status.verbose'))
6956 6950 and not ui.plain()
6957 6951 and not opts.get(b'print0')
6958 6952 ):
6959 6953 morestatus = cmdutil.readmorestatus(repo)
6960 6954
6961 6955 ui.pager(b'status')
6962 6956 fm = ui.formatter(b'status', opts)
6963 6957 fmt = b'%s' + end
6964 6958 showchar = not opts.get(b'no_status')
6965 6959
6966 6960 for state, char, files in changestates:
6967 6961 if state in show:
6968 6962 label = b'status.' + state
6969 6963 for f in files:
6970 6964 fm.startitem()
6971 6965 fm.context(ctx=ctx2)
6972 6966 fm.data(itemtype=b'file', path=f)
6973 6967 fm.condwrite(showchar, b'status', b'%s ', char, label=label)
6974 6968 fm.plain(fmt % uipathfn(f), label=label)
6975 6969 if f in copy:
6976 6970 fm.data(source=copy[f])
6977 6971 fm.plain(
6978 6972 (b' %s' + end) % uipathfn(copy[f]),
6979 6973 label=b'status.copied',
6980 6974 )
6981 6975 if morestatus:
6982 6976 morestatus.formatfile(f, fm)
6983 6977
6984 6978 if morestatus:
6985 6979 morestatus.formatfooter(fm)
6986 6980 fm.end()
6987 6981
6988 6982
6989 6983 @command(
6990 6984 b'summary|sum',
6991 6985 [(b'', b'remote', None, _(b'check for push and pull'))],
6992 6986 b'[--remote]',
6993 6987 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
6994 6988 helpbasic=True,
6995 6989 intents={INTENT_READONLY},
6996 6990 )
6997 6991 def summary(ui, repo, **opts):
6998 6992 """summarize working directory state
6999 6993
7000 6994 This generates a brief summary of the working directory state,
7001 6995 including parents, branch, commit status, phase and available updates.
7002 6996
7003 6997 With the --remote option, this will check the default paths for
7004 6998 incoming and outgoing changes. This can be time-consuming.
7005 6999
7006 7000 Returns 0 on success.
7007 7001 """
7008 7002
7009 7003 opts = pycompat.byteskwargs(opts)
7010 7004 ui.pager(b'summary')
7011 7005 ctx = repo[None]
7012 7006 parents = ctx.parents()
7013 7007 pnode = parents[0].node()
7014 7008 marks = []
7015 7009
7016 7010 try:
7017 7011 ms = mergestatemod.mergestate.read(repo)
7018 7012 except error.UnsupportedMergeRecords as e:
7019 7013 s = b' '.join(e.recordtypes)
7020 7014 ui.warn(
7021 7015 _(b'warning: merge state has unsupported record types: %s\n') % s
7022 7016 )
7023 7017 unresolved = []
7024 7018 else:
7025 7019 unresolved = list(ms.unresolved())
7026 7020
7027 7021 for p in parents:
7028 7022 # label with log.changeset (instead of log.parent) since this
7029 7023 # shows a working directory parent *changeset*:
7030 7024 # i18n: column positioning for "hg summary"
7031 7025 ui.write(
7032 7026 _(b'parent: %d:%s ') % (p.rev(), p),
7033 7027 label=logcmdutil.changesetlabels(p),
7034 7028 )
7035 7029 ui.write(b' '.join(p.tags()), label=b'log.tag')
7036 7030 if p.bookmarks():
7037 7031 marks.extend(p.bookmarks())
7038 7032 if p.rev() == -1:
7039 7033 if not len(repo):
7040 7034 ui.write(_(b' (empty repository)'))
7041 7035 else:
7042 7036 ui.write(_(b' (no revision checked out)'))
7043 7037 if p.obsolete():
7044 7038 ui.write(_(b' (obsolete)'))
7045 7039 if p.isunstable():
7046 7040 instabilities = (
7047 7041 ui.label(instability, b'trouble.%s' % instability)
7048 7042 for instability in p.instabilities()
7049 7043 )
7050 7044 ui.write(b' (' + b', '.join(instabilities) + b')')
7051 7045 ui.write(b'\n')
7052 7046 if p.description():
7053 7047 ui.status(
7054 7048 b' ' + p.description().splitlines()[0].strip() + b'\n',
7055 7049 label=b'log.summary',
7056 7050 )
7057 7051
7058 7052 branch = ctx.branch()
7059 7053 bheads = repo.branchheads(branch)
7060 7054 # i18n: column positioning for "hg summary"
7061 7055 m = _(b'branch: %s\n') % branch
7062 7056 if branch != b'default':
7063 7057 ui.write(m, label=b'log.branch')
7064 7058 else:
7065 7059 ui.status(m, label=b'log.branch')
7066 7060
7067 7061 if marks:
7068 7062 active = repo._activebookmark
7069 7063 # i18n: column positioning for "hg summary"
7070 7064 ui.write(_(b'bookmarks:'), label=b'log.bookmark')
7071 7065 if active is not None:
7072 7066 if active in marks:
7073 7067 ui.write(b' *' + active, label=bookmarks.activebookmarklabel)
7074 7068 marks.remove(active)
7075 7069 else:
7076 7070 ui.write(b' [%s]' % active, label=bookmarks.activebookmarklabel)
7077 7071 for m in marks:
7078 7072 ui.write(b' ' + m, label=b'log.bookmark')
7079 7073 ui.write(b'\n', label=b'log.bookmark')
7080 7074
7081 7075 status = repo.status(unknown=True)
7082 7076
7083 7077 c = repo.dirstate.copies()
7084 7078 copied, renamed = [], []
7085 7079 for d, s in pycompat.iteritems(c):
7086 7080 if s in status.removed:
7087 7081 status.removed.remove(s)
7088 7082 renamed.append(d)
7089 7083 else:
7090 7084 copied.append(d)
7091 7085 if d in status.added:
7092 7086 status.added.remove(d)
7093 7087
7094 7088 subs = [s for s in ctx.substate if ctx.sub(s).dirty()]
7095 7089
7096 7090 labels = [
7097 7091 (ui.label(_(b'%d modified'), b'status.modified'), status.modified),
7098 7092 (ui.label(_(b'%d added'), b'status.added'), status.added),
7099 7093 (ui.label(_(b'%d removed'), b'status.removed'), status.removed),
7100 7094 (ui.label(_(b'%d renamed'), b'status.copied'), renamed),
7101 7095 (ui.label(_(b'%d copied'), b'status.copied'), copied),
7102 7096 (ui.label(_(b'%d deleted'), b'status.deleted'), status.deleted),
7103 7097 (ui.label(_(b'%d unknown'), b'status.unknown'), status.unknown),
7104 7098 (ui.label(_(b'%d unresolved'), b'resolve.unresolved'), unresolved),
7105 7099 (ui.label(_(b'%d subrepos'), b'status.modified'), subs),
7106 7100 ]
7107 7101 t = []
7108 7102 for l, s in labels:
7109 7103 if s:
7110 7104 t.append(l % len(s))
7111 7105
7112 7106 t = b', '.join(t)
7113 7107 cleanworkdir = False
7114 7108
7115 7109 if repo.vfs.exists(b'graftstate'):
7116 7110 t += _(b' (graft in progress)')
7117 7111 if repo.vfs.exists(b'updatestate'):
7118 7112 t += _(b' (interrupted update)')
7119 7113 elif len(parents) > 1:
7120 7114 t += _(b' (merge)')
7121 7115 elif branch != parents[0].branch():
7122 7116 t += _(b' (new branch)')
7123 7117 elif parents[0].closesbranch() and pnode in repo.branchheads(
7124 7118 branch, closed=True
7125 7119 ):
7126 7120 t += _(b' (head closed)')
7127 7121 elif not (
7128 7122 status.modified
7129 7123 or status.added
7130 7124 or status.removed
7131 7125 or renamed
7132 7126 or copied
7133 7127 or subs
7134 7128 ):
7135 7129 t += _(b' (clean)')
7136 7130 cleanworkdir = True
7137 7131 elif pnode not in bheads:
7138 7132 t += _(b' (new branch head)')
7139 7133
7140 7134 if parents:
7141 7135 pendingphase = max(p.phase() for p in parents)
7142 7136 else:
7143 7137 pendingphase = phases.public
7144 7138
7145 7139 if pendingphase > phases.newcommitphase(ui):
7146 7140 t += b' (%s)' % phases.phasenames[pendingphase]
7147 7141
7148 7142 if cleanworkdir:
7149 7143 # i18n: column positioning for "hg summary"
7150 7144 ui.status(_(b'commit: %s\n') % t.strip())
7151 7145 else:
7152 7146 # i18n: column positioning for "hg summary"
7153 7147 ui.write(_(b'commit: %s\n') % t.strip())
7154 7148
7155 7149 # all ancestors of branch heads - all ancestors of parent = new csets
7156 7150 new = len(
7157 7151 repo.changelog.findmissing([pctx.node() for pctx in parents], bheads)
7158 7152 )
7159 7153
7160 7154 if new == 0:
7161 7155 # i18n: column positioning for "hg summary"
7162 7156 ui.status(_(b'update: (current)\n'))
7163 7157 elif pnode not in bheads:
7164 7158 # i18n: column positioning for "hg summary"
7165 7159 ui.write(_(b'update: %d new changesets (update)\n') % new)
7166 7160 else:
7167 7161 # i18n: column positioning for "hg summary"
7168 7162 ui.write(
7169 7163 _(b'update: %d new changesets, %d branch heads (merge)\n')
7170 7164 % (new, len(bheads))
7171 7165 )
7172 7166
7173 7167 t = []
7174 7168 draft = len(repo.revs(b'draft()'))
7175 7169 if draft:
7176 7170 t.append(_(b'%d draft') % draft)
7177 7171 secret = len(repo.revs(b'secret()'))
7178 7172 if secret:
7179 7173 t.append(_(b'%d secret') % secret)
7180 7174
7181 7175 if draft or secret:
7182 7176 ui.status(_(b'phases: %s\n') % b', '.join(t))
7183 7177
7184 7178 if obsolete.isenabled(repo, obsolete.createmarkersopt):
7185 7179 for trouble in (b"orphan", b"contentdivergent", b"phasedivergent"):
7186 7180 numtrouble = len(repo.revs(trouble + b"()"))
7187 7181 # We write all the possibilities to ease translation
7188 7182 troublemsg = {
7189 7183 b"orphan": _(b"orphan: %d changesets"),
7190 7184 b"contentdivergent": _(b"content-divergent: %d changesets"),
7191 7185 b"phasedivergent": _(b"phase-divergent: %d changesets"),
7192 7186 }
7193 7187 if numtrouble > 0:
7194 7188 ui.status(troublemsg[trouble] % numtrouble + b"\n")
7195 7189
7196 7190 cmdutil.summaryhooks(ui, repo)
7197 7191
7198 7192 if opts.get(b'remote'):
7199 7193 needsincoming, needsoutgoing = True, True
7200 7194 else:
7201 7195 needsincoming, needsoutgoing = False, False
7202 7196 for i, o in cmdutil.summaryremotehooks(ui, repo, opts, None):
7203 7197 if i:
7204 7198 needsincoming = True
7205 7199 if o:
7206 7200 needsoutgoing = True
7207 7201 if not needsincoming and not needsoutgoing:
7208 7202 return
7209 7203
7210 7204 def getincoming():
7211 7205 # XXX We should actually skip this if no default is specified, instead
7212 7206 # of passing "default" which will resolve as "./default/" if no default
7213 7207 # path is defined.
7214 7208 source, branches = urlutil.get_unique_pull_path(
7215 7209 b'summary', repo, ui, b'default'
7216 7210 )
7217 7211 sbranch = branches[0]
7218 7212 try:
7219 7213 other = hg.peer(repo, {}, source)
7220 7214 except error.RepoError:
7221 7215 if opts.get(b'remote'):
7222 7216 raise
7223 7217 return source, sbranch, None, None, None
7224 7218 revs, checkout = hg.addbranchrevs(repo, other, branches, None)
7225 7219 if revs:
7226 7220 revs = [other.lookup(rev) for rev in revs]
7227 7221 ui.debug(b'comparing with %s\n' % urlutil.hidepassword(source))
7228 7222 repo.ui.pushbuffer()
7229 7223 commoninc = discovery.findcommonincoming(repo, other, heads=revs)
7230 7224 repo.ui.popbuffer()
7231 7225 return source, sbranch, other, commoninc, commoninc[1]
7232 7226
7233 7227 if needsincoming:
7234 7228 source, sbranch, sother, commoninc, incoming = getincoming()
7235 7229 else:
7236 7230 source = sbranch = sother = commoninc = incoming = None
7237 7231
7238 7232 def getoutgoing():
7239 7233 # XXX We should actually skip this if no default is specified, instead
7240 7234 # of passing "default" which will resolve as "./default/" if no default
7241 7235 # path is defined.
7242 7236 d = None
7243 7237 if b'default-push' in ui.paths:
7244 7238 d = b'default-push'
7245 7239 elif b'default' in ui.paths:
7246 7240 d = b'default'
7247 7241 if d is not None:
7248 7242 path = urlutil.get_unique_push_path(b'summary', repo, ui, d)
7249 7243 dest = path.pushloc or path.loc
7250 7244 dbranch = path.branch
7251 7245 else:
7252 7246 dest = b'default'
7253 7247 dbranch = None
7254 7248 revs, checkout = hg.addbranchrevs(repo, repo, (dbranch, []), None)
7255 7249 if source != dest:
7256 7250 try:
7257 7251 dother = hg.peer(repo, {}, dest)
7258 7252 except error.RepoError:
7259 7253 if opts.get(b'remote'):
7260 7254 raise
7261 7255 return dest, dbranch, None, None
7262 7256 ui.debug(b'comparing with %s\n' % urlutil.hidepassword(dest))
7263 7257 elif sother is None:
7264 7258 # there is no explicit destination peer, but source one is invalid
7265 7259 return dest, dbranch, None, None
7266 7260 else:
7267 7261 dother = sother
7268 7262 if source != dest or (sbranch is not None and sbranch != dbranch):
7269 7263 common = None
7270 7264 else:
7271 7265 common = commoninc
7272 7266 if revs:
7273 7267 revs = [repo.lookup(rev) for rev in revs]
7274 7268 repo.ui.pushbuffer()
7275 7269 outgoing = discovery.findcommonoutgoing(
7276 7270 repo, dother, onlyheads=revs, commoninc=common
7277 7271 )
7278 7272 repo.ui.popbuffer()
7279 7273 return dest, dbranch, dother, outgoing
7280 7274
7281 7275 if needsoutgoing:
7282 7276 dest, dbranch, dother, outgoing = getoutgoing()
7283 7277 else:
7284 7278 dest = dbranch = dother = outgoing = None
7285 7279
7286 7280 if opts.get(b'remote'):
7287 7281 # Help pytype. --remote sets both `needsincoming` and `needsoutgoing`.
7288 7282 # The former always sets `sother` (or raises an exception if it can't);
7289 7283 # the latter always sets `outgoing`.
7290 7284 assert sother is not None
7291 7285 assert outgoing is not None
7292 7286
7293 7287 t = []
7294 7288 if incoming:
7295 7289 t.append(_(b'1 or more incoming'))
7296 7290 o = outgoing.missing
7297 7291 if o:
7298 7292 t.append(_(b'%d outgoing') % len(o))
7299 7293 other = dother or sother
7300 7294 if b'bookmarks' in other.listkeys(b'namespaces'):
7301 7295 counts = bookmarks.summary(repo, other)
7302 7296 if counts[0] > 0:
7303 7297 t.append(_(b'%d incoming bookmarks') % counts[0])
7304 7298 if counts[1] > 0:
7305 7299 t.append(_(b'%d outgoing bookmarks') % counts[1])
7306 7300
7307 7301 if t:
7308 7302 # i18n: column positioning for "hg summary"
7309 7303 ui.write(_(b'remote: %s\n') % (b', '.join(t)))
7310 7304 else:
7311 7305 # i18n: column positioning for "hg summary"
7312 7306 ui.status(_(b'remote: (synced)\n'))
7313 7307
7314 7308 cmdutil.summaryremotehooks(
7315 7309 ui,
7316 7310 repo,
7317 7311 opts,
7318 7312 (
7319 7313 (source, sbranch, sother, commoninc),
7320 7314 (dest, dbranch, dother, outgoing),
7321 7315 ),
7322 7316 )
7323 7317
7324 7318
7325 7319 @command(
7326 7320 b'tag',
7327 7321 [
7328 7322 (b'f', b'force', None, _(b'force tag')),
7329 7323 (b'l', b'local', None, _(b'make the tag local')),
7330 7324 (b'r', b'rev', b'', _(b'revision to tag'), _(b'REV')),
7331 7325 (b'', b'remove', None, _(b'remove a tag')),
7332 7326 # -l/--local is already there, commitopts cannot be used
7333 7327 (b'e', b'edit', None, _(b'invoke editor on commit messages')),
7334 7328 (b'm', b'message', b'', _(b'use text as commit message'), _(b'TEXT')),
7335 7329 ]
7336 7330 + commitopts2,
7337 7331 _(b'[-f] [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...'),
7338 7332 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
7339 7333 )
7340 7334 def tag(ui, repo, name1, *names, **opts):
7341 7335 """add one or more tags for the current or given revision
7342 7336
7343 7337 Name a particular revision using <name>.
7344 7338
7345 7339 Tags are used to name particular revisions of the repository and are
7346 7340 very useful to compare different revisions, to go back to significant
7347 7341 earlier versions or to mark branch points as releases, etc. Changing
7348 7342 an existing tag is normally disallowed; use -f/--force to override.
7349 7343
7350 7344 If no revision is given, the parent of the working directory is
7351 7345 used.
7352 7346
7353 7347 To facilitate version control, distribution, and merging of tags,
7354 7348 they are stored as a file named ".hgtags" which is managed similarly
7355 7349 to other project files and can be hand-edited if necessary. This
7356 7350 also means that tagging creates a new commit. The file
7357 7351 ".hg/localtags" is used for local tags (not shared among
7358 7352 repositories).
7359 7353
7360 7354 Tag commits are usually made at the head of a branch. If the parent
7361 7355 of the working directory is not a branch head, :hg:`tag` aborts; use
7362 7356 -f/--force to force the tag commit to be based on a non-head
7363 7357 changeset.
7364 7358
7365 7359 See :hg:`help dates` for a list of formats valid for -d/--date.
7366 7360
7367 7361 Since tag names have priority over branch names during revision
7368 7362 lookup, using an existing branch name as a tag name is discouraged.
7369 7363
7370 7364 Returns 0 on success.
7371 7365 """
7372 7366 cmdutil.check_incompatible_arguments(opts, 'remove', ['rev'])
7373 7367 opts = pycompat.byteskwargs(opts)
7374 7368 with repo.wlock(), repo.lock():
7375 7369 rev_ = b"."
7376 7370 names = [t.strip() for t in (name1,) + names]
7377 7371 if len(names) != len(set(names)):
7378 7372 raise error.InputError(_(b'tag names must be unique'))
7379 7373 for n in names:
7380 7374 scmutil.checknewlabel(repo, n, b'tag')
7381 7375 if not n:
7382 7376 raise error.InputError(
7383 7377 _(b'tag names cannot consist entirely of whitespace')
7384 7378 )
7385 7379 if opts.get(b'rev'):
7386 7380 rev_ = opts[b'rev']
7387 7381 message = opts.get(b'message')
7388 7382 if opts.get(b'remove'):
7389 7383 if opts.get(b'local'):
7390 7384 expectedtype = b'local'
7391 7385 else:
7392 7386 expectedtype = b'global'
7393 7387
7394 7388 for n in names:
7395 7389 if repo.tagtype(n) == b'global':
7396 7390 alltags = tagsmod.findglobaltags(ui, repo)
7397 7391 if alltags[n][0] == repo.nullid:
7398 7392 raise error.InputError(
7399 7393 _(b"tag '%s' is already removed") % n
7400 7394 )
7401 7395 if not repo.tagtype(n):
7402 7396 raise error.InputError(_(b"tag '%s' does not exist") % n)
7403 7397 if repo.tagtype(n) != expectedtype:
7404 7398 if expectedtype == b'global':
7405 7399 raise error.InputError(
7406 7400 _(b"tag '%s' is not a global tag") % n
7407 7401 )
7408 7402 else:
7409 7403 raise error.InputError(
7410 7404 _(b"tag '%s' is not a local tag") % n
7411 7405 )
7412 7406 rev_ = b'null'
7413 7407 if not message:
7414 7408 # we don't translate commit messages
7415 7409 message = b'Removed tag %s' % b', '.join(names)
7416 7410 elif not opts.get(b'force'):
7417 7411 for n in names:
7418 7412 if n in repo.tags():
7419 7413 raise error.InputError(
7420 7414 _(b"tag '%s' already exists (use -f to force)") % n
7421 7415 )
7422 7416 if not opts.get(b'local'):
7423 7417 p1, p2 = repo.dirstate.parents()
7424 7418 if p2 != repo.nullid:
7425 7419 raise error.StateError(_(b'uncommitted merge'))
7426 7420 bheads = repo.branchheads()
7427 7421 if not opts.get(b'force') and bheads and p1 not in bheads:
7428 7422 raise error.InputError(
7429 7423 _(
7430 7424 b'working directory is not at a branch head '
7431 7425 b'(use -f to force)'
7432 7426 )
7433 7427 )
7434 7428 node = scmutil.revsingle(repo, rev_).node()
7435 7429
7436 7430 if not message:
7437 7431 # we don't translate commit messages
7438 7432 message = b'Added tag %s for changeset %s' % (
7439 7433 b', '.join(names),
7440 7434 short(node),
7441 7435 )
7442 7436
7443 7437 date = opts.get(b'date')
7444 7438 if date:
7445 7439 date = dateutil.parsedate(date)
7446 7440
7447 7441 if opts.get(b'remove'):
7448 7442 editform = b'tag.remove'
7449 7443 else:
7450 7444 editform = b'tag.add'
7451 7445 editor = cmdutil.getcommiteditor(
7452 7446 editform=editform, **pycompat.strkwargs(opts)
7453 7447 )
7454 7448
7455 7449 # don't allow tagging the null rev
7456 7450 if (
7457 7451 not opts.get(b'remove')
7458 7452 and scmutil.revsingle(repo, rev_).rev() == nullrev
7459 7453 ):
7460 7454 raise error.InputError(_(b"cannot tag null revision"))
7461 7455
7462 7456 tagsmod.tag(
7463 7457 repo,
7464 7458 names,
7465 7459 node,
7466 7460 message,
7467 7461 opts.get(b'local'),
7468 7462 opts.get(b'user'),
7469 7463 date,
7470 7464 editor=editor,
7471 7465 )
7472 7466
7473 7467
7474 7468 @command(
7475 7469 b'tags',
7476 7470 formatteropts,
7477 7471 b'',
7478 7472 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
7479 7473 intents={INTENT_READONLY},
7480 7474 )
7481 7475 def tags(ui, repo, **opts):
7482 7476 """list repository tags
7483 7477
7484 7478 This lists both regular and local tags. When the -v/--verbose
7485 7479 switch is used, a third column "local" is printed for local tags.
7486 7480 When the -q/--quiet switch is used, only the tag name is printed.
7487 7481
7488 7482 .. container:: verbose
7489 7483
7490 7484 Template:
7491 7485
7492 7486 The following keywords are supported in addition to the common template
7493 7487 keywords and functions such as ``{tag}``. See also
7494 7488 :hg:`help templates`.
7495 7489
7496 7490 :type: String. ``local`` for local tags.
7497 7491
7498 7492 Returns 0 on success.
7499 7493 """
7500 7494
7501 7495 opts = pycompat.byteskwargs(opts)
7502 7496 ui.pager(b'tags')
7503 7497 fm = ui.formatter(b'tags', opts)
7504 7498 hexfunc = fm.hexfunc
7505 7499
7506 7500 for t, n in reversed(repo.tagslist()):
7507 7501 hn = hexfunc(n)
7508 7502 label = b'tags.normal'
7509 7503 tagtype = repo.tagtype(t)
7510 7504 if not tagtype or tagtype == b'global':
7511 7505 tagtype = b''
7512 7506 else:
7513 7507 label = b'tags.' + tagtype
7514 7508
7515 7509 fm.startitem()
7516 7510 fm.context(repo=repo)
7517 7511 fm.write(b'tag', b'%s', t, label=label)
7518 7512 fmt = b" " * (30 - encoding.colwidth(t)) + b' %5d:%s'
7519 7513 fm.condwrite(
7520 7514 not ui.quiet,
7521 7515 b'rev node',
7522 7516 fmt,
7523 7517 repo.changelog.rev(n),
7524 7518 hn,
7525 7519 label=label,
7526 7520 )
7527 7521 fm.condwrite(
7528 7522 ui.verbose and tagtype, b'type', b' %s', tagtype, label=label
7529 7523 )
7530 7524 fm.plain(b'\n')
7531 7525 fm.end()
7532 7526
7533 7527
7534 7528 @command(
7535 7529 b'tip',
7536 7530 [
7537 7531 (b'p', b'patch', None, _(b'show patch')),
7538 7532 (b'g', b'git', None, _(b'use git extended diff format')),
7539 7533 ]
7540 7534 + templateopts,
7541 7535 _(b'[-p] [-g]'),
7542 7536 helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
7543 7537 )
7544 7538 def tip(ui, repo, **opts):
7545 7539 """show the tip revision (DEPRECATED)
7546 7540
7547 7541 The tip revision (usually just called the tip) is the changeset
7548 7542 most recently added to the repository (and therefore the most
7549 7543 recently changed head).
7550 7544
7551 7545 If you have just made a commit, that commit will be the tip. If
7552 7546 you have just pulled changes from another repository, the tip of
7553 7547 that repository becomes the current tip. The "tip" tag is special
7554 7548 and cannot be renamed or assigned to a different changeset.
7555 7549
7556 7550 This command is deprecated, please use :hg:`heads` instead.
7557 7551
7558 7552 Returns 0 on success.
7559 7553 """
7560 7554 opts = pycompat.byteskwargs(opts)
7561 7555 displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
7562 7556 displayer.show(repo[b'tip'])
7563 7557 displayer.close()
7564 7558
7565 7559
7566 7560 @command(
7567 7561 b'unbundle',
7568 7562 [
7569 7563 (
7570 7564 b'u',
7571 7565 b'update',
7572 7566 None,
7573 7567 _(b'update to new branch head if changesets were unbundled'),
7574 7568 )
7575 7569 ],
7576 7570 _(b'[-u] FILE...'),
7577 7571 helpcategory=command.CATEGORY_IMPORT_EXPORT,
7578 7572 )
7579 7573 def unbundle(ui, repo, fname1, *fnames, **opts):
7580 7574 """apply one or more bundle files
7581 7575
7582 7576 Apply one or more bundle files generated by :hg:`bundle`.
7583 7577
7584 7578 Returns 0 on success, 1 if an update has unresolved files.
7585 7579 """
7586 7580 fnames = (fname1,) + fnames
7587 7581
7588 7582 with repo.lock():
7589 7583 for fname in fnames:
7590 7584 f = hg.openpath(ui, fname)
7591 7585 gen = exchange.readbundle(ui, f, fname)
7592 7586 if isinstance(gen, streamclone.streamcloneapplier):
7593 7587 raise error.InputError(
7594 7588 _(
7595 7589 b'packed bundles cannot be applied with '
7596 7590 b'"hg unbundle"'
7597 7591 ),
7598 7592 hint=_(b'use "hg debugapplystreamclonebundle"'),
7599 7593 )
7600 7594 url = b'bundle:' + fname
7601 7595 try:
7602 7596 txnname = b'unbundle'
7603 7597 if not isinstance(gen, bundle2.unbundle20):
7604 7598 txnname = b'unbundle\n%s' % urlutil.hidepassword(url)
7605 7599 with repo.transaction(txnname) as tr:
7606 7600 op = bundle2.applybundle(
7607 7601 repo, gen, tr, source=b'unbundle', url=url
7608 7602 )
7609 7603 except error.BundleUnknownFeatureError as exc:
7610 7604 raise error.Abort(
7611 7605 _(b'%s: unknown bundle feature, %s') % (fname, exc),
7612 7606 hint=_(
7613 7607 b"see https://mercurial-scm.org/"
7614 7608 b"wiki/BundleFeature for more "
7615 7609 b"information"
7616 7610 ),
7617 7611 )
7618 7612 modheads = bundle2.combinechangegroupresults(op)
7619 7613
7620 7614 if postincoming(ui, repo, modheads, opts.get('update'), None, None):
7621 7615 return 1
7622 7616 else:
7623 7617 return 0
7624 7618
7625 7619
7626 7620 @command(
7627 7621 b'unshelve',
7628 7622 [
7629 7623 (b'a', b'abort', None, _(b'abort an incomplete unshelve operation')),
7630 7624 (
7631 7625 b'c',
7632 7626 b'continue',
7633 7627 None,
7634 7628 _(b'continue an incomplete unshelve operation'),
7635 7629 ),
7636 7630 (b'i', b'interactive', None, _(b'use interactive mode (EXPERIMENTAL)')),
7637 7631 (b'k', b'keep', None, _(b'keep shelve after unshelving')),
7638 7632 (
7639 7633 b'n',
7640 7634 b'name',
7641 7635 b'',
7642 7636 _(b'restore shelved change with given name'),
7643 7637 _(b'NAME'),
7644 7638 ),
7645 7639 (b't', b'tool', b'', _(b'specify merge tool')),
7646 7640 (
7647 7641 b'',
7648 7642 b'date',
7649 7643 b'',
7650 7644 _(b'set date for temporary commits (DEPRECATED)'),
7651 7645 _(b'DATE'),
7652 7646 ),
7653 7647 ],
7654 7648 _(b'hg unshelve [OPTION]... [[-n] SHELVED]'),
7655 7649 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
7656 7650 )
7657 7651 def unshelve(ui, repo, *shelved, **opts):
7658 7652 """restore a shelved change to the working directory
7659 7653
7660 7654 This command accepts an optional name of a shelved change to
7661 7655 restore. If none is given, the most recent shelved change is used.
7662 7656
7663 7657 If a shelved change is applied successfully, the bundle that
7664 7658 contains the shelved changes is moved to a backup location
7665 7659 (.hg/shelve-backup).
7666 7660
7667 7661 Since you can restore a shelved change on top of an arbitrary
7668 7662 commit, it is possible that unshelving will result in a conflict
7669 7663 between your changes and the commits you are unshelving onto. If
7670 7664 this occurs, you must resolve the conflict, then use
7671 7665 ``--continue`` to complete the unshelve operation. (The bundle
7672 7666 will not be moved until you successfully complete the unshelve.)
7673 7667
7674 7668 (Alternatively, you can use ``--abort`` to abandon an unshelve
7675 7669 that causes a conflict. This reverts the unshelved changes, and
7676 7670 leaves the bundle in place.)
7677 7671
7678 7672 If bare shelved change (without interactive, include and exclude
7679 7673 option) was done on newly created branch it would restore branch
7680 7674 information to the working directory.
7681 7675
7682 7676 After a successful unshelve, the shelved changes are stored in a
7683 7677 backup directory. Only the N most recent backups are kept. N
7684 7678 defaults to 10 but can be overridden using the ``shelve.maxbackups``
7685 7679 configuration option.
7686 7680
7687 7681 .. container:: verbose
7688 7682
7689 7683 Timestamp in seconds is used to decide order of backups. More
7690 7684 than ``maxbackups`` backups are kept, if same timestamp
7691 7685 prevents from deciding exact order of them, for safety.
7692 7686
7693 7687 Selected changes can be unshelved with ``--interactive`` flag.
7694 7688 The working directory is updated with the selected changes, and
7695 7689 only the unselected changes remain shelved.
7696 7690 Note: The whole shelve is applied to working directory first before
7697 7691 running interactively. So, this will bring up all the conflicts between
7698 7692 working directory and the shelve, irrespective of which changes will be
7699 7693 unshelved.
7700 7694 """
7701 7695 with repo.wlock():
7702 7696 return shelvemod.unshelvecmd(ui, repo, *shelved, **opts)
7703 7697
7704 7698
7705 7699 statemod.addunfinished(
7706 7700 b'unshelve',
7707 7701 fname=b'shelvedstate',
7708 7702 continueflag=True,
7709 7703 abortfunc=shelvemod.hgabortunshelve,
7710 7704 continuefunc=shelvemod.hgcontinueunshelve,
7711 7705 cmdmsg=_(b'unshelve already in progress'),
7712 7706 )
7713 7707
7714 7708
7715 7709 @command(
7716 7710 b'update|up|checkout|co',
7717 7711 [
7718 7712 (b'C', b'clean', None, _(b'discard uncommitted changes (no backup)')),
7719 7713 (b'c', b'check', None, _(b'require clean working directory')),
7720 7714 (b'm', b'merge', None, _(b'merge uncommitted changes')),
7721 7715 (b'd', b'date', b'', _(b'tipmost revision matching date'), _(b'DATE')),
7722 7716 (b'r', b'rev', b'', _(b'revision'), _(b'REV')),
7723 7717 ]
7724 7718 + mergetoolopts,
7725 7719 _(b'[-C|-c|-m] [-d DATE] [[-r] REV]'),
7726 7720 helpcategory=command.CATEGORY_WORKING_DIRECTORY,
7727 7721 helpbasic=True,
7728 7722 )
7729 7723 def update(ui, repo, node=None, **opts):
7730 7724 """update working directory (or switch revisions)
7731 7725
7732 7726 Update the repository's working directory to the specified
7733 7727 changeset. If no changeset is specified, update to the tip of the
7734 7728 current named branch and move the active bookmark (see :hg:`help
7735 7729 bookmarks`).
7736 7730
7737 7731 Update sets the working directory's parent revision to the specified
7738 7732 changeset (see :hg:`help parents`).
7739 7733
7740 7734 If the changeset is not a descendant or ancestor of the working
7741 7735 directory's parent and there are uncommitted changes, the update is
7742 7736 aborted. With the -c/--check option, the working directory is checked
7743 7737 for uncommitted changes; if none are found, the working directory is
7744 7738 updated to the specified changeset.
7745 7739
7746 7740 .. container:: verbose
7747 7741
7748 7742 The -C/--clean, -c/--check, and -m/--merge options control what
7749 7743 happens if the working directory contains uncommitted changes.
7750 7744 At most of one of them can be specified.
7751 7745
7752 7746 1. If no option is specified, and if
7753 7747 the requested changeset is an ancestor or descendant of
7754 7748 the working directory's parent, the uncommitted changes
7755 7749 are merged into the requested changeset and the merged
7756 7750 result is left uncommitted. If the requested changeset is
7757 7751 not an ancestor or descendant (that is, it is on another
7758 7752 branch), the update is aborted and the uncommitted changes
7759 7753 are preserved.
7760 7754
7761 7755 2. With the -m/--merge option, the update is allowed even if the
7762 7756 requested changeset is not an ancestor or descendant of
7763 7757 the working directory's parent.
7764 7758
7765 7759 3. With the -c/--check option, the update is aborted and the
7766 7760 uncommitted changes are preserved.
7767 7761
7768 7762 4. With the -C/--clean option, uncommitted changes are discarded and
7769 7763 the working directory is updated to the requested changeset.
7770 7764
7771 7765 To cancel an uncommitted merge (and lose your changes), use
7772 7766 :hg:`merge --abort`.
7773 7767
7774 7768 Use null as the changeset to remove the working directory (like
7775 7769 :hg:`clone -U`).
7776 7770
7777 7771 If you want to revert just one file to an older revision, use
7778 7772 :hg:`revert [-r REV] NAME`.
7779 7773
7780 7774 See :hg:`help dates` for a list of formats valid for -d/--date.
7781 7775
7782 7776 Returns 0 on success, 1 if there are unresolved files.
7783 7777 """
7784 7778 cmdutil.check_at_most_one_arg(opts, 'clean', 'check', 'merge')
7785 7779 rev = opts.get('rev')
7786 7780 date = opts.get('date')
7787 7781 clean = opts.get('clean')
7788 7782 check = opts.get('check')
7789 7783 merge = opts.get('merge')
7790 7784 if rev and node:
7791 7785 raise error.InputError(_(b"please specify just one revision"))
7792 7786
7793 7787 if ui.configbool(b'commands', b'update.requiredest'):
7794 7788 if not node and not rev and not date:
7795 7789 raise error.InputError(
7796 7790 _(b'you must specify a destination'),
7797 7791 hint=_(b'for example: hg update ".::"'),
7798 7792 )
7799 7793
7800 7794 if rev is None or rev == b'':
7801 7795 rev = node
7802 7796
7803 7797 if date and rev is not None:
7804 7798 raise error.InputError(_(b"you can't specify a revision and a date"))
7805 7799
7806 7800 updatecheck = None
7807 7801 if check:
7808 7802 updatecheck = b'abort'
7809 7803 elif merge:
7810 7804 updatecheck = b'none'
7811 7805
7812 7806 with repo.wlock():
7813 7807 cmdutil.clearunfinished(repo)
7814 7808 if date:
7815 7809 rev = cmdutil.finddate(ui, repo, date)
7816 7810
7817 7811 # if we defined a bookmark, we have to remember the original name
7818 7812 brev = rev
7819 7813 if rev:
7820 7814 repo = scmutil.unhidehashlikerevs(repo, [rev], b'nowarn')
7821 7815 ctx = scmutil.revsingle(repo, rev, default=None)
7822 7816 rev = ctx.rev()
7823 7817 hidden = ctx.hidden()
7824 7818 overrides = {(b'ui', b'forcemerge'): opts.get('tool', b'')}
7825 7819 with ui.configoverride(overrides, b'update'):
7826 7820 ret = hg.updatetotally(
7827 7821 ui, repo, rev, brev, clean=clean, updatecheck=updatecheck
7828 7822 )
7829 7823 if hidden:
7830 7824 ctxstr = ctx.hex()[:12]
7831 7825 ui.warn(_(b"updated to hidden changeset %s\n") % ctxstr)
7832 7826
7833 7827 if ctx.obsolete():
7834 7828 obsfatemsg = obsutil._getfilteredreason(repo, ctxstr, ctx)
7835 7829 ui.warn(b"(%s)\n" % obsfatemsg)
7836 7830 return ret
7837 7831
7838 7832
7839 7833 @command(
7840 7834 b'verify',
7841 7835 [(b'', b'full', False, b'perform more checks (EXPERIMENTAL)')],
7842 7836 helpcategory=command.CATEGORY_MAINTENANCE,
7843 7837 )
7844 7838 def verify(ui, repo, **opts):
7845 7839 """verify the integrity of the repository
7846 7840
7847 7841 Verify the integrity of the current repository.
7848 7842
7849 7843 This will perform an extensive check of the repository's
7850 7844 integrity, validating the hashes and checksums of each entry in
7851 7845 the changelog, manifest, and tracked files, as well as the
7852 7846 integrity of their crosslinks and indices.
7853 7847
7854 7848 Please see https://mercurial-scm.org/wiki/RepositoryCorruption
7855 7849 for more information about recovery from corruption of the
7856 7850 repository.
7857 7851
7858 7852 Returns 0 on success, 1 if errors are encountered.
7859 7853 """
7860 7854 opts = pycompat.byteskwargs(opts)
7861 7855
7862 7856 level = None
7863 7857 if opts[b'full']:
7864 7858 level = verifymod.VERIFY_FULL
7865 7859 return hg.verify(repo, level)
7866 7860
7867 7861
7868 7862 @command(
7869 7863 b'version',
7870 7864 [] + formatteropts,
7871 7865 helpcategory=command.CATEGORY_HELP,
7872 7866 norepo=True,
7873 7867 intents={INTENT_READONLY},
7874 7868 )
7875 7869 def version_(ui, **opts):
7876 7870 """output version and copyright information
7877 7871
7878 7872 .. container:: verbose
7879 7873
7880 7874 Template:
7881 7875
7882 7876 The following keywords are supported. See also :hg:`help templates`.
7883 7877
7884 7878 :extensions: List of extensions.
7885 7879 :ver: String. Version number.
7886 7880
7887 7881 And each entry of ``{extensions}`` provides the following sub-keywords
7888 7882 in addition to ``{ver}``.
7889 7883
7890 7884 :bundled: Boolean. True if included in the release.
7891 7885 :name: String. Extension name.
7892 7886 """
7893 7887 opts = pycompat.byteskwargs(opts)
7894 7888 if ui.verbose:
7895 7889 ui.pager(b'version')
7896 7890 fm = ui.formatter(b"version", opts)
7897 7891 fm.startitem()
7898 7892 fm.write(
7899 7893 b"ver", _(b"Mercurial Distributed SCM (version %s)\n"), util.version()
7900 7894 )
7901 7895 license = _(
7902 7896 b"(see https://mercurial-scm.org for more information)\n"
7903 7897 b"\nCopyright (C) 2005-2021 Olivia Mackall and others\n"
7904 7898 b"This is free software; see the source for copying conditions. "
7905 7899 b"There is NO\nwarranty; "
7906 7900 b"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
7907 7901 )
7908 7902 if not ui.quiet:
7909 7903 fm.plain(license)
7910 7904
7911 7905 if ui.verbose:
7912 7906 fm.plain(_(b"\nEnabled extensions:\n\n"))
7913 7907 # format names and versions into columns
7914 7908 names = []
7915 7909 vers = []
7916 7910 isinternals = []
7917 7911 for name, module in sorted(extensions.extensions()):
7918 7912 names.append(name)
7919 7913 vers.append(extensions.moduleversion(module) or None)
7920 7914 isinternals.append(extensions.ismoduleinternal(module))
7921 7915 fn = fm.nested(b"extensions", tmpl=b'{name}\n')
7922 7916 if names:
7923 7917 namefmt = b" %%-%ds " % max(len(n) for n in names)
7924 7918 places = [_(b"external"), _(b"internal")]
7925 7919 for n, v, p in zip(names, vers, isinternals):
7926 7920 fn.startitem()
7927 7921 fn.condwrite(ui.verbose, b"name", namefmt, n)
7928 7922 if ui.verbose:
7929 7923 fn.plain(b"%s " % places[p])
7930 7924 fn.data(bundled=p)
7931 7925 fn.condwrite(ui.verbose and v, b"ver", b"%s", v)
7932 7926 if ui.verbose:
7933 7927 fn.plain(b"\n")
7934 7928 fn.end()
7935 7929 fm.end()
7936 7930
7937 7931
7938 7932 def loadcmdtable(ui, name, cmdtable):
7939 7933 """Load command functions from specified cmdtable"""
7940 7934 overrides = [cmd for cmd in cmdtable if cmd in table]
7941 7935 if overrides:
7942 7936 ui.warn(
7943 7937 _(b"extension '%s' overrides commands: %s\n")
7944 7938 % (name, b" ".join(overrides))
7945 7939 )
7946 7940 table.update(cmdtable)
General Comments 0
You need to be logged in to leave comments. Login now