/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: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

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 __future__ import absolute_import
24
 
 
25
 
from . import errors
26
 
 
27
 
 
28
 
class AlreadyBuilding(errors.BzrError):
29
 
 
30
 
    _fmt = "The tree builder is already building a tree."
31
 
 
32
 
 
33
 
class NotBuilding(errors.BzrError):
34
 
 
35
 
    _fmt = "Not currently building a tree."
 
23
from bzrlib import errors
36
24
 
37
25
 
38
26
class TreeBuilder(object):
54
42
        """
55
43
        self._ensure_building()
56
44
        if not self._root_done:
57
 
            self._tree.add('', b'root-id', 'directory')
 
45
            self._tree.add('', 'root-id', 'directory')
58
46
            self._root_done = True
59
47
        for name in recipe:
60
 
            if name.endswith('/'):
 
48
            if name[-1] == '/':
61
49
                self._tree.mkdir(name[:-1])
62
50
            else:
63
 
                end = b'\n'
64
 
                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)
65
53
                self._tree.add(name, None, 'file')
66
 
                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)
67
56
 
68
57
    def _ensure_building(self):
69
58
        """Raise NotBuilding if there is no current tree being built."""
70
59
        if self._tree is None:
71
 
            raise NotBuilding
 
60
            raise errors.NotBuilding
72
61
 
73
62
    def finish_tree(self):
74
63
        """Finish building the current tree."""
84
73
            MutableTree interface.
85
74
        """
86
75
        if self._tree is not None:
87
 
            raise AlreadyBuilding
 
76
            raise errors.AlreadyBuilding
88
77
        self._tree = tree
89
78
        self._tree.lock_tree_write()