Show More
@@ -218,6 +218,7 b' class cmdalias(object):' | |||||
218 | return |
|
218 | return | |
219 |
|
219 | |||
220 | if self.definition.startswith('!'): |
|
220 | if self.definition.startswith('!'): | |
|
221 | self.shell = True | |||
221 | def fn(ui, *args): |
|
222 | def fn(ui, *args): | |
222 | env = {'HG_ARGS': ' '.join((self.name,) + args)} |
|
223 | env = {'HG_ARGS': ' '.join((self.name,) + args)} | |
223 | def _checkvar(m): |
|
224 | def _checkvar(m): | |
@@ -404,18 +405,11 b' def runcommand(lui, repo, cmd, fullargs,' | |||||
404 | result=ret, pats=cmdpats, opts=cmdoptions) |
|
405 | result=ret, pats=cmdpats, opts=cmdoptions) | |
405 | return ret |
|
406 | return ret | |
406 |
|
407 | |||
407 | _loaded = set() |
|
408 | def _getlocal(ui, rpath): | |
408 | def _dispatch(ui, args): |
|
409 | """Return (path, local ui object) for the given target path. | |
409 | # read --config before doing anything else |
|
410 | ||
410 | # (e.g. to change trust settings for reading .hg/hgrc) |
|
411 | Takes paths in [cwd]/.hg/hgrc into account." | |
411 | _parseconfig(ui, _earlygetopt(['--config'], args)) |
|
412 | """ | |
412 |
|
||||
413 | # check for cwd |
|
|||
414 | cwd = _earlygetopt(['--cwd'], args) |
|
|||
415 | if cwd: |
|
|||
416 | os.chdir(cwd[-1]) |
|
|||
417 |
|
||||
418 | # read the local repository .hgrc into a local ui object |
|
|||
419 | try: |
|
413 | try: | |
420 | wd = os.getcwd() |
|
414 | wd = os.getcwd() | |
421 | except OSError, e: |
|
415 | except OSError, e: | |
@@ -431,13 +425,64 b' def _dispatch(ui, args):' | |||||
431 | except IOError: |
|
425 | except IOError: | |
432 | pass |
|
426 | pass | |
433 |
|
427 | |||
434 | # now we can expand paths, even ones in .hg/hgrc |
|
|||
435 | rpath = _earlygetopt(["-R", "--repository", "--repo"], args) |
|
|||
436 | if rpath: |
|
428 | if rpath: | |
437 | path = lui.expandpath(rpath[-1]) |
|
429 | path = lui.expandpath(rpath[-1]) | |
438 | lui = ui.copy() |
|
430 | lui = ui.copy() | |
439 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) |
|
431 | lui.readconfig(os.path.join(path, ".hg", "hgrc")) | |
440 |
|
432 | |||
|
433 | return path, lui | |||
|
434 | ||||
|
435 | def _checkshellalias(ui, args): | |||
|
436 | cwd = os.getcwd() | |||
|
437 | options = {} | |||
|
438 | args = fancyopts.fancyopts(args, commands.globalopts, options) | |||
|
439 | ||||
|
440 | if not args: | |||
|
441 | return | |||
|
442 | ||||
|
443 | _parseconfig(ui, options['config']) | |||
|
444 | if options['cwd']: | |||
|
445 | os.chdir(options['cwd']) | |||
|
446 | ||||
|
447 | path, lui = _getlocal(ui, [options['repository']]) | |||
|
448 | ||||
|
449 | cmdtable = commands.table.copy() | |||
|
450 | addaliases(lui, cmdtable) | |||
|
451 | ||||
|
452 | cmd = args[0] | |||
|
453 | try: | |||
|
454 | aliases, entry = cmdutil.findcmd(cmd, cmdtable, lui.config("ui", "strict")) | |||
|
455 | except error.UnknownCommand: | |||
|
456 | os.chdir(cwd) | |||
|
457 | return | |||
|
458 | ||||
|
459 | cmd = aliases[0] | |||
|
460 | fn = entry[0] | |||
|
461 | ||||
|
462 | if cmd and hasattr(fn, 'shell'): | |||
|
463 | d = lambda: fn(ui, *args[1:]) | |||
|
464 | return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, [], {}) | |||
|
465 | ||||
|
466 | os.chdir(cwd) | |||
|
467 | ||||
|
468 | _loaded = set() | |||
|
469 | def _dispatch(ui, args): | |||
|
470 | shellaliasfn = _checkshellalias(ui, args) | |||
|
471 | if shellaliasfn: | |||
|
472 | return shellaliasfn() | |||
|
473 | ||||
|
474 | # read --config before doing anything else | |||
|
475 | # (e.g. to change trust settings for reading .hg/hgrc) | |||
|
476 | _parseconfig(ui, _earlygetopt(['--config'], args)) | |||
|
477 | ||||
|
478 | # check for cwd | |||
|
479 | cwd = _earlygetopt(['--cwd'], args) | |||
|
480 | if cwd: | |||
|
481 | os.chdir(cwd[-1]) | |||
|
482 | ||||
|
483 | rpath = _earlygetopt(["-R", "--repository", "--repo"], args) | |||
|
484 | path, lui = _getlocal(ui, rpath) | |||
|
485 | ||||
441 | # Configure extensions in phases: uisetup, extsetup, cmdtable, and |
|
486 | # Configure extensions in phases: uisetup, extsetup, cmdtable, and | |
442 | # reposetup. Programs like TortoiseHg will call _dispatch several |
|
487 | # reposetup. Programs like TortoiseHg will call _dispatch several | |
443 | # times so we keep track of configured extensions in _loaded. |
|
488 | # times so we keep track of configured extensions in _loaded. |
@@ -23,6 +23,7 b'' | |||||
23 | > echo2 = !echo '\$2' |
|
23 | > echo2 = !echo '\$2' | |
24 | > echo13 = !echo '\$1' '\$3' |
|
24 | > echo13 = !echo '\$1' '\$3' | |
25 | > count = !hg log -r '\$@' --template='.' | wc -c | sed -e 's/ //g' |
|
25 | > count = !hg log -r '\$@' --template='.' | wc -c | sed -e 's/ //g' | |
|
26 | > mcount = !hg log \$@ --template='.' | wc -c | sed -e 's/ //g' | |||
26 | > rt = root |
|
27 | > rt = root | |
27 | > |
|
28 | > | |
28 | > [defaults] |
|
29 | > [defaults] | |
@@ -158,10 +159,10 b' simple shell aliases' | |||||
158 |
|
159 | |||
159 | $ hg blank foo |
|
160 | $ hg blank foo | |
160 |
|
161 | |||
|
162 | $ hg self | |||
|
163 | self | |||
161 | $ hg echo |
|
164 | $ hg echo | |
162 |
|
165 | |||
163 | $ hg self |
|
|||
164 | self |
|
|||
165 | $ hg echo foo |
|
166 | $ hg echo foo | |
166 | foo |
|
167 | foo | |
167 | $ hg echo 'test $2' foo |
|
168 | $ hg echo 'test $2' foo | |
@@ -180,6 +181,59 b' simple shell aliases' | |||||
180 | 1 |
|
181 | 1 | |
181 | $ hg count 'branch(default)' |
|
182 | $ hg count 'branch(default)' | |
182 | 2 |
|
183 | 2 | |
|
184 | $ hg mcount -r '"branch(default)"' | |||
|
185 | 2 | |||
|
186 | ||||
|
187 | ||||
|
188 | shell aliases with global options | |||
|
189 | ||||
|
190 | $ hg init sub | |||
|
191 | $ cd sub | |||
|
192 | $ hg count 'branch(default)' | |||
|
193 | 0 | |||
|
194 | $ hg -v count 'branch(default)' | |||
|
195 | 0 | |||
|
196 | $ hg -R .. count 'branch(default)' | |||
|
197 | 0 | |||
|
198 | $ hg --cwd .. count 'branch(default)' | |||
|
199 | 2 | |||
|
200 | $ hg echo --cwd .. | |||
|
201 | --cwd .. | |||
|
202 | ||||
|
203 | ||||
|
204 | repo specific shell aliases | |||
|
205 | ||||
|
206 | $ cat >> .hg/hgrc <<EOF | |||
|
207 | > [alias] | |||
|
208 | > subalias = !echo sub \$@ | |||
|
209 | > EOF | |||
|
210 | $ cat >> ../.hg/hgrc <<EOF | |||
|
211 | > [alias] | |||
|
212 | > mainalias = !echo main \$@ | |||
|
213 | > EOF | |||
|
214 | ||||
|
215 | ||||
|
216 | shell alias defined in current repo | |||
|
217 | ||||
|
218 | $ hg subalias | |||
|
219 | sub | |||
|
220 | $ hg --cwd .. subalias > /dev/null | |||
|
221 | hg: unknown command 'subalias' | |||
|
222 | [255] | |||
|
223 | $ hg -R .. subalias > /dev/null | |||
|
224 | hg: unknown command 'subalias' | |||
|
225 | [255] | |||
|
226 | ||||
|
227 | ||||
|
228 | shell alias defined in other repo | |||
|
229 | ||||
|
230 | $ hg mainalias > /dev/null | |||
|
231 | hg: unknown command 'mainalias' | |||
|
232 | [255] | |||
|
233 | $ hg -R .. mainalias | |||
|
234 | main | |||
|
235 | $ hg --cwd .. mainalias | |||
|
236 | main | |||
183 |
|
237 | |||
184 |
|
238 | |||
185 | invalid arguments |
|
239 | invalid arguments |
General Comments 0
You need to be logged in to leave comments.
Login now