changeset 6903:0642d9d7ec80

clone: get a list of files to clone from store
author Matt Mackall <mpm@selenic.com>
date Wed, 13 Aug 2008 20:18:44 -0500
parents 93f761c25dea
children 438e02b4be73
files mercurial/hg.py mercurial/store.py
diffstat 2 files changed, 20 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Wed Aug 13 20:18:44 2008 -0500
+++ b/mercurial/hg.py	Wed Aug 13 20:18:44 2008 -0500
@@ -164,13 +164,6 @@
                 copy = False
 
         if copy:
-            def force_copy(src, dst):
-                if not os.path.exists(src):
-                    # Tolerate empty source repository and optional files
-                    return
-                util.copyfiles(src, dst)
-
-            src_store = os.path.realpath(src_repo.spath)
             if not os.path.exists(dest):
                 os.mkdir(dest)
             try:
@@ -182,28 +175,18 @@
                     raise util.Abort(_("destination '%s' already exists")
                                      % dest)
                 raise
-            if src_repo.spath != src_repo.path:
-                # XXX racy
-                dummy_changelog = os.path.join(dest_path, "00changelog.i")
-                # copy the dummy changelog
-                force_copy(src_repo.join("00changelog.i"), dummy_changelog)
-                dest_store = os.path.join(dest_path, "store")
-                os.mkdir(dest_store)
-            else:
-                dest_store = dest_path
-            # copy the requires file
-            force_copy(src_repo.join("requires"),
-                       os.path.join(dest_path, "requires"))
-            # we lock here to avoid premature writing to the target
-            dest_lock = lock.lock(os.path.join(dest_store, "lock"))
 
-            files = ("data",
-                     "00manifest.d", "00manifest.i",
-                     "00changelog.d", "00changelog.i")
-            for f in files:
-                src = os.path.join(src_store, f)
-                dst = os.path.join(dest_store, f)
-                force_copy(src, dst)
+            for f in src_repo.store.copylist():
+                src = os.path.join(src_repo.path, f)
+                if os.path.exists(src):
+                    dst = os.path.join(dest_path, f)
+                    dstbase = os.path.dirname(dst)
+                    if not os.path.exists(dstbase):
+                        os.mkdir(dstbase)
+                    if dst.endswith('data'):
+                        # lock to avoid premature writing to the target
+                        dest_lock = lock.lock(os.path.join(dstbase, "lock"))
+                    util.copyfiles(src, dst)
 
             # we need to re-init the repo after manually copying the data
             # into it
--- a/mercurial/store.py	Wed Aug 13 20:18:44 2008 -0500
+++ b/mercurial/store.py	Wed Aug 13 20:18:44 2008 -0500
@@ -46,6 +46,8 @@
         mode = None
     return mode
 
+_data = 'data 00manifest.d 00manifest.i 00changelog.d  00changelog.i'
+
 class basicstore:
     '''base class for local repository stores'''
     def __init__(self, path, opener):
@@ -90,6 +92,9 @@
         for x in meta:
             yield x
 
+    def copylist(self):
+        return ['requires'] + _data.split()
+
 class encodedstore(basicstore):
     def __init__(self, path, opener):
         self.path = os.path.join(path, 'store')
@@ -109,6 +114,10 @@
     def join(self, f):
         return os.path.join(self.path, encodefilename(f))
 
+    def copylist(self):
+        return (['requires', '00changelog.i'] +
+                ['store/' + f for f in _data.split()])
+
 def store(requirements, path, opener):
     if 'store' in requirements:
         return encodedstore(path, opener)