changeset 62:5d770477eb1a

`hg fclone` now behaves much like `hg clone`
author Simon Law <simon@akoha.org>
date Mon, 27 Aug 2007 13:40:21 -0400
parents 45f4c6176e27
children 95a1f9aab6ab
files forest.py test-forest test-forest.out
diffstat 3 files changed, 98 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/forest.py	Tue Aug 28 15:27:29 2007 -0400
+++ b/forest.py	Mon Aug 27 13:40:21 2007 -0400
@@ -48,6 +48,7 @@
 import errno
 import os
 import re
+import shutil
 
 from mercurial import cmdutil, commands, hg, node, util
 from mercurial import localrepo, sshrepo, sshserver, httprepo, statichttprepo
@@ -798,32 +799,68 @@
         self.forest.write(ui, oldstyle=True)
 
 
-def clone(ui, source, dest, walkhg, **opts):
-    """Clone a forest."""
-    dest = os.path.normpath(dest)
+def qclone(ui, source, sroot, dest, rpath, opts):
+    """Helper function to clone from a remote repository.
+
+    source is the URL of the source of this repository
+    dest is the directory of the destination
+    rpath is the relative path of the destination
+    opts are a list of options to be passed into the clone
+    """
+    ui.status("[%s]\n" % rpath)
+    assert(dest is not None)
+    destpfx = os.path.normpath(os.path.dirname(dest))
+    if not os.path.exists(destpfx):
+        os.makedirs(destpfx)
+    repo = hg.repository(ui, source)
+    mqdir = None
+    assert(source is not None)
+    if hg.islocal(source):
+        Forest.Tree(repo=repo).die_on_mq(sroot)
+    url = urltopath(repo.url())
+    ui.note(_("cloning %s to %s\n") % (url, dest))
+    commands.clone(ui, url, dest, **opts)
+    repo = None
+
 
-    def doit(repo, root, path, rev, *unused):
-        if root == '.':
-            destpath = dest
+def clone(ui, source, dest=None, **opts):
+    """make a clone of an existing forest of repositories
+
+    Create a clone of an existing forest in a new directory.
+
+    Look at the help text for the clone command for more information.
+    """
+    die_on_numeric_revs(opts['rev'])
+    source = ui.expandpath(source) or source
+    islocalsrc = hg.islocal(source)
+    if islocalsrc:
+        source = os.path.abspath(urltopath(source))
+    if dest:
+        dest = os.path.normpath(dest)
+    else:
+        dest = hg.defaultdest(source)
+    toprepo = hg.repository(ui, source)
+    forests = toprepo.forests(walkhgenabled(ui, opts['walkhg']))
+    for rpath in forests:
+        if rpath == '.':
+            rpath = ''
+        if islocalsrc:
+            srcpath = source
+            srcpath = os.path.join(source, util.localpath(rpath))
         else:
-            destpath = os.path.join(dest, util.localpath(root))
-            destpfx = os.path.dirname(destpath)
-            if not os.path.exists(destpfx):
-                os.makedirs(destpfx)
-        if rev:
-            opts['rev'] = [rev]
+            srcpath = '/'.join((source, rpath))
+        if rpath:
+            destpath = os.path.join(dest, util.localpath(rpath))
         else:
-            opts['rev'] = []
-        url = repo.url()
-        if hasattr(repo, "root"):
-            url = repo.root
-        commands.clone(ui, url, destpath, **opts)
-
-    snapshot = ForestSnapshot()
-    repo = hg.repository(ui, source)
-    snapshot.update(ui, repo, hasattr(repo, "root"),
-                    walkhgenabled(ui, walkhg), True)
-    snapshot(ui, repo, doit, mq_check=False)
+            destpath = dest
+        try:
+            qclone(ui=ui,
+                   source=srcpath, sroot=source,
+                   dest=destpath, rpath=os.path.normpath(rpath),
+                   opts=opts)
+        except util.Abort, err:
+            ui.warn(_("skipped: %s\n") % err)
+        ui.status("\n")
 
 
 def pull(ui, toprepo, snapfile, pathalias, **opts):
@@ -974,10 +1011,10 @@
     walkhgopts = ('', 'walkhg', '',
                  _("walk repositories under '.hg' (yes/no)"))
     cmdtable = {
-        "fclone" :
+        "^fclone" :
             (clone,
-             [walkhgopts] + cmd_options(ui, 'clone', remove=('r',)),
-             _('hg fclone [OPTIONS] SOURCE DESTINATION')),
+             [walkhgopts] + cmd_options(ui, 'clone'),
+             _('hg fclone [OPTION]... SOURCE [DEST]')),
         "fpull" :
             (pull,
              cmd_options(ui, 'pull', remove=('f', 'r')),
--- a/test-forest	Tue Aug 28 15:27:29 2007 -0400
+++ b/test-forest	Mon Aug 27 13:40:21 2007 -0400
@@ -1,5 +1,7 @@
 #! /bin/sh
 
+#alias hg='hg --traceback'
+
 HGRCPATH=$HGTMP/.hgrc
 export HGRCPATH
 echo "[extensions]" >> $HGRCPATH
@@ -117,6 +119,13 @@
 hg add --cwd topcopy/t z
 hg qrefresh --cwd topcopy/t
 
+# create a versioned mq patch in topcopy/t
+hg qinit -c --cwd topcopy/t/t
+hg qnew --cwd topcopy/t/t mq-patch
+echo "zzz" > topcopy/t/t/z
+hg add --cwd topcopy/t/t z
+hg qrefresh --cwd topcopy/t/t
+
 echo "# fstatus + mq"
 hg fstatus --cwd topcopy
 
--- a/test-forest.out	Tue Aug 28 15:27:29 2007 -0400
+++ b/test-forest.out	Mon Aug 27 13:40:21 2007 -0400
@@ -338,9 +338,32 @@
 *mq*
 
 [t/t]
+*mq*
+
+[t/t/.hg/patches]
+A .hgignore
+A mq-patch
+A series
 
 # fclone + mq
-abort: 't' has mq patches applied
+[.]
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[d/d/t]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[e/d]
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+[t]
+skipped: 't' has mq patches applied
+
+[t/t]
+skipped: 't/t' has mq patches applied
+
+[t/t/.hg/patches]
+0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
 # fsnap + mq
 abort: 't' has mq patches applied
 # fpull + mq
@@ -363,9 +386,7 @@
 skipped, mq patches applied
 
 [t/t]
-pulling from HGTMP/test-forest/toplevel/t/t
-searching for changes
-no changes found
+skipped, mq patches applied
 
 # fpush + mq
 [.]
@@ -387,9 +408,7 @@
 skipped, mq patches applied
 
 [t/t]
-pushing to HGTMP/test-forest/toplevel/t/t
-searching for changes
-no changes found
+skipped, mq patches applied
 
 # walk **/.hg
 .