share: don't recreate the source repo each time
authorDurham Goode <durham@fb.com>
Mon, 11 Jul 2016 13:40:02 -0700
changeset 29506 2550604f5ec7
parent 29505 2dce3f96ad7b
child 29507 97dcdcf75f4f
share: don't recreate the source repo each time Previously, every time you asked for the source repo of a shared working copy it would recreate the repo object, which required calling reposetup. With certain extension enabled, this can be quite expensive, and it can happen many times (for instance, share attaches a post transaction hook to update bookmarks that triggers this). The fix is to just cache the repo object instead of constantly recreating it.
hgext/share.py
--- a/hgext/share.py	Mon Jul 11 10:44:18 2016 +0200
+++ b/hgext/share.py	Mon Jul 11 13:40:02 2016 -0700
@@ -157,10 +157,15 @@
     if repo.sharedpath == repo.path:
         return None
 
+    if util.safehasattr(repo, 'srcrepo') and repo.srcrepo:
+        return repo.srcrepo
+
     # the sharedpath always ends in the .hg; we want the path to the repo
     source = repo.vfs.split(repo.sharedpath)[0]
     srcurl, branches = parseurl(source)
-    return repository(repo.ui, srcurl)
+    srcrepo = repository(repo.ui, srcurl)
+    repo.srcrepo = srcrepo
+    return srcrepo
 
 def getbkfile(orig, repo):
     if _hassharedbookmarks(repo):