/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

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    controldir,
23
23
    commit,
24
24
    errors,
25
 
    memorytree,
26
25
    revision,
27
26
    )
28
27
from .sixish import (
51
50
    ...     revision_id=b'rev-id')
52
51
    'rev-id'
53
52
    >>> builder.build_snapshot([b'rev-id'],
54
 
    ...     [('modify', (b'f-id', b'new-content\n'))],
 
53
    ...     [('modify', ('filename', b'new-content\n'))],
55
54
    ...     revision_id=b'rev2-id')
56
55
    'rev2-id'
57
56
    >>> builder.finish_series()
110
109
            else:
111
110
                base_id = parent_ids[0]
112
111
            if base_id != self._branch.last_revision():
113
 
                self._move_branch_pointer(base_id,
114
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
112
                self._move_branch_pointer(
 
113
                    base_id, allow_leftmost_as_ghost=allow_leftmost_as_ghost)
115
114
        tree = self._branch.create_memorytree()
116
115
        with tree.lock_write():
117
116
            if parent_ids is not None:
118
 
                tree.set_parent_ids(parent_ids,
 
117
                tree.set_parent_ids(
 
118
                    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,
129
 
            **kwargs)
 
128
                           reporter=reporter, **kwargs)
130
129
 
131
130
    def _move_branch_pointer(self, new_revision_id,
132
 
        allow_leftmost_as_ghost=False):
 
131
                             allow_leftmost_as_ghost=False):
133
132
        """Point self._branch to a different revision id."""
134
133
        with self._branch.lock_write():
135
134
            # We don't seem to have a simple set_last_revision(), so we
137
136
            cur_revno, cur_revision_id = self._branch.last_revision_info()
138
137
            try:
139
138
                g = self._branch.repository.get_graph()
140
 
                new_revno = g.find_distance_to_null(new_revision_id,
141
 
                    [(cur_revision_id, cur_revno)])
 
139
                new_revno = g.find_distance_to_null(
 
140
                    new_revision_id, [(cur_revision_id, cur_revno)])
142
141
                self._branch.set_last_revision_info(new_revno, new_revision_id)
143
142
            except errors.GhostRevisionsHaveNoRevno:
144
143
                if not allow_leftmost_as_ghost:
175
174
        self._tree = None
176
175
 
177
176
    def build_snapshot(self, parent_ids, actions, message=None, timestamp=None,
178
 
            allow_leftmost_as_ghost=False, committer=None, timezone=None,
179
 
            message_callback=None, revision_id=None):
 
177
                       allow_leftmost_as_ghost=False, committer=None,
 
178
                       timezone=None, message_callback=None, revision_id=None):
180
179
        """Build a commit, shaped in a specific way.
181
180
 
182
181
        Most of the actions are self-explanatory.  'flush' is special action to
211
210
            else:
212
211
                base_id = parent_ids[0]
213
212
            if base_id != self._branch.last_revision():
214
 
                self._move_branch_pointer(base_id,
215
 
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
 
213
                self._move_branch_pointer(
 
214
                    base_id, allow_leftmost_as_ghost=allow_leftmost_as_ghost)
216
215
 
217
216
        if self._tree is not None:
218
217
            tree = self._tree
220
219
            tree = self._branch.create_memorytree()
221
220
        with tree.lock_write():
222
221
            if parent_ids is not None:
223
 
                tree.set_parent_ids(parent_ids,
 
222
                tree.set_parent_ids(
 
223
                    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(tree, message=message, rev_id=revision_id,
 
255
            return self._do_commit(
 
256
                tree, message=message, rev_id=revision_id,
256
257
                timestamp=timestamp, timezone=timezone, committer=committer,
257
258
                message_callback=message_callback)
258
259
 
259
260
    def _flush_pending(self, tree, pending):
260
 
        """Flush the pending actions in 'pending', i.e. apply them to 'tree'."""
 
261
        """Flush the pending actions in 'pending', i.e. apply them to tree."""
261
262
        for path, file_id in pending.to_add_directories:
262
263
            if path == '':
263
 
                if tree.has_filename(path) and path in pending.to_unversion_paths:
 
264
                if tree.has_filename(path) \
 
265
                        and path in pending.to_unversion_paths:
264
266
                    # We're overwriting this path, no need to unversion
265
267
                    pending.to_unversion_paths.discard(path)
266
268
                # Special case, because the path already exists
271
273
            tree.rename_one(from_relpath, to_relpath)
272
274
        if pending.to_unversion_paths:
273
275
            tree.unversion(pending.to_unversion_paths)
274
 
        tree.add(pending.to_add_files, pending.to_add_file_ids, pending.to_add_kinds)
 
276
        tree.add(pending.to_add_files, pending.to_add_file_ids,
 
277
                 pending.to_add_kinds)
275
278
        for path, content in viewitems(pending.new_contents):
276
279
            tree.put_file_bytes_non_atomic(path, content)
277
280
 
295
298
        self.new_contents = {}
296
299
        self.to_unversion_paths = set()
297
300
        self.to_rename = []
298