/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

Merge bzr.dev.

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
 
702
689
        if updated:
703
690
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
704
691
 
 
692
    def path_content_summary(self, path, _lstat=osutils.lstat,
 
693
        _mapper=osutils.file_kind_from_stat_mode):
 
694
        """See Tree.path_content_summary."""
 
695
        abspath = self.abspath(path)
 
696
        try:
 
697
            stat_result = _lstat(abspath)
 
698
        except OSError, e:
 
699
            if getattr(e, 'errno', None) == errno.ENOENT:
 
700
                # no file.
 
701
                return ('missing', None, None, None)
 
702
            # propagate other errors
 
703
            raise
 
704
        kind = _mapper(stat_result.st_mode)
 
705
        if kind == 'file':
 
706
            size = stat_result.st_size
 
707
            # try for a stat cache lookup
 
708
            if not supports_executable():
 
709
                executable = None # caller can decide policy.
 
710
            else:
 
711
                mode = stat_result.st_mode
 
712
                executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
 
713
            return (kind, size, executable, self._sha_from_stat(
 
714
                path, stat_result))
 
715
        elif kind == 'directory':
 
716
            # perhaps it looks like a plain directory, but it's really a
 
717
            # reference.
 
718
            if self._directory_is_tree_reference(path):
 
719
                kind = 'tree-reference'
 
720
            return kind, None, None, None
 
721
        elif kind == 'symlink':
 
722
            return ('symlink', None, None, os.readlink(abspath))
 
723
        else:
 
724
            return (kind, None, None, None)
 
725
 
705
726
    @deprecated_method(zero_eleven)
706
727
    @needs_read_lock
707
728
    def pending_merges(self):
744
765
        :param revision_ids: The revision_ids to set as the parent ids of this
745
766
            working tree. Any of these may be ghosts.
746
767
        """
747
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
748
768
        self._check_parents_for_ghosts(revision_ids,
749
769
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
750
770
        for revision_id in revision_ids:
760
780
    @needs_tree_write_lock
761
781
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
762
782
        """See MutableTree.set_parent_trees."""
763
 
        parent_ids = [osutils.safe_revision_id(rev) for (rev, tree) in parents_list]
 
783
        parent_ids = [rev for (rev, tree) in parents_list]
764
784
        for revision_id in parent_ids:
765
785
            _mod_revision.check_not_reserved_id(revision_id)
766
786
 
799
819
                yield Stanza(file_id=file_id.decode('utf8'), hash=hash)
800
820
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
801
821
 
 
822
    def _sha_from_stat(self, path, stat_result):
 
823
        """Get a sha digest from the tree's stat cache.
 
824
 
 
825
        The default implementation assumes no stat cache is present.
 
826
 
 
827
        :param path: The path.
 
828
        :param stat_result: The stat result being looked up.
 
829
        """
 
830
        return None
 
831
 
802
832
    def _put_rio(self, filename, stanzas, header):
803
833
        self._must_be_locked()
804
834
        my_file = rio_file(stanzas, header)
826
856
            merger.check_basis(check_clean=True, require_commits=False)
827
857
            if to_revision is None:
828
858
                to_revision = _mod_revision.ensure_null(branch.last_revision())
829
 
            else:
830
 
                to_revision = osutils.safe_revision_id(to_revision)
831
859
            merger.other_rev_id = to_revision
832
860
            if _mod_revision.is_null(merger.other_rev_id):
833
861
                raise errors.NoCommits(branch)
898
926
        return file_id
899
927
 
900
928
    def get_symlink_target(self, file_id):
901
 
        file_id = osutils.safe_file_id(file_id)
902
929
        return os.readlink(self.id2abspath(file_id))
903
930
 
904
931
    @needs_write_lock
943
970
            other_tree.unlock()
944
971
        other_tree.bzrdir.retire_bzrdir()
945
972
 
 
973
    def _directory_is_tree_reference(self, relpath):
 
974
        # as a special case, if a directory contains control files then 
 
975
        # it's a tree reference, except that the root of the tree is not
 
976
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
 
977
        # TODO: We could ask all the control formats whether they
 
978
        # recognize this directory, but at the moment there's no cheap api
 
979
        # to do that.  Since we probably can only nest bzr checkouts and
 
980
        # they always use this name it's ok for now.  -- mbp 20060306
 
981
        #
 
982
        # FIXME: There is an unhandled case here of a subdirectory
 
983
        # containing .bzr but not a branch; that will probably blow up
 
984
        # when you try to commit it.  It might happen if there is a
 
985
        # checkout in a subdirectory.  This can be avoided by not adding
 
986
        # it.  mbp 20070306
 
987
 
946
988
    @needs_tree_write_lock
947
989
    def extract(self, file_id, format=None):
948
990
        """Extract a subtree from this tree.
