[PATCH 4 of 5 V2] clone: add --subrepos flag

Angel Ezquerra angel.ezquerra at gmail.com
Sun Mar 3 15:05:48 CST 2013


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1362270678 -3600
# Node ID 3afce3036bc8c06a3aa32d9a54ca2c9c67379153
# Parent  70724cf5d021de541cf545440dd0937dade6e471
clone: add --subrepos flag

This flag is similar to the pull --subrepos flag. With this flag mercurial will
look for subrepos on all the revisions on the cloned repository. Mercurial will
clone all the subrepos that it finds, even if you use the --noupdate clone flag.

With this new flag, pull --subrepos will now also work as expected when a new
subrepo containing subrepos is cloned into the repository.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1127,6 +1127,7 @@
     ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
     ('', 'pull', None, _('use pull protocol to copy metadata')),
     ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
+    ('S', 'subrepos', None, _('clone all subrepos')),
     ] + remoteopts,
     _('[OPTION]... SOURCE [DEST]'))
 def clone(ui, source, dest=None, **opts):
@@ -1233,7 +1234,8 @@
                  stream=opts.get('uncompressed'),
                  rev=opts.get('rev'),
                  update=opts.get('updaterev') or not opts.get('noupdate'),
-                 branch=opts.get('branch'))
+                 branch=opts.get('branch'),
+                 subrepos=opts.get('subrepos'))
 
     return r is None
 
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -225,7 +225,7 @@
         raise
 
 def clone(ui, peeropts, source, dest=None, pull=False, rev=None,
-          update=True, stream=False, branch=None):
+          update=True, stream=False, branch=None, subrepos=None):
     """Make a copy of an existing repository.
 
     Create a copy of an existing repository in a new directory.  The
@@ -259,6 +259,8 @@
     anything else is treated as a revision)
 
     branch: branches to clone
+
+    subrepos: clone all subrepos recursively
     """
 
     if isinstance(source, str):
@@ -368,6 +370,8 @@
                 revs = [srcpeer.lookup(r) for r in rev]
                 checkout = revs[0]
             if destpeer.local():
+                # do not pass the subrepos option to clone,
+                # that will be handled once the hgrc file has been written
                 destpeer.local().clone(srcpeer, heads=revs, stream=stream)
             elif srcrepo:
                 srcrepo.push(destpeer, revs=revs)
@@ -404,6 +408,9 @@
 
             destrepo.ui.setconfig('paths', 'default', defaulturl)
 
+            if subrepos:
+                destrepo.getsubrepos(source=source)
+
             if update:
                 if update is not True:
                     checkout = srcpeer.lookup(update)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -10,7 +10,7 @@
 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
 import lock, transaction, store, encoding, base85
 import scmutil, util, extensions, hook, error, revset
-import config
+import config, urllib2
 import match as matchmod
 import merge as mergemod
 import tags as tagsmod
@@ -2547,7 +2547,7 @@
         finally:
             lock.release()
 
-    def clone(self, remote, heads=[], stream=False):
+    def clone(self, remote, heads=[], stream=False, subrepos=False):
         '''clone remote repository.
 
         keyword arguments:
@@ -2569,15 +2569,21 @@
         if stream and not heads:
             # 'stream' means remote revlog format is revlogv1 only
             if remote.capable('stream'):
-                return self.stream_in(remote, set(('revlogv1',)))
+                res = self.stream_in(remote, set(('revlogv1',)))
+                if subrepos:
+                    self.getsubrepos(source=remote.url())
+                return res
             # otherwise, 'streamreqs' contains the remote revlog format
             streamreqs = remote.capable('streamreqs')
             if streamreqs:
                 streamreqs = set(streamreqs.split(','))
                 # if we support it, stream in and adjust our requirements
                 if not streamreqs - self.supportedformats:
-                    return self.stream_in(remote, streamreqs)
-        return self.pull(remote, heads)
+                    res = self.stream_in(remote, streamreqs)
+                    if subrepos:
+                        self.getsubrepos(source=remote.url())
+                    return res
+        return self.pull(remote, heads, subrepos=subrepos)
 
     def pushkey(self, namespace, key, old, new):
         self.hook('prepushkey', throw=True, namespace=namespace, key=key,
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -551,7 +551,7 @@
                 shutil.rmtree(self._repo.path)
                 other, cloned = hg.clone(self._repo._subparent.baseui, {},
                                          other, self._repo.root,
-                                         update=False)
+                                         update=False, subrepos=subrepos)
                 self._repo = cloned.local()
                 self._initrepo(parentrepo, source, create=True)
             else:
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -196,7 +196,7 @@
   $ hg debugcommands
   add: include, exclude, subrepos, dry-run
   annotate: rev, follow, no-follow, text, user, file, date, number, changeset, line-number, ignore-all-space, ignore-space-change, ignore-blank-lines, include, exclude
-  clone: noupdate, updaterev, rev, branch, pull, uncompressed, ssh, remotecmd, insecure
+  clone: noupdate, updaterev, rev, branch, pull, uncompressed, subrepos, ssh, remotecmd, insecure
   commit: addremove, close-branch, amend, include, exclude, message, logfile, date, user, subrepos
   diff: rev, change, text, git, nodates, show-function, reverse, ignore-all-space, ignore-space-change, ignore-blank-lines, unified, stat, include, exclude, subrepos
   export: output, switch-parent, rev, text, git, nodates


More information about the Mercurial-devel mailing list