comparison hgext/githelp.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 7752cd3a2f83
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
27 fancyopts, 27 fancyopts,
28 pycompat, 28 pycompat,
29 registrar, 29 registrar,
30 scmutil, 30 scmutil,
31 ) 31 )
32 from mercurial.utils import ( 32 from mercurial.utils import procutil
33 procutil,
34 )
35 33
36 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for 34 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
37 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 35 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
38 # be specifying the version(s) of Mercurial they are tested with, or 36 # be specifying the version(s) of Mercurial they are tested with, or
39 # leave the attribute unspecified. 37 # leave the attribute unspecified.
40 testedwith = 'ships-with-hg-core' 38 testedwith = 'ships-with-hg-core'
41 39
42 cmdtable = {} 40 cmdtable = {}
43 command = registrar.command(cmdtable) 41 command = registrar.command(cmdtable)
42
44 43
45 def convert(s): 44 def convert(s):
46 if s.startswith("origin/"): 45 if s.startswith("origin/"):
47 return s[7:] 46 return s[7:]
48 if 'HEAD' in s: 47 if 'HEAD' in s:
49 s = s.replace('HEAD', '.') 48 s = s.replace('HEAD', '.')
50 # HEAD~ in git is .~1 in mercurial 49 # HEAD~ in git is .~1 in mercurial
51 s = re.sub('~$', '~1', s) 50 s = re.sub('~$', '~1', s)
52 return s 51 return s
53 52
54 @command('githelp|git', [ 53
55 ], _('hg githelp'), 54 @command(
56 helpcategory=command.CATEGORY_HELP, helpbasic=True) 55 'githelp|git',
56 [],
57 _('hg githelp'),
58 helpcategory=command.CATEGORY_HELP,
59 helpbasic=True,
60 )
57 def githelp(ui, repo, *args, **kwargs): 61 def githelp(ui, repo, *args, **kwargs):
58 '''suggests the Mercurial equivalent of the given git command 62 '''suggests the Mercurial equivalent of the given git command
59 63
60 Usage: hg githelp -- <git command> 64 Usage: hg githelp -- <git command>
61 ''' 65 '''
62 66
63 if len(args) == 0 or (len(args) == 1 and args[0] =='git'): 67 if len(args) == 0 or (len(args) == 1 and args[0] == 'git'):
64 raise error.Abort(_('missing git command - ' 68 raise error.Abort(
65 'usage: hg githelp -- <git command>')) 69 _('missing git command - ' 'usage: hg githelp -- <git command>')
70 )
66 71
67 if args[0] == 'git': 72 if args[0] == 'git':
68 args = args[1:] 73 args = args[1:]
69 74
70 cmd = args[0] 75 cmd = args[0]
71 if not cmd in gitcommands: 76 if not cmd in gitcommands:
72 raise error.Abort(_("error: unknown git command %s") % (cmd)) 77 raise error.Abort(_("error: unknown git command %s") % cmd)
73 78
74 ui.pager('githelp') 79 ui.pager('githelp')
75 args = args[1:] 80 args = args[1:]
76 return gitcommands[cmd](ui, repo, *args, **kwargs) 81 return gitcommands[cmd](ui, repo, *args, **kwargs)
82
77 83
78 def parseoptions(ui, cmdoptions, args): 84 def parseoptions(ui, cmdoptions, args):
79 cmdoptions = list(cmdoptions) 85 cmdoptions = list(cmdoptions)
80 opts = {} 86 opts = {}
81 args = list(args) 87 args = list(args)
89 if (r'--' + ex.opt) in ex.msg: 95 if (r'--' + ex.opt) in ex.msg:
90 flag = '--' + pycompat.bytestr(ex.opt) 96 flag = '--' + pycompat.bytestr(ex.opt)
91 elif (r'-' + ex.opt) in ex.msg: 97 elif (r'-' + ex.opt) in ex.msg:
92 flag = '-' + pycompat.bytestr(ex.opt) 98 flag = '-' + pycompat.bytestr(ex.opt)
93 else: 99 else:
94 raise error.Abort(_("unknown option %s") % 100 raise error.Abort(
95 pycompat.bytestr(ex.opt)) 101 _("unknown option %s") % pycompat.bytestr(ex.opt)
102 )
96 try: 103 try:
97 args.remove(flag) 104 args.remove(flag)
98 except Exception: 105 except Exception:
99 msg = _("unknown option '%s' packed with other options") 106 msg = _("unknown option '%s' packed with other options")
100 hint = _("please try passing the option as its own flag: -%s") 107 hint = _("please try passing the option as its own flag: -%s")
101 raise error.Abort(msg % pycompat.bytestr(ex.opt), 108 raise error.Abort(
102 hint=hint % pycompat.bytestr(ex.opt)) 109 msg % pycompat.bytestr(ex.opt),
110 hint=hint % pycompat.bytestr(ex.opt),
111 )
103 112
104 ui.warn(_("ignoring unknown option %s\n") % flag) 113 ui.warn(_("ignoring unknown option %s\n") % flag)
105 114
106 args = list([convert(x) for x in args]) 115 args = list([convert(x) for x in args])
107 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v) 116 opts = dict(
108 for k, v in opts.iteritems()]) 117 [
118 (k, convert(v)) if isinstance(v, str) else (k, v)
119 for k, v in opts.iteritems()
120 ]
121 )
109 122
110 return args, opts 123 return args, opts
124
111 125
112 class Command(object): 126 class Command(object):
113 def __init__(self, name): 127 def __init__(self, name):
114 self.name = name 128 self.name = name
115 self.args = [] 129 self.args = []
147 values.append(value) 161 values.append(value)
148 162
149 def __and__(self, other): 163 def __and__(self, other):
150 return AndCommand(self, other) 164 return AndCommand(self, other)
151 165
166
152 class AndCommand(object): 167 class AndCommand(object):
153 def __init__(self, left, right): 168 def __init__(self, left, right):
154 self.left = left 169 self.left = left
155 self.right = right 170 self.right = right
156 171
158 return "%s && %s" % (self.left, self.right) 173 return "%s && %s" % (self.left, self.right)
159 174
160 def __and__(self, other): 175 def __and__(self, other):
161 return AndCommand(self, other) 176 return AndCommand(self, other)
162 177
178
163 def add(ui, repo, *args, **kwargs): 179 def add(ui, repo, *args, **kwargs):
164 cmdoptions = [ 180 cmdoptions = [
165 ('A', 'all', None, ''), 181 ('A', 'all', None, ''),
166 ('p', 'patch', None, ''), 182 ('p', 'patch', None, ''),
167 ] 183 ]
168 args, opts = parseoptions(ui, cmdoptions, args) 184 args, opts = parseoptions(ui, cmdoptions, args)
169 185
170 if (opts.get('patch')): 186 if opts.get('patch'):
171 ui.status(_("note: Mercurial will commit when complete, " 187 ui.status(
172 "as there is no staging area in Mercurial\n\n")) 188 _(
189 "note: Mercurial will commit when complete, "
190 "as there is no staging area in Mercurial\n\n"
191 )
192 )
173 cmd = Command('commit --interactive') 193 cmd = Command('commit --interactive')
174 else: 194 else:
175 cmd = Command("add") 195 cmd = Command("add")
176 196
177 if not opts.get('all'): 197 if not opts.get('all'):
178 cmd.extend(args) 198 cmd.extend(args)
179 else: 199 else:
180 ui.status(_("note: use hg addremove to remove files that have " 200 ui.status(
181 "been deleted\n\n")) 201 _(
182 202 "note: use hg addremove to remove files that have "
183 ui.status((bytes(cmd)), "\n") 203 "been deleted\n\n"
204 )
205 )
206
207 ui.status((bytes(cmd)), "\n")
208
184 209
185 def am(ui, repo, *args, **kwargs): 210 def am(ui, repo, *args, **kwargs):
186 cmdoptions=[ 211 cmdoptions = []
187 ]
188 args, opts = parseoptions(ui, cmdoptions, args) 212 args, opts = parseoptions(ui, cmdoptions, args)
189 cmd = Command('import') 213 cmd = Command('import')
190 ui.status(bytes(cmd), "\n") 214 ui.status(bytes(cmd), "\n")
191 215
216
192 def apply(ui, repo, *args, **kwargs): 217 def apply(ui, repo, *args, **kwargs):
193 cmdoptions = [ 218 cmdoptions = [
194 ('p', 'p', int, ''), 219 ('p', 'p', int, ''),
195 ('', 'directory', '', ''), 220 ('', 'directory', '', ''),
196 ] 221 ]
197 args, opts = parseoptions(ui, cmdoptions, args) 222 args, opts = parseoptions(ui, cmdoptions, args)
198 223
199 cmd = Command('import --no-commit') 224 cmd = Command('import --no-commit')
200 if (opts.get('p')): 225 if opts.get('p'):
201 cmd['-p'] = opts.get('p') 226 cmd['-p'] = opts.get('p')
202 if opts.get('directory'): 227 if opts.get('directory'):
203 cmd['--prefix'] = opts.get('directory') 228 cmd['--prefix'] = opts.get('directory')
204 cmd.extend(args) 229 cmd.extend(args)
205 230
206 ui.status((bytes(cmd)), "\n") 231 ui.status((bytes(cmd)), "\n")
207 232
233
208 def bisect(ui, repo, *args, **kwargs): 234 def bisect(ui, repo, *args, **kwargs):
209 ui.status(_("see 'hg help bisect' for how to use bisect\n\n")) 235 ui.status(_("see 'hg help bisect' for how to use bisect\n\n"))
210 236
237
211 def blame(ui, repo, *args, **kwargs): 238 def blame(ui, repo, *args, **kwargs):
212 cmdoptions = [ 239 cmdoptions = []
213 ]
214 args, opts = parseoptions(ui, cmdoptions, args) 240 args, opts = parseoptions(ui, cmdoptions, args)
215 cmd = Command('annotate -udl') 241 cmd = Command('annotate -udl')
216 cmd.extend([convert(v) for v in args]) 242 cmd.extend([convert(v) for v in args])
217 ui.status((bytes(cmd)), "\n") 243 ui.status((bytes(cmd)), "\n")
244
218 245
219 def branch(ui, repo, *args, **kwargs): 246 def branch(ui, repo, *args, **kwargs):
220 cmdoptions = [ 247 cmdoptions = [
221 ('', 'set-upstream', None, ''), 248 ('', 'set-upstream', None, ''),
222 ('', 'set-upstream-to', '', ''), 249 ('', 'set-upstream-to', '', ''),
257 cmd.append(args[0]) 284 cmd.append(args[0])
258 elif len(args) == 1: 285 elif len(args) == 1:
259 cmd.append(args[0]) 286 cmd.append(args[0])
260 ui.status((bytes(cmd)), "\n") 287 ui.status((bytes(cmd)), "\n")
261 288
289
262 def ispath(repo, string): 290 def ispath(repo, string):
263 """ 291 """
264 The first argument to git checkout can either be a revision or a path. Let's 292 The first argument to git checkout can either be a revision or a path. Let's
265 generally assume it's a revision, unless it's obviously a path. There are 293 generally assume it's a revision, unless it's obviously a path. There are
266 too many ways to spell revisions in git for us to reasonably catch all of 294 too many ways to spell revisions in git for us to reasonably catch all of
285 313
286 didexist = (repopath in manifest) or manifest.hasdir(repopath) 314 didexist = (repopath in manifest) or manifest.hasdir(repopath)
287 315
288 return didexist 316 return didexist
289 317
318
290 def checkout(ui, repo, *args, **kwargs): 319 def checkout(ui, repo, *args, **kwargs):
291 cmdoptions = [ 320 cmdoptions = [
292 ('b', 'branch', '', ''), 321 ('b', 'branch', '', ''),
293 ('B', 'branch', '', ''), 322 ('B', 'branch', '', ''),
294 ('f', 'force', None, ''), 323 ('f', 'force', None, ''),
295 ('p', 'patch', None, ''), 324 ('p', 'patch', None, ''),
296 ] 325 ]
297 paths = [] 326 paths = []
298 if '--' in args: 327 if '--' in args:
299 sepindex = args.index('--') 328 sepindex = args.index('--')
300 paths.extend(args[sepindex + 1:]) 329 paths.extend(args[sepindex + 1 :])
301 args = args[:sepindex] 330 args = args[:sepindex]
302 331
303 args, opts = parseoptions(ui, cmdoptions, args) 332 args, opts = parseoptions(ui, cmdoptions, args)
304 333
305 rev = None 334 rev = None
348 else: 377 else:
349 raise error.Abort(_("a commit must be specified")) 378 raise error.Abort(_("a commit must be specified"))
350 379
351 ui.status((bytes(cmd)), "\n") 380 ui.status((bytes(cmd)), "\n")
352 381
382
353 def cherrypick(ui, repo, *args, **kwargs): 383 def cherrypick(ui, repo, *args, **kwargs):
354 cmdoptions = [ 384 cmdoptions = [
355 ('', 'continue', None, ''), 385 ('', 'continue', None, ''),
356 ('', 'abort', None, ''), 386 ('', 'abort', None, ''),
357 ('e', 'edit', None, ''), 387 ('e', 'edit', None, ''),
370 else: 400 else:
371 cmd.extend(args) 401 cmd.extend(args)
372 402
373 ui.status((bytes(cmd)), "\n") 403 ui.status((bytes(cmd)), "\n")
374 404
405
375 def clean(ui, repo, *args, **kwargs): 406 def clean(ui, repo, *args, **kwargs):
376 cmdoptions = [ 407 cmdoptions = [
377 ('d', 'd', None, ''), 408 ('d', 'd', None, ''),
378 ('f', 'force', None, ''), 409 ('f', 'force', None, ''),
379 ('x', 'x', None, ''), 410 ('x', 'x', None, ''),
385 cmd['--all'] = None 416 cmd['--all'] = None
386 cmd.extend(args) 417 cmd.extend(args)
387 418
388 ui.status((bytes(cmd)), "\n") 419 ui.status((bytes(cmd)), "\n")
389 420
421
390 def clone(ui, repo, *args, **kwargs): 422 def clone(ui, repo, *args, **kwargs):
391 cmdoptions = [ 423 cmdoptions = [
392 ('', 'bare', None, ''), 424 ('', 'bare', None, ''),
393 ('n', 'no-checkout', None, ''), 425 ('n', 'no-checkout', None, ''),
394 ('b', 'branch', '', ''), 426 ('b', 'branch', '', ''),
403 if len(args) > 1: 435 if len(args) > 1:
404 cmd.append(args[1]) 436 cmd.append(args[1])
405 437
406 if opts.get('bare'): 438 if opts.get('bare'):
407 cmd['-U'] = None 439 cmd['-U'] = None
408 ui.status(_("note: Mercurial does not have bare clones. " 440 ui.status(
409 "-U will clone the repo without checking out a commit\n\n")) 441 _(
442 "note: Mercurial does not have bare clones. "
443 "-U will clone the repo without checking out a commit\n\n"
444 )
445 )
410 elif opts.get('no_checkout'): 446 elif opts.get('no_checkout'):
411 cmd['-U'] = None 447 cmd['-U'] = None
412 448
413 if opts.get('branch'): 449 if opts.get('branch'):
414 cocmd = Command("update") 450 cocmd = Command("update")
415 cocmd.append(opts.get('branch')) 451 cocmd.append(opts.get('branch'))
416 cmd = cmd & cocmd 452 cmd = cmd & cocmd
417 453
418 ui.status((bytes(cmd)), "\n") 454 ui.status((bytes(cmd)), "\n")
455
419 456
420 def commit(ui, repo, *args, **kwargs): 457 def commit(ui, repo, *args, **kwargs):
421 cmdoptions = [ 458 cmdoptions = [
422 ('a', 'all', None, ''), 459 ('a', 'all', None, ''),
423 ('m', 'message', '', ''), 460 ('m', 'message', '', ''),
446 483
447 if opts.get('message'): 484 if opts.get('message'):
448 cmd['-m'] = "'%s'" % (opts.get('message'),) 485 cmd['-m'] = "'%s'" % (opts.get('message'),)
449 486
450 if opts.get('all'): 487 if opts.get('all'):
451 ui.status(_("note: Mercurial doesn't have a staging area, " 488 ui.status(
452 "so there is no --all. -A will add and remove files " 489 _(
453 "for you though.\n\n")) 490 "note: Mercurial doesn't have a staging area, "
491 "so there is no --all. -A will add and remove files "
492 "for you though.\n\n"
493 )
494 )
454 495
455 if opts.get('file'): 496 if opts.get('file'):
456 cmd['-l'] = opts.get('file') 497 cmd['-l'] = opts.get('file')
457 498
458 if opts.get('author'): 499 if opts.get('author'):
463 504
464 cmd.extend(args) 505 cmd.extend(args)
465 506
466 ui.status((bytes(cmd)), "\n") 507 ui.status((bytes(cmd)), "\n")
467 508
509
468 def deprecated(ui, repo, *args, **kwargs): 510 def deprecated(ui, repo, *args, **kwargs):
469 ui.warn(_('this command has been deprecated in the git project, ' 511 ui.warn(
470 'thus isn\'t supported by this tool\n\n')) 512 _(
513 'this command has been deprecated in the git project, '
514 'thus isn\'t supported by this tool\n\n'
515 )
516 )
517
471 518
472 def diff(ui, repo, *args, **kwargs): 519 def diff(ui, repo, *args, **kwargs):
473 cmdoptions = [ 520 cmdoptions = [
474 ('a', 'all', None, ''), 521 ('a', 'all', None, ''),
475 ('', 'cached', None, ''), 522 ('', 'cached', None, ''),
478 args, opts = parseoptions(ui, cmdoptions, args) 525 args, opts = parseoptions(ui, cmdoptions, args)
479 526
480 cmd = Command('diff') 527 cmd = Command('diff')
481 528
482 if opts.get('cached'): 529 if opts.get('cached'):
483 ui.status(_('note: Mercurial has no concept of a staging area, ' 530 ui.status(
484 'so --cached does nothing\n\n')) 531 _(
532 'note: Mercurial has no concept of a staging area, '
533 'so --cached does nothing\n\n'
534 )
535 )
485 536
486 if opts.get('reverse'): 537 if opts.get('reverse'):
487 cmd['--reverse'] = None 538 cmd['--reverse'] = None
488 539
489 for a in list(args): 540 for a in list(args):
494 except Exception: 545 except Exception:
495 cmd.append(a) 546 cmd.append(a)
496 547
497 ui.status((bytes(cmd)), "\n") 548 ui.status((bytes(cmd)), "\n")
498 549
550
499 def difftool(ui, repo, *args, **kwargs): 551 def difftool(ui, repo, *args, **kwargs):
500 ui.status(_('Mercurial does not enable external difftool by default. You ' 552 ui.status(
501 'need to enable the extdiff extension in your .hgrc file by adding\n' 553 _(
502 'extdiff =\n' 554 'Mercurial does not enable external difftool by default. You '
503 'to the [extensions] section and then running\n\n' 555 'need to enable the extdiff extension in your .hgrc file by adding\n'
504 'hg extdiff -p <program>\n\n' 556 'extdiff =\n'
505 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more ' 557 'to the [extensions] section and then running\n\n'
506 'information.\n')) 558 'hg extdiff -p <program>\n\n'
559 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
560 'information.\n'
561 )
562 )
563
507 564
508 def fetch(ui, repo, *args, **kwargs): 565 def fetch(ui, repo, *args, **kwargs):
509 cmdoptions = [ 566 cmdoptions = [
510 ('', 'all', None, ''), 567 ('', 'all', None, ''),
511 ('f', 'force', None, ''), 568 ('f', 'force', None, ''),
515 cmd = Command('pull') 572 cmd = Command('pull')
516 573
517 if len(args) > 0: 574 if len(args) > 0:
518 cmd.append(args[0]) 575 cmd.append(args[0])
519 if len(args) > 1: 576 if len(args) > 1:
520 ui.status(_("note: Mercurial doesn't have refspecs. " 577 ui.status(
521 "-r can be used to specify which commits you want to " 578 _(
522 "pull. -B can be used to specify which bookmark you " 579 "note: Mercurial doesn't have refspecs. "
523 "want to pull.\n\n")) 580 "-r can be used to specify which commits you want to "
581 "pull. -B can be used to specify which bookmark you "
582 "want to pull.\n\n"
583 )
584 )
524 for v in args[1:]: 585 for v in args[1:]:
525 if v in repo._bookmarks: 586 if v in repo._bookmarks:
526 cmd['-B'] = v 587 cmd['-B'] = v
527 else: 588 else:
528 cmd['-r'] = v 589 cmd['-r'] = v
529 590
530 ui.status((bytes(cmd)), "\n") 591 ui.status((bytes(cmd)), "\n")
531 592
593
532 def grep(ui, repo, *args, **kwargs): 594 def grep(ui, repo, *args, **kwargs):
533 cmdoptions = [ 595 cmdoptions = []
534 ]
535 args, opts = parseoptions(ui, cmdoptions, args) 596 args, opts = parseoptions(ui, cmdoptions, args)
536 597
537 cmd = Command('grep') 598 cmd = Command('grep')
538 599
539 # For basic usage, git grep and hg grep are the same. They both have the 600 # For basic usage, git grep and hg grep are the same. They both have the
540 # pattern first, followed by paths. 601 # pattern first, followed by paths.
541 cmd.extend(args) 602 cmd.extend(args)
542 603
543 ui.status((bytes(cmd)), "\n") 604 ui.status((bytes(cmd)), "\n")
544 605
606
545 def init(ui, repo, *args, **kwargs): 607 def init(ui, repo, *args, **kwargs):
546 cmdoptions = [ 608 cmdoptions = []
547 ]
548 args, opts = parseoptions(ui, cmdoptions, args) 609 args, opts = parseoptions(ui, cmdoptions, args)
549 610
550 cmd = Command('init') 611 cmd = Command('init')
551 612
552 if len(args) > 0: 613 if len(args) > 0:
553 cmd.append(args[0]) 614 cmd.append(args[0])
554 615
555 ui.status((bytes(cmd)), "\n") 616 ui.status((bytes(cmd)), "\n")
617
556 618
557 def log(ui, repo, *args, **kwargs): 619 def log(ui, repo, *args, **kwargs):
558 cmdoptions = [ 620 cmdoptions = [
559 ('', 'follow', None, ''), 621 ('', 'follow', None, ''),
560 ('', 'decorate', None, ''), 622 ('', 'decorate', None, ''),
566 ('', 'stat', None, ''), 628 ('', 'stat', None, ''),
567 ('', 'graph', None, ''), 629 ('', 'graph', None, ''),
568 ('p', 'patch', None, ''), 630 ('p', 'patch', None, ''),
569 ] 631 ]
570 args, opts = parseoptions(ui, cmdoptions, args) 632 args, opts = parseoptions(ui, cmdoptions, args)
571 ui.status(_('note: -v prints the entire commit message like Git does. To ' 633 ui.status(
572 'print just the first line, drop the -v.\n\n')) 634 _(
573 ui.status(_("note: see hg help revset for information on how to filter " 635 'note: -v prints the entire commit message like Git does. To '
574 "log output\n\n")) 636 'print just the first line, drop the -v.\n\n'
637 )
638 )
639 ui.status(
640 _(
641 "note: see hg help revset for information on how to filter "
642 "log output\n\n"
643 )
644 )
575 645
576 cmd = Command('log') 646 cmd = Command('log')
577 cmd['-v'] = None 647 cmd['-v'] = None
578 648
579 if opts.get('number'): 649 if opts.get('number'):
588 cmd['-p'] = None 658 cmd['-p'] = None
589 659
590 if opts.get('pretty') or opts.get('format') or opts.get('oneline'): 660 if opts.get('pretty') or opts.get('format') or opts.get('oneline'):
591 format = opts.get('format', '') 661 format = opts.get('format', '')
592 if 'format:' in format: 662 if 'format:' in format:
593 ui.status(_("note: --format format:??? equates to Mercurial's " 663 ui.status(
594 "--template. See hg help templates for more info.\n\n")) 664 _(
665 "note: --format format:??? equates to Mercurial's "
666 "--template. See hg help templates for more info.\n\n"
667 )
668 )
595 cmd['--template'] = '???' 669 cmd['--template'] = '???'
596 else: 670 else:
597 ui.status(_("note: --pretty/format/oneline equate to Mercurial's " 671 ui.status(
598 "--style or --template. See hg help templates for " 672 _(
599 "more info.\n\n")) 673 "note: --pretty/format/oneline equate to Mercurial's "
674 "--style or --template. See hg help templates for "
675 "more info.\n\n"
676 )
677 )
600 cmd['--style'] = '???' 678 cmd['--style'] = '???'
601 679
602 if len(args) > 0: 680 if len(args) > 0:
603 if '..' in args[0]: 681 if '..' in args[0]:
604 since, until = args[0].split('..') 682 since, until = args[0].split('..')
605 cmd['-r'] = "'%s::%s'" % (since, until) 683 cmd['-r'] = "'%s::%s'" % (since, until)
606 del args[0] 684 del args[0]
607 cmd.extend(args) 685 cmd.extend(args)
608 686
609 ui.status((bytes(cmd)), "\n") 687 ui.status((bytes(cmd)), "\n")
688
610 689
611 def lsfiles(ui, repo, *args, **kwargs): 690 def lsfiles(ui, repo, *args, **kwargs):
612 cmdoptions = [ 691 cmdoptions = [
613 ('c', 'cached', None, ''), 692 ('c', 'cached', None, ''),
614 ('d', 'deleted', None, ''), 693 ('d', 'deleted', None, ''),
618 ('s', 'stage', None, ''), 697 ('s', 'stage', None, ''),
619 ('z', '_zero', None, ''), 698 ('z', '_zero', None, ''),
620 ] 699 ]
621 args, opts = parseoptions(ui, cmdoptions, args) 700 args, opts = parseoptions(ui, cmdoptions, args)
622 701
623 if (opts.get('modified') or opts.get('deleted') 702 if (
624 or opts.get('others') or opts.get('ignored')): 703 opts.get('modified')
704 or opts.get('deleted')
705 or opts.get('others')
706 or opts.get('ignored')
707 ):
625 cmd = Command('status') 708 cmd = Command('status')
626 if opts.get('deleted'): 709 if opts.get('deleted'):
627 cmd['-d'] = None 710 cmd['-d'] = None
628 if opts.get('modified'): 711 if opts.get('modified'):
629 cmd['-m'] = None 712 cmd['-m'] = None
632 if opts.get('ignored'): 715 if opts.get('ignored'):
633 cmd['-i'] = None 716 cmd['-i'] = None
634 else: 717 else:
635 cmd = Command('files') 718 cmd = Command('files')
636 if opts.get('stage'): 719 if opts.get('stage'):
637 ui.status(_("note: Mercurial doesn't have a staging area, ignoring " 720 ui.status(
638 "--stage\n")) 721 _(
722 "note: Mercurial doesn't have a staging area, ignoring "
723 "--stage\n"
724 )
725 )
639 if opts.get('_zero'): 726 if opts.get('_zero'):
640 cmd['-0'] = None 727 cmd['-0'] = None
641 cmd.append('.') 728 cmd.append('.')
642 for include in args: 729 for include in args:
643 cmd['-I'] = procutil.shellquote(include) 730 cmd['-I'] = procutil.shellquote(include)
644 731
645 ui.status((bytes(cmd)), "\n") 732 ui.status((bytes(cmd)), "\n")
646 733
734
647 def merge(ui, repo, *args, **kwargs): 735 def merge(ui, repo, *args, **kwargs):
648 cmdoptions = [ 736 cmdoptions = []
649 ]
650 args, opts = parseoptions(ui, cmdoptions, args) 737 args, opts = parseoptions(ui, cmdoptions, args)
651 738
652 cmd = Command('merge') 739 cmd = Command('merge')
653 740
654 if len(args) > 0: 741 if len(args) > 0:
655 cmd.append(args[len(args) - 1]) 742 cmd.append(args[len(args) - 1])
656 743
657 ui.status((bytes(cmd)), "\n") 744 ui.status((bytes(cmd)), "\n")
658 745
746
659 def mergebase(ui, repo, *args, **kwargs): 747 def mergebase(ui, repo, *args, **kwargs):
660 cmdoptions = [] 748 cmdoptions = []
661 args, opts = parseoptions(ui, cmdoptions, args) 749 args, opts = parseoptions(ui, cmdoptions, args)
662 750
663 if len(args) != 2: 751 if len(args) != 2:
664 args = ['A', 'B'] 752 args = ['A', 'B']
665 753
666 cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'" 754 cmd = Command(
667 % (args[0], args[1])) 755 "log -T '{node}\\n' -r 'ancestor(%s,%s)'" % (args[0], args[1])
668 756 )
669 ui.status(_('note: ancestors() is part of the revset language\n'), 757
670 _("(learn more about revsets with 'hg help revsets')\n\n")) 758 ui.status(
671 ui.status((bytes(cmd)), "\n") 759 _('note: ancestors() is part of the revset language\n'),
760 _("(learn more about revsets with 'hg help revsets')\n\n"),
761 )
762 ui.status((bytes(cmd)), "\n")
763
672 764
673 def mergetool(ui, repo, *args, **kwargs): 765 def mergetool(ui, repo, *args, **kwargs):
674 cmdoptions = [] 766 cmdoptions = []
675 args, opts = parseoptions(ui, cmdoptions, args) 767 args, opts = parseoptions(ui, cmdoptions, args)
676 768
678 770
679 if len(args) == 0: 771 if len(args) == 0:
680 cmd['--all'] = None 772 cmd['--all'] = None
681 cmd.extend(args) 773 cmd.extend(args)
682 ui.status((bytes(cmd)), "\n") 774 ui.status((bytes(cmd)), "\n")
775
683 776
684 def mv(ui, repo, *args, **kwargs): 777 def mv(ui, repo, *args, **kwargs):
685 cmdoptions = [ 778 cmdoptions = [
686 ('f', 'force', None, ''), 779 ('f', 'force', None, ''),
687 ('n', 'dry-run', None, ''), 780 ('n', 'dry-run', None, ''),
696 if opts.get('dry_run'): 789 if opts.get('dry_run'):
697 cmd['-n'] = None 790 cmd['-n'] = None
698 791
699 ui.status((bytes(cmd)), "\n") 792 ui.status((bytes(cmd)), "\n")
700 793
794
701 def pull(ui, repo, *args, **kwargs): 795 def pull(ui, repo, *args, **kwargs):
702 cmdoptions = [ 796 cmdoptions = [
703 ('', 'all', None, ''), 797 ('', 'all', None, ''),
704 ('f', 'force', None, ''), 798 ('f', 'force', None, ''),
705 ('r', 'rebase', None, ''), 799 ('r', 'rebase', None, ''),
710 cmd['--rebase'] = None 804 cmd['--rebase'] = None
711 805
712 if len(args) > 0: 806 if len(args) > 0:
713 cmd.append(args[0]) 807 cmd.append(args[0])
714 if len(args) > 1: 808 if len(args) > 1:
715 ui.status(_("note: Mercurial doesn't have refspecs. " 809 ui.status(
716 "-r can be used to specify which commits you want to " 810 _(
717 "pull. -B can be used to specify which bookmark you " 811 "note: Mercurial doesn't have refspecs. "
718 "want to pull.\n\n")) 812 "-r can be used to specify which commits you want to "
813 "pull. -B can be used to specify which bookmark you "
814 "want to pull.\n\n"
815 )
816 )
719 for v in args[1:]: 817 for v in args[1:]:
720 if v in repo._bookmarks: 818 if v in repo._bookmarks:
721 cmd['-B'] = v 819 cmd['-B'] = v
722 else: 820 else:
723 cmd['-r'] = v 821 cmd['-r'] = v
724 822
725 ui.status((bytes(cmd)), "\n") 823 ui.status((bytes(cmd)), "\n")
726 824
825
727 def push(ui, repo, *args, **kwargs): 826 def push(ui, repo, *args, **kwargs):
728 cmdoptions = [ 827 cmdoptions = [
729 ('', 'all', None, ''), 828 ('', 'all', None, ''),
730 ('f', 'force', None, ''), 829 ('f', 'force', None, ''),
731 ] 830 ]
734 cmd = Command('push') 833 cmd = Command('push')
735 834
736 if len(args) > 0: 835 if len(args) > 0:
737 cmd.append(args[0]) 836 cmd.append(args[0])
738 if len(args) > 1: 837 if len(args) > 1:
739 ui.status(_("note: Mercurial doesn't have refspecs. " 838 ui.status(
740 "-r can be used to specify which commits you want " 839 _(
741 "to push. -B can be used to specify which bookmark " 840 "note: Mercurial doesn't have refspecs. "
742 "you want to push.\n\n")) 841 "-r can be used to specify which commits you want "
842 "to push. -B can be used to specify which bookmark "
843 "you want to push.\n\n"
844 )
845 )
743 for v in args[1:]: 846 for v in args[1:]:
744 if v in repo._bookmarks: 847 if v in repo._bookmarks:
745 cmd['-B'] = v 848 cmd['-B'] = v
746 else: 849 else:
747 cmd['-r'] = v 850 cmd['-r'] = v
748 851
749 if opts.get('force'): 852 if opts.get('force'):
750 cmd['-f'] = None 853 cmd['-f'] = None
751 854
752 ui.status((bytes(cmd)), "\n") 855 ui.status((bytes(cmd)), "\n")
856
753 857
754 def rebase(ui, repo, *args, **kwargs): 858 def rebase(ui, repo, *args, **kwargs):
755 cmdoptions = [ 859 cmdoptions = [
756 ('', 'all', None, ''), 860 ('', 'all', None, ''),
757 ('i', 'interactive', None, ''), 861 ('i', 'interactive', None, ''),
761 ('', 'skip', None, ''), 865 ('', 'skip', None, ''),
762 ] 866 ]
763 args, opts = parseoptions(ui, cmdoptions, args) 867 args, opts = parseoptions(ui, cmdoptions, args)
764 868
765 if opts.get('interactive'): 869 if opts.get('interactive'):
766 ui.status(_("note: hg histedit does not perform a rebase. " 870 ui.status(
767 "It just edits history.\n\n")) 871 _(
872 "note: hg histedit does not perform a rebase. "
873 "It just edits history.\n\n"
874 )
875 )
768 cmd = Command('histedit') 876 cmd = Command('histedit')
769 if len(args) > 0: 877 if len(args) > 0:
770 ui.status(_("also note: 'hg histedit' will automatically detect" 878 ui.status(
771 " your stack, so no second argument is necessary\n\n")) 879 _(
880 "also note: 'hg histedit' will automatically detect"
881 " your stack, so no second argument is necessary\n\n"
882 )
883 )
772 ui.status((bytes(cmd)), "\n") 884 ui.status((bytes(cmd)), "\n")
773 return 885 return
774 886
775 if opts.get('skip'): 887 if opts.get('skip'):
776 cmd = Command('revert --all -r .') 888 cmd = Command('revert --all -r .')
782 cmd['--continue'] = None 894 cmd['--continue'] = None
783 if opts.get('abort'): 895 if opts.get('abort'):
784 cmd['--abort'] = None 896 cmd['--abort'] = None
785 897
786 if opts.get('onto'): 898 if opts.get('onto'):
787 ui.status(_("note: if you're trying to lift a commit off one branch, " 899 ui.status(
788 "try hg rebase -d <destination commit> -s <commit to be " 900 _(
789 "lifted>\n\n")) 901 "note: if you're trying to lift a commit off one branch, "
902 "try hg rebase -d <destination commit> -s <commit to be "
903 "lifted>\n\n"
904 )
905 )
790 cmd['-d'] = convert(opts.get('onto')) 906 cmd['-d'] = convert(opts.get('onto'))
791 if len(args) < 2: 907 if len(args) < 2:
792 raise error.Abort(_("expected format: git rebase --onto X Y Z")) 908 raise error.Abort(_("expected format: git rebase --onto X Y Z"))
793 cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0])) 909 cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
794 else: 910 else:
798 cmd['-d'] = convert(args[0]) 914 cmd['-d'] = convert(args[0])
799 cmd['-b'] = convert(args[1]) 915 cmd['-b'] = convert(args[1])
800 916
801 ui.status((bytes(cmd)), "\n") 917 ui.status((bytes(cmd)), "\n")
802 918
919
803 def reflog(ui, repo, *args, **kwargs): 920 def reflog(ui, repo, *args, **kwargs):
804 cmdoptions = [ 921 cmdoptions = [
805 ('', 'all', None, ''), 922 ('', 'all', None, ''),
806 ] 923 ]
807 args, opts = parseoptions(ui, cmdoptions, args) 924 args, opts = parseoptions(ui, cmdoptions, args)
811 cmd['--all'] = None 928 cmd['--all'] = None
812 if len(args) > 0: 929 if len(args) > 0:
813 cmd.append(args[0]) 930 cmd.append(args[0])
814 931
815 ui.status(bytes(cmd), "\n\n") 932 ui.status(bytes(cmd), "\n\n")
816 ui.status(_("note: in hg commits can be deleted from repo but we always" 933 ui.status(
817 " have backups\n")) 934 _(
935 "note: in hg commits can be deleted from repo but we always"
936 " have backups\n"
937 )
938 )
939
818 940
819 def reset(ui, repo, *args, **kwargs): 941 def reset(ui, repo, *args, **kwargs):
820 cmdoptions = [ 942 cmdoptions = [
821 ('', 'soft', None, ''), 943 ('', 'soft', None, ''),
822 ('', 'hard', None, ''), 944 ('', 'hard', None, ''),
826 948
827 commit = convert(args[0] if len(args) > 0 else '.') 949 commit = convert(args[0] if len(args) > 0 else '.')
828 hard = opts.get('hard') 950 hard = opts.get('hard')
829 951
830 if opts.get('mixed'): 952 if opts.get('mixed'):
831 ui.status(_('note: --mixed has no meaning since Mercurial has no ' 953 ui.status(
832 'staging area\n\n')) 954 _(
955 'note: --mixed has no meaning since Mercurial has no '
956 'staging area\n\n'
957 )
958 )
833 if opts.get('soft'): 959 if opts.get('soft'):
834 ui.status(_('note: --soft has no meaning since Mercurial has no ' 960 ui.status(
835 'staging area\n\n')) 961 _(
962 'note: --soft has no meaning since Mercurial has no '
963 'staging area\n\n'
964 )
965 )
836 966
837 cmd = Command('update') 967 cmd = Command('update')
838 if hard: 968 if hard:
839 cmd.append('--clean') 969 cmd.append('--clean')
840 970
841 cmd.append(commit) 971 cmd.append(commit)
842 972
843 ui.status((bytes(cmd)), "\n") 973 ui.status((bytes(cmd)), "\n")
844 974
975
845 def revert(ui, repo, *args, **kwargs): 976 def revert(ui, repo, *args, **kwargs):
846 cmdoptions = [ 977 cmdoptions = []
847 ]
848 args, opts = parseoptions(ui, cmdoptions, args) 978 args, opts = parseoptions(ui, cmdoptions, args)
849 979
850 if len(args) > 1: 980 if len(args) > 1:
851 ui.status(_("note: hg backout doesn't support multiple commits at " 981 ui.status(
852 "once\n\n")) 982 _(
983 "note: hg backout doesn't support multiple commits at "
984 "once\n\n"
985 )
986 )
853 987
854 cmd = Command('backout') 988 cmd = Command('backout')
855 if args: 989 if args:
856 cmd.append(args[0]) 990 cmd.append(args[0])
857 991
858 ui.status((bytes(cmd)), "\n") 992 ui.status((bytes(cmd)), "\n")
993
859 994
860 def revparse(ui, repo, *args, **kwargs): 995 def revparse(ui, repo, *args, **kwargs):
861 cmdoptions = [ 996 cmdoptions = [
862 ('', 'show-cdup', None, ''), 997 ('', 'show-cdup', None, ''),
863 ('', 'show-toplevel', None, ''), 998 ('', 'show-toplevel', None, ''),
870 ui.status(_("note: hg root prints the root of the repository\n\n")) 1005 ui.status(_("note: hg root prints the root of the repository\n\n"))
871 ui.status((bytes(cmd)), "\n") 1006 ui.status((bytes(cmd)), "\n")
872 else: 1007 else:
873 ui.status(_("note: see hg help revset for how to refer to commits\n")) 1008 ui.status(_("note: see hg help revset for how to refer to commits\n"))
874 1009
1010
875 def rm(ui, repo, *args, **kwargs): 1011 def rm(ui, repo, *args, **kwargs):
876 cmdoptions = [ 1012 cmdoptions = [
877 ('f', 'force', None, ''), 1013 ('f', 'force', None, ''),
878 ('n', 'dry-run', None, ''), 1014 ('n', 'dry-run', None, ''),
879 ] 1015 ]
886 cmd['-f'] = None 1022 cmd['-f'] = None
887 if opts.get('dry_run'): 1023 if opts.get('dry_run'):
888 cmd['-n'] = None 1024 cmd['-n'] = None
889 1025
890 ui.status((bytes(cmd)), "\n") 1026 ui.status((bytes(cmd)), "\n")
1027
891 1028
892 def show(ui, repo, *args, **kwargs): 1029 def show(ui, repo, *args, **kwargs):
893 cmdoptions = [ 1030 cmdoptions = [
894 ('', 'name-status', None, ''), 1031 ('', 'name-status', None, ''),
895 ('', 'pretty', '', ''), 1032 ('', 'pretty', '', ''),
918 cmd.append('--config diff.unified=%d' % (opts['unified'],)) 1055 cmd.append('--config diff.unified=%d' % (opts['unified'],))
919 else: 1056 else:
920 cmd = Command('export') 1057 cmd = Command('export')
921 1058
922 ui.status((bytes(cmd)), "\n") 1059 ui.status((bytes(cmd)), "\n")
1060
923 1061
924 def stash(ui, repo, *args, **kwargs): 1062 def stash(ui, repo, *args, **kwargs):
925 cmdoptions = [ 1063 cmdoptions = [
926 ('p', 'patch', None, ''), 1064 ('p', 'patch', None, ''),
927 ] 1065 ]
954 if len(args) > 1: 1092 if len(args) > 1:
955 cmd.append(args[1]) 1093 cmd.append(args[1])
956 if action == 'apply': 1094 if action == 'apply':
957 cmd['--keep'] = None 1095 cmd['--keep'] = None
958 elif action == 'branch' or action == 'create': 1096 elif action == 'branch' or action == 'create':
959 ui.status(_("note: Mercurial doesn't have equivalents to the " 1097 ui.status(
960 "git stash branch or create actions\n\n")) 1098 _(
1099 "note: Mercurial doesn't have equivalents to the "
1100 "git stash branch or create actions\n\n"
1101 )
1102 )
961 return 1103 return
962 else: 1104 else:
963 if len(args) > 0: 1105 if len(args) > 0:
964 if args[0] != 'save': 1106 if args[0] != 'save':
965 cmd['--name'] = args[0] 1107 cmd['--name'] = args[0]
966 elif len(args) > 1: 1108 elif len(args) > 1:
967 cmd['--name'] = args[1] 1109 cmd['--name'] = args[1]
968 1110
969 ui.status((bytes(cmd)), "\n") 1111 ui.status((bytes(cmd)), "\n")
970 1112
1113
971 def status(ui, repo, *args, **kwargs): 1114 def status(ui, repo, *args, **kwargs):
972 cmdoptions = [ 1115 cmdoptions = [
973 ('', 'ignored', None, ''), 1116 ('', 'ignored', None, ''),
974 ] 1117 ]
975 args, opts = parseoptions(ui, cmdoptions, args) 1118 args, opts = parseoptions(ui, cmdoptions, args)
979 1122
980 if opts.get('ignored'): 1123 if opts.get('ignored'):
981 cmd['-i'] = None 1124 cmd['-i'] = None
982 1125
983 ui.status((bytes(cmd)), "\n") 1126 ui.status((bytes(cmd)), "\n")
1127
984 1128
985 def svn(ui, repo, *args, **kwargs): 1129 def svn(ui, repo, *args, **kwargs):
986 if not args: 1130 if not args:
987 raise error.Abort(_('missing svn command')) 1131 raise error.Abort(_('missing svn command'))
988 svncmd = args[0] 1132 svncmd = args[0]
989 if svncmd not in gitsvncommands: 1133 if svncmd not in gitsvncommands:
990 raise error.Abort(_('unknown git svn command "%s"') % (svncmd)) 1134 raise error.Abort(_('unknown git svn command "%s"') % svncmd)
991 1135
992 args = args[1:] 1136 args = args[1:]
993 return gitsvncommands[svncmd](ui, repo, *args, **kwargs) 1137 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
994 1138
1139
995 def svndcommit(ui, repo, *args, **kwargs): 1140 def svndcommit(ui, repo, *args, **kwargs):
996 cmdoptions = [ 1141 cmdoptions = []
997 ]
998 args, opts = parseoptions(ui, cmdoptions, args) 1142 args, opts = parseoptions(ui, cmdoptions, args)
999 1143
1000 cmd = Command('push') 1144 cmd = Command('push')
1001 1145
1002 ui.status((bytes(cmd)), "\n") 1146 ui.status((bytes(cmd)), "\n")
1003 1147
1148
1004 def svnfetch(ui, repo, *args, **kwargs): 1149 def svnfetch(ui, repo, *args, **kwargs):
1005 cmdoptions = [ 1150 cmdoptions = []
1006 ]
1007 args, opts = parseoptions(ui, cmdoptions, args) 1151 args, opts = parseoptions(ui, cmdoptions, args)
1008 1152
1009 cmd = Command('pull') 1153 cmd = Command('pull')
1010 cmd.append('default-push') 1154 cmd.append('default-push')
1011 1155
1012 ui.status((bytes(cmd)), "\n") 1156 ui.status((bytes(cmd)), "\n")
1013 1157
1158
1014 def svnfindrev(ui, repo, *args, **kwargs): 1159 def svnfindrev(ui, repo, *args, **kwargs):
1015 cmdoptions = [ 1160 cmdoptions = []
1016 ]
1017 args, opts = parseoptions(ui, cmdoptions, args) 1161 args, opts = parseoptions(ui, cmdoptions, args)
1018 1162
1019 if not args: 1163 if not args:
1020 raise error.Abort(_('missing find-rev argument')) 1164 raise error.Abort(_('missing find-rev argument'))
1021 1165
1022 cmd = Command('log') 1166 cmd = Command('log')
1023 cmd['-r'] = args[0] 1167 cmd['-r'] = args[0]
1024 1168
1025 ui.status((bytes(cmd)), "\n") 1169 ui.status((bytes(cmd)), "\n")
1170
1026 1171
1027 def svnrebase(ui, repo, *args, **kwargs): 1172 def svnrebase(ui, repo, *args, **kwargs):
1028 cmdoptions = [ 1173 cmdoptions = [
1029 ('l', 'local', None, ''), 1174 ('l', 'local', None, ''),
1030 ] 1175 ]
1037 1182
1038 cmd = pullcmd & rebasecmd 1183 cmd = pullcmd & rebasecmd
1039 1184
1040 ui.status((bytes(cmd)), "\n") 1185 ui.status((bytes(cmd)), "\n")
1041 1186
1187
1042 def tag(ui, repo, *args, **kwargs): 1188 def tag(ui, repo, *args, **kwargs):
1043 cmdoptions = [ 1189 cmdoptions = [
1044 ('f', 'force', None, ''), 1190 ('f', 'force', None, ''),
1045 ('l', 'list', None, ''), 1191 ('l', 'list', None, ''),
1046 ('d', 'delete', None, ''), 1192 ('d', 'delete', None, ''),
1064 1210
1065 if opts.get('force'): 1211 if opts.get('force'):
1066 cmd['-f'] = None 1212 cmd['-f'] = None
1067 1213
1068 ui.status((bytes(cmd)), "\n") 1214 ui.status((bytes(cmd)), "\n")
1215
1069 1216
1070 gitcommands = { 1217 gitcommands = {
1071 'add': add, 1218 'add': add,
1072 'am': am, 1219 'am': am,
1073 'apply': apply, 1220 'apply': apply,