/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/bundle/serializer/v08.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Serializer factory for reading and writing bundles.
18
18
"""
19
19
 
20
 
import os
 
20
from __future__ import absolute_import
21
21
 
22
 
from bzrlib import (
 
22
from breezy import (
23
23
    errors,
24
24
    ui,
25
25
    )
26
 
from bzrlib.bundle.serializer import (BundleSerializer,
 
26
from breezy.bundle.serializer import (BundleSerializer,
27
27
                                      _get_bundle_header,
28
28
                                     )
29
 
from bzrlib.bundle.serializer import binary_diff
30
 
from bzrlib.bundle.bundle_data import (RevisionInfo, BundleInfo, BundleTree)
31
 
from bzrlib.diff import internal_diff
32
 
from bzrlib.osutils import pathjoin
33
 
from bzrlib.revision import NULL_REVISION
34
 
from bzrlib.testament import StrictTestament
35
 
from bzrlib.timestamp import (
 
29
from breezy.bundle.serializer import binary_diff
 
30
from breezy.bundle.bundle_data import (RevisionInfo, BundleInfo)
 
31
from breezy.diff import internal_diff
 
32
from breezy.revision import NULL_REVISION
 
33
from breezy.testament import StrictTestament
 
34
from breezy.timestamp import (
36
35
    format_highres_date,
37
 
    unpack_highres_date,
38
 
)
39
 
from bzrlib.textfile import text_file
40
 
from bzrlib.trace import mutter
 
36
    )
 
37
from breezy.textfile import text_file
 
38
from breezy.trace import mutter
41
39
 
42
40
bool_text = {True: 'yes', False: 'no'}
43
41
 
117
115
        self.forced_bases = forced_bases
118
116
        self.to_file = f
119
117
        self.check_compatible()
120
 
        source.lock_read()
121
 
        try:
 
118
        with source.lock_read():
122
119
            self._write_main_header()
123
120
            pb = ui.ui_factory.nested_progress_bar()
124
121
            try:
125
122
                self._write_revisions(pb)
126
123
            finally:
127
124
                pb.finished()
128
 
        finally:
129
 
            source.unlock()
130
125
 
131
126
    def write_bundle(self, repository, target, base, fileobj):
132
127
        return self._write_bundle(repository, target, base, fileobj)
262
257
        new_label = ''
263
258
 
264
259
        def do_diff(file_id, old_path, new_path, action, force_binary):
265
 
            def tree_lines(tree, require_text=False):
266
 
                if file_id in tree:
267
 
                    tree_file = tree.get_file(file_id)
 
260
            def tree_lines(tree, path, require_text=False):
 
261
                if tree.has_id(file_id):
 
262
                    tree_file = tree.get_file(path, file_id)
268
263
                    if require_text is True:
269
264
                        tree_file = text_file(tree_file)
270
265
                    return tree_file.readlines()
274
269
            try:
275
270
                if force_binary:
276
271
                    raise errors.BinaryFile()
277
 
                old_lines = tree_lines(old_tree, require_text=True)
278
 
                new_lines = tree_lines(new_tree, require_text=True)
 
272
                old_lines = tree_lines(old_tree, old_path, require_text=True)
 
273
                new_lines = tree_lines(new_tree, new_path, require_text=True)
279
274
                action.write(self.to_file)
280
275
                internal_diff(old_path, old_lines, new_path, new_lines,
281
276
                              self.to_file)
282
277
            except errors.BinaryFile:
283
 
                old_lines = tree_lines(old_tree, require_text=False)
284
 
                new_lines = tree_lines(new_tree, require_text=False)
 
278
                old_lines = tree_lines(old_tree, old_path, require_text=False)
 
279
                new_lines = tree_lines(new_tree, new_path, require_text=False)
285
280
                action.add_property('encoding', 'base64')
286
281
                action.write(self.to_file)
287
282
                binary_diff(old_path, old_lines, new_path, new_lines,
289
284
 
290
285
        def finish_action(action, file_id, kind, meta_modified, text_modified,
291
286
                          old_path, new_path):
292
 
            entry = new_tree.inventory[file_id]
 
287
            entry = new_tree.root_inventory[file_id]
293
288
            if entry.revision != default_revision_id:
294
289
                action.add_utf8_property('last-changed', entry.revision)
295
290
            if meta_modified:
309
304
        for path, file_id, kind in delta.added:
310
305
            action = Action('added', [kind, path], [('file-id', file_id)])
311
306
            meta_modified = (kind=='file' and
312
 
                             new_tree.is_executable(file_id))
 
307
                             new_tree.is_executable(path, file_id))
313
308
            finish_action(action, file_id, kind, meta_modified, True,
314
309
                          DEVNULL, path)
315
310
 
326
321
                          path, path)
327
322
 
328
323
        for path, file_id, kind in delta.unchanged:
329
 
            ie = new_tree.inventory[file_id]
330
 
            new_rev = getattr(ie, 'revision', None)
 
324
            new_rev = new_tree.get_file_revision(path, file_id)
331
325
            if new_rev is None:
332
326
                continue
333
 
            old_rev = getattr(old_tree.inventory[ie.file_id], 'revision', None)
 
327
            old_rev = old_tree.get_file_revision(path, file_id)
334
328
            if new_rev != old_rev:
335
 
                action = Action('modified', [ie.kind,
336
 
                                             new_tree.id2path(ie.file_id)])
337
 
                action.add_utf8_property('last-changed', ie.revision)
 
329
                action = Action('modified', [new_tree.kind(path, file_id),
 
330
                                             path])
 
331
                action.add_utf8_property('last-changed', new_rev)
338
332
                action.write(self.to_file)
339
333
 
340
334
 
363
357
        return BundleInfo08()
364
358
 
365
359
    def _read(self):
366
 
        self._next().next()
 
360
        next(self._next())
367
361
        while self._next_line is not None:
368
362
            if not self._read_revision_header():
369
363
                break
540
534
                break
541
535
            if not self._next_line.startswith('#'):
542
536
                # Consume the trailing \n and stop processing
543
 
                self._next().next()
 
537
                next(self._next())
544
538
                break
545
539
 
546
540
class BundleInfo08(BundleInfo):
553
547
        testament = StrictTestament.from_revision(repository, revision_id)
554
548
        return testament.as_sha1()
555
549
 
556
 
    def _testament_sha1(self, revision, inventory):
557
 
        return StrictTestament(revision, inventory).as_sha1()
 
550
    def _testament_sha1(self, revision, tree):
 
551
        return StrictTestament(revision, tree).as_sha1()