# HG changeset patch # User Steve Losh # Date 1247623914 14400 # Node ID e3db619bb352fadacff7de0c500d48e303b7fbd1 # Parent 68ca814becdc44b5f85f19d0c3adc14d95857f5c Refactor the _incoming functionality into something that outgoing can share. diff -r 68ca814becdc -r e3db619bb352 prompt.py --- a/prompt.py Tue Jul 14 22:08:26 2009 -0400 +++ b/prompt.py Tue Jul 14 22:11:54 2009 -0400 @@ -97,30 +97,32 @@ def _basename(m): return _with_groups(m.groups(), path.basename(repo.root)) if repo.root else '' - def _incoming(m): - g = m.groups() - out_g = (g[0],) + (g[-1],) - - cache_dir = path.join(repo.root, CACHE_PATH) - cache = path.join(cache_dir, 'incoming') - if not path.isdir(cache_dir): - os.makedirs(cache_dir) - - cache_exists = path.isfile(cache) - - cache_time = datetime.fromtimestamp(os.stat(cache).st_mtime) - if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT: - subprocess.Popen(['hg', 'prompt', '--cache-incoming']) - - if cache_exists: - with open(cache) as c: - count = len(c.readlines()) - if g[1]: - return _with_groups(out_g, str(count)) if count else '' - else: - return _with_groups(out_g, '') if count else '' - else: - return '' + def _remote(kind): + def _r(m): + g = m.groups() + out_g = (g[0],) + (g[-1],) + + cache_dir = path.join(repo.root, CACHE_PATH) + cache = path.join(cache_dir, kind) + if not path.isdir(cache_dir): + os.makedirs(cache_dir) + + cache_exists = path.isfile(cache) + + cache_time = datetime.fromtimestamp(os.stat(cache).st_mtime) + if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT: + subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind]) + + if cache_exists: + with open(cache) as c: + count = len(c.readlines()) + if g[1]: + return _with_groups(out_g, str(count)) if count else '' + else: + return _with_groups(out_g, '') if count else '' + else: + return '' + return _r def _outgoing(m): g = m.groups() @@ -145,7 +147,7 @@ 'bookmark': _bookmark, 'root': _root, 'root\|basename': _basename, - 'incoming(\|count)?': _incoming, + 'incoming(\|count)?': _remote('incoming'), 'outgoing(\|count)?': _outgoing, }