[PATCH 4 of 5] clone: add --subrev option

Angel Ezquerra angel.ezquerra at gmail.com
Sat Nov 23 14:28:03 CST 2013


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1362270678 -3600
#      Sun Mar 03 01:31:18 2013 +0100
# Node ID 1dfe3011f816afbd233f559bfe0afefcf7ab9b0c
# Parent  4b1f0241786e8c6b5e5117950f4e1d4857718618
clone: add --subrev option

This flag is similar to the pull --subrev option. With this flag mercurial will
look for subrepos on the revisions on the cloned repository specified by the
--subrev revision set(s). Mercurial will clone all the subrepos that it finds,
even if you use the --noupdate clone flag.

With this new flag, pull --subrev 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
@@ -1176,6 +1176,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', 'subrev', [], _('clone subrepos from these revisions')),
     ] + remoteopts,
     _('[OPTION]... SOURCE [DEST]'))
 def clone(ui, source, dest=None, **opts):
@@ -1282,7 +1283,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'),
+                 subrev=opts.get('subrev'))
 
     return r is None
 
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -227,7 +227,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, subrev=None):
     """Make a copy of an existing repository.
 
     Create a copy of an existing repository in a new directory.  The
@@ -261,6 +261,8 @@
     anything else is treated as a revision)
 
     branch: branches to clone
+
+    subrev: recursively clone all subrepos found on these revsets
     """
 
     if isinstance(source, str):
@@ -370,6 +372,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)
@@ -406,6 +410,9 @@
 
             destrepo.ui.setconfig('paths', 'default', defaulturl)
 
+            if subrev:
+                destrepo.getsubrepos(subrev=subrev, 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
@@ -2423,12 +2423,14 @@
         finally:
             lock.release()
 
-    def clone(self, remote, heads=[], stream=False):
+    def clone(self, remote, heads=[], stream=False, subrev=None):
         '''clone remote repository.
 
         keyword arguments:
         heads: list of revs to clone (forces use of pull)
-        stream: use streaming clone if possible'''
+        stream: use streaming clone if possible
+        subrev: list of revisions to look for subrepos to pull
+        '''
 
         # now, all clients that can request uncompressed clones can
         # read repo formats supported by all servers that can serve
@@ -2445,15 +2447,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 subrev:
+                    self.getsubrepos(subrev=subrev, 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 subrev:
+                        self.getsubrepos(subrev=subrev, source=remote.url())
+                    return res
+        return self.pull(remote, heads, subrev=subrev)
 
     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
@@ -679,7 +679,7 @@
             shutil.rmtree(self._repo.path)
             other, cloned = hg.clone(self._repo._subparent.baseui, {},
                                      other, self._repo.root,
-                                     update=False, heads=heads)
+                                     update=False, subrev=subrev)
             self._repo = cloned.local()
             self._initrepo(parentrepo, source, create=True)
             self._cachestorehash(srcurl)
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -198,7 +198,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, subrev, ssh, remotecmd, insecure
   commit: addremove, close-branch, amend, secret, 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hg-2.4-4.patch
Type: text/x-patch
Size: 6448 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20131123/1d3d67fe/attachment.bin>


More information about the Mercurial-devel mailing list