Mercurial > hgsubversion
annotate tests/test_rebuildmeta.py @ 650:685f91015ed6
replay: always fetch the entire first revision
The entire revision is fetched using the just-added get_revision()
wrapper.
Essentially, this allows us to begin a conversion with a non-zero
start revision. As an extra safety feature, this mode is *always* used
for the very first revision, even if no start revision is
specified. For most repositories, this shouldn't matter; the entire
revision will be fetched regardless. However, there are repositories
that currently `confuse' us, such as bzr-svn conversions, and where
this is an improvement.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Tue, 20 Jul 2010 11:55:07 +0200 |
parents | d2ef7220a079 |
children | dcac6dc1abe6 |
rev | line source |
---|---|
643
d2ef7220a079
tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
638
diff
changeset
|
1 import test_util |
d2ef7220a079
tests: import test_util as the first module in all relevant tests
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
638
diff
changeset
|
2 |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
3 import os |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 import pickle |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 import unittest |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
6 |
638
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
7 from mercurial import context |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
8 from mercurial import extensions |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
9 from mercurial import hg |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
10 from mercurial import ui |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
11 |
337
46e69be8e2c8
Reorganize to have a more conventional module structure.
Augie Fackler <durin42@gmail.com>
parents:
331
diff
changeset
|
12 from hgsubversion import svncommands |
416
cd6317fe70be
invert the svnmeta/editor relationship
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
414
diff
changeset
|
13 from hgsubversion import svnmeta |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
15 def _do_case(self, name, stupid, single): |
194
13ae1bded5e7
Add some comprehensive tests that can be run with nose in order to make it easier to verify stupid and real replay do the same thing.
Augie Fackler <durin42@gmail.com>
parents:
182
diff
changeset
|
16 subdir = test_util.subdir.get(name, '') |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
17 layout = 'auto' |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
18 if single: |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
19 layout = 'single' |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
20 self._load_fixture_and_fetch(name, subdir=subdir, stupid=stupid, layout=layout) |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
21 assert len(self.repo) > 0 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
22 wc2_path = self.wc_path + '_clone' |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
23 u = ui.ui() |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
24 src, dest = hg.clone(u, self.wc_path, wc2_path, update=False) |
638
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
25 |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
26 # insert a wrapper that prevents calling changectx.children() |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
27 def failfn(orig, ctx): |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
28 self.fail('calling %s is forbidden; it can cause massive slowdowns ' |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
29 'when rebuilding large repositories' % orig) |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
30 |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
31 origchildren = getattr(context.changectx, 'children') |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
32 extensions.wrapfunction(context.changectx, 'children', failfn) |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
33 |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
34 try: |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
35 svncommands.rebuildmeta(u, dest, |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
36 args=[test_util.fileurl(self.repo_path + |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
37 subdir), ]) |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
38 finally: |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
39 # remove the wrapper |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
40 context.changectx.children = origchildren |
ea0f42e0004d
tests: disallow calling changectx.children() during rebuildmeta
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
622
diff
changeset
|
41 |
331
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
42 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
43 'no .hg/svn directory in the source!') |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
44 self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
45 'no .hg/svn directory in the destination!') |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
46 dest = hg.repository(u, os.path.dirname(dest.path)) |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
47 for tf in ('rev_map', 'uuid', 'tagmap', 'layout', ): |
331
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
48 stf = os.path.join(src.path, 'svn', tf) |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
49 self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf) |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
50 dtf = os.path.join(dest.path, 'svn', tf) |
75f082b5897e
Switch to using url scheme wrappers instead of duplicating each command we wrap.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
246
diff
changeset
|
51 self.assertTrue(os.path.isfile(dtf), '%r is missing!' % tf) |
447
0d3b5acb1d51
tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents:
416
diff
changeset
|
52 old, new = open(stf).read(), open(dtf).read() |
622
25714b4954b7
test_rebuildmeta: use just added diff support when comparing files.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
573
diff
changeset
|
53 self.assertMultiLineEqual(old, new) |
447
0d3b5acb1d51
tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents:
416
diff
changeset
|
54 self.assertEqual(src.branchtags(), dest.branchtags()) |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
55 srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info'))) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
56 destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info'))) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
57 self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys())) |
416
cd6317fe70be
invert the svnmeta/editor relationship
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
414
diff
changeset
|
58 revkeys = svnmeta.SVNMeta(dest).revmap.keys() |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
59 for branch in destbi: |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
60 srcinfo = srcbi[branch] |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
61 destinfo = destbi[branch] |
447
0d3b5acb1d51
tags: handle edits to tags as gracefully as possible
Augie Fackler <durin42@gmail.com>
parents:
416
diff
changeset
|
62 if srcinfo[:2] == (None, 0) or destinfo[:2] == (None, 0): |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
63 self.assert_(srcinfo[2] <= destinfo[2]) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
64 self.assertEqual(srcinfo[0], destinfo[0]) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
65 else: |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
66 pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1], |
405
a98b8d424221
editor: simplify HgChangeReceiver constructor signature
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
383
diff
changeset
|
67 revkeys), reverse=True)[0][0] |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
68 self.assertEqual(pr, destinfo[1]) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
69 self.assertEqual(srcinfo[2], destinfo[2]) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
70 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
71 |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
72 def buildmethod(case, name, stupid, single): |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
73 m = lambda self: self._do_case(case, stupid, single) |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
74 m.__name__ = name |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
75 m.__doc__ = ('Test rebuildmeta on %s with %s replay. (%s)' % |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
76 (case, |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
77 (stupid and 'stupid') or 'real', |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
78 (single and 'single') or 'standard', |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
79 ) |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
80 ) |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
81 return m |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
82 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
83 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
84 attrs = {'_do_case': _do_case, |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
85 } |
182
47d25d61abfa
remove generators (compat with python2.3)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
155
diff
changeset
|
86 for case in [f for f in os.listdir(test_util.FIXTURES) if f.endswith('.svndump')]: |
347
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
337
diff
changeset
|
87 # this fixture results in an empty repository, don't use it |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
337
diff
changeset
|
88 if case == 'project_root_not_repo_root.svndump': |
537de0300510
Remove the 'outgoing' wrapper, and use the Mercurial infrastructure instead.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
337
diff
changeset
|
89 continue |
499
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
90 bname = 'test_' + case[:-len('.svndump')] |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
91 attrs[bname] = buildmethod(case, bname, False, False) |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
92 name = bname + '_stupid' |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
93 attrs[name] = buildmethod(case, name, True, False) |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
94 name = bname + '_single' |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
95 attrs[name] = buildmethod(case, name, False, True) |
1fd3cfa47c5e
Support for single-directory clones.
Augie Fackler <durin42@gmail.com>
parents:
474
diff
changeset
|
96 |
155
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
97 RebuildMetaTests = type('RebuildMetaTests', (test_util.TestBase, ), attrs) |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
98 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
99 |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
100 def suite(): |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
101 all = [unittest.TestLoader().loadTestsFromTestCase(RebuildMetaTests), |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
102 ] |
ba801f44d240
utility_commands: Implement rebuildmeta so that metadata can be rebuilt.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
103 return unittest.TestSuite(all) |