14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib.selftest import TestCaseInTempDir, TestCase
17
from bzrlib.selftest import TestCaseInTempDir
18
from bzrlib.revision import is_ancestor, MultipleRevisionSources
19
from bzrlib.revision import combined_graph
20
21
def make_branches():
21
22
from bzrlib.branch import Branch
22
23
from bzrlib.commit import commit
24
25
os.mkdir("branch1")
25
br1 = Branch("branch1", init=True)
26
br1 = Branch.initialize("branch1")
27
28
commit(br1, "Commit one", rev_id="a@u-0-0")
28
29
commit(br1, "Commit two", rev_id="a@u-0-1")
29
30
commit(br1, "Commit three", rev_id="a@u-0-2")
31
32
os.mkdir("branch2")
32
br2 = Branch("branch2", init=True)
33
br2 = Branch.initialize("branch2")
33
34
br2.update_revisions(br1)
34
35
commit(br2, "Commit four", rev_id="b@u-0-3")
35
36
commit(br2, "Commit five", rev_id="b@u-0-4")
128
128
self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10',
129
129
'c@u-0-6', self.br2.revision_history())
131
class TestIntermediateRevisions(TestCaseInTempDir):
134
from bzrlib.commit import commit
135
TestCaseInTempDir.setUp(self)
136
self.br1, self.br2 = make_branches()
137
commit(self.br2, "Commit eleven", rev_id="b@u-0-7")
138
commit(self.br2, "Commit twelve", rev_id="b@u-0-8")
139
commit(self.br2, "Commit thirtteen", rev_id="b@u-0-9")
140
self.br1.add_pending_merge(self.br2.revision_history()[6])
141
commit(self.br1, "Commit fourtten", rev_id="a@u-0-6")
142
self.br2.add_pending_merge(self.br1.revision_history()[6])
143
commit(self.br2, "Commit fifteen", rev_id="b@u-0-10")
145
from bzrlib.revision import MultipleRevisionSources
146
self.sources = MultipleRevisionSources(self.br1, self.br2)
148
def intervene(self, ancestor, revision, revision_history=None):
149
from bzrlib.revision import get_intervening_revisions
150
return get_intervening_revisions(ancestor,revision, self.sources,
153
def test_intervene(self):
154
"""Find intermediate revisions, without requiring history"""
155
from bzrlib.errors import NotAncestor, NoSuchRevision
156
assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
157
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
158
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'),
159
['a@u-0-1', 'a@u-0-2'])
160
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-3'),
161
['a@u-0-1', 'a@u-0-2', 'b@u-0-3'])
162
self.assertEqual(self.intervene('b@u-0-3', 'a@u-0-3'),
163
['b@u-0-4', 'a@u-0-3'])
164
self.assertEqual(self.intervene('a@u-0-2', 'a@u-0-3',
165
self.br1.revision_history()),
167
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-5',
168
self.br1.revision_history()),
169
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
171
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6',
172
self.br1.revision_history()),
173
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
175
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'),
176
['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
178
self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6',
179
self.br2.revision_history()),
180
['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
181
self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10'),
182
['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
183
self.assertEqual(self.intervene('b@u-0-6', 'b@u-0-10',
184
self.br2.revision_history()),
185
['b@u-0-7', 'b@u-0-8', 'b@u-0-9', 'b@u-0-10'])
186
self.assertRaises(NotAncestor, self.intervene, 'b@u-0-10', 'b@u-0-6',
187
self.br2.revision_history())
188
self.assertRaises(NoSuchRevision, self.intervene, 'c@u-0-10',
189
'b@u-0-6', self.br2.revision_history())
190
self.assertRaises(NoSuchRevision, self.intervene, 'b@u-0-10',
191
'c@u-0-6', self.br2.revision_history())
194
132
class TestCommonAncestor(TestCaseInTempDir):
195
133
"""Test checking whether a revision is an ancestor of another revision"""
270
210
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
274
class TestCreateSignedRevision(TestCaseInTempDir):
276
def test_create_signed_revision(self):
278
# create a revision, sign it, apply to the store.
282
class TestOperators(TestCase):
284
def test___eq__(self):
285
from bzrlib.revision import Revision, RevisionReference
286
revision1 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
287
revision2 = Revision("invid", "sha", "revid", 100, "boo", "john", [])
288
revision3 = Revision("invid", "sha", "rev2id", 100, "bp", "john",
289
[RevisionReference("revid")])
290
self.assertEqual(revision1, revision1)
291
self.assertEqual(revision1, revision2)
292
self.assertNotEqual(revision1, revision3)
293
self.assertEqual(revision2, revision1)
294
self.assertEqual(revision2, revision2)
295
self.assertNotEqual(revision2, revision3)
296
self.assertNotEqual(revision3, revision1)
297
self.assertNotEqual(revision3, revision2)
298
self.assertEqual(revision3, revision3)
300
def test__eq__reference(self):
301
from bzrlib.revision import Revision, RevisionReference
302
ref1 = RevisionReference('revid', '1'*40)
303
ref2 = RevisionReference('revid', '1'*40)
304
ref3 = RevisionReference('revid', '2'*40)
305
ref4 = RevisionReference('revid2', '3'*40)
306
self.assertEqual(ref1, ref1)
307
self.assertEqual(ref1, ref2)
308
self.assertNotEqual(ref1, ref3)
309
self.assertNotEqual(ref1, ref4)
310
self.assertEqual(ref2, ref1)
311
self.assertEqual(ref2, ref2)
312
self.assertNotEqual(ref2, ref3)
313
self.assertNotEqual(ref2, ref4)
314
self.assertNotEqual(ref3, ref1)
315
self.assertNotEqual(ref3, ref2)
316
self.assertEqual(ref3, ref3)
317
self.assertNotEqual(ref3, ref4)
318
self.assertNotEqual(ref4, ref1)
319
self.assertNotEqual(ref4, ref2)
320
self.assertNotEqual(ref4, ref3)
321
self.assertEqual(ref4, ref4)
213
def test_combined(self):
215
Ensure it's not order-sensitive
217
br1, br2 = make_branches()
218
source = MultipleRevisionSources(br1, br2)
219
combined_1 = combined_graph(br1.last_patch(), br2.last_patch(), source)
220
combined_2 = combined_graph(br2.last_patch(), br1.last_patch(), source)
221
assert combined_1[1] == combined_2[1]
222
assert combined_1[2] == combined_2[2]
223
assert combined_1[3] == combined_2[3]
224
assert combined_1 == combined_2