~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branchbuilder.py

  • Committer: Robert Collins
  • Date: 2009-03-27 04:10:25 UTC
  • mfrom: (4208 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4216.
  • Revision ID: robertc@robertcollins.net-20090327041025-rgutx4q03xo4pq6l
Resolve NEWS conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    commit,
22
22
    errors,
23
23
    memorytree,
24
 
    revision,
25
24
    )
26
25
 
27
26
 
57
56
        a series in progress, it should be None.
58
57
    """
59
58
 
60
 
    def __init__(self, transport=None, format=None, branch=None):
 
59
    def __init__(self, transport, format=None):
61
60
        """Construct a BranchBuilder on transport.
62
61
 
63
62
        :param transport: The transport the branch should be created on.
65
64
            it will be created.
66
65
        :param format: Either a BzrDirFormat, or the name of a format in the
67
66
            bzrdir format registry for the branch to be built.
68
 
        :param branch: An already constructed branch to use.  This param is
69
 
            mutually exclusive with the transport and format params.
70
67
        """
71
 
        if branch is not None:
72
 
            if format is not None:
73
 
                raise AssertionError(
74
 
                    "branch and format kwargs are mutually exclusive")
75
 
            if transport is not None:
76
 
                raise AssertionError(
77
 
                    "branch and transport kwargs are mutually exclusive")
78
 
            self._branch = branch
79
 
        else:
80
 
            if not transport.has('.'):
81
 
                transport.mkdir('.')
82
 
            if format is None:
83
 
                format = 'default'
84
 
            if isinstance(format, str):
85
 
                format = bzrdir.format_registry.make_bzrdir(format)
86
 
            self._branch = bzrdir.BzrDir.create_branch_convenience(
87
 
                transport.base, format=format, force_new_tree=False)
 
68
        if not transport.has('.'):
 
69
            transport.mkdir('.')
 
70
        if format is None:
 
71
            format = 'default'
 
72
        if isinstance(format, str):
 
73
            format = bzrdir.format_registry.make_bzrdir(format)
 
74
        self._branch = bzrdir.BzrDir.create_branch_convenience(transport.base,
 
75
            format=format, force_new_tree=False)
88
76
        self._tree = None
89
77
 
90
78
    def build_commit(self, **commit_kwargs):
104
92
        finally:
105
93
            tree.unlock()
106
94
 
107
 
    def _do_commit(self, tree, message=None, message_callback=None, **kwargs):
 
95
    def _do_commit(self, tree, message=None, **kwargs):
108
96
        reporter = commit.NullCommitReporter()
109
 
        if message is None and message_callback is None:
 
97
        if message is None:
110
98
            message = u'commit %d' % (self._branch.revno() + 1,)
111
 
        return tree.commit(message, message_callback=message_callback,
 
99
        return tree.commit(message,
112
100
            reporter=reporter,
113
101
            **kwargs)
114
102
 
115
 
    def _move_branch_pointer(self, new_revision_id,
116
 
        allow_leftmost_as_ghost=False):
 
103
    def _move_branch_pointer(self, new_revision_id):
117
104
        """Point self._branch to a different revision id."""
118
105
        self._branch.lock_write()
119
106
        try:
120
107
            # We don't seem to have a simple set_last_revision(), so we
121
108
            # implement it here.
122
109
            cur_revno, cur_revision_id = self._branch.last_revision_info()
123
 
            try:
124
 
                g = self._branch.repository.get_graph()
125
 
                new_revno = g.find_distance_to_null(new_revision_id,
126
 
                    [(cur_revision_id, cur_revno)])
127
 
                self._branch.set_last_revision_info(new_revno, new_revision_id)
128
 
            except errors.GhostRevisionsHaveNoRevno:
129
 
                if not allow_leftmost_as_ghost:
130
 
                    raise
131
 
                new_revno = 1
 
110
            g = self._branch.repository.get_graph()
 
111
            new_revno = g.find_distance_to_null(new_revision_id,
 
112
                                                [(cur_revision_id, cur_revno)])
 
113
            self._branch.set_last_revision_info(new_revno, new_revision_id)
132
114
        finally:
133
115
            self._branch.unlock()
134
116
        if self._tree is not None:
162
144
        self._tree = None
163
145
 
164
146
    def build_snapshot(self, revision_id, parent_ids, actions,
165
 
        message=None, timestamp=None, allow_leftmost_as_ghost=False,
166
 
        committer=None, timezone=None, message_callback=None):
 
147
                       message=None, timestamp=None):
167
148
        """Build a commit, shaped in a specific way.
168
149
 
169
150
        :param revision_id: The handle for the new commit, can be None
176
157
            ('rename', ('orig-path', 'new-path'))
177
158
        :param message: An optional commit message, if not supplied, a default
178
159
            commit message will be written.
179
 
        :param message_callback: A message callback to use for the commit, as
180
 
            per mutabletree.commit.
181
160
        :param timestamp: If non-None, set the timestamp of the commit to this
182
161
            value.
183
 
        :param timezone: An optional timezone for timestamp.
184
 
        :param committer: An optional username to use for commit
185
 
        :param allow_leftmost_as_ghost: True if the leftmost parent should be
186
 
            permitted to be a ghost.
187
162
        :return: The revision_id of the new commit
188
163
        """
189
164
        if parent_ids is not None:
190
 
            if len(parent_ids) == 0:
191
 
                base_id = revision.NULL_REVISION
192
 
            else:
193
 
                base_id = parent_ids[0]
 
165
            base_id = parent_ids[0]
194
166
            if base_id != self._branch.last_revision():
195
 
                self._move_branch_pointer(base_id,
196
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
167
                self._move_branch_pointer(base_id)
197
168
 
198
169
        if self._tree is not None:
199
170
            tree = self._tree
202
173
        tree.lock_write()
203
174
        try:
204
175
            if parent_ids is not None:
205
 
                tree.set_parent_ids(parent_ids,
206
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
176
                tree.set_parent_ids(parent_ids)
207
177
            # Unfortunately, MemoryTree.add(directory) just creates an
208
178
            # inventory entry. And the only public function to create a
209
179
            # directory is MemoryTree.mkdir() which creates the directory, but
250
220
            for file_id, content in new_contents.iteritems():
251
221
                tree.put_file_bytes_non_atomic(file_id, content)
252
222
            return self._do_commit(tree, message=message, rev_id=revision_id,
253
 
                timestamp=timestamp, timezone=timezone, committer=committer,
254
 
                message_callback=message_callback)
 
223
                timestamp=timestamp)
255
224
        finally:
256
225
            tree.unlock()
257
226