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