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

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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