Patchwork share: don't recreate the source repo each time

login
register
mail settings
Submitter Durham Goode
Date July 11, 2016, 8:40 p.m.
Message ID <6696a8a974423d6ba363.1468269639@dev8486.prn1.facebook.com>
Download mbox | patch
Permalink /patch/15796/
State Accepted
Headers show

Comments

Durham Goode - July 11, 2016, 8:40 p.m.
# HG changeset patch
# User Durham Goode <durham@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.
Yuya Nishihara - July 12, 2016, 2:21 p.m.
On Mon, 11 Jul 2016 13:40:39 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@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.

Seems fine to me. Queued, thanks.

Perhaps we'd better to add a formal API to cache shared source, but it's
unclear to me whether or not the whole repo should be kept. We might want
to cache the source bmstore and features set, instead.

Patch

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):