# HG changeset patch # User Steve Losh # Date 1247624667 14400 # Node ID 7a87d26c99ac893750a94f78e7a558bfb55f1321 # Parent e3db619bb352fadacff7de0c500d48e303b7fbd1 Implement the {outgoing} caching. Still needs new documentation. diff -r e3db619bb352 -r 7a87d26c99ac prompt.py --- a/prompt.py Tue Jul 14 22:11:54 2009 -0400 +++ b/prompt.py Tue Jul 14 22:24:27 2009 -0400 @@ -18,6 +18,13 @@ CACHE_PATH = ".hg/prompt/cache" CACHE_TIMEOUT = timedelta(minutes=10) +def _cache_remote(repo, kind): + cache = path.join(repo.root, CACHE_PATH, kind) + c_tmp = cache + '.temp' + subprocess.call(['hg', kind, '--quiet'], stdout=file(c_tmp, 'w')) + os.rename(c_tmp, cache) + return + def _with_groups(g, out): if any(g) and not all(g): print 'ERROR' @@ -109,7 +116,8 @@ cache_exists = path.isfile(cache) - cache_time = datetime.fromtimestamp(os.stat(cache).st_mtime) + cache_time = (datetime.fromtimestamp(os.stat(cache).st_mtime) + if cache_exists else None) if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT: subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind]) @@ -124,21 +132,6 @@ return '' return _r - def _outgoing(m): - g = m.groups() - out_g = (g[0],) + (g[-1],) - - cache = path.join(repo.root, CACHE_PATH, 'outgoing') - if path.isfile(cache): - with open(cache) as c: - count = c.readline().strip() - if g[1]: - return _with_groups(out_g, count) if int(count) else '' - else: - return _with_groups(out_g, '') if int(count) else '' - else: - return '' - tag_start = r'\{([^{}]*?\{)?' tag_end = r'(\}[^{}]*?)?\}' patterns = { @@ -148,15 +141,14 @@ 'root': _root, 'root\|basename': _basename, 'incoming(\|count)?': _remote('incoming'), - 'outgoing(\|count)?': _outgoing, + 'outgoing(\|count)?': _remote('outgoing'), } if opts.get("cache_incoming"): - cache = path.join(repo.root, CACHE_PATH, 'incoming') - c_tmp = cache + '.temp' - subprocess.call(['hg', 'incoming', '--quiet'], stdout=file(c_tmp, 'w')) - os.rename(c_tmp, cache) - return + _cache_remote(repo, 'incoming') + + if opts.get("cache_outgoing"): + _cache_remote(repo, 'outgoing') for tag, repl in patterns.items(): fs = re.sub(tag_start + tag + tag_end, repl, fs)