/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/workingtree.py

  • Committer: Martin Pool
  • Date: 2007-09-25 08:14:12 UTC
  • mto: This revision was merged to the branch mainline in revision 2895.
  • Revision ID: mbp@sourcefrog.net-20070925081412-ta60zj5qxfuokev3
Remove most calls to safe_file_id and safe_revision_id.

The deprecation period for passing unicode objects as revision ids is now over.

Show diffs side-by-side

added added

removed removed

Lines of Context:
453
453
 
454
454
    def get_file(self, file_id, path=None):
455
455
        if path is None:
456
 
            file_id = osutils.safe_file_id(file_id)
457
456
            path = self.id2path(file_id)
458
457
        return self.get_file_byname(path)
459
458
 
460
459
    def get_file_text(self, file_id):
461
 
        file_id = osutils.safe_file_id(file_id)
462
460
        return self.get_file(file_id).read()
463
461
 
464
462
    def get_file_byname(self, filename):
475
473
        incorrectly attributed to CURRENT_REVISION (but after committing, the
476
474
        attribution will be correct).
477
475
        """
478
 
        file_id = osutils.safe_file_id(file_id)
479
476
        basis = self.basis_tree()
480
477
        basis.lock_read()
481
478
        try:
526
523
            pass
527
524
        else:
528
525
            for l in merges_file.readlines():
529
 
                revision_id = osutils.safe_revision_id(l.rstrip('\n'))
 
526
                revision_id = l.rstrip('\n')
530
527
                parents.append(revision_id)
531
528
        return parents
532
529
 
537
534
        
538
535
    def _get_store_filename(self, file_id):
539
536
        ## XXX: badly named; this is not in the store at all
540
 
        file_id = osutils.safe_file_id(file_id)
541
537
        return self.abspath(self.id2path(file_id))
542
538
 
543
539
    @needs_read_lock
572
568
            tree.set_parent_ids([revision_id])
573
569
 
574
570
    def id2abspath(self, file_id):
575
 
        file_id = osutils.safe_file_id(file_id)
576
571
        return self.abspath(self.id2path(file_id))
577
572
 
578
573
    def has_id(self, file_id):
579
574
        # files that have been deleted are excluded
580
 
        file_id = osutils.safe_file_id(file_id)
581
575
        inv = self.inventory
582
576
        if not inv.has_id(file_id):
583
577
            return False
585
579
        return osutils.lexists(self.abspath(path))
586
580
 
587
581
    def has_or_had_id(self, file_id):
588
 
        file_id = osutils.safe_file_id(file_id)
589
582
        if file_id == self.inventory.root.file_id:
590
583
            return True
591
584
        return self.inventory.has_id(file_id)
593
586
    __contains__ = has_id
594
587
 
595
588
    def get_file_size(self, file_id):
596
 
        file_id = osutils.safe_file_id(file_id)
597
589
        return os.path.getsize(self.id2abspath(file_id))
598
590
 
599
591
    @needs_read_lock
600
592
    def get_file_sha1(self, file_id, path=None, stat_value=None):
601
 
        file_id = osutils.safe_file_id(file_id)
602
593
        if not path:
603
594
            path = self._inventory.id2path(file_id)
604
595
        return self._hashcache.get_sha1(path, stat_value)
605
596
 
606
597
    def get_file_mtime(self, file_id, path=None):
607
 
        file_id = osutils.safe_file_id(file_id)
608
598
        if not path:
609
599
            path = self.inventory.id2path(file_id)
610
600
        return os.lstat(self.abspath(path)).st_mtime
611
601
 
612
602
    if not supports_executable():
613
603
        def is_executable(self, file_id, path=None):
614
 
            file_id = osutils.safe_file_id(file_id)
615
604
            return self._inventory[file_id].executable
616
605
    else:
617
606
        def is_executable(self, file_id, path=None):
618
607
            if not path:
619
 
                file_id = osutils.safe_file_id(file_id)
620
608
                path = self.id2path(file_id)
621
609
            mode = os.lstat(self.abspath(path)).st_mode
622
610
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
634
622
            if file_id is None:
635
623
                inv.add_path(f, kind=kind)
636
624
            else:
637
 
                file_id = osutils.safe_file_id(file_id)
638
625
                inv.add_path(f, kind=kind, file_id=file_id)
639
626
            self._inventory_is_modified = True
640
627
 
744
731
        :param revision_ids: The revision_ids to set as the parent ids of this
745
732
            working tree. Any of these may be ghosts.
746
733
        """
