[PATCH] share: don't recreate the source repo each time

Durham Goode durham at fb.com
Mon Jul 11 20:40:39 UTC 2016


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1468269602 25200
#      Mon Jul 11 13:40:02 2016 -0700
# Node ID 6696a8a974423d6ba363fa1f32e683509132d1f0
# Parent  4b16a5bd99484cac96ade9af76e6deee1fc57b54
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.

diff --git a/hgext/share.py b/hgext/share.py
--- a/hgext/share.py
+++ b/hgext/share.py
@@ -157,10 +157,15 @@ def _getsrcrepo(repo):
     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):


More information about the Mercurial-devel mailing list