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