~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/serializer/v08.py

  • Committer: Adeodato Simó
  • Date: 2006-07-13 00:25:34 UTC
  • mto: (1711.2.88 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1862.
  • Revision ID: dato@net.com.org.es-20060713002534-0f6001589ff30c28
Really use terminal_width() for pending-merge display. r1707 mentioned
this in NEWS, but did not include that part of the fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import errors
23
 
from bzrlib.bundle.serializer import (BundleSerializer,
24
 
                                      BUNDLE_HEADER,
 
22
from bzrlib.bundle.serializer import (BundleSerializer, 
 
23
                                      BUNDLE_HEADER, 
25
24
                                      format_highres_date,
26
25
                                      unpack_highres_date,
27
26
                                     )
28
27
from bzrlib.bundle.serializer import binary_diff
29
28
from bzrlib.bundle.bundle_data import (RevisionInfo, BundleInfo, BundleTree)
 
29
from bzrlib.delta import compare_trees
30
30
from bzrlib.diff import internal_diff
 
31
import bzrlib.errors as errors
31
32
from bzrlib.osutils import pathjoin
32
33
from bzrlib.progress import DummyProgress
33
34
from bzrlib.revision import NULL_REVISION
158
159
            if rev_id == last_rev_id:
159
160
                rev_tree = last_rev_tree
160
161
            else:
161
 
                rev_tree = self.source.revision_tree(rev_id)
 
162
                base_tree = self.source.revision_tree(rev_id)
 
163
            rev_tree = self.source.revision_tree(rev_id)
162
164
            if rev_id in self.forced_bases:
163
165
                explicit_base = True
164
166
                base_id = self.forced_bases[rev_id]
267
269
            else:
268
270
                action.write(self.to_file)
269
271
 
270
 
        delta = new_tree.changes_from(old_tree, want_unchanged=True)
 
272
        delta = compare_trees(old_tree, new_tree, want_unchanged=True)
271
273
        for path, file_id, kind in delta.removed:
272
274
            action = Action('removed', [kind, path]).write(self.to_file)
273
275
 
316
318
        self.from_file = iter(from_file)
317
319
        self._next_line = None
318
320
        
319
 
        self.info = BundleInfo08()
 
321
        self.info = BundleInfo()
320
322
        # We put the actual inventory ids in the footer, so that the patch
321
323
        # is easier to read for humans.
322
324
        # Unfortunately, that means we need to read everything before we
365
367
            # which does not start with '#'
366
368
            if line is None or line == '\n':
367
369
                break
368
 
            if not line.startswith('#'):
369
 
                continue
370
370
            found_something = True
371
371
            self._handle_next(line)
372
372
        if not found_something:
378
378
        """Read in a key-value pair
379
379
        """
380
380
        if not line.startswith('#'):
381
 
            raise errors.MalformedHeader('Bzr header did not start with #')
 
381
            raise MalformedHeader('Bzr header did not start with #')
382
382
        line = line[1:-1].decode('utf-8') # Remove the '#' and '\n'
383
383
        if line[:indent] == ' '*indent:
384
384
            line = line[indent:]
395
395
            key = line[:-1]
396
396
            value = self._read_many(indent=indent+2)
397
397
        else:
398
 
            raise errors.MalformedHeader('While looking for key: value pairs,'
 
398
            raise MalformedHeader('While looking for key: value pairs,'
399
399
                    ' did not find the colon %r' % (line))
400
400
 
401
401
        key = key.replace(' ', '_')
411
411
            return
412
412
 
413
413
        revision_info = self.info.revisions[-1]
414
 
        if key in revision_info.__dict__:
 
414
        if hasattr(revision_info, key):
415
415
            if getattr(revision_info, key) is None:
416
416
                setattr(revision_info, key, value)
417
417
            else:
418
 
                raise errors.MalformedHeader('Duplicated Key: %s' % key)
 
418
                raise MalformedHeader('Duplicated Key: %s' % key)
419
419
        else:
420
420
            # What do we do with a key we don't recognize
421
 
            raise errors.MalformedHeader('Unknown Key: "%s"' % key)
 
421
            raise MalformedHeader('Unknown Key: "%s"' % key)
422
422
    
423
423
    def _read_many(self, indent):
424
424
        """If a line ends with no entry, that means that it should be
455
455
        for line in self._next():
456
456
            if first:
457
457
                if not line.startswith('==='):
458
 
                    raise errors.MalformedPatches('The first line of all patches'
 
458
                    raise MalformedPatches('The first line of all patches'
459
459
                        ' should be a bzr meta line "==="'
460
460
                        ': %r' % line)
461
461
                action = line[4:-1].decode('utf-8')
493
493
        """
494
494
        for line in self._next():
495
495
            self._handle_next(line)
496
 
            if self._next_line is None:
497
 
                break
498
496
            if not self._next_line.startswith('#'):
499
 
                # Consume the trailing \n and stop processing
500
497
                self._next().next()
501
498
                break
502
 
 
503
 
 
504
 
class BundleInfo08(BundleInfo):
505
 
    def _update_tree(self, bundle_tree, revision_id):
506
 
        bundle_tree.note_last_changed('', revision_id)
507
 
        BundleInfo._update_tree(self, bundle_tree, revision_id)
 
499
            if self._next_line is None:
 
500
                break