~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionnamespaces.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-04 18:59:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070504185936-1mjdoqmtz74xe5mg
A C implementation of _fields_to_entry_0_parents drops the time from 400ms to 330ms for a 21k-entry tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    errors,
25
25
    repository,
26
26
    )
 
27
from bzrlib.builtins import merge
27
28
from bzrlib.tests import TestCase, TestCaseWithTransport
28
29
from bzrlib.revisionspec import (
29
30
    RevisionSpec,
49
50
 
50
51
        self.tree = self.make_branch_and_tree('tree')
51
52
        self.build_tree(['tree/a'])
52
 
        self.tree.lock_write()
53
 
        self.addCleanup(self.tree.unlock)
54
53
        self.tree.add(['a'])
55
54
        self.tree.commit('a', rev_id='r1')
56
55
 
57
56
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
58
57
        self.tree2.commit('alt', rev_id='alt_r2')
59
58
 
60
 
        self.tree.merge_from_branch(self.tree2.branch)
 
59
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
 
60
                                          revision_id='alt_r2')
 
61
        self.tree.set_pending_merges(['alt_r2'])
61
62
        self.tree.commit('second', rev_id='r2')
62
63
 
63
64
    def get_in_history(self, revision_spec):
83
84
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
85
                      % (revision_spec,))
85
86
 
86
 
    def assertAsRevisionId(self, revision_id, revision_spec):
87
 
        """Calling as_revision_id() should return the specified id."""
88
 
        spec = RevisionSpec.from_string(revision_spec)
89
 
        self.assertEqual(revision_id,
90
 
                         spec.as_revision_id(self.tree.branch))
91
 
 
92
87
 
93
88
class TestOddRevisionSpec(TestRevisionSpec):
94
89
    """Test things that aren't normally thought of as revision specs"""
95
90
 
96
91
    def test_none(self):
97
 
        self.assertInHistoryIs(None, None, None)
 
92
        self.assertInHistoryIs(0, None, None)
98
93
 
99
94
    def test_object(self):
100
95
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
122
117
class TestRevisionSpec_revno(TestRevisionSpec):
123
118
 
124
119
    def test_positive_int(self):
125
 
        self.assertInHistoryIs(0, 'null:', '0')
 
120
        self.assertInHistoryIs(0, None, '0')
126
121
        self.assertInHistoryIs(1, 'r1', '1')
127
122
        self.assertInHistoryIs(2, 'r2', '2')
128
123
        self.assertInvalid('3')
139
134
        self.assertInHistoryIs(1, 'r1', '-100')
140
135
 
141
136
    def test_positive(self):
142
 
        self.assertInHistoryIs(0, 'null:', 'revno:0')
 
137
        self.assertInHistoryIs(0, None, 'revno:0')
143
138
        self.assertInHistoryIs(1, 'r1', 'revno:1')
144
139
        self.assertInHistoryIs(2, 'r2', 'revno:2')
145
140
 
252
247
        self.assertEqual((2, 'b@r-0-2'),
253
248
                         spec_in_history('revno:2:b/', None))
254
249
 
255
 
    def test_as_revision_id(self):
256
 
        self.assertAsRevisionId('null:', '0')
257
 
        self.assertAsRevisionId('r1', '1')
258
 
        self.assertAsRevisionId('r2', '2')
259
 
        self.assertAsRevisionId('r1', '-2')
260
 
        self.assertAsRevisionId('r2', '-1')
261
 
        self.assertAsRevisionId('alt_r2', '1.1.1')
262
250
 
263
251
 
264
252
class TestRevisionSpec_revid(TestRevisionSpec):
296
284
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
297
285
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
298
286
 
299
 
    def test_as_revision_id(self):
300
 
        self.assertAsRevisionId('r1', 'revid:r1')
301
 
        self.assertAsRevisionId('r2', 'revid:r2')
302
 
        self.assertAsRevisionId('alt_r2', 'revid:alt_r2')
303
 
 
304
287
 
305
288
class TestRevisionSpec_last(TestRevisionSpec):
306
289
 
307
290
    def test_positive(self):
308
291
        self.assertInHistoryIs(2, 'r2', 'last:1')
309
292
        self.assertInHistoryIs(1, 'r1', 'last:2')
310
 
        self.assertInHistoryIs(0, 'null:', 'last:3')
 
293
        self.assertInHistoryIs(0, None, 'last:3')
311
294
 
312
295
    def test_empty(self):
313
296
        self.assertInHistoryIs(2, 'r2', 'last:')
