##// END OF EJS Templates
githelp: make argument parsing more compatible with Python 3...
Gregory Szorc -
r41459:031d9162 default
parent child Browse files
Show More
@@ -1,1089 +1,1092 b''
1 1 # githelp.py - Try to map Git commands to Mercurial equivalents.
2 2 #
3 3 # Copyright 2013 Facebook, Inc.
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 """try mapping git commands to Mercurial commands
8 8
9 9 Tries to map a given git command to a Mercurial command:
10 10
11 11 $ hg githelp -- git checkout master
12 12 hg update master
13 13
14 14 If an unknown command or parameter combination is detected, an error is
15 15 produced.
16 16 """
17 17
18 18 from __future__ import absolute_import
19 19
20 20 import getopt
21 21 import re
22 22
23 23 from mercurial.i18n import _
24 24 from mercurial import (
25 25 encoding,
26 26 error,
27 27 fancyopts,
28 pycompat,
28 29 registrar,
29 30 scmutil,
30 31 )
31 32 from mercurial.utils import (
32 33 procutil,
33 34 )
34 35
35 36 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
36 37 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
37 38 # be specifying the version(s) of Mercurial they are tested with, or
38 39 # leave the attribute unspecified.
39 40 testedwith = 'ships-with-hg-core'
40 41
41 42 cmdtable = {}
42 43 command = registrar.command(cmdtable)
43 44
44 45 def convert(s):
45 46 if s.startswith("origin/"):
46 47 return s[7:]
47 48 if 'HEAD' in s:
48 49 s = s.replace('HEAD', '.')
49 50 # HEAD~ in git is .~1 in mercurial
50 51 s = re.sub('~$', '~1', s)
51 52 return s
52 53
53 54 @command('githelp|git', [
54 55 ], _('hg githelp'),
55 56 helpcategory=command.CATEGORY_HELP, helpbasic=True)
56 57 def githelp(ui, repo, *args, **kwargs):
57 58 '''suggests the Mercurial equivalent of the given git command
58 59
59 60 Usage: hg githelp -- <git command>
60 61 '''
61 62
62 63 if len(args) == 0 or (len(args) == 1 and args[0] =='git'):
63 64 raise error.Abort(_('missing git command - '
64 65 'usage: hg githelp -- <git command>'))
65 66
66 67 if args[0] == 'git':
67 68 args = args[1:]
68 69
69 70 cmd = args[0]
70 71 if not cmd in gitcommands:
71 72 raise error.Abort(_("error: unknown git command %s") % (cmd))
72 73
73 74 ui.pager('githelp')
74 75 args = args[1:]
75 76 return gitcommands[cmd](ui, repo, *args, **kwargs)
76 77
77 78 def parseoptions(ui, cmdoptions, args):
78 79 cmdoptions = list(cmdoptions)
79 80 opts = {}
80 81 args = list(args)
81 82 while True:
82 83 try:
83 84 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
84 85 break
85 86 except getopt.GetoptError as ex:
86 if "requires argument" in ex.msg:
87 if r"requires argument" in ex.msg:
87 88 raise
88 if ('--' + ex.opt) in ex.msg:
89 flag = '--' + ex.opt
90 elif ('-' + ex.opt) in ex.msg:
91 flag = '-' + ex.opt
89 if (r'--' + ex.opt) in ex.msg:
90 flag = '--' + pycompat.bytestr(ex.opt)
91 elif (r'-' + ex.opt) in ex.msg:
92 flag = '-' + pycompat.bytestr(ex.opt)
92 93 else:
93 raise error.Abort(_("unknown option %s") % ex.opt)
94 raise error.Abort(_("unknown option %s") %
95 pycompat.bytestr(ex.opt))
94 96 try:
95 97 args.remove(flag)
96 98 except Exception:
97 99 msg = _("unknown option '%s' packed with other options")
98 100 hint = _("please try passing the option as its own flag: -%s")
99 raise error.Abort(msg % ex.opt, hint=hint % ex.opt)
101 raise error.Abort(msg % pycompat.bytestr(ex.opt),
102 hint=hint % pycompat.bytestr(ex.opt))
100 103
101 104 ui.warn(_("ignoring unknown option %s\n") % flag)
102 105
103 106 args = list([convert(x) for x in args])
104 107 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)
105 108 for k, v in opts.iteritems()])
106 109
107 110 return args, opts
108 111
109 112 class Command(object):
110 113 def __init__(self, name):
111 114 self.name = name
112 115 self.args = []
113 116 self.opts = {}
114 117
115 118 def __bytes__(self):
116 119 cmd = "hg " + self.name
117 120 if self.opts:
118 121 for k, values in sorted(self.opts.iteritems()):
119 122 for v in values:
120 123 if v:
121 124 cmd += " %s %s" % (k, v)
122 125 else:
123 126 cmd += " %s" % (k,)
124 127 if self.args:
125 128 cmd += " "
126 129 cmd += " ".join(self.args)
127 130 return cmd
128 131
129 132 __str__ = encoding.strmethod(__bytes__)
130 133
131 134 def append(self, value):
132 135 self.args.append(value)
133 136
134 137 def extend(self, values):
135 138 self.args.extend(values)
136 139
137 140 def __setitem__(self, key, value):
138 141 values = self.opts.setdefault(key, [])
139 142 values.append(value)
140 143
141 144 def __and__(self, other):
142 145 return AndCommand(self, other)
143 146
144 147 class AndCommand(object):
145 148 def __init__(self, left, right):
146 149 self.left = left
147 150 self.right = right
148 151
149 152 def __str__(self):
150 153 return "%s && %s" % (self.left, self.right)
151 154
152 155 def __and__(self, other):
153 156 return AndCommand(self, other)
154 157
155 158 def add(ui, repo, *args, **kwargs):
156 159 cmdoptions = [
157 160 ('A', 'all', None, ''),
158 161 ('p', 'patch', None, ''),
159 162 ]
160 163 args, opts = parseoptions(ui, cmdoptions, args)
161 164
162 165 if (opts.get('patch')):
163 166 ui.status(_("note: Mercurial will commit when complete, "
164 167 "as there is no staging area in Mercurial\n\n"))
165 168 cmd = Command('commit --interactive')
166 169 else:
167 170 cmd = Command("add")
168 171
169 172 if not opts.get('all'):
170 173 cmd.extend(args)
171 174 else:
172 175 ui.status(_("note: use hg addremove to remove files that have "
173 176 "been deleted\n\n"))
174 177
175 178 ui.status((bytes(cmd)), "\n")
176 179
177 180 def am(ui, repo, *args, **kwargs):
178 181 cmdoptions=[
179 182 ]
180 183 args, opts = parseoptions(ui, cmdoptions, args)
181 184 cmd = Command('import')
182 185 ui.status(bytes(cmd), "\n")
183 186
184 187 def apply(ui, repo, *args, **kwargs):
185 188 cmdoptions = [
186 189 ('p', 'p', int, ''),
187 190 ]
188 191 args, opts = parseoptions(ui, cmdoptions, args)
189 192
190 193 cmd = Command('import --no-commit')
191 194 if (opts.get('p')):
192 195 cmd['-p'] = opts.get('p')
193 196 cmd.extend(args)
194 197
195 198 ui.status((bytes(cmd)), "\n")
196 199
197 200 def bisect(ui, repo, *args, **kwargs):
198 201 ui.status(_("see 'hg help bisect' for how to use bisect\n\n"))
199 202
200 203 def blame(ui, repo, *args, **kwargs):
201 204 cmdoptions = [
202 205 ]
203 206 args, opts = parseoptions(ui, cmdoptions, args)
204 207 cmd = Command('annotate -udl')
205 208 cmd.extend([convert(v) for v in args])
206 209 ui.status((bytes(cmd)), "\n")
207 210
208 211 def branch(ui, repo, *args, **kwargs):
209 212 cmdoptions = [
210 213 ('', 'set-upstream', None, ''),
211 214 ('', 'set-upstream-to', '', ''),
212 215 ('d', 'delete', None, ''),
213 216 ('D', 'delete', None, ''),
214 217 ('m', 'move', None, ''),
215 218 ('M', 'move', None, ''),
216 219 ]
217 220 args, opts = parseoptions(ui, cmdoptions, args)
218 221
219 222 cmd = Command("bookmark")
220 223
221 224 if opts.get('set_upstream') or opts.get('set_upstream_to'):
222 225 ui.status(_("Mercurial has no concept of upstream branches\n"))
223 226 return
224 227 elif opts.get('delete'):
225 228 cmd = Command("strip")
226 229 for branch in args:
227 230 cmd['-B'] = branch
228 231 else:
229 232 cmd['-B'] = None
230 233 elif opts.get('move'):
231 234 if len(args) > 0:
232 235 if len(args) > 1:
233 236 old = args.pop(0)
234 237 else:
235 238 # shell command to output the active bookmark for the active
236 239 # revision
237 240 old = '`hg log -T"{activebookmark}" -r .`'
238 241 else:
239 242 raise error.Abort(_('missing newbranch argument'))
240 243 new = args[0]
241 244 cmd['-m'] = old
242 245 cmd.append(new)
243 246 else:
244 247 if len(args) > 1:
245 248 cmd['-r'] = args[1]
246 249 cmd.append(args[0])
247 250 elif len(args) == 1:
248 251 cmd.append(args[0])
249 252 ui.status((bytes(cmd)), "\n")
250 253
251 254 def ispath(repo, string):
252 255 """
253 256 The first argument to git checkout can either be a revision or a path. Let's
254 257 generally assume it's a revision, unless it's obviously a path. There are
255 258 too many ways to spell revisions in git for us to reasonably catch all of
256 259 them, so let's be conservative.
257 260 """
258 261 if scmutil.isrevsymbol(repo, string):
259 262 # if it's definitely a revision let's not even check if a file of the
260 263 # same name exists.
261 264 return False
262 265
263 266 cwd = repo.getcwd()
264 267 if cwd == '':
265 268 repopath = string
266 269 else:
267 270 repopath = cwd + '/' + string
268 271
269 272 exists = repo.wvfs.exists(repopath)
270 273 if exists:
271 274 return True
272 275
273 276 manifest = repo['.'].manifest()
274 277
275 278 didexist = (repopath in manifest) or manifest.hasdir(repopath)
276 279
277 280 return didexist
278 281
279 282 def checkout(ui, repo, *args, **kwargs):
280 283 cmdoptions = [
281 284 ('b', 'branch', '', ''),
282 285 ('B', 'branch', '', ''),
283 286 ('f', 'force', None, ''),
284 287 ('p', 'patch', None, ''),
285 288 ]
286 289 paths = []
287 290 if '--' in args:
288 291 sepindex = args.index('--')
289 292 paths.extend(args[sepindex + 1:])
290 293 args = args[:sepindex]
291 294
292 295 args, opts = parseoptions(ui, cmdoptions, args)
293 296
294 297 rev = None
295 298 if args and ispath(repo, args[0]):
296 299 paths = args + paths
297 300 elif args:
298 301 rev = args[0]
299 302 paths = args[1:] + paths
300 303
301 304 cmd = Command('update')
302 305
303 306 if opts.get('force'):
304 307 if paths or rev:
305 308 cmd['-C'] = None
306 309
307 310 if opts.get('patch'):
308 311 cmd = Command('revert')
309 312 cmd['-i'] = None
310 313
311 314 if opts.get('branch'):
312 315 if len(args) == 0:
313 316 cmd = Command('bookmark')
314 317 cmd.append(opts.get('branch'))
315 318 else:
316 319 cmd.append(args[0])
317 320 bookcmd = Command('bookmark')
318 321 bookcmd.append(opts.get('branch'))
319 322 cmd = cmd & bookcmd
320 323 # if there is any path argument supplied, use revert instead of update
321 324 elif len(paths) > 0:
322 325 ui.status(_("note: use --no-backup to avoid creating .orig files\n\n"))
323 326 cmd = Command('revert')
324 327 if opts.get('patch'):
325 328 cmd['-i'] = None
326 329 if rev:
327 330 cmd['-r'] = rev
328 331 cmd.extend(paths)
329 332 elif rev:
330 333 if opts.get('patch'):
331 334 cmd['-r'] = rev
332 335 else:
333 336 cmd.append(rev)
334 337 elif opts.get('force'):
335 338 cmd = Command('revert')
336 339 cmd['--all'] = None
337 340 else:
338 341 raise error.Abort(_("a commit must be specified"))
339 342
340 343 ui.status((bytes(cmd)), "\n")
341 344
342 345 def cherrypick(ui, repo, *args, **kwargs):
343 346 cmdoptions = [
344 347 ('', 'continue', None, ''),
345 348 ('', 'abort', None, ''),
346 349 ('e', 'edit', None, ''),
347 350 ]
348 351 args, opts = parseoptions(ui, cmdoptions, args)
349 352
350 353 cmd = Command('graft')
351 354
352 355 if opts.get('edit'):
353 356 cmd['--edit'] = None
354 357 if opts.get('continue'):
355 358 cmd['--continue'] = None
356 359 elif opts.get('abort'):
357 360 ui.status(_("note: hg graft does not have --abort\n\n"))
358 361 return
359 362 else:
360 363 cmd.extend(args)
361 364
362 365 ui.status((bytes(cmd)), "\n")
363 366
364 367 def clean(ui, repo, *args, **kwargs):
365 368 cmdoptions = [
366 369 ('d', 'd', None, ''),
367 370 ('f', 'force', None, ''),
368 371 ('x', 'x', None, ''),
369 372 ]
370 373 args, opts = parseoptions(ui, cmdoptions, args)
371 374
372 375 cmd = Command('purge')
373 376 if opts.get('x'):
374 377 cmd['--all'] = None
375 378 cmd.extend(args)
376 379
377 380 ui.status((bytes(cmd)), "\n")
378 381
379 382 def clone(ui, repo, *args, **kwargs):
380 383 cmdoptions = [
381 384 ('', 'bare', None, ''),
382 385 ('n', 'no-checkout', None, ''),
383 386 ('b', 'branch', '', ''),
384 387 ]
385 388 args, opts = parseoptions(ui, cmdoptions, args)
386 389
387 390 if len(args) == 0:
388 391 raise error.Abort(_("a repository to clone must be specified"))
389 392
390 393 cmd = Command('clone')
391 394 cmd.append(args[0])
392 395 if len(args) > 1:
393 396 cmd.append(args[1])
394 397
395 398 if opts.get('bare'):
396 399 cmd['-U'] = None
397 400 ui.status(_("note: Mercurial does not have bare clones. "
398 401 "-U will clone the repo without checking out a commit\n\n"))
399 402 elif opts.get('no_checkout'):
400 403 cmd['-U'] = None
401 404
402 405 if opts.get('branch'):
403 406 cocmd = Command("update")
404 407 cocmd.append(opts.get('branch'))
405 408 cmd = cmd & cocmd
406 409
407 410 ui.status((bytes(cmd)), "\n")
408 411
409 412 def commit(ui, repo, *args, **kwargs):
410 413 cmdoptions = [
411 414 ('a', 'all', None, ''),
412 415 ('m', 'message', '', ''),
413 416 ('p', 'patch', None, ''),
414 417 ('C', 'reuse-message', '', ''),
415 418 ('F', 'file', '', ''),
416 419 ('', 'author', '', ''),
417 420 ('', 'date', '', ''),
418 421 ('', 'amend', None, ''),
419 422 ('', 'no-edit', None, ''),
420 423 ]
421 424 args, opts = parseoptions(ui, cmdoptions, args)
422 425
423 426 cmd = Command('commit')
424 427 if opts.get('patch'):
425 428 cmd = Command('commit --interactive')
426 429
427 430 if opts.get('amend'):
428 431 if opts.get('no_edit'):
429 432 cmd = Command('amend')
430 433 else:
431 434 cmd['--amend'] = None
432 435
433 436 if opts.get('reuse_message'):
434 437 cmd['-M'] = opts.get('reuse_message')
435 438
436 439 if opts.get('message'):
437 440 cmd['-m'] = "'%s'" % (opts.get('message'),)
438 441
439 442 if opts.get('all'):
440 443 ui.status(_("note: Mercurial doesn't have a staging area, "
441 444 "so there is no --all. -A will add and remove files "
442 445 "for you though.\n\n"))
443 446
444 447 if opts.get('file'):
445 448 cmd['-l'] = opts.get('file')
446 449
447 450 if opts.get('author'):
448 451 cmd['-u'] = opts.get('author')
449 452
450 453 if opts.get('date'):
451 454 cmd['-d'] = opts.get('date')
452 455
453 456 cmd.extend(args)
454 457
455 458 ui.status((bytes(cmd)), "\n")
456 459
457 460 def deprecated(ui, repo, *args, **kwargs):
458 461 ui.warn(_('this command has been deprecated in the git project, '
459 462 'thus isn\'t supported by this tool\n\n'))
460 463
461 464 def diff(ui, repo, *args, **kwargs):
462 465 cmdoptions = [
463 466 ('a', 'all', None, ''),
464 467 ('', 'cached', None, ''),
465 468 ('R', 'reverse', None, ''),
466 469 ]
467 470 args, opts = parseoptions(ui, cmdoptions, args)
468 471
469 472 cmd = Command('diff')
470 473
471 474 if opts.get('cached'):
472 475 ui.status(_('note: Mercurial has no concept of a staging area, '
473 476 'so --cached does nothing\n\n'))
474 477
475 478 if opts.get('reverse'):
476 479 cmd['--reverse'] = None
477 480
478 481 for a in list(args):
479 482 args.remove(a)
480 483 try:
481 484 repo.revs(a)
482 485 cmd['-r'] = a
483 486 except Exception:
484 487 cmd.append(a)
485 488
486 489 ui.status((bytes(cmd)), "\n")
487 490
488 491 def difftool(ui, repo, *args, **kwargs):
489 492 ui.status(_('Mercurial does not enable external difftool by default. You '
490 493 'need to enable the extdiff extension in your .hgrc file by adding\n'
491 494 'extdiff =\n'
492 495 'to the [extensions] section and then running\n\n'
493 496 'hg extdiff -p <program>\n\n'
494 497 'See \'hg help extdiff\' and \'hg help -e extdiff\' for more '
495 498 'information.\n'))
496 499
497 500 def fetch(ui, repo, *args, **kwargs):
498 501 cmdoptions = [
499 502 ('', 'all', None, ''),
500 503 ('f', 'force', None, ''),
501 504 ]
502 505 args, opts = parseoptions(ui, cmdoptions, args)
503 506
504 507 cmd = Command('pull')
505 508
506 509 if len(args) > 0:
507 510 cmd.append(args[0])
508 511 if len(args) > 1:
509 512 ui.status(_("note: Mercurial doesn't have refspecs. "
510 513 "-r can be used to specify which commits you want to "
511 514 "pull. -B can be used to specify which bookmark you "
512 515 "want to pull.\n\n"))
513 516 for v in args[1:]:
514 517 if v in repo._bookmarks:
515 518 cmd['-B'] = v
516 519 else:
517 520 cmd['-r'] = v
518 521
519 522 ui.status((bytes(cmd)), "\n")
520 523
521 524 def grep(ui, repo, *args, **kwargs):
522 525 cmdoptions = [
523 526 ]
524 527 args, opts = parseoptions(ui, cmdoptions, args)
525 528
526 529 cmd = Command('grep')
527 530
528 531 # For basic usage, git grep and hg grep are the same. They both have the
529 532 # pattern first, followed by paths.
530 533 cmd.extend(args)
531 534
532 535 ui.status((bytes(cmd)), "\n")
533 536
534 537 def init(ui, repo, *args, **kwargs):
535 538 cmdoptions = [
536 539 ]
537 540 args, opts = parseoptions(ui, cmdoptions, args)
538 541
539 542 cmd = Command('init')
540 543
541 544 if len(args) > 0:
542 545 cmd.append(args[0])
543 546
544 547 ui.status((bytes(cmd)), "\n")
545 548
546 549 def log(ui, repo, *args, **kwargs):
547 550 cmdoptions = [
548 551 ('', 'follow', None, ''),
549 552 ('', 'decorate', None, ''),
550 553 ('n', 'number', '', ''),
551 554 ('1', '1', None, ''),
552 555 ('', 'pretty', '', ''),
553 556 ('', 'format', '', ''),
554 557 ('', 'oneline', None, ''),
555 558 ('', 'stat', None, ''),
556 559 ('', 'graph', None, ''),
557 560 ('p', 'patch', None, ''),
558 561 ]
559 562 args, opts = parseoptions(ui, cmdoptions, args)
560 563 ui.status(_('note: -v prints the entire commit message like Git does. To '
561 564 'print just the first line, drop the -v.\n\n'))
562 565 ui.status(_("note: see hg help revset for information on how to filter "
563 566 "log output\n\n"))
564 567
565 568 cmd = Command('log')
566 569 cmd['-v'] = None
567 570
568 571 if opts.get('number'):
569 572 cmd['-l'] = opts.get('number')
570 573 if opts.get('1'):
571 574 cmd['-l'] = '1'
572 575 if opts.get('stat'):
573 576 cmd['--stat'] = None
574 577 if opts.get('graph'):
575 578 cmd['-G'] = None
576 579 if opts.get('patch'):
577 580 cmd['-p'] = None
578 581
579 582 if opts.get('pretty') or opts.get('format') or opts.get('oneline'):
580 583 format = opts.get('format', '')
581 584 if 'format:' in format:
582 585 ui.status(_("note: --format format:??? equates to Mercurial's "
583 586 "--template. See hg help templates for more info.\n\n"))
584 587 cmd['--template'] = '???'
585 588 else:
586 589 ui.status(_("note: --pretty/format/oneline equate to Mercurial's "
587 590 "--style or --template. See hg help templates for "
588 591 "more info.\n\n"))
589 592 cmd['--style'] = '???'
590 593
591 594 if len(args) > 0:
592 595 if '..' in args[0]:
593 596 since, until = args[0].split('..')
594 597 cmd['-r'] = "'%s::%s'" % (since, until)
595 598 del args[0]
596 599 cmd.extend(args)
597 600
598 601 ui.status((bytes(cmd)), "\n")
599 602
600 603 def lsfiles(ui, repo, *args, **kwargs):
601 604 cmdoptions = [
602 605 ('c', 'cached', None, ''),
603 606 ('d', 'deleted', None, ''),
604 607 ('m', 'modified', None, ''),
605 608 ('o', 'others', None, ''),
606 609 ('i', 'ignored', None, ''),
607 610 ('s', 'stage', None, ''),
608 611 ('z', '_zero', None, ''),
609 612 ]
610 613 args, opts = parseoptions(ui, cmdoptions, args)
611 614
612 615 if (opts.get('modified') or opts.get('deleted')
613 616 or opts.get('others') or opts.get('ignored')):
614 617 cmd = Command('status')
615 618 if opts.get('deleted'):
616 619 cmd['-d'] = None
617 620 if opts.get('modified'):
618 621 cmd['-m'] = None
619 622 if opts.get('others'):
620 623 cmd['-o'] = None
621 624 if opts.get('ignored'):
622 625 cmd['-i'] = None
623 626 else:
624 627 cmd = Command('files')
625 628 if opts.get('stage'):
626 629 ui.status(_("note: Mercurial doesn't have a staging area, ignoring "
627 630 "--stage\n"))
628 631 if opts.get('_zero'):
629 632 cmd['-0'] = None
630 633 cmd.append('.')
631 634 for include in args:
632 635 cmd['-I'] = procutil.shellquote(include)
633 636
634 637 ui.status((bytes(cmd)), "\n")
635 638
636 639 def merge(ui, repo, *args, **kwargs):
637 640 cmdoptions = [
638 641 ]
639 642 args, opts = parseoptions(ui, cmdoptions, args)
640 643
641 644 cmd = Command('merge')
642 645
643 646 if len(args) > 0:
644 647 cmd.append(args[len(args) - 1])
645 648
646 649 ui.status((bytes(cmd)), "\n")
647 650
648 651 def mergebase(ui, repo, *args, **kwargs):
649 652 cmdoptions = []
650 653 args, opts = parseoptions(ui, cmdoptions, args)
651 654
652 655 if len(args) != 2:
653 656 args = ['A', 'B']
654 657
655 658 cmd = Command("log -T '{node}\\n' -r 'ancestor(%s,%s)'"
656 659 % (args[0], args[1]))
657 660
658 661 ui.status(_('note: ancestors() is part of the revset language\n'),
659 662 _("(learn more about revsets with 'hg help revsets')\n\n"))
660 663 ui.status((bytes(cmd)), "\n")
661 664
662 665 def mergetool(ui, repo, *args, **kwargs):
663 666 cmdoptions = []
664 667 args, opts = parseoptions(ui, cmdoptions, args)
665 668
666 669 cmd = Command("resolve")
667 670
668 671 if len(args) == 0:
669 672 cmd['--all'] = None
670 673 cmd.extend(args)
671 674 ui.status((bytes(cmd)), "\n")
672 675
673 676 def mv(ui, repo, *args, **kwargs):
674 677 cmdoptions = [
675 678 ('f', 'force', None, ''),
676 679 ]
677 680 args, opts = parseoptions(ui, cmdoptions, args)
678 681
679 682 cmd = Command('mv')
680 683 cmd.extend(args)
681 684
682 685 if opts.get('force'):
683 686 cmd['-f'] = None
684 687
685 688 ui.status((bytes(cmd)), "\n")
686 689
687 690 def pull(ui, repo, *args, **kwargs):
688 691 cmdoptions = [
689 692 ('', 'all', None, ''),
690 693 ('f', 'force', None, ''),
691 694 ('r', 'rebase', None, ''),
692 695 ]
693 696 args, opts = parseoptions(ui, cmdoptions, args)
694 697
695 698 cmd = Command('pull')
696 699 cmd['--rebase'] = None
697 700
698 701 if len(args) > 0:
699 702 cmd.append(args[0])
700 703 if len(args) > 1:
701 704 ui.status(_("note: Mercurial doesn't have refspecs. "
702 705 "-r can be used to specify which commits you want to "
703 706 "pull. -B can be used to specify which bookmark you "
704 707 "want to pull.\n\n"))
705 708 for v in args[1:]:
706 709 if v in repo._bookmarks:
707 710 cmd['-B'] = v
708 711 else:
709 712 cmd['-r'] = v
710 713
711 714 ui.status((bytes(cmd)), "\n")
712 715
713 716 def push(ui, repo, *args, **kwargs):
714 717 cmdoptions = [
715 718 ('', 'all', None, ''),
716 719 ('f', 'force', None, ''),
717 720 ]
718 721 args, opts = parseoptions(ui, cmdoptions, args)
719 722
720 723 cmd = Command('push')
721 724
722 725 if len(args) > 0:
723 726 cmd.append(args[0])
724 727 if len(args) > 1:
725 728 ui.status(_("note: Mercurial doesn't have refspecs. "
726 729 "-r can be used to specify which commits you want "
727 730 "to push. -B can be used to specify which bookmark "
728 731 "you want to push.\n\n"))
729 732 for v in args[1:]:
730 733 if v in repo._bookmarks:
731 734 cmd['-B'] = v
732 735 else:
733 736 cmd['-r'] = v
734 737
735 738 if opts.get('force'):
736 739 cmd['-f'] = None
737 740
738 741 ui.status((bytes(cmd)), "\n")
739 742
740 743 def rebase(ui, repo, *args, **kwargs):
741 744 cmdoptions = [
742 745 ('', 'all', None, ''),
743 746 ('i', 'interactive', None, ''),
744 747 ('', 'onto', '', ''),
745 748 ('', 'abort', None, ''),
746 749 ('', 'continue', None, ''),
747 750 ('', 'skip', None, ''),
748 751 ]
749 752 args, opts = parseoptions(ui, cmdoptions, args)
750 753
751 754 if opts.get('interactive'):
752 755 ui.status(_("note: hg histedit does not perform a rebase. "
753 756 "It just edits history.\n\n"))
754 757 cmd = Command('histedit')
755 758 if len(args) > 0:
756 759 ui.status(_("also note: 'hg histedit' will automatically detect"
757 760 " your stack, so no second argument is necessary\n\n"))
758 761 ui.status((bytes(cmd)), "\n")
759 762 return
760 763
761 764 if opts.get('skip'):
762 765 cmd = Command('revert --all -r .')
763 766 ui.status((bytes(cmd)), "\n")
764 767
765 768 cmd = Command('rebase')
766 769
767 770 if opts.get('continue') or opts.get('skip'):
768 771 cmd['--continue'] = None
769 772 if opts.get('abort'):
770 773 cmd['--abort'] = None
771 774
772 775 if opts.get('onto'):
773 776 ui.status(_("note: if you're trying to lift a commit off one branch, "
774 777 "try hg rebase -d <destination commit> -s <commit to be "
775 778 "lifted>\n\n"))
776 779 cmd['-d'] = convert(opts.get('onto'))
777 780 if len(args) < 2:
778 781 raise error.Abort(_("expected format: git rebase --onto X Y Z"))
779 782 cmd['-s'] = "'::%s - ::%s'" % (convert(args[1]), convert(args[0]))
780 783 else:
781 784 if len(args) == 1:
782 785 cmd['-d'] = convert(args[0])
783 786 elif len(args) == 2:
784 787 cmd['-d'] = convert(args[0])
785 788 cmd['-b'] = convert(args[1])
786 789
787 790 ui.status((bytes(cmd)), "\n")
788 791
789 792 def reflog(ui, repo, *args, **kwargs):
790 793 cmdoptions = [
791 794 ('', 'all', None, ''),
792 795 ]
793 796 args, opts = parseoptions(ui, cmdoptions, args)
794 797
795 798 cmd = Command('journal')
796 799 if opts.get('all'):
797 800 cmd['--all'] = None
798 801 if len(args) > 0:
799 802 cmd.append(args[0])
800 803
801 804 ui.status(bytes(cmd), "\n\n")
802 805 ui.status(_("note: in hg commits can be deleted from repo but we always"
803 806 " have backups\n"))
804 807
805 808 def reset(ui, repo, *args, **kwargs):
806 809 cmdoptions = [
807 810 ('', 'soft', None, ''),
808 811 ('', 'hard', None, ''),
809 812 ('', 'mixed', None, ''),
810 813 ]
811 814 args, opts = parseoptions(ui, cmdoptions, args)
812 815
813 816 commit = convert(args[0] if len(args) > 0 else '.')
814 817 hard = opts.get('hard')
815 818
816 819 if opts.get('mixed'):
817 820 ui.status(_('note: --mixed has no meaning since Mercurial has no '
818 821 'staging area\n\n'))
819 822 if opts.get('soft'):
820 823 ui.status(_('note: --soft has no meaning since Mercurial has no '
821 824 'staging area\n\n'))
822 825
823 826 cmd = Command('update')
824 827 if hard:
825 828 cmd.append('--clean')
826 829
827 830 cmd.append(commit)
828 831
829 832 ui.status((bytes(cmd)), "\n")
830 833
831 834 def revert(ui, repo, *args, **kwargs):
832 835 cmdoptions = [
833 836 ]
834 837 args, opts = parseoptions(ui, cmdoptions, args)
835 838
836 839 if len(args) > 1:
837 840 ui.status(_("note: hg backout doesn't support multiple commits at "
838 841 "once\n\n"))
839 842
840 843 cmd = Command('backout')
841 844 if args:
842 845 cmd.append(args[0])
843 846
844 847 ui.status((bytes(cmd)), "\n")
845 848
846 849 def revparse(ui, repo, *args, **kwargs):
847 850 cmdoptions = [
848 851 ('', 'show-cdup', None, ''),
849 852 ('', 'show-toplevel', None, ''),
850 853 ]
851 854 args, opts = parseoptions(ui, cmdoptions, args)
852 855
853 856 if opts.get('show_cdup') or opts.get('show_toplevel'):
854 857 cmd = Command('root')
855 858 if opts.get('show_cdup'):
856 859 ui.status(_("note: hg root prints the root of the repository\n\n"))
857 860 ui.status((bytes(cmd)), "\n")
858 861 else:
859 862 ui.status(_("note: see hg help revset for how to refer to commits\n"))
860 863
861 864 def rm(ui, repo, *args, **kwargs):
862 865 cmdoptions = [
863 866 ('f', 'force', None, ''),
864 867 ('n', 'dry-run', None, ''),
865 868 ]
866 869 args, opts = parseoptions(ui, cmdoptions, args)
867 870
868 871 cmd = Command('rm')
869 872 cmd.extend(args)
870 873
871 874 if opts.get('force'):
872 875 cmd['-f'] = None
873 876 if opts.get('dry_run'):
874 877 cmd['-n'] = None
875 878
876 879 ui.status((bytes(cmd)), "\n")
877 880
878 881 def show(ui, repo, *args, **kwargs):
879 882 cmdoptions = [
880 883 ('', 'name-status', None, ''),
881 884 ('', 'pretty', '', ''),
882 885 ('U', 'unified', int, ''),
883 886 ]
884 887 args, opts = parseoptions(ui, cmdoptions, args)
885 888
886 889 if opts.get('name_status'):
887 890 if opts.get('pretty') == 'format:':
888 891 cmd = Command('status')
889 892 cmd['--change'] = '.'
890 893 else:
891 894 cmd = Command('log')
892 895 cmd.append('--style status')
893 896 cmd.append('-r .')
894 897 elif len(args) > 0:
895 898 if ispath(repo, args[0]):
896 899 cmd = Command('cat')
897 900 else:
898 901 cmd = Command('export')
899 902 cmd.extend(args)
900 903 if opts.get('unified'):
901 904 cmd.append('--config diff.unified=%d' % (opts['unified'],))
902 905 elif opts.get('unified'):
903 906 cmd = Command('export')
904 907 cmd.append('--config diff.unified=%d' % (opts['unified'],))
905 908 else:
906 909 cmd = Command('export')
907 910
908 911 ui.status((bytes(cmd)), "\n")
909 912
910 913 def stash(ui, repo, *args, **kwargs):
911 914 cmdoptions = [
912 915 ]
913 916 args, opts = parseoptions(ui, cmdoptions, args)
914 917
915 918 cmd = Command('shelve')
916 919 action = args[0] if len(args) > 0 else None
917 920
918 921 if action == 'list':
919 922 cmd['-l'] = None
920 923 elif action == 'drop':
921 924 cmd['-d'] = None
922 925 if len(args) > 1:
923 926 cmd.append(args[1])
924 927 else:
925 928 cmd.append('<shelve name>')
926 929 elif action == 'pop' or action == 'apply':
927 930 cmd = Command('unshelve')
928 931 if len(args) > 1:
929 932 cmd.append(args[1])
930 933 if action == 'apply':
931 934 cmd['--keep'] = None
932 935 elif (action == 'branch' or action == 'show' or action == 'clear'
933 936 or action == 'create'):
934 937 ui.status(_("note: Mercurial doesn't have equivalents to the "
935 938 "git stash branch, show, clear, or create actions\n\n"))
936 939 return
937 940 else:
938 941 if len(args) > 0:
939 942 if args[0] != 'save':
940 943 cmd['--name'] = args[0]
941 944 elif len(args) > 1:
942 945 cmd['--name'] = args[1]
943 946
944 947 ui.status((bytes(cmd)), "\n")
945 948
946 949 def status(ui, repo, *args, **kwargs):
947 950 cmdoptions = [
948 951 ('', 'ignored', None, ''),
949 952 ]
950 953 args, opts = parseoptions(ui, cmdoptions, args)
951 954
952 955 cmd = Command('status')
953 956 cmd.extend(args)
954 957
955 958 if opts.get('ignored'):
956 959 cmd['-i'] = None
957 960
958 961 ui.status((bytes(cmd)), "\n")
959 962
960 963 def svn(ui, repo, *args, **kwargs):
961 964 if not args:
962 965 raise error.Abort(_('missing svn command'))
963 966 svncmd = args[0]
964 967 if svncmd not in gitsvncommands:
965 968 raise error.Abort(_('unknown git svn command "%s"') % (svncmd))
966 969
967 970 args = args[1:]
968 971 return gitsvncommands[svncmd](ui, repo, *args, **kwargs)
969 972
970 973 def svndcommit(ui, repo, *args, **kwargs):
971 974 cmdoptions = [
972 975 ]
973 976 args, opts = parseoptions(ui, cmdoptions, args)
974 977
975 978 cmd = Command('push')
976 979
977 980 ui.status((bytes(cmd)), "\n")
978 981
979 982 def svnfetch(ui, repo, *args, **kwargs):
980 983 cmdoptions = [
981 984 ]
982 985 args, opts = parseoptions(ui, cmdoptions, args)
983 986
984 987 cmd = Command('pull')
985 988 cmd.append('default-push')
986 989
987 990 ui.status((bytes(cmd)), "\n")
988 991
989 992 def svnfindrev(ui, repo, *args, **kwargs):
990 993 cmdoptions = [
991 994 ]
992 995 args, opts = parseoptions(ui, cmdoptions, args)
993 996
994 997 if not args:
995 998 raise error.Abort(_('missing find-rev argument'))
996 999
997 1000 cmd = Command('log')
998 1001 cmd['-r'] = args[0]
999 1002
1000 1003 ui.status((bytes(cmd)), "\n")
1001 1004
1002 1005 def svnrebase(ui, repo, *args, **kwargs):
1003 1006 cmdoptions = [
1004 1007 ('l', 'local', None, ''),
1005 1008 ]
1006 1009 args, opts = parseoptions(ui, cmdoptions, args)
1007 1010
1008 1011 pullcmd = Command('pull')
1009 1012 pullcmd.append('default-push')
1010 1013 rebasecmd = Command('rebase')
1011 1014 rebasecmd.append('tip')
1012 1015
1013 1016 cmd = pullcmd & rebasecmd
1014 1017
1015 1018 ui.status((bytes(cmd)), "\n")
1016 1019
1017 1020 def tag(ui, repo, *args, **kwargs):
1018 1021 cmdoptions = [
1019 1022 ('f', 'force', None, ''),
1020 1023 ('l', 'list', None, ''),
1021 1024 ('d', 'delete', None, ''),
1022 1025 ]
1023 1026 args, opts = parseoptions(ui, cmdoptions, args)
1024 1027
1025 1028 if opts.get('list'):
1026 1029 cmd = Command('tags')
1027 1030 else:
1028 1031 cmd = Command('tag')
1029 1032
1030 1033 if not args:
1031 1034 raise error.Abort(_('missing tag argument'))
1032 1035
1033 1036 cmd.append(args[0])
1034 1037 if len(args) > 1:
1035 1038 cmd['-r'] = args[1]
1036 1039
1037 1040 if opts.get('delete'):
1038 1041 cmd['--remove'] = None
1039 1042
1040 1043 if opts.get('force'):
1041 1044 cmd['-f'] = None
1042 1045
1043 1046 ui.status((bytes(cmd)), "\n")
1044 1047
1045 1048 gitcommands = {
1046 1049 'add': add,
1047 1050 'am': am,
1048 1051 'apply': apply,
1049 1052 'bisect': bisect,
1050 1053 'blame': blame,
1051 1054 'branch': branch,
1052 1055 'checkout': checkout,
1053 1056 'cherry-pick': cherrypick,
1054 1057 'clean': clean,
1055 1058 'clone': clone,
1056 1059 'commit': commit,
1057 1060 'diff': diff,
1058 1061 'difftool': difftool,
1059 1062 'fetch': fetch,
1060 1063 'grep': grep,
1061 1064 'init': init,
1062 1065 'log': log,
1063 1066 'ls-files': lsfiles,
1064 1067 'merge': merge,
1065 1068 'merge-base': mergebase,
1066 1069 'mergetool': mergetool,
1067 1070 'mv': mv,
1068 1071 'pull': pull,
1069 1072 'push': push,
1070 1073 'rebase': rebase,
1071 1074 'reflog': reflog,
1072 1075 'reset': reset,
1073 1076 'revert': revert,
1074 1077 'rev-parse': revparse,
1075 1078 'rm': rm,
1076 1079 'show': show,
1077 1080 'stash': stash,
1078 1081 'status': status,
1079 1082 'svn': svn,
1080 1083 'tag': tag,
1081 1084 'whatchanged': deprecated,
1082 1085 }
1083 1086
1084 1087 gitsvncommands = {
1085 1088 'dcommit': svndcommit,
1086 1089 'fetch': svnfetch,
1087 1090 'find-rev': svnfindrev,
1088 1091 'rebase': svnrebase,
1089 1092 }
General Comments 0
You need to be logged in to leave comments. Login now