comparison prompt.py @ 141:13435b80c672

Replace c09729100dd2 with a wrapper hook implementation
author IBBoard <dev@ibboard.co.uk>
date Sat, 18 Jan 2020 21:01:23 +0000
parents c09729100dd2
children 503a7a8df2e2
comparison
equal deleted inserted replaced
140:f5dd593cc018 141:13435b80c672
281 281
282 cache_exists = path.isfile(cache) 282 cache_exists = path.isfile(cache)
283 283
284 cache_time = (datetime.fromtimestamp(os.stat(cache).st_mtime) 284 cache_time = (datetime.fromtimestamp(os.stat(cache).st_mtime)
285 if cache_exists else None) 285 if cache_exists else None)
286 if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT \ 286 if not cache_exists or cache_time < datetime.now() - CACHE_TIMEOUT:
287 or (kind == b'outgoing' and cache_time < datetime.fromtimestamp(os.stat('.hg/last-message.txt').st_mtime)):
288 if not cache_exists: 287 if not cache_exists:
289 open(cache, 'w').close() 288 open(cache, 'w').close()
290 subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind.decode('ascii')]) 289 subprocess.Popen(['hg', 'prompt', '--cache-%s' % kind.decode('ascii')])
291 290
292 if cache_exists: 291 if cache_exists:
448 for tag, repl in patterns.items(): 447 for tag, repl in patterns.items():
449 fs = re.sub(tag_start + tag + tag_end, repl, fs) 448 fs = re.sub(tag_start + tag + tag_end, repl, fs)
450 449
451 ui.status(fs) 450 ui.status(fs)
452 451
452 def _commit_with_cache(orig, ui, repo, *args, **opts):
453 """Wrap the commit command to fake an entry until we re-cache"""
454 res = orig(ui, repo, *args, **opts)
455 cache = path.join(repo.root, CACHE_PATH, b'outgoing')
456 if path.isfile(cache):
457 with open(cache, 'a') as cache_file:
458 cache_file.write('Local Commit\n')
459
453 def _pull_with_cache(orig, ui, repo, *args, **opts): 460 def _pull_with_cache(orig, ui, repo, *args, **opts):
454 """Wrap the pull command to delete the incoming cache as well.""" 461 """Wrap the pull command to delete the incoming cache as well."""
455 res = orig(ui, repo, *args, **opts) 462 res = orig(ui, repo, *args, **opts)
456 cache = path.join(repo.root, CACHE_PATH, b'incoming') 463 cache = path.join(repo.root, CACHE_PATH, b'incoming')
457 if path.isfile(cache): 464 if path.isfile(cache):
465 if path.isfile(cache): 472 if path.isfile(cache):
466 os.remove(cache) 473 os.remove(cache)
467 return res 474 return res
468 475
469 def uisetup(ui): 476 def uisetup(ui):
477 extensions.wrapcommand(commands.table, b'commit', _commit_with_cache)
470 extensions.wrapcommand(commands.table, b'pull', _pull_with_cache) 478 extensions.wrapcommand(commands.table, b'pull', _pull_with_cache)
471 extensions.wrapcommand(commands.table, b'push', _push_with_cache) 479 extensions.wrapcommand(commands.table, b'push', _push_with_cache)
472 try: 480 try:
473 extensions.wrapcommand(extensions.find(b"fetch").cmdtable, b'fetch', _pull_with_cache) 481 extensions.wrapcommand(extensions.find(b"fetch").cmdtable, b'fetch', _pull_with_cache)
474 except KeyError: 482 except KeyError: