~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-06 22:55:29 UTC
  • mfrom: (1946.2.16 reduce-knit-churn)
  • Revision ID: pqm@pqm.ubuntu.com-20060906225529-7b367edabbb1ffc2
(jam) delay creating knit contents for significantly better new commit and push performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import difflib
21
21
 
22
22
 
23
 
from bzrlib.errors import KnitError, RevisionAlreadyPresent
 
23
from bzrlib.errors import KnitError, RevisionAlreadyPresent, NoSuchFile
24
24
from bzrlib.knit import (
25
25
    KnitVersionedFile,
26
26
    KnitPlainFactory,
36
36
class KnitTests(TestCaseWithTransport):
37
37
    """Class containing knit test helper routines."""
38
38
 
39
 
    def make_test_knit(self, annotate=False):
 
39
    def make_test_knit(self, annotate=False, delay_create=False):
40
40
        if not annotate:
41
41
            factory = KnitPlainFactory()
42
42
        else:
43
43
            factory = None
44
 
        return KnitVersionedFile('test', get_transport('.'), access_mode='w', factory=factory, create=True)
 
44
        return KnitVersionedFile('test', get_transport('.'), access_mode='w',
 
45
                                 factory=factory, create=True,
 
46
                                 delay_create=delay_create)
45
47
 
46
48
 
47
49
class BasicKnitTests(KnitTests):
312
314
        # this tests that a new knit index file has the expected content
313
315
        # and that is writes the data we expect as records are added.
314
316
        knit = self.make_test_knit(True)
 
317
        # Now knit files are not created until we first add data to them
315
318
        self.assertFileEqual("# bzr knit index 8\n", 'test.kndx')
316
319
        knit.add_lines_with_ghosts('revid', ['a_ghost'], ['a\n'])
317
320
        self.assertFileEqual(
342
345
        self.assertEqual(['revid', 'revid2', 'revid3'], knit.versions())
343
346
        self.assertEqual(['revid2'], knit.get_parents('revid3'))
344
347
 
 
348
    def test_delay_create(self):
 
349
        """Test that passing delay_create=True creates files late"""
 
350
        knit = self.make_test_knit(annotate=True, delay_create=True)
 
351
        self.failIfExists('test.knit')
 
352
        self.failIfExists('test.kndx')
 
353
        knit.add_lines_with_ghosts('revid', ['a_ghost'], ['a\n'])
 
354
        self.failUnlessExists('test.knit')
 
355
        self.assertFileEqual(
 
356
            "# bzr knit index 8\n"
 
357
            "\n"
 
358
            "revid fulltext 0 84 .a_ghost :",
 
359
            'test.kndx')
 
360
 
 
361
    def test_create_parent_dir(self):
 
362
        """create_parent_dir can create knits in nonexistant dirs"""
 
363
        # Has no effect if we don't set 'delay_create'
 
364
        trans = get_transport('.')
 
365
        self.assertRaises(NoSuchFile, KnitVersionedFile, 'dir/test',
 
366
                          trans, access_mode='w', factory=None,
 
367
                          create=True, create_parent_dir=True)
 
368
        # Nothing should have changed yet
 
369
        knit = KnitVersionedFile('dir/test', trans, access_mode='w',
 
370
                                 factory=None, create=True,
 
371
                                 create_parent_dir=True,
 
372
                                 delay_create=True)
 
373
        self.failIfExists('dir/test.knit')
 
374
        self.failIfExists('dir/test.kndx')
 
375
        self.failIfExists('dir')
 
376
        knit.add_lines('revid', [], ['a\n'])
 
377
        self.failUnlessExists('dir')
 
378
        self.failUnlessExists('dir/test.knit')
 
379
        self.assertFileEqual(
 
380
            "# bzr knit index 8\n"
 
381
            "\n"
 
382
            "revid fulltext 0 84  :",
 
383
            'dir/test.kndx')
 
384
 
 
385
    def test_create_mode_700(self):
 
386
        trans = get_transport('.')
 
387
        if not trans._can_roundtrip_unix_modebits():
 
388
            # Can't roundtrip, so no need to run this test
 
389
            return
 
390
        knit = KnitVersionedFile('dir/test', trans, access_mode='w',
 
391
                                 factory=None, create=True,
 
392
                                 create_parent_dir=True,
 
393
                                 delay_create=True,
 
394
                                 file_mode=0600,
 
395
                                 dir_mode=0700)
 
396
        knit.add_lines('revid', [], ['a\n'])
 
397
        self.assertTransportMode(trans, 'dir', 0700)
 
398
        self.assertTransportMode(trans, 'dir/test.knit', 0600)
 
399
        self.assertTransportMode(trans, 'dir/test.kndx', 0600)
 
400
 
 
401
    def test_create_mode_770(self):
 
402
        trans = get_transport('.')
 
403
        if not trans._can_roundtrip_unix_modebits():
 
404
            # Can't roundtrip, so no need to run this test
 
405
            return
 
406
        knit = KnitVersionedFile('dir/test', trans, access_mode='w',
 
407
                                 factory=None, create=True,
 
408
                                 create_parent_dir=True,
 
409
                                 delay_create=True,
 
410
                                 file_mode=0660,
 
411
                                 dir_mode=0770)
 
412
        knit.add_lines('revid', [], ['a\n'])
 
413
        self.assertTransportMode(trans, 'dir', 0770)
 
414
        self.assertTransportMode(trans, 'dir/test.knit', 0660)
 
415
        self.assertTransportMode(trans, 'dir/test.kndx', 0660)
 
416
 
 
417
    def test_create_mode_777(self):
 
418
        trans = get_transport('.')
 
419
        if not trans._can_roundtrip_unix_modebits():
 
420
            # Can't roundtrip, so no need to run this test
 
421
            return
 
422
        knit = KnitVersionedFile('dir/test', trans, access_mode='w',
 
423
                                 factory=None, create=True,
 
424
                                 create_parent_dir=True,
 
425
                                 delay_create=True,
 
426
                                 file_mode=0666,
 
427
                                 dir_mode=0777)
 
428
        knit.add_lines('revid', [], ['a\n'])
 
429
        self.assertTransportMode(trans, 'dir', 0777)
 
430
        self.assertTransportMode(trans, 'dir/test.knit', 0666)
 
431
        self.assertTransportMode(trans, 'dir/test.kndx', 0666)
 
432
 
345
433
    def test_plan_merge(self):
346
434
        my_knit = self.make_test_knit(annotate=True)
347
435
        my_knit.add_lines('text1', [], split_lines(TEXT_1))