/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/branchbuilder.py

Merge test-run support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    controldir,
23
23
    commit,
24
24
    errors,
 
25
    memorytree,
25
26
    revision,
26
27
    )
27
28
from .sixish import (
46
47
    >>> builder.start_series()
47
48
    >>> builder.build_snapshot(None, [
48
49
    ...     ('add', ('', b'root-id', 'directory', '')),
49
 
    ...     ('add', ('filename', b'f-id', 'file', b'content\n'))],
 
50
    ...     ('add', ('filename', b'f-id', 'file', 'content\n'))],
50
51
    ...     revision_id=b'rev-id')
51
52
    'rev-id'
52
 
    >>> builder.build_snapshot([b'rev-id'],
53
 
    ...     [('modify', ('filename', b'new-content\n'))],
 
53
    >>> builder.build_snapshot(['rev-id'],
 
54
    ...     [('modify', (b'f-id', 'new-content\n'))],
54
55
    ...     revision_id=b'rev2-id')
55
56
    'rev2-id'
56
57
    >>> builder.finish_series()
109
110
            else:
110
111
                base_id = parent_ids[0]
111
112
            if base_id != self._branch.last_revision():
112
 
                self._move_branch_pointer(
113
 
                    base_id, allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
113
                self._move_branch_pointer(base_id,
 
114
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
114
115
        tree = self._branch.create_memorytree()
115
116
        with tree.lock_write():
116
117
            if parent_ids is not None:
117
 
                tree.set_parent_ids(
118
 
                    parent_ids,
 
118
                tree.set_parent_ids(parent_ids,
119
119
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
120
120
            tree.add('')
121
121
            return self._do_commit(tree, **commit_kwargs)
125
125
        if message is None and message_callback is None:
126
126
            message = u'commit %d' % (self._branch.revno() + 1,)
127
127
        return tree.commit(message, message_callback=message_callback,
128
 
                           reporter=reporter, **kwargs)
 
128
            reporter=reporter,
 
129
            **kwargs)
129
130
 
130
131
    def _move_branch_pointer(self, new_revision_id,
131
 
                             allow_leftmost_as_ghost=False):
 
132
        allow_leftmost_as_ghost=False):
132
133
        """Point self._branch to a different revision id."""
133
134
        with self._branch.lock_write():
134
135
            # We don't seem to have a simple set_last_revision(), so we
136
137
            cur_revno, cur_revision_id = self._branch.last_revision_info()
137
138
            try:
138
139
                g = self._branch.repository.get_graph()
139
 
                new_revno = g.find_distance_to_null(
140
 
                    new_revision_id, [(cur_revision_id, cur_revno)])
 
140
                new_revno = g.find_distance_to_null(new_revision_id,
 
141
                    [(cur_revision_id, cur_revno)])
141
142
                self._branch.set_last_revision_info(new_revno, new_revision_id)
142
143
            except errors.GhostRevisionsHaveNoRevno:
143
144
                if not allow_leftmost_as_ghost:
174
175
        self._tree = None
175
176
 
176
177
    def build_snapshot(self, parent_ids, actions, message=None, timestamp=None,
177
 
                       allow_leftmost_as_ghost=False, committer=None,
178
 
                       timezone=None, message_callback=None, revision_id=None):
 
178
            allow_leftmost_as_ghost=False, committer=None, timezone=None,
 
179
            message_callback=None, revision_id=None):
179
180
        """Build a commit, shaped in a specific way.
180
181
 
181
182
        Most of the actions are self-explanatory.  'flush' is special action to
186
187
        :param parent_ids: A list of parent_ids to use for the commit.
187
188
            It can be None, which indicates to use the last commit.
188
189
        :param actions: A list of actions to perform. Supported actions are:
189
 
            ('add', ('path', b'file-id', 'kind', b'content' or None))
190
 
            ('modify', ('path', b'new-content'))
 
190
            ('add', ('path', 'file-id', 'kind', 'content' or None))
 
191
            ('modify', ('path', 'new-content'))
191
192
            ('unversion', 'path')
192
193
            ('rename', ('orig-path', 'new-path'))
193
194
            ('flush', None)
210
211
            else:
211
212
                base_id = parent_ids[0]
212
213
            if base_id != self._branch.last_revision():
213
 
                self._move_branch_pointer(
214
 
                    base_id, allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
214
                self._move_branch_pointer(base_id,
 
215
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
215
216
 
216
217
        if self._tree is not None:
217
218
            tree = self._tree
219
220
            tree = self._branch.create_memorytree()
220
221
        with tree.lock_write():
221
222
            if parent_ids is not None:
222
 
                tree.set_parent_ids(
223
 
                    parent_ids,
 
223
                tree.set_parent_ids(parent_ids,
224
224
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
225
225
            # Unfortunately, MemoryTree.add(directory) just creates an
226
226
            # inventory entry. And the only public function to create a
252
252
                else:
253
253
                    raise ValueError('Unknown build action: "%s"' % (action,))
254
254
            self._flush_pending(tree, pending)
255
 
            return self._do_commit(
256
 
                tree, message=message, rev_id=revision_id,
 
255
            return self._do_commit(tree, message=message, rev_id=revision_id,
257
256
                timestamp=timestamp, timezone=timezone, committer=committer,
258
257
                message_callback=message_callback)
259
258
 
260
259
    def _flush_pending(self, tree, pending):
261
 
        """Flush the pending actions in 'pending', i.e. apply them to tree."""
 
260
        """Flush the pending actions in 'pending', i.e. apply them to 'tree'."""
262
261
        for path, file_id in pending.to_add_directories:
263
262
            if path == '':
264
 
                if tree.has_filename(path) \
265
 
                        and path in pending.to_unversion_paths:
 
263
                if tree.has_filename(path) and path in pending.to_unversion_paths:
266
264
                    # We're overwriting this path, no need to unversion
267
265
                    pending.to_unversion_paths.discard(path)
268
266
                # Special case, because the path already exists
273
271
            tree.rename_one(from_relpath, to_relpath)
274
272
        if pending.to_unversion_paths:
275
273
            tree.unversion(pending.to_unversion_paths)
276
 
        tree.add(pending.to_add_files, pending.to_add_file_ids,
277
 
                 pending.to_add_kinds)
 
274
        tree.add(pending.to_add_files, pending.to_add_file_ids, pending.to_add_kinds)
278
275
        for path, content in viewitems(pending.new_contents):
279
276
            tree.put_file_bytes_non_atomic(path, content)
280
277
 
298
295
        self.new_contents = {}
299
296
        self.to_unversion_paths = set()
300
297
        self.to_rename = []
 
298