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