Show More
@@ -221,15 +221,17 b' class cmdalias(object):' | |||
|
221 | 221 | def fn(ui, *args): |
|
222 | 222 | env = {'HG_ARGS': ' '.join((self.name,) + args)} |
|
223 | 223 | def _checkvar(m): |
|
224 |
if |
|
|
224 | if m.groups()[0] == '$': | |
|
225 | return m.group() | |
|
226 | elif int(m.groups()[0]) <= len(args): | |
|
225 | 227 | return m.group() |
|
226 | 228 | else: |
|
227 | 229 | return '' |
|
228 | cmd = re.sub(r'\$(\d+)', _checkvar, self.definition[1:]) | |
|
230 | cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:]) | |
|
229 | 231 | replace = dict((str(i + 1), arg) for i, arg in enumerate(args)) |
|
230 | 232 | replace['0'] = self.name |
|
231 | 233 | replace['@'] = ' '.join(args) |
|
232 | cmd = util.interpolate(r'\$', replace, cmd) | |
|
234 | cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True) | |
|
233 | 235 | return util.system(cmd, environ=env) |
|
234 | 236 | self.fn = fn |
|
235 | 237 | return |
@@ -1502,7 +1502,7 b' except NameError:' | |||
|
1502 | 1502 | return False |
|
1503 | 1503 | return True |
|
1504 | 1504 | |
|
1505 | def interpolate(prefix, mapping, s, fn=None): | |
|
1505 | def interpolate(prefix, mapping, s, fn=None, escape_prefix=False): | |
|
1506 | 1506 | """Return the result of interpolating items in the mapping into string s. |
|
1507 | 1507 | |
|
1508 | 1508 | prefix is a single character string, or a two character string with |
@@ -1511,9 +1511,20 b' def interpolate(prefix, mapping, s, fn=N' | |||
|
1511 | 1511 | |
|
1512 | 1512 | fn is an optional function that will be applied to the replacement text |
|
1513 | 1513 | just before replacement. |
|
1514 | ||
|
1515 | escape_prefix is an optional flag that allows using doubled prefix for | |
|
1516 | its escaping. | |
|
1514 | 1517 | """ |
|
1515 | 1518 | fn = fn or (lambda s: s) |
|
1516 |
r = |
|
|
1519 | patterns = '|'.join(mapping.keys()) | |
|
1520 | if escape_prefix: | |
|
1521 | patterns += '|' + prefix | |
|
1522 | if len(prefix) > 1: | |
|
1523 | prefix_char = prefix[1:] | |
|
1524 | else: | |
|
1525 | prefix_char = prefix | |
|
1526 | mapping[prefix_char] = prefix_char | |
|
1527 | r = re.compile(r'%s(%s)' % (prefix, patterns)) | |
|
1517 | 1528 | return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) |
|
1518 | 1529 | |
|
1519 | 1530 | def getport(port): |
General Comments 0
You need to be logged in to leave comments.
Login now