/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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 __future__ import absolute_import
 
24
 
 
25
from bzrlib import errors
34
26
 
35
27
 
36
28
class TreeBuilder(object):
52
44
        """
53
45
        self._ensure_building()
54
46
        if not self._root_done:
55
 
            self._tree.add('', b'root-id', 'directory')
 
47
            self._tree.add('', 'root-id', 'directory')
56
48
            self._root_done = True
57
49
        for name in recipe:
58
 
            if name.endswith('/'):
 
50
            if name[-1] == '/':
59
51
                self._tree.mkdir(name[:-1])
60
52
            else:
61
 
                end = b'\n'
62
 
                content = b"contents of %s%s" % (name.encode('utf-8'), end)
 
53
                end = '\n'
 
54
                content = "contents of %s%s" % (name.encode('utf-8'), end)
63
55
                self._tree.add(name, None, 'file')
64
 
                self._tree.put_file_bytes_non_atomic(name, content)
 
56
                file_id = self._tree.path2id(name)
 
57
                self._tree.put_file_bytes_non_atomic(file_id, content)
65
58
 
66
59
    def _ensure_building(self):
67
60
        """Raise NotBuilding if there is no current tree being built."""
68
61
        if self._tree is None:
69
 
            raise NotBuilding
 
62
            raise errors.NotBuilding
70
63
 
71
64
    def finish_tree(self):
72
65
        """Finish building the current tree."""
82
75
            MutableTree interface.
83
76
        """
84
77
        if self._tree is not None:
85
 
            raise AlreadyBuilding
 
78
            raise errors.AlreadyBuilding
86
79
        self._tree = tree
87
80
        self._tree.lock_tree_write()