332
315
            pass
333
316
        self.assertInvalid('last:Y', extra='\n' + str(e))
334
317
 
335
 
    def test_as_revision_id(self):
336
 
        self.assertAsRevisionId('r2', 'last:1')
337
 
        self.assertAsRevisionId('r1', 'last:2')
338
 
 
339
318
 
340
319
class TestRevisionSpec_before(TestRevisionSpec):
341
320
 
344
323
        self.assertInHistoryIs(1, 'r1', 'before:-1')
345
324
 
346
325
    def test_before_one(self):
347
 
        self.assertInHistoryIs(0, 'null:', 'before:1')
 
326
        self.assertInHistoryIs(0, None, 'before:1')
348
327
 
349
328
    def test_before_none(self):
350
329
        self.assertInvalid('before:0',
365
344
        new_tree.commit('first', rev_id='new_r1')
366
345
        self.tree.branch.repository.fetch(new_tree.branch.repository,
367
346
                                          revision_id='new_r1')
368
 
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
369
 
 
370
 
    def test_as_revision_id(self):
371
 
        self.assertAsRevisionId('r1', 'before:revid:r2')
372
 
        self.assertAsRevisionId('r1', 'before:2')
373
 
        self.assertAsRevisionId('r1', 'before:1.1.1')
374
 
        self.assertAsRevisionId('r1', 'before:revid:alt_r2')
 
347
        self.assertInHistoryIs(0, None, 'before:revid:new_r1')
375
348
 
376
349
 
377
350
class TestRevisionSpec_tag(TestRevisionSpec):
378
351
    
379
352
    def make_branch_and_tree(self, relpath):
380
353
        # override format as the default one may not support tags
381
 
        return TestRevisionSpec.make_branch_and_tree(
382
 
            self, relpath, format='dirstate-tags')
 
354
        control = bzrdir.BzrDir.create(relpath)
 
355
        control.create_repository()
 
356
        branch.BzrBranchExperimental.initialize(control)
 
357
        return control.create_workingtree()
383
358
 
384
359
    def test_from_string_tag(self):
385
360
        spec = RevisionSpec.from_string('tag:bzr-0.14')
389
364
    def test_lookup_tag(self):
390
365
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
391
366
        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
392
 
        self.tree.branch.tags.set_tag('null_rev', 'null:')
393
 
        self.assertInHistoryIs(0, 'null:', 'tag:null_rev')
394
367
 
395
368
    def test_failed_lookup(self):
396
369
        # tags that don't exist give a specific message: arguably we should
399
372
            self.get_in_history,
400
373
            'tag:some-random-tag')
401
374
 
402
 
    def test_as_revision_id(self):
403
 
        self.tree.branch.tags.set_tag('my-tag', 'r2')
404
 
        self.tree.branch.tags.set_tag('null_rev', 'null:')
405
 
        self.assertAsRevisionId('r2', 'tag:my-tag')
406
 
        self.assertAsRevisionId('null:', 'tag:null_rev')
407
 
        self.assertAsRevisionId('r1', 'before:tag:my-tag')
408
 
 
409
375
 
410
376
class TestRevisionSpec_date(TestRevisionSpec):
411
377
 
442
408
        self.assertInHistoryIs(2, 'new_r2',
443
409
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
444
410
 
445
 
    def test_as_revision_id(self):
446
 
        self.assertAsRevisionId('new_r2', 'date:today')
447
 
 
448
411
 
449
412
class TestRevisionSpec_ancestor(TestRevisionSpec):
450
413
    
488
451
                          spec_in_history, 'ancestor:tree',
489
452
                                           new_tree.branch)
490
453
 
491
 
    def test_as_revision_id(self):
492
 
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
493
 
 
494
454
 
495
455
class TestRevisionSpec_branch(TestRevisionSpec):
496
456
    
525
485
        self.assertRaises(errors.NoCommits,
526
486
                          self.get_in_history, 'branch:new_tree')
527
487
 
528
 
    def test_as_revision_id(self):
529
 
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
530
 
 
531
488
 
532
489
class TestRevisionSpec_submit(TestRevisionSpec):
533
490
 
543
500
        # submit branch overrides parent branch
544
501
        self.tree.branch.set_submit_branch('tree2')
545
502
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
546
 
 
547
 
    def test_as_revision_id(self):
548
 
        self.tree.branch.set_submit_branch('tree2')
549
 
        self.assertAsRevisionId('alt_r2', 'branch:tree2')