comparison tests/test_rebuildmeta.py @ 890:78db88de9622

Partial metadata rebuilding For highly active subversion repositories, it can be excruciatingly slow to pull updates one at a time from subversion. One way around this is to setup another mercurial repo that pulls new commits from svn periodicly (say every 5 minutes). When you want to update your repository, you can pull commits from this mercurial repository via native mercurial protocols, which will be much faster than pulling directly from svn. Unfortunately, your metadata will be out of date after doing so. Highly active repositories also tend to be very large, which means that it takes a long time to rebuild your metadata from scratch. To address this, this adds support to do a partial rebuild on the metadata by processing only revisions that have been added to the repository after the last revision we processed. With the rev map 1k revisions (~2 days) behind tip updatemeta is dramatically faster than rebuild meta: $ hg --time svn updatemeta Time: real 0.570 secs (user 0.480+0.000 sys 0.060+0.000) $ hg --time svn rebuildmeta Time: real 129.160 secs (user 128.570+0.000 sys 0.320+0.000)
author David Schleimer <dschleimer@fb.com>
date Sat, 12 May 2012 07:28:23 -0700
parents 50c13e01c7e3
children 295a8b48e4e2
comparison
equal deleted inserted replaced
889:7a98fbadcae9 890:78db88de9622
49 subdir), ]) 49 subdir), ])
50 finally: 50 finally:
51 # remove the wrapper 51 # remove the wrapper
52 context.changectx.children = origchildren 52 context.changectx.children = origchildren
53 53
54 self._run_assertions(name, stupid, single, src, dest, u)
55
56 wc3_path = self.wc_path + '_partial'
57 src, dest = test_util.hgclone(u,
58 self.wc_path,
59 wc3_path,
60 update=False,
61 rev=[0])
62
63 # insert a wrapper that prevents calling changectx.children()
64 extensions.wrapfunction(context.changectx, 'children', failfn)
65
66 try:
67 svncommands.rebuildmeta(u, dest,
68 args=[test_util.fileurl(repo_path +
69 subdir), ])
70 finally:
71 # remove the wrapper
72 context.changectx.children = origchildren
73
74 dest.pull(src)
75
76 # insert a wrapper that prevents calling changectx.children()
77 extensions.wrapfunction(context.changectx, 'children', failfn)
78 try:
79 svncommands.updatemeta(u, dest,
80 args=[test_util.fileurl(repo_path +
81 subdir), ])
82 finally:
83 # remove the wrapper
84 context.changectx.children = origchildren
85
86 self._run_assertions(name, stupid, single, src, dest, u)
87
88
89 def _run_assertions(self, name, stupid, single, src, dest, u):
90
54 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), 91 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
55 'no .hg/svn directory in the source!') 92 'no .hg/svn directory in the source!')
56 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), 93 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
57 'no .hg/svn directory in the destination!') 94 'no .hg/svn directory in the destination!')
58 dest = hg.repository(u, os.path.dirname(dest.path)) 95 dest = hg.repository(u, os.path.dirname(dest.path))
66 if tf == 'lastpulled' and (name, 103 if tf == 'lastpulled' and (name,
67 stupid, single) in expect_youngest_skew: 104 stupid, single) in expect_youngest_skew:
68 self.assertNotEqual(old, new, 105 self.assertNotEqual(old, new,
69 'rebuildmeta unexpected match on youngest rev!') 106 'rebuildmeta unexpected match on youngest rev!')
70 continue 107 continue
71 self.assertMultiLineEqual(old, new) 108 self.assertMultiLineEqual(old, new, tf + ' differs')
72 self.assertEqual(src.branchtags(), dest.branchtags()) 109 self.assertEqual(src.branchtags(), dest.branchtags())
73 srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info'))) 110 srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
74 destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info'))) 111 destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
75 self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys())) 112 self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
76 revkeys = svnmeta.SVNMeta(dest).revmap.keys() 113 revkeys = svnmeta.SVNMeta(dest).revmap.keys()
100 ) 137 )
101 return m 138 return m
102 139
103 140
104 attrs = {'_do_case': _do_case, 141 attrs = {'_do_case': _do_case,
142 '_run_assertions': _run_assertions,
105 } 143 }
106 for case in [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')]: 144 for case in [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')]:
107 # this fixture results in an empty repository, don't use it 145 # this fixture results in an empty repository, don't use it
108 if case == 'project_root_not_repo_root.svndump': 146 if case == 'project_root_not_repo_root.svndump':
109 continue 147 continue