diff hgext/share.py @ 29506:2550604f5ec7

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.
author Durham Goode <durham@fb.com>
date Mon, 11 Jul 2016 13:40:02 -0700
parents 6a98f9408a50
children d5883fd055c6
line wrap: on
line diff
--- 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):