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