/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: John Arbash Meinel
  • Date: 2011-01-25 22:54:08 UTC
  • mto: This revision was merged to the branch mainline in revision 5636.
  • Revision ID: john@arbash-meinel.com-20110125225408-w5b5mmh117q4jjz1
Implement a reset-to-known-state ability for DirState.

Use this in reset_state(). Allow it to use header information if it can
be parsed, otherwise allow us to pass in the information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Tests for Knit data structure"""
18
18
 
19
19
from cStringIO import StringIO
20
 
import difflib
21
20
import gzip
22
21
import sys
23
22
 
24
23
from bzrlib import (
25
24
    errors,
26
 
    generate_ids,
27
25
    knit,
28
26
    multiparent,
29
27
    osutils,
30
28
    pack,
31
29
    tests,
 
30
    transport,
32
31
    )
33
32
from bzrlib.errors import (
34
 
    RevisionAlreadyPresent,
35
33
    KnitHeaderError,
36
 
    RevisionNotPresent,
37
34
    NoSuchFile,
38
35
    )
39
36
from bzrlib.index import *
40
37
from bzrlib.knit import (
41
38
    AnnotatedKnitContent,
42
39
    KnitContent,
43
 
    KnitSequenceMatcher,
44
40
    KnitVersionedFiles,
45
41
    PlainKnitContent,
46
42
    _VFContentMapGenerator,
50
46
    _KnitKeyAccess,
51
47
    make_file_factory,
52
48
    )
 
49
from bzrlib.patiencediff import PatienceSequenceMatcher
53
50
from bzrlib.repofmt import pack_repo
54
51
from bzrlib.tests import (
55
 
    Feature,
56
 
    KnownFailure,
57
52
    TestCase,
58
53
    TestCaseWithMemoryTransport,
59
54
    TestCaseWithTransport,
60
55
    TestNotApplicable,
61
56
    )
62
 
from bzrlib.transport import get_transport
63
 
from bzrlib.transport.memory import MemoryTransport
64
 
from bzrlib.tuned_gzip import GzipFile
65
57
from bzrlib.versionedfile import (
66
58
    AbsentContentFactory,
67
59
    ConstantMapper,
106
98
        line_delta = source_content.line_delta(target_content)
107
99
        delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
108
100
            source_lines, target_lines))
109
 
        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
110
 
        matcher_blocks = list(list(matcher.get_matching_blocks()))
 
101
        matcher = PatienceSequenceMatcher(None, source_lines, target_lines)
 
102
        matcher_blocks = list(matcher.get_matching_blocks())
111
103
        self.assertEqual(matcher_blocks, delta_blocks)
112
104
 
113
105
    def test_get_line_delta_blocks(self):
346
338
        writer.end()
347
339
        return memos
348
340
 
 
341
    def test_pack_collection_pack_retries(self):
 
342
        """An explicit pack of a pack collection succeeds even when a
 
343
        concurrent pack happens.
 
344
        """
 
345
        builder = self.make_branch_builder('.')
 
346
        builder.start_series()
 
347
        builder.build_snapshot('rev-1', None, [
 
348
            ('add', ('', 'root-id', 'directory', None)),
 
349
            ('add', ('file', 'file-id', 'file', 'content\nrev 1\n')),
 
350
            ])
 
351
        builder.build_snapshot('rev-2', ['rev-1'], [
 
352
            ('modify', ('file-id', 'content\nrev 2\n')),
 
353
            ])
 
354
        builder.build_snapshot('rev-3', ['rev-2'], [
 
355
            ('modify', ('file-id', 'content\nrev 3\n')),
 
356
            ])
 
357
        self.addCleanup(builder.finish_series)
 
358
        b = builder.get_branch()
 
359
        self.addCleanup(b.lock_write().unlock)
 
360
        repo = b.repository
 
361
        collection = repo._pack_collection
 
362
        # Concurrently repack the repo.
 
363
        reopened_repo = repo.bzrdir.open_repository()
 
364
        reopened_repo.pack()
 
365
        # Pack the new pack.
 
366
        collection.pack()
 
367
 
349
368
    def make_vf_for_retrying(self):
350
369
        """Create 3 packs and a reload function.
351
370
 
1579
1598
        # could leave an empty .kndx file, which bzr would later claim was a
1580
1599
        # corrupted file since the header was not present. In reality, the file
1581
1600
        # just wasn't created, so it should be ignored.
1582
 
        t = get_transport('.')
 
1601
        t = transport.get_transport('.')
1583
1602
        t.put_bytes('test.kndx', '')
1584
1603
 
1585
1604
        knit = self.make_test_knit()
1586
1605
 
1587
1606
    def test_knit_index_checks_header(self):
1588
 
        t = get_transport('.')
 
1607
        t = transport.get_transport('.')
1589
1608
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1590
1609
        k = self.make_test_knit()
1591
1610
        self.assertRaises(KnitHeaderError, k.keys)