Mercurial > hgsubversion
comparison tests/test_updatemeta.py @ 922:6b7ac659c855
updatemeta: correctly handle empty metadata
When the repo metadata is empty (just created/cloned but not populated yet),
there is no lastpulled file or the revmap doesn't have a last entry with hash.
Currently "hg svn updatemeta" would crash due to unexpected exception.
See issue reported at https://bitbucket.org/durin42/hgsubversion/issue/356/updatemeta-crashes-with-traceback-if-there
The fix is to check the existence of lastpulled file and the hash entry in
revmap, as part of "hg svn updatemeta" command. When they are not present,
do a rebuildmetadata.
Also added a new unit test, test_updatemeta.py.
author | Jun Fang <junfang@fb.com> |
---|---|
date | Mon, 06 Aug 2012 10:35:51 -0700 |
parents | |
children | 5bacb9c63e3e |
comparison
equal
deleted
inserted
replaced
921:8faa91951bb1 | 922:6b7ac659c855 |
---|---|
1 import test_util | |
2 | |
3 import os | |
4 import pickle | |
5 import unittest | |
6 import test_rebuildmeta | |
7 | |
8 from mercurial import context | |
9 from mercurial import extensions | |
10 from mercurial import hg | |
11 from mercurial import ui | |
12 | |
13 from hgsubversion import svncommands | |
14 from hgsubversion import svnmeta | |
15 | |
16 | |
17 | |
18 def _do_case(self, name, stupid, single): | |
19 subdir = test_util.subdir.get(name, '') | |
20 layout = 'auto' | |
21 if single: | |
22 layout = 'single' | |
23 repo, repo_path = self.load_and_fetch(name, subdir=subdir, stupid=stupid, | |
24 layout=layout) | |
25 assert len(self.repo) > 0 | |
26 wc2_path = self.wc_path + '_clone' | |
27 u = ui.ui() | |
28 src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) | |
29 src = getattr(src, 'local', lambda: src)() | |
30 dest = getattr(dest, 'local', lambda: dest)() | |
31 | |
32 # insert a wrapper that prevents calling changectx.children() | |
33 def failfn(orig, ctx): | |
34 self.fail('calling %s is forbidden; it can cause massive slowdowns ' | |
35 'when rebuilding large repositories' % orig) | |
36 | |
37 origchildren = getattr(context.changectx, 'children') | |
38 extensions.wrapfunction(context.changectx, 'children', failfn) | |
39 | |
40 # test updatemeta on an empty repo | |
41 try: | |
42 svncommands.updatemeta(u, dest, | |
43 args=[test_util.fileurl(repo_path + | |
44 subdir), ]) | |
45 finally: | |
46 # remove the wrapper | |
47 context.changectx.children = origchildren | |
48 | |
49 self._run_assertions(name, stupid, single, src, dest, u) | |
50 | |
51 | |
52 def _run_assertions(self, name, stupid, single, src, dest, u): | |
53 test_rebuildmeta._run_assertions(self, name, stupid, single, src, dest, u) | |
54 | |
55 | |
56 skip = set([ | |
57 'project_root_not_repo_root.svndump', | |
58 'corrupt.svndump', | |
59 ]) | |
60 | |
61 attrs = {'_do_case': _do_case, | |
62 '_run_assertions': _run_assertions, | |
63 } | |
64 for case in [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')]: | |
65 # this fixture results in an empty repository, don't use it | |
66 if case in skip: | |
67 continue | |
68 bname = 'test_' + case[:-len('.svndump')] | |
69 attrs[bname] = test_rebuildmeta.buildmethod(case, bname, False, False) | |
70 name = bname + '_stupid' | |
71 attrs[name] = test_rebuildmeta.buildmethod(case, name, True, False) | |
72 name = bname + '_single' | |
73 attrs[name] = test_rebuildmeta.buildmethod(case, name, False, True) | |
74 | |
75 UpdateMetaTests = type('UpdateMetaTests', (test_util.TestBase,), attrs) | |
76 | |
77 | |
78 def suite(): | |
79 all_tests = [unittest.TestLoader().loadTestsFromTestCase(UpdateMetaTests), | |
80 ] | |
81 return unittest.TestSuite(all_tests) |