/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/treebuilder.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-22 14:12:22 UTC
  • mfrom: (5809 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110422141222-nx2j0hbkihcb8j16
Merge newer bzr.dev and resolve conflicts.
Try to write some documentation about how the _dirblock_state works.
Fix up the tests so that they pass again.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
can be extremely useful in testing for instance.
21
21
"""
22
22
 
23
 
from . import errors
24
 
 
25
 
 
26
 
class AlreadyBuilding(errors.BzrError):
27
 
 
28
 
    _fmt = "The tree builder is already building a tree."
29
 
 
30
 
 
31
 
class NotBuilding(errors.BzrError):
32
 
 
33
 
    _fmt = "Not currently building a tree."
 
23
from bzrlib import errors
34
24
 
35
25
 
36
26
class TreeBuilder(object):
52
42
        """
53
43
        self._ensure_building()
54
44
        if not self._root_done:
55
 
            self._tree.add('', b'root-id', 'directory')
 
45
            self._tree.add('', 'root-id', 'directory')
56
46
            self._root_done = True
57
47
        for name in recipe:
58
 
            if name.endswith('/'):
 
48
            if name[-1] == '/':
59
49
                self._tree.mkdir(name[:-1])
60
50
            else:
61
 
                end = b'\n'
62
 
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
 
51
                end = '\n'
 
52
                content = "contents of %s%s" % (name.encode('utf-8'), end)
63
53
                self._tree.add(name, None, 'file')
64
 
                self._tree.put_file_bytes_non_atomic(name, content)
 
54
                file_id = self._tree.path2id(name)
 
55
                self._tree.put_file_bytes_non_atomic(file_id, content)
65
56
 
66
57
    def _ensure_building(self):
67
58
        """Raise NotBuilding if there is no current tree being built."""
68
59
        if self._tree is None:
69
 
            raise NotBuilding
 
60
            raise errors.NotBuilding
70
61
 
71
62
    def finish_tree(self):
72
63
        """Finish building the current tree."""
82
73
            MutableTree interface.
83
74
        """
84
75
        if self._tree is not None:
85
 
            raise AlreadyBuilding
 
76
            raise errors.AlreadyBuilding
86
77
        self._tree = tree
87
78
        self._tree.lock_tree_write()