995
1037
        return wt
996
1038
 
997
1039
    def _serialize(self, inventory, out_file):
998
 
        xml5.serializer_v5.write_inventory(self._inventory, out_file)
 
1040
        xml5.serializer_v5.write_inventory(self._inventory, out_file,
 
1041
            working=True)
999
1042
 
1000
1043
    def _deserialize(selt, in_file):
1001
1044
        return xml5.serializer_v5.read_inventory(in_file)
1427
1470
        :raises: NoSuchId if any fileid is not currently versioned.
1428
1471
        """
1429
1472
        for file_id in file_ids:
1430
 
            file_id = osutils.safe_file_id(file_id)
1431
1473
            if self._inventory.has_id(file_id):
1432
1474
                self._inventory.remove_recursive_id(file_id)
1433
1475
            else:
1462
1504
 
1463
1505
    @needs_write_lock
1464
1506
    def pull(self, source, overwrite=False, stop_revision=None,
1465
 
             change_reporter=None):
 
1507
             change_reporter=None, possible_transports=None):
1466
1508
        top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1467
1509
        source.lock_read()
1468
1510
        try:
1470
1512
            pp.next_phase()
1471
1513
            old_revision_info = self.branch.last_revision_info()
1472
1514
            basis_tree = self.basis_tree()
1473
 
            count = self.branch.pull(source, overwrite, stop_revision)
 
1515
            count = self.branch.pull(source, overwrite, stop_revision,
 
1516
                                     possible_transports=possible_transports)
1474
1517
            new_revision_info = self.branch.last_revision_info()
1475
1518
            if new_revision_info != old_revision_info:
1476
1519
                pp.next_phase()
1514
1557
    @needs_write_lock
1515
1558
    def put_file_bytes_non_atomic(self, file_id, bytes):
1516
1559
        """See MutableTree.put_file_bytes_non_atomic."""
1517
 
        file_id = osutils.safe_file_id(file_id)
1518
1560
        stream = file(self.id2abspath(file_id), 'wb')
1519
1561
        try:
1520
1562
            stream.write(bytes)
1699
1741
    @needs_tree_write_lock
1700
1742
    def set_last_revision(self, new_revision):
1701
1743
        """Change the last revision in the working tree."""
1702
 
        new_revision = osutils.safe_revision_id(new_revision)
1703
1744
        if self._change_last_revision(new_revision):
1704
1745
            self._cache_basis_inventory(new_revision)
1705
1746
 
1728
1769
 
1729
1770
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1730
1771
        """Create the text that will be saved in basis-inventory"""
1731
 
        # TODO: jam 20070209 This should be redundant, as the revision_id
1732
 
        #       as all callers should have already converted the revision_id to
1733
 
        #       utf8
1734
 
        inventory.revision_id = osutils.safe_revision_id(revision_id)
 
1772
        inventory.revision_id = revision_id
1735
1773
        return xml7.serializer_v7.write_inventory_to_string(inventory)
1736
1774
 
1737
1775
    def _cache_basis_inventory(self, new_revision):
1903
1941
        self.apply_inventory_delta(inv_delta)
1904
1942
 
1905
1943
    @needs_tree_write_lock
1906
 
    def revert(self, filenames, old_tree=None, backups=True, 
 
1944
    def revert(self, filenames=None, old_tree=None, backups=True,
1907
1945
               pb=DummyProgress(), report_changes=False):
1908
1946
        from bzrlib.conflicts import resolve
 
1947
        if filenames == []:
 
1948
            filenames = None
 
1949
            symbol_versioning.warn('Using [] to revert all files is deprecated'
 
1950
                ' as of bzr 0.91.  Please use None (the default) instead.',
 
1951
                DeprecationWarning, stacklevel=2)
1909
1952
        if old_tree is None:
1910
1953
            old_tree = self.basis_tree()
1911
1954
        conflicts = transform.revert(self, old_tree, filenames, backups, pb,
1912
1955
                                     report_changes)
1913
 
        if not len(filenames):
 
1956
        if filenames is None:
1914
1957
            self.set_parent_ids(self.get_parent_ids()[:1])
1915
1958
            resolve(self)
1916
1959
        else:
2017
2060
        """
