[PATCH 4 of 4 V2] largefiles: setup "largefiles" feature in each repositories individually

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat Sep 29 06:28:48 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1348917084 -32400
# Node ID a851c510dda3b34f0f20c13a3048f9f83085e212
# Parent  b460a0bb2715122cb23f6787f96dd73a70dc3b76
largefiles: setup "largefiles" feature in each repositories individually

Before this patch, if largefiles extension is enabled once in any of
target repositories, commands handling multiple repositories at a time
like below misunderstand that "largefiles" feature is supported also
in all other local repositories:

  - clone/pull from or push to localhost
  - recursive execution in subrepo tree

This patch registers "featuresetup()" into "featuresetupfuncs" of
"localrepository" to support "largefiles" features only in
repositories enabling largefiles extension, instead of adding
"largefiles" feature to class variable "_basesupported" of
"localrepository".

This patch also adds checking below to the largefiles specific class
derived from "localrepository":

  - push to localhost: whether features supported in the local(= dst)
    repository satisfies ones required in the remote(= src)

This can prevent useless looking up in the remote repository, when
supported and required features are mismatched: "push()" of
"localrepository" also checks it, but it is executed after looking up
in the remote.

diff -r b460a0bb2715 -r a851c510dda3 hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py	Sat Sep 29 20:11:24 2012 +0900
+++ b/hgext/largefiles/__init__.py	Sat Sep 29 20:11:24 2012 +0900
@@ -87,15 +87,26 @@
 '''
 
 from mercurial import commands
+from mercurial import commands, localrepo, extensions
 
 import lfcommands
 import reposetup
-import uisetup
+import uisetup as uisetupmod
 
 testedwith = 'internal'
 
 reposetup = reposetup.reposetup
-uisetup = uisetup.uisetup
+
+def featuresetup(ui, supported):
+    for name, module in extensions.extensions(ui):
+        if __name__ == module.__name__:
+            # don't die on seeing a repo with the largefiles requirement
+            supported |= set(['largefiles'])
+            return
+
+def uisetup(ui):
+    localrepo.localrepository.featuresetupfuncs.add(featuresetup)
+    uisetupmod.uisetup(ui)
 
 commands.norepo += " lfconvert"
 
diff -r b460a0bb2715 -r a851c510dda3 hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py	Sat Sep 29 20:11:24 2012 +0900
+++ b/hgext/largefiles/reposetup.py	Sat Sep 29 20:11:24 2012 +0900
@@ -431,6 +431,14 @@
                 wlock.release()
 
         def push(self, remote, force=False, revs=None, newbranch=False):
+            if remote.local():
+                missing = set(self.requirements) - remote.local().supported
+                if missing:
+                    msg = _("any of required features are not"
+                            " supported in the destination:"
+                            " %s") % (', '.join(sorted(missing)))
+                    raise util.Abort(msg)
+
             o = lfutil.findoutgoing(repo, remote, force)
             if o:
                 toupload = set()
diff -r b460a0bb2715 -r a851c510dda3 hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py	Sat Sep 29 20:11:24 2012 +0900
+++ b/hgext/largefiles/uisetup.py	Sat Sep 29 20:11:24 2012 +0900
@@ -9,7 +9,7 @@
 '''setup for largefiles extension: uisetup'''
 
 from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
-    httppeer, localrepo, merge, scmutil, sshpeer, sshserver, wireproto
+    httppeer, merge, scmutil, sshpeer, sshserver, wireproto
 from mercurial.i18n import _
 from mercurial.hgweb import hgweb_mod, protocol, webcommands
 from mercurial.subrepo import hgsubrepo
@@ -151,9 +151,6 @@
     sshpeer.sshpeer._callstream = proto.sshrepocallstream
     httppeer.httppeer._callstream = proto.httprepocallstream
 
-    # don't die on seeing a repo with the largefiles requirement
-    localrepo.localrepository._basesupported |= set(['largefiles'])
-
     # override some extensions' stuff as well
     for name, module in extensions.extensions():
         if name == 'fetch':
diff -r b460a0bb2715 -r a851c510dda3 tests/test-largefiles.t
--- a/tests/test-largefiles.t	Sat Sep 29 20:11:24 2012 +0900
+++ b/tests/test-largefiles.t	Sat Sep 29 20:11:24 2012 +0900
@@ -1620,3 +1620,64 @@
   .hglf/large2.dat
 
   $ cd ..
+
+Check whether "largefiles" feature is supported only in repositories
+enabling largefiles extension.
+
+  $ mkdir individualenabling
+  $ cd individualenabling
+
+  $ hg init enabledlocally
+  $ echo large > enabledlocally/large
+  $ hg -R enabledlocally add --large enabledlocally/large
+  $ hg -R enabledlocally commit -m '#0'
+  Invoking status precommit hook
+  A large
+
+  $ hg init notenabledlocally
+  $ echo large > notenabledlocally/large
+  $ hg -R notenabledlocally add --large notenabledlocally/large
+  $ hg -R notenabledlocally commit -m '#0'
+  Invoking status precommit hook
+  A large
+
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > # disable globally
+  > largefiles=!
+  > EOF
+  $ cat >> enabledlocally/.hg/hgrc <<EOF
+  > [extensions]
+  > # enable locally
+  > largefiles=
+  > EOF
+  $ hg -R enabledlocally root
+  $TESTTMP/individualenabling/enabledlocally
+  $ hg -R notenabledlocally root
+  abort: unknown repository format: requires features 'largefiles' (upgrade Mercurial)!
+  [255]
+
+  $ hg init push-dst
+  $ hg -R enabledlocally push push-dst
+  pushing to push-dst
+  abort: any of required features are not supported in the destination: largefiles
+  [255]
+
+  $ hg init pull-src
+  $ hg -R pull-src pull enabledlocally
+  pulling from enabledlocally
+  abort: any of required features are not supported in the destination: largefiles
+  [255]
+
+  $ hg clone enabledlocally clone-dst
+  abort: unknown repository format: requires features 'largefiles' (upgrade Mercurial)!
+  [255]
+  $ test -d clone-dst
+  [1]
+  $ hg clone --pull enabledlocally clone-pull-dst
+  abort: any of required features are not supported in the destination: largefiles
+  [255]
+  $ test -d clone-pull-dst
+  [1]
+
+  $ cd ..


More information about the Mercurial-devel mailing list