changeset 436:404162e4bb53

editor: move find missing files routine into RevisionData class
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 16 Jun 2009 09:11:52 +0200
parents 7c576ae19d80
children 45ce07a4807f
files hgsubversion/editor.py hgsubversion/replay.py
diffstat 2 files changed, 36 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/editor.py
+++ b/hgsubversion/editor.py
@@ -77,6 +77,41 @@ class RevisionData(object):
         self.symlinks[path] = False
         self.ui.note('D %s\n' % path)
 
+    def findmissing(self, svn):
+
+        if not self.missing:
+            return
+
+        msg = 'fetching %s files that could not use replay.\n'
+        self.ui.debug(msg % len(self.missing))
+        root = svn.subdir and svn.subdir[1:] or ''
+        r = self.rev.revnum
+
+        files = set()
+        for p in self.missing:
+            self.ui.note('.')
+            self.ui.flush()
+            if p[-1] == '/':
+                dir = p[len(root):]
+                new = [dir + f for f, k in svn.list_files(dir, r) if k == 'f']
+                files.update(new)
+            else:
+                files.add(p[len(root):])
+
+        i = 1
+        self.ui.note('\nfetching files...\n')
+        for p in files:
+            self.ui.note('.')
+            self.ui.flush()
+            if i % 50 == 0:
+                svn.init_ra_and_client()
+            i += 1
+            data, mode = svn.get_file(p, r)
+            self.set(p, data, 'x' in mode, 'l' in mode)
+
+        self.missing = set()
+        self.ui.note('\n')
+
 
 class HgEditor(delta.Editor):
 
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -26,33 +26,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
     hg_editor.current.rev = r
     meta.save_tbdelta(tbdelta) # needed by get_replay()
     svn.get_replay(r.revnum, meta.editor)
-    i = 1
-    if hg_editor.current.missing:
-        meta.ui.debug('Fetching %s files that could not use replay.\n' %
-                      len(hg_editor.current.missing))
-        files_to_grab = set()
-        rootpath = svn.subdir and svn.subdir[1:] or ''
-        for p in hg_editor.current.missing:
-            meta.ui.note('.')
-            meta.ui.flush()
-            if p[-1] == '/':
-                dirpath = p[len(rootpath):]
-                files_to_grab.update([dirpath + f for f,k in
-                                      svn.list_files(dirpath, r.revnum)
-                                      if k == 'f'])
-            else:
-                files_to_grab.add(p[len(rootpath):])
-        meta.ui.note('\nFetching files...\n')
-        for p in files_to_grab:
-            meta.ui.note('.')
-            meta.ui.flush()
-            if i % 50 == 0:
-                svn.init_ra_and_client()
-            i += 1
-            data, mode = svn.get_file(p, r.revnum)
-            hg_editor.current.set(p, data, 'x' in mode, 'l' in mode)
-        hg_editor.current.missing = set()
-        meta.ui.note('\n')
+    hg_editor.current.findmissing(svn)
     _updateexternals(meta, hg_editor.current)
     return commit_current_delta(meta, tbdelta, hg_editor.current)