2018
2061
        raise NotImplementedError(self.unlock)
2019
2062
 
2020
 
    def update(self, change_reporter=None):
 
2063
    def update(self, change_reporter=None, possible_transports=None):
2021
2064
        """Update a working tree along its branch.
2022
2065
 
2023
2066
        This will update the branch if its bound too, which means we have
2042
2085
          basis.
2043
2086
        - Do a 'normal' merge of the old branch basis if it is relevant.
2044
2087
        """
2045
 
        if self.branch.get_master_branch() is not None:
 
2088
        if self.branch.get_master_branch(possible_transports) is not None:
2046
2089
            self.lock_write()
2047
2090
            update_branch = True
2048
2091
        else:
2050
2093
            update_branch = False
2051
2094
        try:
2052
2095
            if update_branch:
2053
 
                old_tip = self.branch.update()
 
2096
                old_tip = self.branch.update(possible_transports)
2054
2097
            else:
2055
2098
                old_tip = None
2056
2099
            return self._update_tree(old_tip, change_reporter)
2453
2496
    def _last_revision(self):
2454
2497
        """See Mutable.last_revision."""
2455
2498
        try:
2456
 
            return osutils.safe_revision_id(
2457
 
                        self._control_files.get('last-revision').read())
 
2499
            return self._control_files.get('last-revision').read()
2458
2500
        except errors.NoSuchFile:
2459
2501
            return _mod_revision.NULL_REVISION
2460
2502
 
2635
2677
        """
2636
2678
        sio = StringIO()
2637
2679
        inv = Inventory()
2638
 
        xml5.serializer_v5.write_inventory(inv, sio)
 
2680
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2639
2681
        sio.seek(0)
2640
2682
        control_files.put('inventory', sio)
2641
2683
 
2649
2691
        branch = a_bzrdir.open_branch()
2650
2692
        if revision_id is None:
2651
2693
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2652
 
        else:
2653
 
            revision_id = osutils.safe_revision_id(revision_id)
2654
2694
        branch.lock_write()
2655
2695
        try:
2656
2696
            branch.generate_revision_history(revision_id)
2749
2789
        branch = a_bzrdir.open_branch()
2750
2790
        if revision_id is None:
2751
2791
            revision_id = _mod_revision.ensure_null(branch.last_revision())
2752
 
        else:
2753
 
            revision_id = osutils.safe_revision_id(revision_id)
2754
2792
        # WorkingTree3 can handle an inventory which has a unique root id.
2755
2793
        # as of bzr 0.12. However, bzr 0.11 and earlier fail to handle
2756
2794
        # those trees. And because there isn't a format bump inbetween, we