/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 bzrlib/bundle/bundle_data.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-02 11:53:00 UTC
  • mfrom: (3400.2.1 integrate-1.3)
  • Revision ID: pqm@pqm.ubuntu.com-20080502115300-98iunzq9437108n5
(mbp) merge 1.3.1 news into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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,
78
78
            for property in self.properties:
79
79
                key_end = property.find(': ')
80
80
                if key_end == -1:
81
 
                    if not property.endswith(':'):
82
 
                        raise ValueError(property)
 
81
                    assert property.endswith(':')
83
82
                    key = str(property[:-1])
84
83
                    value = ''
85
84
                else:
159
158
    def get_base(self, revision):
160
159
        revision_info = self.get_revision_info(revision.revision_id)
161
160
        if revision_info.base_id is not None:
162
 
            return revision_info.base_id
 
161
            if revision_info.base_id == NULL_REVISION:
 
162
                return None
 
163
            else:
 
164
                return revision_info.base_id
163
165
        if len(revision.parent_ids) == 0:
164
166
            # There is no base listed, and
165
167
            # the lowest revision doesn't have a parent
166
168
            # so this is probably against the empty tree
167
 
            # and thus base truly is NULL_REVISION
168
 
            return NULL_REVISION
 
169
            # and thus base truly is None
 
170
            return None
169
171
        else:
170
172
            return revision.parent_ids[-1]
171
173
 
194
196
    def revision_tree(self, repository, revision_id, base=None):
195
197
        revision = self.get_revision(revision_id)
196
198
        base = self.get_base(revision)
197
 
        if base == revision_id:
198
 
            raise AssertionError()
 
199
        assert base != revision_id
199
200
        if not self._validated_revisions_against_repo:
200
201
            self._validate_references_from_repository(repository)
201
202
        revision_info = self.get_revision_info(revision_id)
202
203
        inventory_revision_id = revision_id
