Patchwork [STABLE] hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 28, 2014, 5:05 p.m.
Message ID <f5f2c92b7abc6f6b5619.1396026323@feefifofum>
Download mbox | patch
Permalink /patch/4100/
State Accepted
Commit bc56ec9e64df9f633fe7977f63ef2e337b1ea8ae
Headers show

Comments

Katsunori FUJIWARA - March 28, 2014, 5:05 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1396023607 -32400
#      Sat Mar 29 01:20:07 2014 +0900
# Branch stable
# Node ID f5f2c92b7abc6f6b5619bb08622001ca8a149ea3
# Parent  dd2e25e49862213c73b5ea3412aa1fa5d8c92bab
hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)

Since changeset 6f72e7d28b35, "reposetup()" of each extensions is
invoked only on repositories enabling corresponded extensions.

This causes that largefiles specific interactions between the
repository enabling largefiles locally and remote (wire) peer fail,
because there is no way to know whether largefiles is enabled on the
remote repository behind the wire peer, and largefiles specific
"wireproto functions" are not given to any wire peers.

To avoid this problem, largefiles should be enabled in wider scope
than each repositories (e.g. user-wide "${HOME}/.hgrc").

This patch introduces "wirepeersetupfuncs" to setup wire peer by
extensions already enabled. Functions registered into
"wirepeersetupfuncs" are invoked for all wire peers.

This patch uses plain list instead of "util.hooks" for
"wirepeersetupfuncs", because the former allows to control order of
function invocation by order of extension enabling: it may be useful
for workaround of problems with combination of enabled extensions
Matt Mackall - March 28, 2014, 5:14 p.m.
On Sat, 2014-03-29 at 02:05 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1396023607 -32400
> #      Sat Mar 29 01:20:07 2014 +0900
> # Branch stable
> # Node ID f5f2c92b7abc6f6b5619bb08622001ca8a149ea3
> # Parent  dd2e25e49862213c73b5ea3412aa1fa5d8c92bab
> hg: introduce "wirepeersetupfuncs" to setup wire peer by extensions (issue4109)

Excellent, queued for stable.

Patch

diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -105,9 +105,10 @@ 
 command.
 '''
 
-from mercurial import commands, localrepo
+from mercurial import commands, hg, localrepo
 
 import lfcommands
+import proto
 import reposetup
 import uisetup as uisetupmod
 
@@ -121,6 +122,7 @@ 
 
 def uisetup(ui):
     localrepo.localrepository.featuresetupfuncs.add(featuresetup)
+    hg.wirepeersetupfuncs.append(proto.wirereposetup)
     uisetupmod.uisetup(ui)
 
 commands.norepo += " lfconvert"
diff --git a/hgext/largefiles/reposetup.py b/hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py
+++ b/hgext/largefiles/reposetup.py
@@ -16,14 +16,13 @@ 
 from mercurial import localrepo
 
 import lfcommands
-import proto
 import lfutil
 
 def reposetup(ui, repo):
-    # wire repositories should be given new wireproto functions but not the
-    # other largefiles modifications
+    # wire repositories should be given new wireproto functions
+    # by "proto.wirereposetup()" via "hg.wirepeersetupfuncs"
     if not repo.local():
-        return proto.wirereposetup(ui, repo)
+        return
 
     class lfilesrepo(repo.__class__):
         lfstatus = False
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -98,6 +98,9 @@ 
     else:
         return url.open(ui, path)
 
+# a list of (ui, repo) functions called for wire peer initialization
+wirepeersetupfuncs = []
+
 def _peerorrepo(ui, path, create=False):
     """return a repository object for the specified path"""
     obj = _peerlookup(path).instance(ui, path, create)
@@ -106,6 +109,9 @@ 
         hook = getattr(module, 'reposetup', None)
         if hook:
             hook(ui, obj)
+    if not obj.local():
+        for f in wirepeersetupfuncs:
+            f(ui, obj)
     return obj
 
 def repository(ui, path='', create=False):
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -2285,4 +2285,30 @@ 
   $ test -d clone-pull-dst
   [1]
 
+#if serve
+
+Test largefiles specific peer setup, when largefiles is enabled
+locally (issue4109)
+
+  $ hg showconfig extensions | grep largefiles
+  extensions.largefiles=!
+  $ mkdir -p $TESTTMP/individualenabling/usercache
+
+  $ hg serve -R enabledlocally -d -p $HGPORT --pid-file hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ hg init pull-dst
+  $ cat > pull-dst/.hg/hgrc <<EOF
+  > [extensions]
+  > # enable locally
+  > largefiles=
+  > [largefiles]
+  > # ignore system cache to force largefiles specific wire proto access
+  > usercache=$TESTTMP/individualenabling/usercache
+  > EOF
+  $ hg -R pull-dst -q pull -u http://localhost:$HGPORT
+
+  $ "$TESTDIR/killdaemons.py" $DAEMON_PIDS
+#endif
+
   $ cd ..