/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: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

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., 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
"""WorkingTree object and friends.
18
18
 
80
80
import bzrlib.branch
81
81
from bzrlib.transport import get_transport
82
82
import bzrlib.ui
83
 
from bzrlib.workingtree_4 import WorkingTreeFormat4, WorkingTreeFormat5
 
83
from bzrlib.workingtree_4 import (
 
84
    WorkingTreeFormat4,
 
85
    WorkingTreeFormat5,
 
86
    WorkingTreeFormat6,
 
87
    )
84
88
""")
85
89
 
86
90
from bzrlib import symbol_versioning
103
107
    splitpath,
104
108
    supports_executable,
105
109
    )
 
110
from bzrlib.filters import filtered_input_file
106
111
from bzrlib.trace import mutter, note
107
112
from bzrlib.transport.local import LocalTransport
108
113
from bzrlib.progress import DummyProgress, ProgressPhase
230
235
        wt_trans = self.bzrdir.get_workingtree_transport(None)
231
236
        cache_filename = wt_trans.local_abspath('stat-cache')
232
237
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
233
 
            self.bzrdir._get_file_mode())
 
238
            self.bzrdir._get_file_mode(),
 
239
            self._content_filter_stack_provider())
234
240
        hc = self._hashcache
235
241
        hc.read()
236
242
        # is this scan needed ? it makes things kinda slow.
413
419
            return self.branch.repository.revision_tree(revision_id)
414
420
        except (errors.RevisionNotPresent, errors.NoSuchRevision):
415
421
            # the basis tree *may* be a ghost or a low level error may have
416
 
            # occured. If the revision is present, its a problem, if its not
 
422
            # occurred. If the revision is present, its a problem, if its not
417
423
            # its a ghost.
418
424
            if self.branch.repository.has_revision(revision_id):
419
425
                raise
435
441
    def has_filename(self, filename):
436
442
        return osutils.lexists(self.abspath(filename))
437
443
 
438
 
    def get_file(self, file_id, path=None):
439
 
        return self.get_file_with_stat(file_id, path)[0]
 
444
    def get_file(self, file_id, path=None, filtered=True):
 
445
        return self.get_file_with_stat(file_id, path, filtered=filtered)[0]
440
446
 
441
 
    def get_file_with_stat(self, file_id, path=None, _fstat=os.fstat):
 
447
    def get_file_with_stat(self, file_id, path=None, filtered=True,
 
448
        _fstat=os.fstat):
442
449
        """See MutableTree.get_file_with_stat."""
443
450
        if path is None:
444
451
            path = self.id2path(file_id)
445
 
        file_obj = self.get_file_byname(path)
446
 
        return (file_obj, _fstat(file_obj.fileno()))
447
 
 
448
 
    def get_file_byname(self, filename):
449
 
        return file(self.abspath(filename), 'rb')
450
 
 
451
 
    def get_file_lines(self, file_id, path=None):
 
452
        file_obj = self.get_file_byname(path, filtered=False)
 
453
        stat_value = _fstat(file_obj.fileno())
 
454
        if self.supports_content_filtering() and filtered:
 
455
            filters = self._content_filter_stack(path)
 
456
            file_obj = filtered_input_file(file_obj, filters)
 
457
        return (file_obj, stat_value)
 
458
 
 
459
    def get_file_text(self, file_id, path=None, filtered=True):
 
460
        return self.get_file(file_id, path=path, filtered=filtered).read()
 
461
 
 
462
    def get_file_byname(self, filename, filtered=True):
 
463
        path = self.abspath(filename)
 
464
        f = file(path, 'rb')
 
465
        if self.supports_content_filtering() and filtered:
 
466
            filters = self._content_filter_stack(filename)
 
467
            return filtered_input_file(f, filters)
 
468
        else:
 
469
            return f
 
470
 
 
471
    def get_file_lines(self, file_id, path=None, filtered=True):
452
472
        """See Tree.get_file_lines()"""
453
 
        file = self.get_file(file_id, path)
 
473
        file = self.get_file(file_id, path, filtered=filtered)
454
474
        try:
455
475
            return file.readlines()
456
476
        finally:
541
561
 
542
562
        revision
543
563
            If not None, the cloned tree will have its last revision set to
544
 
            revision, and and difference between the source trees last revision
 
564
            revision, and difference between the source trees last revision
545
565
            and this one merged in.
546
566
        """
547
567
        # assumes the target bzr dir format is compatible.
729
749
                kind = 'tree-reference'
730
750
            return kind, None, None, None
731
751
        elif kind == 'symlink':
732
 
            return ('symlink', None, None,
733
 
                    os.readlink(abspath.encode(osutils._fs_enc)
734
 
                                ).decode(osutils._fs_enc))
 
752
            target = osutils.readlink(abspath)
 
753
            return ('symlink', None, None, target)
735
754
        else:
736
755
            return (kind, None, None, None)
737
756
 
750
769
    def _set_merges_from_parent_ids(self, parent_ids):
751
770
        merges = parent_ids[1:]
752
771
        self._transport.put_bytes('pending-merges', '\n'.join(merges),
753
 
            mode=self._control_files._file_mode)
 
772
            mode=self.bzrdir._get_file_mode())
754
773
 
755
774
    def _filter_parent_ids_by_ancestry(self, revision_ids):
756
775
        """Check that all merged revisions are proper 'heads'.
856
875
        self._must_be_locked()
857
876
        my_file = rio_file(stanzas, header)
858
877
        self._transport.put_file(filename, my_file,
859
 
            mode=self._control_files._file_mode)
 
878
            mode=self.bzrdir._get_file_mode())
860
879
 
861
880
    @needs_write_lock # because merge pulls data into the branch.
862
881
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
953
972
        return file_id
954
973
 
