Commits

Steve Losh  committed 03164fd

Add timestamp checking so caching doesn't hammer remote repos.

  • Participants
  • Parent commits d7e61ff

Comments (0)

Files changed (1)

 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):
     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: