changeset 897:6bc8046e3d0a

move verify to a file of its own
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Sun, 13 May 2012 15:36:45 +0200
parents 04dfc23688b9
children 6524260be543
files hgsubversion/svncommands.py hgsubversion/verify.py tests/comprehensive/test_verify_and_startrev.py tests/test_fetch_mappings.py tests/test_utility_commands.py
diffstat 5 files changed, 88 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svncommands.py
+++ b/hgsubversion/svncommands.py
@@ -16,77 +16,9 @@ import svnwrap
 import svnrepo
 import util
 import svnexternals
+import verify
 
 
-def verify(ui, repo, args=None, **opts):
-    '''verify current revision against Subversion repository
-    '''
-
-    if repo is None:
-        raise error.RepoError("There is no Mercurial repository"
-                              " here (.hg not found)")
-
-    ctx = repo[opts.get('rev', '.')]
-    if 'close' in ctx.extra():
-        ui.write('cannot verify closed branch')
-        return 0
-    convert_revision = ctx.extra().get('convert_revision')
-    if convert_revision is None or not convert_revision.startswith('svn:'):
-        raise hgutil.Abort('revision %s not from SVN' % ctx)
-
-    if args:
-        url = repo.ui.expandpath(args[0])
-    else:
-        url = repo.ui.expandpath('default')
-
-    svn = svnrepo.svnremoterepo(ui, url).svn
-    meta = repo.svnmeta(svn.uuid, svn.subdir)
-    srev, branch, branchpath = meta.get_source_rev(ctx=ctx)
-
-    branchpath = branchpath[len(svn.subdir.lstrip('/')):]
-    branchurl = ('%s/%s' % (url, branchpath)).strip('/')
-
-    ui.write('verifying %s against %s@%i\n' % (ctx, branchurl, srev))
-
-    svnfiles = set()
-    result = 0
-
-    svndata = svn.list_files(branchpath, srev)
-    for i, (fn, type) in enumerate(svndata):
-        util.progress(ui, 'verify', i)
-        if type != 'f':
-            continue
-        svnfiles.add(fn)
-        fp = fn
-        if branchpath:
-            fp = branchpath + '/' + fn
-        data, mode = svn.get_file(posixpath.normpath(fp), srev)
-        try:
-            fctx = ctx[fn]
-        except error.LookupError:
-            result = 1
-            continue
-        if not fctx.data() == data:
-            ui.write('difference in: %s\n' % fn)
-            result = 1
-        if not fctx.flags() == mode:
-            ui.write('wrong flags for: %s\n' % fn)
-            result = 1
-
-    hgfiles = set(ctx) - util.ignoredfiles
-    if hgfiles != svnfiles:
-        unexpected = hgfiles - svnfiles
-        for f in sorted(unexpected):
-            ui.write('unexpected file: %s\n' % f)
-        missing = svnfiles - hgfiles
-        for f in sorted(missing):
-            ui.write('missing file: %s\n' % f)
-        result = 1
-
-    util.progress(ui, 'verify', None)
-
-    return result
-
 def updatemeta(ui, repo, args, **opts):
     """Do a partial rebuild of the subversion metadata.
 
@@ -563,6 +495,6 @@ table = {
     'updatemeta': updatemeta,
     'rebuildmeta': rebuildmeta,
     'updateexternals': svnexternals.updateexternals,
-    'verify': verify,
+    'verify': verify.verify,
 }
 svn.__doc__ = _helpgen()
new file mode 100644
--- /dev/null
+++ b/hgsubversion/verify.py
@@ -0,0 +1,75 @@
+import posixpath
+
+from mercurial import error
+
+import svnrepo
+import util
+
+def verify(ui, repo, args=None, **opts):
+    '''verify current revision against Subversion repository
+    '''
+
+    if repo is None:
+        raise error.RepoError("There is no Mercurial repository"
+                              " here (.hg not found)")
+
+    ctx = repo[opts.get('rev', '.')]
+    if 'close' in ctx.extra():
+        ui.write('cannot verify closed branch')
+        return 0
+    convert_revision = ctx.extra().get('convert_revision')
+    if convert_revision is None or not convert_revision.startswith('svn:'):
+        raise hgutil.Abort('revision %s not from SVN' % ctx)
+
+    if args:
+        url = repo.ui.expandpath(args[0])
+    else:
+        url = repo.ui.expandpath('default')
+
+    svn = svnrepo.svnremoterepo(ui, url).svn
+    meta = repo.svnmeta(svn.uuid, svn.subdir)
+    srev, branch, branchpath = meta.get_source_rev(ctx=ctx)
+
+    branchpath = branchpath[len(svn.subdir.lstrip('/')):]
+    branchurl = ('%s/%s' % (url, branchpath)).strip('/')
+
+    ui.write('verifying %s against %s@%i\n' % (ctx, branchurl, srev))
+
+    svnfiles = set()
+    result = 0
+
+    svndata = svn.list_files(branchpath, srev)
+    for i, (fn, type) in enumerate(svndata):
+        util.progress(ui, 'verify', i)
+        if type != 'f':
+            continue
+        svnfiles.add(fn)
+        fp = fn
+        if branchpath:
+            fp = branchpath + '/' + fn
+        data, mode = svn.get_file(posixpath.normpath(fp), srev)
+        try:
+            fctx = ctx[fn]
+        except error.LookupError:
+            result = 1
+            continue
+        if not fctx.data() == data:
+            ui.write('difference in: %s\n' % fn)
+            result = 1
+        if not fctx.flags() == mode:
+            ui.write('wrong flags for: %s\n' % fn)
+            result = 1
+
+    hgfiles = set(ctx) - util.ignoredfiles
+    if hgfiles != svnfiles:
+        unexpected = hgfiles - svnfiles
+        for f in sorted(unexpected):
+            ui.write('unexpected file: %s\n' % f)
+        missing = svnfiles - hgfiles
+        for f in sorted(missing):
+            ui.write('missing file: %s\n' % f)
+        result = 1
+
+    util.progress(ui, 'verify', None)
+
+    return result
--- a/tests/comprehensive/test_verify_and_startrev.py
+++ b/tests/comprehensive/test_verify_and_startrev.py
@@ -14,7 +14,7 @@ except ImportError:
 from mercurial import hg
 from mercurial import ui
 
-from hgsubversion import svncommands
+from hgsubversion import verify
 
 # these fixtures contain no files at HEAD and would result in empty clones
 _skipshallow = set([
@@ -42,7 +42,7 @@ def _do_case(self, name, stupid, layout)
     assert len(self.repo) > 0
     for i in repo:
         ctx = repo[i]
-        self.assertEqual(svncommands.verify(repo.ui, repo, rev=ctx.node()), 0)
+        self.assertEqual(verify.verify(repo.ui, repo, rev=ctx.node()), 0)
 
     # check a startrev clone
     if layout == 'single' and name not in _skipshallow:
@@ -58,8 +58,8 @@ def _do_case(self, name, stupid, layout)
         shallowtip = shallowrepo['tip']
 
         repo.ui.pushbuffer()
-        self.assertEqual(0, svncommands.verify(repo.ui, shallowrepo,
-                                               rev=shallowtip.node()))
+        self.assertEqual(0, verify.verify(repo.ui, shallowrepo,
+                                          rev=shallowtip.node()))
 
         # viewing diff's of lists of files is easier on the eyes
         self.assertMultiLineEqual('\n'.join(fulltip), '\n'.join(shallowtip),
--- a/tests/test_fetch_mappings.py
+++ b/tests/test_fetch_mappings.py
@@ -12,6 +12,7 @@ from mercurial import util as hgutil
 
 from hgsubversion import maps
 from hgsubversion import svncommands
+from hgsubversion import verify
 from hgsubversion import util
 
 class MapTests(test_util.TestBase):
@@ -270,7 +271,7 @@ class MapTests(test_util.TestBase):
         repo = self.repo
 
         for r in repo:
-            self.assertEquals(svncommands.verify(ui, repo, rev=r), 0)
+            self.assertEquals(verify.verify(ui, repo, rev=r), 0)
 
     def test_branchmap_verify_stupid(self):
         '''test verify on a branchmapped clone (stupid)'''
--- a/tests/test_utility_commands.py
+++ b/tests/test_utility_commands.py
@@ -14,6 +14,7 @@ from mercurial import util as hgutil
 
 from hgsubversion import util
 from hgsubversion import svncommands
+from hgsubversion import verify
 from hgsubversion import wrappers
 
 expected_info_output = '''URL: %(repourl)s/%(branch)s
@@ -248,13 +249,12 @@ class UtilityTests(test_util.TestBase):
     def test_svnverify(self):
         repo, repo_path = self.load_and_fetch('binaryfiles.svndump',
                                               noupdate=False)
-        ret = svncommands.verify(self.ui(), repo, [], rev=1)
+        ret = verify.verify(self.ui(), repo, [], rev=1)
         self.assertEqual(0, ret)
         repo_path = self.load_svndump('binaryfiles-broken.svndump')
         u = self.ui()
         u.pushbuffer()
-        ret = svncommands.verify(u, repo, [test_util.fileurl(repo_path)],
-                                 rev=1)
+        ret = verify.verify(u, repo, [test_util.fileurl(repo_path)], rev=1)
         output = u.popbuffer()
         self.assertEqual(1, ret)
         output = re.sub(r'file://\S+', 'file://', output)
@@ -274,14 +274,14 @@ missing file: binary3
 
         ui = self.ui()
 
-        self.assertEqual(SUCCESS, svncommands.verify(ui, self.repo, rev='tip'))
+        self.assertEqual(SUCCESS, verify.verify(ui, self.repo, rev='tip'))
 
         corrupt_source = test_util.fileurl(self.load_svndump('corrupt.svndump'))
 
         repo.ui.setconfig('paths', 'default', corrupt_source)
 
         ui.pushbuffer()
-        code = svncommands.verify(ui, repo, rev='tip')
+        code = verify.verify(ui, repo, rev='tip')
         actual = ui.popbuffer()
 
         actual = actual.replace(corrupt_source, '$REPO')