747
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
748
734
        self._check_parents_for_ghosts(revision_ids,
749
735
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
750
736
        for revision_id in revision_ids:
760
746
    @needs_tree_write_lock
761
747
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
762
748
        """See MutableTree.set_parent_trees."""
763
 
        parent_ids = [osutils.safe_revision_id(rev) for (rev, tree) in parents_list]
 
749
        parent_ids = [rev for (rev, tree) in parents_list]
764
750
        for revision_id in parent_ids:
765
751
            _mod_revision.check_not_reserved_id(revision_id)
766
752
 
826
812
            merger.check_basis(check_clean=True, require_commits=False)
827
813
            if to_revision is None:
828
814
                to_revision = _mod_revision.ensure_null(branch.last_revision())
829
 
            else:
830
 
                to_revision = osutils.safe_revision_id(to_revision)
831
815
            merger.other_rev_id = to_revision
832
816
            if _mod_revision.is_null(merger.other_rev_id):
833
817
                raise errors.NoCommits(branch)
898
882
        return file_id
899
883
 
900
884
    def get_symlink_target(self, file_id):
901
 
        file_id = osutils.safe_file_id(file_id)
902
885
        return os.readlink(self.id2abspath(file_id))
903
886
 
904
887
    @needs_write_lock
1428
1411
        :raises: NoSuchId if any fileid is not currently versioned.
1429
1412
        """
1430
1413
        for file_id in file_ids:
1431
 
            file_id = osutils.safe_file_id(file_id)
1432
1414
            if self._inventory.has_id(file_id):
1433
1415
                self._inventory.remove_recursive_id(file_id)
1434
1416
            else:
1515
1497
    @needs_write_lock
1516
1498
    def put_file_bytes_non_atomic(self, file_id, bytes):
1517
1499
        """See MutableTree.put_file_bytes_non_atomic."""
1518
 
        file_id = osutils.safe_file_id(file_id)
1519
1500
        stream = file(self.id2abspath(file_id), 'wb')
1520
1501
        try:
1521
1502
            stream.write(bytes)
1700
1681
    @needs_tree_write_lock
1701
1682
    def set_last_revision(self, new_revision):
1702
1683
        """Change the last revision in the working tree."""
1703
 
        new_revision = osutils.safe_revision_id(new_revision)
1704
1684
        if self._change_last_revision(new_revision):
1705
1685
            self._cache_basis_inventory(new_revision)
1706
1686
 
1729
1709
 
1730
1710
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1731
1711
        """Create the text that will be saved in basis-inventory"""
1732
 
        # TODO: jam 20070209 This should be redundant, as the revision_id
1733
 
        #       as all callers should have already converted the revision_id to
1734
 
        #       utf8
1735
 
        inventory.revision_id = osutils.safe_revision_id(revision_id)
1736
1712
        return xml7.serializer_v7.write_inventory_to_string(inventory)
1737
1713
 
1738
1714
    def _cache_basis_inventory(self, new_revision):
1975
1951
    @needs_tree_write_lock
1976
1952
    def set_root_id(self, file_id):
1977
1953
        """Set the root id for this tree."""
1978
 
        # for compatability 
1979
 
        if file_id is None:
1980
 
            symbol_versioning.warn(symbol_versioning.zero_twelve
1981
 
                % 'WorkingTree.set_root_id with fileid=None',
1982
 
                DeprecationWarning,
1983
 
                stacklevel=3)
1984
 
            file_id = ROOT_ID
1985
 
        else:
1986
 
            file_id = osutils.safe_file_id(file_id)
1987
1954
        self._set_root_id(file_id)
1988
1955
 
1989
1956
    def _set_root_id(self, file_id):
2459
2426
    def _last_revision(self):
2460
2427
        """See Mutable.last_revision."""
2461
2428
        try:
2462
 
            return osutils.safe_revision_id(
2463
 
                        self._control_files.get('last-revision').read())
 
2429
            return self._control_files.get('last-revision').read()
2464
2430
        except errors.NoSuchFile:
2465
2431
            return _mod_revision.NULL_REVISION
2466
2432
 
2655
2621
        branch = a_bzrdir.open_branch()
2656
2622
        if revision_id is None:
2657
2623
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2658
 
        else:
2659
 
            revision_id = osutils.safe_revision_id(revision_id)
2660
2624
        branch.lock_write()
2661
2625
        try:
2662
2626
            branch.generate_revision_history(revision_id)
2755
2719
        branch = a_bzrdir.open_branch()
2756
2720
        if revision_id is None:
2757
2721
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2758
 
        else:
2759
 
            revision_id = osutils.safe_revision_id(revision_id)
2760
2722
        # WorkingTree3 can handle an inventory which has a unique root id.
2761
2723
        # as of bzr 0.12. However, bzr 0.11 and earlier fail to handle
2762
2724
        # those trees. And because there isn't a format bump inbetween, we