diff mercurial/streamclone.py @ 6840:80e51429cb9a

introduce store classes move store walking from streamclone.py into store.py
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 24 Jul 2008 16:32:52 +0200
parents 8ff321a381d0
children 43a817f3a649
line wrap: on
line diff
--- a/mercurial/streamclone.py	Thu Jul 24 16:32:51 2008 +0200
+++ b/mercurial/streamclone.py	Thu Jul 24 16:32:52 2008 +0200
@@ -5,40 +5,12 @@
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-import os, osutil, stat, util, lock
+import util, lock
 
 # if server supports streaming clone, it advertises "stream"
 # capability with value that is version+flags of repo it is serving.
 # client only streams if it can read that repo format.
 
-def walkrepo(root):
-    '''iterate over metadata files in repository.
-    walk in natural (sorted) order.
-    yields 2-tuples: name of .d or .i file, size of file.'''
-
-    strip_count = len(root) + len(os.sep)
-    def walk(path, recurse):
-        for e, kind, st in osutil.listdir(path, stat=True):
-            pe = os.path.join(path, e)
-            if kind == stat.S_IFDIR:
-                if recurse:
-                    for x in walk(pe, True):
-                        yield x
-            else:
-                if kind != stat.S_IFREG or len(e) < 2:
-                    continue
-                sfx = e[-2:]
-                if sfx in ('.d', '.i'):
-                    yield pe[strip_count:], st.st_size
-    # write file data first
-    for x in walk(os.path.join(root, 'data'), True):
-        yield x
-    # write manifest before changelog
-    meta = util.sort(walk(root, False))
-    meta.reverse()
-    for x in meta:
-        yield x
-
 # stream file format is simple.
 #
 # server writes out line that says how many files, how many total
@@ -59,28 +31,14 @@
         fileobj.write('1\n')
         return
 
-    # get consistent snapshot of repo. lock during scan so lock not
-    # needed while we stream, and commits can happen.
-    repolock = None
     try:
-        try:
-            repolock = repo.lock()
-        except (lock.LockHeld, lock.LockUnavailable), inst:
-            repo.ui.warn('locking the repository failed: %s\n' % (inst,))
-            fileobj.write('2\n')
-            return
+        entries, total_bytes = repo.storefiles()
+    except (lock.LockHeld, lock.LockUnavailable), inst:
+        repo.ui.warn('locking the repository failed: %s\n' % (inst,))
+        fileobj.write('2\n')
+        return
 
-        fileobj.write('0\n')
-        repo.ui.debug('scanning\n')
-        entries = []
-        total_bytes = 0
-        for name, size in walkrepo(repo.spath):
-            name = repo.decodefn(util.pconvert(name))
-            entries.append((name, size))
-            total_bytes += size
-    finally:
-        del repolock
-
+    fileobj.write('0\n')
     repo.ui.debug('%d files, %d bytes to transfer\n' %
                   (len(entries), total_bytes))
     fileobj.write('%d %d\n' % (len(entries), total_bytes))