~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Read in a bundle stream, and process it into a BundleReader object."""
18
18
 
27
27
    )
28
28
import bzrlib.errors
29
29
from bzrlib.bundle import apply_bundle
30
 
from bzrlib.errors import (TestamentMismatch, BzrError, 
 
30
from bzrlib.errors import (TestamentMismatch, BzrError,
31
31
                           MalformedHeader, MalformedPatches, NotABundle)
32
32
from bzrlib.inventory import (Inventory, InventoryEntry,
33
33
                              InventoryDirectory, InventoryFile,
200
200
            self._validate_references_from_repository(repository)
201
201
        revision_info = self.get_revision_info(revision_id)
202
202
        inventory_revision_id = revision_id
203
 
        bundle_tree = BundleTree(repository.revision_tree(base), 
 
203
        bundle_tree = BundleTree(repository.revision_tree(base),
204
204
                                  inventory_revision_id)
205
205
        self._update_tree(bundle_tree, revision_id)
206
206
 
239
239
        for rev_info in self.revisions:
240
240
            checked[rev_info.revision_id] = True
241
241
            add_sha(rev_to_sha, rev_info.revision_id, rev_info.sha1)
242
 
                
 
242
 
243
243
        for (rev, rev_info) in zip(self.real_revisions, self.revisions):
244
244
            add_sha(inv_to_sha, rev_info.revision_id, rev_info.inventory_sha1)
245
245
 
247
247
        missing = {}
248
248
        for revision_id, sha1 in rev_to_sha.iteritems():
249
249
            if repository.has_revision(revision_id):
250
 
                testament = StrictTestament.from_revision(repository, 
 
250
                testament = StrictTestament.from_revision(repository,
251
251
                                                          revision_id)
252
252
                local_sha1 = self._testament_sha1_from_revision(repository,
253
253
                                                                revision_id)
254
254
                if sha1 != local_sha1:
255
 
                    raise BzrError('sha1 mismatch. For revision id {%s}' 
 
255
                    raise BzrError('sha1 mismatch. For revision id {%s}'
256
256
                            'local: %s, bundle: %s' % (revision_id, local_sha1, sha1))
257
257
                else:
258
258
                    count += 1
278
278
        if rev.revision_id != revision_id:
279
279
            raise AssertionError()
280
280
        if sha1 != rev.inventory_sha1:
281
 
            open(',,bogus-inv', 'wb').write(s)
 
281
            f = open(',,bogus-inv', 'wb')
 
282
            try:
 
283
                f.write(s)
 
284
            finally:
 
285
                f.close()
282
286
            warning('Inventory sha hash mismatch for revision %s. %s'
283
287
                    ' != %s' % (revision_id, sha1, rev.inventory_sha1))
284
288
 
287
291
 
288
292
        # This is a mapping from each revision id to it's sha hash
289
293
        rev_to_sha1 = {}
290
 
        
 
294
 
291
295
        rev = self.get_revision(revision_id)
292
296
        rev_info = self.get_revision_info(revision_id)
293
297
        if not (rev.revision_id == rev_info.revision_id):
327
331
                try:
328
332
                    name, value = info_item.split(':', 1)
329
333
                except ValueError:
330
 
                    raise 'Value %r has no colon' % info_item
 
334
                    raise ValueError('Value %r has no colon' % info_item)
331
335
                if name == 'last-changed':
332
336
                    last_changed = value
333
337
                elif name == 'executable':
411
415
            revision = get_rev_id(last_modified, path, kind)
412
416
            if lines:
413
417
                do_patch(path, lines, encoding)
414
 
            
 
418
 
415
419
        valid_actions = {
416
420
            'renamed':renamed,
417
421
            'removed':removed,
539
543
        #renamed_r
540
544
        if old_path in self._renamed_r:
541
545
            return None
542
 
        return old_path 
 
546
        return old_path
543
547
 
544
548
    def new_path(self, old_path):
545
549
        """Get the new_path (path in the target_tree) for the file at old_path
565
569
        #renamed_r
566
570
        if new_path in self._renamed:
567
571
            return None
568
 
        return new_path 
 
572
        return new_path
569
573
 
570
574
    def path2id(self, path):
571
575
        """Return the id of the file present at path in the target tree."""
605
609
                return None
606
610
        new_path = self.id2path(file_id)
607
611
        return self.base_tree.path2id(new_path)
608
 
        
 
612
 
609
613
    def get_file(self, file_id):
610
614
        """Return a file-like object containing the new contents of the
611
615
        file given by file_id.
622
626
            patch_original = None
623
627
        file_patch = self.patches.get(self.id2path(file_id))
624
628
        if file_patch is None:
625
 
            if (patch_original is None and 
 
629
            if (patch_original is None and
626
630
                self.get_kind(file_id) == 'directory'):
627
631
                return StringIO()
628
632
            if patch_original is None:
711
715
                ie.symlink_target = self.get_symlink_target(file_id)
712
716
            ie.revision = revision_id
713
717
 
714
 
            if kind in ('directory', 'symlink'):
715
 
                ie.text_size, ie.text_sha1 = None, None
716
 
            else:
 
718
            if kind == 'file':
717
719
                ie.text_size, ie.text_sha1 = self.get_size_and_sha1(file_id)
718
 
            if (ie.text_size is None) and (kind == 'file'):
719
 
                raise BzrError('Got a text_size of None for file_id %r' % file_id)
 
720
                if ie.text_size is None:
 
721
                    raise BzrError(
 
722
                        'Got a text_size of None for file_id %r' % file_id)
720
723
            inv.add(ie)
721
724
 
722
725
        sorted_entries = self.sorted_path_id()