955
974
    def get_symlink_target(self, file_id):
956
 
        return os.readlink(self.id2abspath(file_id).encode(osutils._fs_enc))
 
975
        abspath = self.id2abspath(file_id)
 
976
        target = osutils.readlink(abspath)
 
977
        return target
957
978
 
958
979
    @needs_write_lock
959
980
    def subsume(self, other_tree):
1088
1109
        self._serialize(self._inventory, sio)
1089
1110
        sio.seek(0)
1090
1111
        self._transport.put_file('inventory', sio,
1091
 
            mode=self._control_files._file_mode)
 
1112
            mode=self.bzrdir._get_file_mode())
1092
1113
        self._inventory_is_modified = False
1093
1114
 
1094
1115
    def _kind(self, relpath):
1511
1532
        :raises: NoSuchId if any fileid is not currently versioned.
1512
1533
        """
1513
1534
        for file_id in file_ids:
 
1535
            if file_id not in self._inventory:
 
1536
                raise errors.NoSuchId(self, file_id)
 
1537
        for file_id in file_ids:
1514
1538
            if self._inventory.has_id(file_id):
1515
1539
                self._inventory.remove_recursive_id(file_id)
1516
 
            else:
1517
 
                raise errors.NoSuchId(self, file_id)
1518
1540
        if len(file_ids):
1519
1541
            # in the future this should just set a dirty bit to wait for the
1520
1542
            # final unlock. However, until all methods of workingtree start
1539
1561
 
1540
1562
    @needs_write_lock
1541
1563
    def pull(self, source, overwrite=False, stop_revision=None,
1542
 
             change_reporter=None, possible_transports=None):
 
1564
             change_reporter=None, possible_transports=None, local=False):
1543
1565
        top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1544
1566
        source.lock_read()
1545
1567
        try:
1548
1570
            old_revision_info = self.branch.last_revision_info()
1549
1571
            basis_tree = self.basis_tree()
1550
1572
            count = self.branch.pull(source, overwrite, stop_revision,
1551
 
                                     possible_transports=possible_transports)
 
1573
                                     possible_transports=possible_transports,
 
1574
                                     local=local)
1552
1575
            new_revision_info = self.branch.last_revision_info()
1553
1576
            if new_revision_info != old_revision_info:
1554
1577
                pp.next_phase()
1619
1642
 
1620
1643
            fl = []
1621
1644
            for subf in os.listdir(dirabs):
1622
 
                if subf == '.bzr':
 
1645
                if self.bzrdir.is_control_filename(subf):
1623
1646
                    continue
1624
1647
                if subf not in dir_entry.children:
1625
1648
                    try:
1811
1834
        path = self._basis_inventory_name()
1812
1835
        sio = StringIO(xml)
1813
1836
        self._transport.put_file(path, sio,
1814
 
            mode=self._control_files._file_mode)
 
1837
            mode=self.bzrdir._get_file_mode())
1815
1838
 
1816
1839
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1817
1840
        """Create the text that will be saved in basis-inventory"""
1945
1968
                        tree_delta.unversioned.extend((unknown_file,))
1946
1969
                raise errors.BzrRemoveChangedFilesError(tree_delta)
1947
1970
 
1948
 
        # Build inv_delta and delete files where applicaple,
 
1971
        # Build inv_delta and delete files where applicable,
1949
1972
        # do this before any modifications to inventory.
1950
1973
        for f in files:
1951
1974
            fid = self.path2id(f)
2202
2225
            parent_trees = [(self.branch.last_revision(), to_tree)]
2203
2226
            merges = self.get_parent_ids()[1:]
2204
2227
            # Ideally we ask the tree for the trees here, that way the working
2205
 
            # tree can decide whether to give us teh entire tree or give us a
 
2228
            # tree can decide whether to give us the entire tree or give us a
2206
2229
            # lazy initialised tree. dirstate for instance will have the trees
2207
2230
            # in ram already, whereas a last-revision + basis-inventory tree
2208
2231
            # will not, but also does not need them when setting parents.
2351
2374
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
2352
2375
                        ('.bzr', '.bzr'))
2353
2376
                    if (bzrdir_loc < len(cur_disk_dir_content)
2354
 
                        and cur_disk_dir_content[bzrdir_loc][0] == '.bzr'):
 
2377
                        and self.bzrdir.is_control_filename(
 
2378
                            cur_disk_dir_content[bzrdir_loc][0])):
2355
2379
                        # we dont yield the contents of, or, .bzr itself.
2356
2380
                        del cur_disk_dir_content[bzrdir_loc]
2357
2381
            if inv_finished:
2607
2631
            return False
2608
2632
        else:
2609
2633
            self._transport.put_bytes('last-revision', revision_id,
2610
 
                mode=self._control_files._file_mode)
 
2634
                mode=self.bzrdir._get_file_mode())
2611
2635
            return True
2612
2636
 
2613
2637
    @needs_tree_write_lock
2888
2912
        control_files.create_lock()
2889
2913
        control_files.lock_write()
2890
2914
        transport.put_bytes('format', self.get_format_string(),
2891
 
            mode=control_files._file_mode)
 
2915
            mode=a_bzrdir._get_file_mode())
2892
2916
        if from_branch is not None:
2893
2917
            branch = from_branch
2894
2918
        else:
2964
2988
 
2965
2989
__default_format = WorkingTreeFormat4()
2966
2990
WorkingTreeFormat.register_format(__default_format)
 
2991
WorkingTreeFormat.register_format(WorkingTreeFormat6())
2967
2992
WorkingTreeFormat.register_format(WorkingTreeFormat5())
2968
2993
WorkingTreeFormat.register_format(WorkingTreeFormat3())
2969
2994
WorkingTreeFormat.set_default_format(__default_format)