# HG changeset patch
# User Matt Mackall <m...@selenic.com>
# Date 1474294391 18000
#      Mon Sep 19 09:13:11 2016 -0500
# Node ID 133b35066bef5d9c31d13c4f0b2e4a50d1ceae87
# Parent  9c8847df32a0c5045e60aded2e03a9c97507f909
extdata: add basic caching

Sources used for log templating will be queried for every changeset
printed. So we need a cache. We attach the cache to the repo object to
give it a bounded lifetime.

diff -r 9c8847df32a0 -r 133b35066bef mercurial/scmutil.py
--- a/mercurial/scmutil.py      Mon Sep 19 09:05:00 2016 -0500
+++ b/mercurial/scmutil.py      Mon Sep 19 09:13:11 2016 -0500
@@ -1453,6 +1453,14 @@
         raise error.Abort(_("extdata doesn't support parameters yet"),
                           hint=_("use double % for escaping"))
 
+    # we cache external data sources for the lifetime of a repo object
+    # users like log templates may consult a data source very frequently
+    if not util.safehasattr(repo, "_extdatacache"):
+        repo._extdatacache = {}
+    cache = repo._extdatacache
+    if spec in cache:
+        return cache[spec]
+
     data = {}
     if spec.startswith("shell:"):
         # external commands should be run relative to the repo root
@@ -1481,4 +1489,5 @@
     finally:
         src.close()
 
+    cache[spec] = data
     return data
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to