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