~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branchbuilder.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-04 14:07:42 UTC
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090804140742-elu5athah3e0s4uj
Fix deserialization of deletes in inventory deltas, don't give up on serialized deltas from a supports_tree_refs repo unless the delta contains tree refs, and experiment to add automatic_root param to branchbuilder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    commit,
22
22
    errors,
23
23
    memorytree,
 
24
    revision as _mod_revision,
24
25
    )
25
26
 
26
27
 
56
57
        a series in progress, it should be None.
57
58
    """
58
59
 
59
 
    def __init__(self, transport=None, format=None, branch=None):
 
60
    def __init__(self, transport=None, format=None, branch=None,
 
61
            automatic_root=False):
60
62
        """Construct a BranchBuilder on transport.
61
63
 
62
64
        :param transport: The transport the branch should be created on.
66
68
            bzrdir format registry for the branch to be built.
67
69
        :param branch: An already constructed branch to use.  This param is
68
70
            mutually exclusive with the transport and format params.
 
71
        :param automatic_root: if True, a root entry will be created
 
72
            automatically.  The rich-root support of the branch's repository is
 
73
            taken into account when automatically creating a root.  Pass False
 
74
            if you want to add the root explicitly (and handle rich-root vs.
 
75
            not manually).
69
76
        """
70
77
        if branch is not None:
71
78
            if format is not None:
85
92
            self._branch = bzrdir.BzrDir.create_branch_convenience(
86
93
                transport.base, format=format, force_new_tree=False)
87
94
        self._tree = None
 
95
        self._automatic_root = automatic_root
88
96
 
89
97
    def build_commit(self, **commit_kwargs):
90
98
        """Build a commit on the branch.
198
206
            if parent_ids is not None:
199
207
                tree.set_parent_ids(parent_ids,
200
208
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
209
            elif self._branch.last_revision() == _mod_revision.NULL_REVISION:
 
210
                if self._automatic_root:
 
211
                    # No parent revision, and automatic_root.  Create an
 
212
                    # appropriate root entry.
 
213
                    if self._branch.repository.supports_rich_root():
 
214
                        from bzrlib.generate_ids import gen_root_id
 
215
                        new_root_id = gen_root_id()
 
216
                    else:
 
217
                        from bzrlib.inventory import ROOT_ID
 
218
                        new_root_id = ROOT_ID
 
219
                    add_root_action = (
 
220
                        'add', ('', new_root_id, 'directory', None))
 
221
                    actions = [add_root_action] + list(actions)
 
222
 
201
223
            # Unfortunately, MemoryTree.add(directory) just creates an
202
224
            # inventory entry. And the only public function to create a
203
225
            # directory is MemoryTree.mkdir() which creates the directory, but