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

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon Jul 16 10:15:07 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1342451578 -32400
# Branch stable
# Node ID 3980b89b2f15744acacdf7d72f2b16a2510827bb
# Parent  2792d09973cff9d5c0f922af9b39b2326105e823
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 mis-recognize that "largefiles" feature is supported also
in all other local repositories:

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

This patch registers "supportsetup()" into "supportsetups" of
"localrepository" to support "largefiles" features only in repositories
enabling largefiles extension, instead of adding "largefiles" feature
to class variable "supported" 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 2792d09973cf -r 3980b89b2f15 hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py	Tue Jul 17 00:12:58 2012 +0900
+++ b/hgext/largefiles/__init__.py	Tue Jul 17 00:12:58 2012 +0900
@@ -86,14 +86,24 @@
 command.
 '''
 
-from mercurial import commands
+from mercurial import commands, localrepo, extensions
 
 import lfcommands
 import reposetup
-import uisetup
+import uisetup as uisetupmod
 
 reposetup = reposetup.reposetup
-uisetup = uisetup.uisetup
+
+def supportsetup(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.supportsetups.add(supportsetup)
+    uisetupmod.uisetup(ui)
 
 commands.norepo += " lfconvert"
 
diff -r 2792d09973cf -r 3980b89b2f15 hgext/largefiles/reposetup.py
--- a/hgext/largefiles/reposetup.py	Tue Jul 17 00:12:58 2012 +0900
+++ b/hgext/largefiles/reposetup.py	Tue Jul 17 00:12:58 2012 +0900
@@ -427,6 +427,14 @@
                 wlock.release()
 
         def push(self, remote, force=False, revs=None, newbranch=False):
+            if remote.local():
+                missing = set(self.requirements) - remote.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 2792d09973cf -r 3980b89b2f15 hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py	Tue Jul 17 00:12:58 2012 +0900
+++ b/hgext/largefiles/uisetup.py	Tue Jul 17 00:12:58 2012 +0900
@@ -9,7 +9,7 @@
 '''setup for largefiles extension: uisetup'''
 
 from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
-    httprepo, localrepo, merge, sshrepo, sshserver, wireproto
+    httprepo, merge, sshrepo, sshserver, wireproto
 from mercurial.i18n import _
 from mercurial.hgweb import hgweb_mod, protocol, webcommands
 from mercurial.subrepo import hgsubrepo
@@ -138,9 +138,6 @@
     sshrepo.sshrepository._callstream = proto.sshrepocallstream
     httprepo.httprepository._callstream = proto.httprepocallstream
 
-    # don't die on seeing a repo with the largefiles requirement
-    localrepo.localrepository.supported |= set(['largefiles'])
-
     # override some extensions' stuff as well
     for name, module in extensions.extensions():
         if name == 'fetch':
diff -r 2792d09973cf -r 3980b89b2f15 tests/test-largefiles.t
--- a/tests/test-largefiles.t	Tue Jul 17 00:12:58 2012 +0900
+++ b/tests/test-largefiles.t	Tue Jul 17 00:12:58 2012 +0900
@@ -1137,3 +1137,51 @@
   (use --subrepos for recursive commit)
   [255]
   $ cd ..
+
+Check whether "largefiles" feature is supported only in repositories
+enabling largefiles extension.
+
+  $ 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
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > # disable globally
+  > largefiles=!
+  > EOF
+  $ cat >> enabledlocally/.hg/hgrc <<EOF
+  > [extensions]
+  > # enable locally
+  > largefiles=
+  > EOF
+  $ hg -R a root
+  abort: unknown repository format: requires features 'largefiles' (upgrade Mercurial)!
+  [255]
+  $ hg -R enabledlocally root
+  $TESTTMP/enabledlocally
+
+  $ 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]


More information about the Mercurial-devel mailing list