~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branchbuilder.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Utility for create branches with particular contents."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from bzrlib import (
20
 
    bzrdir,
 
22
    controldir,
21
23
    commit,
22
24
    errors,
23
25
    memorytree,
64
66
            If the path of the transport does not exist but its parent does
65
67
            it will be created.
66
68
        :param format: Either a BzrDirFormat, or the name of a format in the
67
 
            bzrdir format registry for the branch to be built.
 
69
            controldir format registry for the branch to be built.
68
70
        :param branch: An already constructed branch to use.  This param is
69
71
            mutually exclusive with the transport and format params.
70
72
        """
82
84
            if format is None:
83
85
                format = 'default'
84
86
            if isinstance(format, str):
85
 
                format = bzrdir.format_registry.make_bzrdir(format)
86
 
            self._branch = bzrdir.BzrDir.create_branch_convenience(
 
87
                format = controldir.format_registry.make_bzrdir(format)
 
88
            self._branch = controldir.ControlDir.create_branch_convenience(
87
89
                transport.base, format=format, force_new_tree=False)
88
90
        self._tree = None
89
91
 
90
 
    def build_commit(self, **commit_kwargs):
 
92
    def build_commit(self, parent_ids=None, allow_leftmost_as_ghost=False,
 
93
                     **commit_kwargs):
91
94
        """Build a commit on the branch.
92
95
 
93
96
        This makes a commit with no real file content for when you only want
96
99
        :param commit_kwargs: Arguments to pass through to commit, such as
97
100
             timestamp.
98
101
        """
 
102
        if parent_ids is not None:
 
103
            if len(parent_ids) == 0:
 
104
                base_id = revision.NULL_REVISION
 
105
            else:
 
106
                base_id = parent_ids[0]
 
107
            if base_id != self._branch.last_revision():
 
108
                self._move_branch_pointer(base_id,
 
109
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
99
110
        tree = memorytree.MemoryTree.create_on_branch(self._branch)
100
111
        tree.lock_write()
101
112
        try:
 
113
            if parent_ids is not None:
 
114
                tree.set_parent_ids(parent_ids,
 
115
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
102
116
            tree.add('')
103
117
            return self._do_commit(tree, **commit_kwargs)
104
118
        finally: