annotate mercurial/error.py @ 12536:208fc9ad6a48

alias: only allow global options before a shell alias, pass later ones through This patch refactors the dispatch code to change how arguments to shell aliases are handled. A separate "pass" to determine whether a command is a shell alias has been added. The rough steps dispatch now performs when a command is given are these: * Parse all arguments up to the command name. * If any arguments such as --repository or --cwd are given (which could change the config file used, and therefore the definition of aliases), they are taken into account. * We determine whether the command is a shell alias. * If so, execute the alias. The --repo and --cwd arguments are still in effect. Any arguments *after* the command name are passed unchanged through to the shell command (and interpolated as normal. * If the command is *not* a shell alias, the dispatching is effectively "reset" and reparsed as normal in its entirety. The net effect of this patch is to make shell alias commands behave as you would expect. Any arguments you give to a shell alias *after* the alias name are passed through unchanged. This lets you do something like the following: [alias] filereleased = !$HG log -r 'descendants(adds("$1")) and tagged()' -l1 $2 $3 $4 $5 $ hg filereleased hgext/bookmarks.py --style compact Previously the `--style compact` part would fail because Mercurial would interpret those arguments as arguments to the alias command itself (which doesn't take any arguments). Also: running something like `hg -R ~/src/hg-crew filereleased hgext/bookmarks.py` when `filereleased` is only defined in that repo's config will now work. These global arguments can *only* be given to a shell alias *before* the alias name. For example, this will *not* work in the above situation: $ hg filereleased -R ~/src/hg-crew hgext/bookmarks.py The reason for this is that you may want to pass arguments like --repository to the alias (or, more likely, their short versions like -R): [alias] own = !chown $@ `$HG root` $ hg own steve $ hg own -R steve
author Steve Losh <steve@stevelosh.com>
date Tue, 24 Aug 2010 18:25:33 -0400
parents 6381fa7bfa53
children 931a72e00efa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
1 # error.py - Mercurial exceptions
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
2 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
3 # Copyright 2005-2008 Matt Mackall <mpm@selenic.com>
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
4 #
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
5 # This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9423
diff changeset
6 # GNU General Public License version 2 or any later version.
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
7
8227
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
8 """Mercurial exceptions.
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
9
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
10 This allows us to catch exceptions at higher levels without forcing
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
11 imports.
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
12 """
0a9542703300 turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents: 8226
diff changeset
13
7633
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
14 # Do not import anything here, please
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
15
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
16 class RevlogError(Exception):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
17 pass
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
18
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
19 class LookupError(RevlogError, KeyError):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
20 def __init__(self, name, index, message):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
21 self.name = name
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
22 if isinstance(name, str) and len(name) == 20:
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
23 from node import short
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
24 name = short(name)
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
25 RevlogError.__init__(self, '%s@%s: %s' % (index, name, message))
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
26
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
27 def __str__(self):
08cabecfa8a8 errors: move revlog errors
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
28 return RevlogError.__str__(self)
7636
e3f8c6d6b72e error: move ParseError
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
29
11287
b901bb751999 error: change ParseError to CommandError
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
30 class CommandError(Exception):
7636
e3f8c6d6b72e error: move ParseError
Matt Mackall <mpm@selenic.com>
parents: 7633
diff changeset
31 """Exception raised on errors in parsing the command line."""
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
32
11288
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
33 class Abort(Exception):
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
34 """Raised if a command needs to print an error and exit."""
11574
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11292
diff changeset
35 def __init__(self, *args, **kw):
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11292
diff changeset
36 Exception.__init__(self, *args)
6381fa7bfa53 Abort: add a hint argument, printed in the next line inside parenthesis
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 11292
diff changeset
37 self.hint = kw.get('hint')
11288
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
38
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
39 class ConfigError(Abort):
8144
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 7947
diff changeset
40 'Exception raised when parsing config files'
fca54469480e ui: introduce new config parser
Matt Mackall <mpm@selenic.com>
parents: 7947
diff changeset
41
11292
037d910734de error: fix up test-hgrc
Matt Mackall <mpm@selenic.com>
parents: 11288
diff changeset
42 class ParseError(Exception):
11288
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
43 'Exception raised when parsing config files (msg[, pos])'
2123aad24d56 error: add new ParseError for various parsing errors
Matt Mackall <mpm@selenic.com>
parents: 11287
diff changeset
44
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
45 class RepoError(Exception):
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
46 pass
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
47
9423
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
48 class RepoLookupError(RepoError):
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
49 pass
1444a42f6052 Make distinct lookup error for localrepo.lookup
Matt Mackall <mpm@selenic.com>
parents: 8227
diff changeset
50
7637
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
51 class CapabilityError(RepoError):
1d54e2f6c0b7 error: move repo errors
Matt Mackall <mpm@selenic.com>
parents: 7636
diff changeset
52 pass
7640
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
53
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
54 class LockError(IOError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
55 def __init__(self, errno, strerror, filename, desc):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
56 IOError.__init__(self, errno, strerror, filename)
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
57 self.desc = desc
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
58
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
59 class LockHeld(LockError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
60 def __init__(self, errno, filename, desc, locker):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
61 LockError.__init__(self, errno, 'Lock held', filename, desc)
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
62 self.locker = locker
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
63
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
64 class LockUnavailable(LockError):
7197812e8d44 error: move lock errors
Matt Mackall <mpm@selenic.com>
parents: 7637
diff changeset
65 pass
7641
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
66
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
67 class ResponseError(Exception):
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
68 """Raised to print an error with part of output and exit."""
d2f753830f80 error: move UnexpectedOutput (now ResponseError)
Matt Mackall <mpm@selenic.com>
parents: 7640
diff changeset
69
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
70 class UnknownCommand(Exception):
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
71 """Exception raised if command is not in the command table."""
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
72
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
73 class AmbiguousCommand(Exception):
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
74 """Exception raised if command shortcut matches more than one command."""
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7641
diff changeset
75
7644
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
76 # derived from KeyboardInterrupt to simplify some breakout code
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
77 class SignalInterrupt(KeyboardInterrupt):
182b7114d35a error: move SignalInterrupt
Matt Mackall <mpm@selenic.com>
parents: 7643
diff changeset
78 """Exception raised on SIGTERM and SIGHUP."""
7646
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
79
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
80 class SignatureError(Exception):
e62a456b8dc5 error: move SignatureError
Matt Mackall <mpm@selenic.com>
parents: 7644
diff changeset
81 pass