# HG changeset patch # User Steve Losh # Date 1259109252 18000 # Node ID b6989b5b27efad8c1478dc5c57afbfdbfe6a21ff # Parent 2a8eea4463c35f07f0028be9879b9ffa4d5498ae Add some utility methods for parsing filters. diff -r 2a8eea4463c3 -r b6989b5b27ef prompt.py --- a/prompt.py Thu Nov 19 22:51:34 2009 -0500 +++ b/prompt.py Tue Nov 24 19:34:12 2009 -0500 @@ -21,6 +21,8 @@ CACHE_PATH = ".hg/prompt/cache" CACHE_TIMEOUT = timedelta(minutes=15) +FILTER_ARG = re.compile(r'\|.+\((.*)\)') + def _cache_remote(repo, kind): cache = path.join(repo.root, CACHE_PATH, kind) c_tmp = cache + '.temp' @@ -38,6 +40,24 @@ return ("%s" + out + "%s") % (g[0][:-1] if g[0] else '', g[1][1:] if g[1] else '') +def _get_filter(name, g): + '''Return the filter with the given name, or None if it was not used.''' + matching_filters = filter(lambda s: s and s.startswith('|%s' % name), g) + if not matching_filters: + return None + + # Later filters will override earlier ones, for now. + f = matching_filters[-1] + + return f + +def _get_filter_arg(f): + args = FILTER_ARG.match(f).groups() + if args: + return args[0] + else: + return None + def prompt(ui, repo, fs='', **opts): '''get repository information for use in a shell prompt