annotate tests/test_push_renames.py @ 70:49b7cbe4c8e3

push_cmd: handle copies at file level Mercurial store knows only file-level copies, directory copies are handle with heuristics. Implement the former one in svn backends.
author Patrick Mezard <pmezard@gmail.com>
date Wed, 05 Nov 2008 13:37:08 +0100
parents
children 072010a271c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
1 import os
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
2 import shutil
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
3 import sys
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
4 import tempfile
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
5 import unittest
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
6
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
7 from mercurial import context
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
8 from mercurial import commands
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
9 from mercurial import hg
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
10 from mercurial import node
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
11 from mercurial import ui
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
12 from mercurial import revlog
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
13
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
14 import fetch_command
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
15 import push_cmd
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
16 import test_util
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
17
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
18 class TestPushRenames(unittest.TestCase):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
19 def setUp(self):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
20 self.oldwd = os.getcwd()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
21 self.tmpdir = tempfile.mkdtemp('svnwrap_test')
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
22 self.repo_path = '%s/testrepo' % self.tmpdir
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
23 self.wc_path = '%s/testrepo_wc' % self.tmpdir
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
24 test_util.load_svndump_fixture(self.repo_path, 'pushrenames.svndump')
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
25 fetch_command.fetch_revisions(ui.ui(),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
26 svn_url='file://%s' % self.repo_path,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
27 hg_repo_path=self.wc_path)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
28
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
29 # define this as a property so that it reloads anytime we need it
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
30 @property
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
31 def repo(self):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
32 return hg.repository(ui.ui(), self.wc_path)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
33
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
34 def tearDown(self):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
35 shutil.rmtree(self.tmpdir)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
36 os.chdir(self.oldwd)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
37
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
38 def _commitchanges(self, repo, changes):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
39 parentctx = repo['tip']
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
40
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
41 changed, removed = [], []
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
42 for source, dest, newdata in changes:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
43 if dest is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
44 removed.append(source)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
45 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
46 changed.append(dest)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
47
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
48 def filectxfn(repo, memctx, path):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
49 if path in removed:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
50 raise IOError()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
51 entry = [e for e in changes if path == e[1]][0]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
52 source, dest, newdata = entry
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
53 if newdata is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
54 newdata = parentctx[source].data()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
55 copied = None
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
56 if source != dest:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
57 copied = source
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
58 return context.memfilectx(path=dest,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
59 data=newdata,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
60 islink=False,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
61 isexec=False,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
62 copied=copied)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
63
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
64 ctx = context.memctx(repo,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
65 (parentctx.node(), node.nullid),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
66 'automated test',
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
67 changed + removed,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
68 filectxfn,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
69 'an_author',
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
70 '2008-10-07 20:59:48 -0500')
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
71 return repo.commitctx(ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
72
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
73 def _debug_print_copies(self, ctx):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
74 w = sys.stderr.write
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
75 for f in ctx.files():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
76 if f not in ctx:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
77 w('R %s\n' % f)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
78 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
79 w('U %s %r\n' % (f, ctx[f].data()))
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
80 if ctx[f].renamed():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
81 w('%s copied from %s\n' % (f, ctx[f].renamed()[0]))
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
82
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
83 def assertchanges(self, changes, ctx):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
84 for source, dest, data in changes:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
85 if dest is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
86 self.assertTrue(source not in ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
87 else:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
88 self.assertTrue(dest in ctx)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
89 if data is None:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
90 data = ctx.parents()[0][source].data()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
91 self.assertEqual(data, ctx[dest].data())
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
92 if dest != source:
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
93 copy = ctx[dest].renamed()
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
94 self.assertEqual(copy[0], source)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
95
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
96 def test_push_renames(self, commit=True):
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
97 repo = self.repo
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
98
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
99 changes = [
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
100 # Regular copy of a single file
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
101 ('a', 'a2', None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
102 # Copy and update of target
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
103 ('a', 'a3', 'aa\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
104 # Regular move of a single file
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
105 ('b', 'b2', None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
106 ('b', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
107 # Regular move and update of target
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
108 ('c', 'c2', 'c\nc\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
109 ('c', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
110 # Copy and update of source and targets
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
111 ('d', 'd2', 'd\nd2\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
112 ('d', 'd', 'd\nd\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
113 # Double copy and removal (aka copy and move)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
114 ('e', 'e2', 'e\ne2\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
115 ('e', 'e3', 'e\ne3\n'),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
116 ('e', None, None),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
117 ]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
118 self._commitchanges(repo, changes)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
119
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
120 hg.update(repo, repo['tip'].node())
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
121 push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
122 hg_repo_path=self.wc_path,
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
123 svn_url='file://'+self.repo_path)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
124 tip = self.repo['tip']
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
125 # self._debug_print_copies(tip)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
126 self.assertchanges(changes, tip)
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
127
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
128 def suite():
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
129 all = [unittest.TestLoader().loadTestsFromTestCase(TestPushRenames),
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
130 ]
49b7cbe4c8e3 push_cmd: handle copies at file level
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
131 return unittest.TestSuite(all)