203
 
        bundle_tree = BundleTree(repository.revision_tree(base),
 
204
        bundle_tree = BundleTree(repository.revision_tree(base), 
204
205
                                  inventory_revision_id)
205
206
        self._update_tree(bundle_tree, revision_id)
206
207
 
239
240
        for rev_info in self.revisions:
240
241
            checked[rev_info.revision_id] = True
241
242
            add_sha(rev_to_sha, rev_info.revision_id, rev_info.sha1)
242
 
 
 
243
                
243
244
        for (rev, rev_info) in zip(self.real_revisions, self.revisions):
244
245
            add_sha(inv_to_sha, rev_info.revision_id, rev_info.inventory_sha1)
245
246
 
247
248
        missing = {}
248
249
        for revision_id, sha1 in rev_to_sha.iteritems():
249
250
            if repository.has_revision(revision_id):
250
 
                testament = StrictTestament.from_revision(repository,
 
251
                testament = StrictTestament.from_revision(repository, 
251
252
                                                          revision_id)
252
253
                local_sha1 = self._testament_sha1_from_revision(repository,
253
254
                                                                revision_id)
254
255
                if sha1 != local_sha1:
255
 
                    raise BzrError('sha1 mismatch. For revision id {%s}'
 
256
                    raise BzrError('sha1 mismatch. For revision id {%s}' 
256
257
                            'local: %s, bundle: %s' % (revision_id, local_sha1, sha1))
257
258
                else:
258
259
                    count += 1
270
271
        """At this point we should have generated the BundleTree,
271
272
        so build up an inventory, and make sure the hashes match.
272
273
        """
 
274
 
 
275
        assert inv is not None
 
276
 
273
277
        # Now we should have a complete inventory entry.
274
278
        s = serializer_v5.write_inventory_to_string(inv)
275
279
        sha1 = sha_string(s)
276
280
        # Target revision is the last entry in the real_revisions list
277
281
        rev = self.get_revision(revision_id)
278
 
        if rev.revision_id != revision_id:
279
 
            raise AssertionError()
 
282
        assert rev.revision_id == revision_id
280
283
        if sha1 != rev.inventory_sha1:
281
284
            open(',,bogus-inv', 'wb').write(s)
282
285
            warning('Inventory sha hash mismatch for revision %s. %s'
287
290
 
288
291
        # This is a mapping from each revision id to it's sha hash
289
292
        rev_to_sha1 = {}
290
 
 
 
293
        
291
294
        rev = self.get_revision(revision_id)
292
295
        rev_info = self.get_revision_info(revision_id)
293
 
        if not (rev.revision_id == rev_info.revision_id):
294
 
            raise AssertionError()
295
 
        if not (rev.revision_id == revision_id):
296
 
            raise AssertionError()
 
296
        assert rev.revision_id == rev_info.revision_id
 
297
        assert rev.revision_id == revision_id
297
298
        sha1 = self._testament_sha1(rev, inventory)
298
299
        if sha1 != rev_info.sha1:
299
300
            raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1)
331
332
                if name == 'last-changed':
332
333
                    last_changed = value
333
334
                elif name == 'executable':
 
335
                    assert value in ('yes', 'no'), value
334
336
                    val = (value == 'yes')
335
337
                    bundle_tree.note_executable(new_path, val)
336
338
                elif name == 'target':
340
342
            return last_changed, encoding
341
343
 
342
344
        def do_patch(path, lines, encoding):
343
 
            if encoding == 'base64':
 
345
            if encoding is not None:
 
346
                assert encoding == 'base64'
344
347
                patch = base64.decodestring(''.join(lines))
345
 
            elif encoding is None:
 
348
            else:
346
349
                patch =  ''.join(lines)
347
 
            else:
348
 
                raise ValueError(encoding)
349
350
            bundle_tree.note_patch(path, patch)
350
351
 
351
352
        def renamed(kind, extra, lines):
411
412
            revision = get_rev_id(last_modified, path, kind)
412
413
            if lines:
413
414
                do_patch(path, lines, encoding)
414
 
 
 
415
            
415
416
        valid_actions = {
416
417
            'renamed':renamed,
417
418
            'removed':removed,
479
480
 
480
481
    def note_rename(self, old_path, new_path):
481
482
        """A file/directory has been renamed from old_path => new_path"""
482
 
        if new_path in self._renamed:
483
 
            raise AssertionError(new_path)
484
 
        if old_path in self._renamed_r:
485
 
            raise AssertionError(old_path)
 
483
        assert new_path not in self._renamed
 
484
        assert old_path not in self._renamed_r
486
485
        self._renamed[new_path] = old_path
487
486
        self._renamed_r[old_path] = new_path
488
487
 
518
517
 
519
518
    def old_path(self, new_path):
520
519
        """Get the old_path (path in the base_tree) for the file at new_path"""
521
 
        if new_path[:1] in ('\\', '/'):
522
 
            raise ValueError(new_path)
 
520
        assert new_path[:1] not in ('\\', '/')
523
521
        old_path = self._renamed.get(new_path)
524
522
        if old_path is not None:
525
523
            return old_path
539
537
        #renamed_r
540
538
        if old_path in self._renamed_r:
541
539
            return None
542
 
        return old_path
 
540
        return old_path 
543
541
 
544
542
    def new_path(self, old_path):
545
543
        """Get the new_path (path in the target_tree) for the file at old_path
546
544
        in the base tree.
547
545
        """
548
 
        if old_path[:1] in ('\\', '/'):
549
 
            raise ValueError(old_path)
 
546
        assert old_path[:1] not in ('\\', '/')
550
547
        new_path = self._renamed_r.get(old_path)
551
548
        if new_path is not None:
552
549
            return new_path
565
562
        #renamed_r
566
563
        if new_path in self._renamed:
567
564
            return None
568
 
        return new_path
 
565
        return new_path 
569
566
 
570
567
    def path2id(self, path):
571
568
        """Return the id of the file present at path in the target tree."""
605
602
                return None
606
603
        new_path = self.id2path(file_id)
607
604
        return self.base_tree.path2id(new_path)
608
 
 
 
605
        
609
606
    def get_file(self, file_id):
610
607
        """Return a file-like object containing the new contents of the
611
608
        file given by file_id.
622
619
            patch_original = None
623
620
        file_patch = self.patches.get(self.id2path(file_id))
624
621
        if file_patch is None:
625
 
            if (patch_original is None and
 
622
            if (patch_original is None and 
626
623
                self.get_kind(file_id) == 'directory'):
627
624
                return StringIO()
628
 
            if patch_original is None:
629
 
                raise AssertionError("None: %s" % file_id)
 
625
            assert patch_original is not None, "None: %s" % file_id
630
626
            return patch_original
631
627
 
632
 
        if file_patch.startswith('\\'):
633
 
            raise ValueError(
634
 
                'Malformed patch for %s, %r' % (file_id, file_patch))
 
628
        assert not file_patch.startswith('\\'), \
 
629
            'Malformed patch for %s, %r' % (file_id, file_patch)
635
630
        return patched_file(file_patch, patch_original)
636
631
 
637
632
    def get_symlink_target(self, file_id):
684
679
        This need to be called before ever accessing self.inventory
685
680
        """
686
681
        from os.path import dirname, basename
 
682
 
 
683
        assert self.base_tree is not None
687
684
        base_inv = self.base_tree.inventory
688
685
        inv = Inventory(None, self.revision_id)
689
686