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