/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: 2018-03-24 17:48:04 UTC
  • mfrom: (6921 work)
  • mto: This revision was merged to the branch mainline in revision 6923.
  • Revision ID: jelmer@jelmer.uk-20180324174804-xf22o05byoj12x1q
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    >>> builder = BranchBuilder(MemoryTransport("memory:///"))
47
47
    >>> builder.start_series()
48
48
    >>> builder.build_snapshot(None, [
49
 
    ...     ('add', ('', b'root-id', 'directory', '')),
50
 
    ...     ('add', ('filename', b'f-id', 'file', 'content\n'))],
51
 
    ...     revision_id=b'rev-id')
 
49
    ...     ('add', ('', 'root-id', 'directory', '')),
 
50
    ...     ('add', ('filename', 'f-id', 'file', 'content\n'))],
 
51
    ...     revision_id='rev-id')
52
52
    'rev-id'
53
53
    >>> builder.build_snapshot(['rev-id'],
54
 
    ...     [('modify', (b'f-id', 'new-content\n'))],
55
 
    ...     revision_id=b'rev2-id')
 
54
    ...     [('modify', ('f-id', 'new-content\n'))],
 
55
    ...     revision_id='rev2-id')
56
56
    'rev2-id'
57
57
    >>> builder.finish_series()
58
58
    >>> branch = builder.get_branch()
194
194
            It can be None, which indicates to use the last commit.
195
195
        :param actions: A list of actions to perform. Supported actions are:
196
196
            ('add', ('path', 'file-id', 'kind', 'content' or None))
197
 
            ('modify', ('path', 'new-content'))
198
 
            ('unversion', 'path')
 
197
            ('modify', ('file-id', 'new-content'))
 
198
            ('unversion', 'file-id')
199
199
            ('rename', ('orig-path', 'new-path'))
200
200
            ('flush', None)
201
201
        :param message: An optional commit message, if not supplied, a default
224
224
            tree = self._tree
225
225
        else:
226
226
            tree = self._branch.create_memorytree()
227
 
        with tree.lock_write():
 
227
        tree.lock_write()
 
228
        try:
228
229
            if parent_ids is not None:
229
230
                tree.set_parent_ids(parent_ids,
230
231
                    allow_leftmost_as_ghost=allow_leftmost_as_ghost)
243
244
                        pending.to_add_file_ids.append(file_id)
244
245
                        pending.to_add_kinds.append(kind)
245
246
                        if content is not None:
246
 
                            pending.new_contents[path] = content
 
247
                            pending.new_contents[file_id] = content
247
248
                elif action == 'modify':
248
 
                    path, content = info
249
 
                    pending.new_contents[path] = content
 
249
                    file_id, content = info
 
250
                    pending.new_contents[file_id] = content
250
251
                elif action == 'unversion':
251
 
                    pending.to_unversion_paths.add(info)
 
252
                    pending.to_unversion_ids.add(info)
252
253
                elif action == 'rename':
253
254
                    from_relpath, to_relpath = info
254
255
                    pending.to_rename.append((from_relpath, to_relpath))
261
262
            return self._do_commit(tree, message=message, rev_id=revision_id,
262
263
                timestamp=timestamp, timezone=timezone, committer=committer,
263
264
                message_callback=message_callback)
 
265
        finally:
 
266
            tree.unlock()
264
267
 
265
268
    def _flush_pending(self, tree, pending):
266
269
        """Flush the pending actions in 'pending', i.e. apply them to 'tree'."""
267
270
        for path, file_id in pending.to_add_directories:
268
271
            if path == '':
269
 
                if tree.has_filename(path) and path in pending.to_unversion_paths:
 
272
                old_id = tree.path2id(path)
 
273
                if old_id is not None and old_id in pending.to_unversion_ids:
270
274
                    # We're overwriting this path, no need to unversion
271
 
                    pending.to_unversion_paths.discard(path)
 
275
                    pending.to_unversion_ids.discard(old_id)
272
276
                # Special case, because the path already exists
273
277
                tree.add([path], [file_id], ['directory'])
274
278
            else:
275
279
                tree.mkdir(path, file_id)
276
280
        for from_relpath, to_relpath in pending.to_rename:
277
281
            tree.rename_one(from_relpath, to_relpath)
278
 
        if pending.to_unversion_paths:
279
 
            tree.unversion(pending.to_unversion_paths)
 
282
        if pending.to_unversion_ids:
 
283
            tree.unversion([tree.id2path(fid) for fid in pending.to_unversion_ids])
280
284
        tree.add(pending.to_add_files, pending.to_add_file_ids, pending.to_add_kinds)
281
 
        for path, content in viewitems(pending.new_contents):
282
 
            tree.put_file_bytes_non_atomic(path, content)
 
285
        for file_id, content in viewitems(pending.new_contents):
 
286
            tree.put_file_bytes_non_atomic(
 
287
                    tree.id2path(file_id), content,
 
288
                    file_id=file_id)
283
289
 
284
290
    def get_branch(self):
285
291
        """Return the branch created by the builder."""
299
305
        self.to_add_file_ids = []
300
306
        self.to_add_kinds = []
301
307
        self.new_contents = {}
302
 
        self.to_unversion_paths = set()
 
308
        self.to_unversion_ids = set()
303
309
        self.to_rename = []
304
310