~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Martin Pool
  • Date: 2008-05-08 04:12:06 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080508041206-tkrr8ucmcyrlzkum
Some review cleanups for assertion removal

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,
159
159
    def get_base(self, revision):
160
160
        revision_info = self.get_revision_info(revision.revision_id)
161
161
        if revision_info.base_id is not None:
162
 
            return revision_info.base_id
 
162
            if revision_info.base_id == NULL_REVISION:
 
163
                return None
 
164
            else:
 
165
                return revision_info.base_id
163
166
        if len(revision.parent_ids) == 0:
164
167
            # There is no base listed, and
165
168
            # the lowest revision doesn't have a parent
166
169
            # so this is probably against the empty tree
167
 
            # and thus base truly is NULL_REVISION
168
 
            return NULL_REVISION
 
170
            # and thus base truly is None
 
171
            return None
169
172
        else:
170
173
            return revision.parent_ids[-1]
171
174
 
200
203
            self._validate_references_from_repository(repository)
201
204
        revision_info = self.get_revision_info(revision_id)
202
205
        inventory_revision_id = revision_id
203
 
        bundle_tree = BundleTree(repository.revision_tree(base),
 
206
        bundle_tree = BundleTree(repository.revision_tree(base), 
204
207
                                  inventory_revision_id)
205
208
        self._update_tree(bundle_tree, revision_id)
206
209
 
239
242
        for rev_info in self.revisions:
240
243
            checked[rev_info.revision_id] = True
241
244
            add_sha(rev_to_sha, rev_info.revision_id, rev_info.sha1)
242
 
 
 
245
                
243
246
        for (rev, rev_info) in zip(self.real_revisions, self.revisions):
244
247
            add_sha(inv_to_sha, rev_info.revision_id, rev_info.inventory_sha1)
245
248
 
247
250
        missing = {}
248
251
        for revision_id, sha1 in rev_to_sha.iteritems():
249
252
            if repository.has_revision(revision_id):
250
 
                testament = StrictTestament.from_revision(repository,
 
253
                testament = StrictTestament.from_revision(repository, 
251
254
                                                          revision_id)
252
255
                local_sha1 = self._testament_sha1_from_revision(repository,
253
256
                                                                revision_id)
254
257
                if sha1 != local_sha1:
255
 
                    raise BzrError('sha1 mismatch. For revision id {%s}'
 
258
                    raise BzrError('sha1 mismatch. For revision id {%s}' 
256
259
                            'local: %s, bundle: %s' % (revision_id, local_sha1, sha1))
257
260
                else:
258
261
                    count += 1
259
262
            elif revision_id not in checked:
260
263
                missing[revision_id] = sha1
261
264
 
 
265
        for inv_id, sha1 in inv_to_sha.iteritems():
 
266
            if repository.has_revision(inv_id):
 
267
                # Note: branch.get_inventory_sha1() just returns the value that
 
268
                # is stored in the revision text, and that value may be out
 
269
                # of date. This is bogus, because that means we aren't
 
270
                # validating the actual text, just that we wrote and read the
 
271
                # string. But for now, what the hell.
 
272
                local_sha1 = repository.get_inventory_sha1(inv_id)
 
273
                if sha1 != local_sha1:
 
274
                    raise BzrError('sha1 mismatch. For inventory id {%s}' 
 
275
                                   'local: %s, bundle: %s' % 
 
276
                                   (inv_id, local_sha1, sha1))
 
277
                else:
 
278
                    count += 1
 
279
 
262
280
        if len(missing) > 0:
263
281
            # I don't know if this is an error yet
264
282
            warning('Not all revision hashes could be validated.'
287
305
 
288
306
        # This is a mapping from each revision id to it's sha hash
289
307
        rev_to_sha1 = {}
290
 
 
 
308
        
291
309
        rev = self.get_revision(revision_id)
292
310
        rev_info = self.get_revision_info(revision_id)
293
311
        if not (rev.revision_id == rev_info.revision_id):
411
429
            revision = get_rev_id(last_modified, path, kind)
412
430
            if lines:
413
431
                do_patch(path, lines, encoding)
414
 
 
 
432
            
415
433
        valid_actions = {
416
434
            'renamed':renamed,
417
435
            'removed':removed,
539
557
        #renamed_r
540
558
        if old_path in self._renamed_r:
541
559
            return None
542
 
        return old_path
 
560
        return old_path 
543
561
 
544
562
    def new_path(self, old_path):
545
563
        """Get the new_path (path in the target_tree) for the file at old_path
565
583
        #renamed_r
566
584
        if new_path in self._renamed:
567
585
            return None
568
 
        return new_path
 
586
        return new_path 
569
587
 
570
588
    def path2id(self, path):
571
589
        """Return the id of the file present at path in the target tree."""
605
623
                return None
606
624
        new_path = self.id2path(file_id)
607
625
        return self.base_tree.path2id(new_path)
608
 
 
 
626
        
609
627
    def get_file(self, file_id):
610
628
        """Return a file-like object containing the new contents of the
611
629
        file given by file_id.
622
640
            patch_original = None
623
641
        file_patch = self.patches.get(self.id2path(file_id))
624
642
        if file_patch is None:
625
 
            if (patch_original is None and
 
643
            if (patch_original is None and 
626
644
                self.get_kind(file_id) == 'directory'):
627
645
                return StringIO()
628
646
            if patch_original is None: