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