Add timestamp checking so caching doesn't hammer remote repos.
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 14 Jul 2009 21:55:27 -0400 |
parents |
d7e61ff5eced
|
children |
68ca814becdc
|
branches/tags |
(none) |
files |
prompt.py |
Changes
--- a/prompt.py Tue Jul 14 21:44:16 2009 -0400
+++ b/prompt.py Tue Jul 14 21:55:27 2009 -0400
@@ -11,10 +11,12 @@
import re
import os
import subprocess
+import datetime
from os import path
from mercurial import extensions, hg, cmdutil
CACHE_PATH = ".hg/prompt/cache"
+CACHE_TIMEOUT = datetime.timedelta(minutes=10)
def _with_groups(g, out):
if any(g) and not all(g):
@@ -98,11 +100,11 @@
def _incoming(m):
g = m.groups()
out_g = (g[0],) + (g[-1],)
+ cache = path.join(repo.root, CACHE_PATH, 'incoming')
- cache = path.join(repo.root, CACHE_PATH, 'incoming')
- cache_out = cache + '.out'
-
- subprocess.Popen(['hg', 'prompt', '--cache-incoming'])
+ c_refreshed = datetime.datetime.fromtimestamp(os.stat(cache).st_mtime)
+ if c_refreshed < datetime.datetime.now() - CACHE_TIMEOUT:
+ subprocess.Popen(['hg', 'prompt', '--cache-incoming'])
if path.isfile(cache):
with open(cache) as c: