/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: 2009-06-05 23:21:51 UTC
  • mfrom: (4415 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4416.
  • Revision ID: mbp@sourcefrog.net-20090605232151-luwmyyl95siraqyz
merge 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., 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):
442
 
        """See MutableTree.get_file_with_stat."""
 
447
    def get_file_with_stat(self, file_id, path=None, filtered=True,
 
448
        _fstat=os.fstat):
 
449
        """See Tree.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, os.readlink(abspath.encode(osutils._fs_enc)))
 
752
            target = osutils.readlink(abspath)
 
753
            return ('symlink', None, None, target)
733
754
        else:
734
755
            return (kind, None, None, None)
735
756
 
748
769
    def _set_merges_from_parent_ids(self, parent_ids):
749
770
        merges = parent_ids[1:]
750
771
        self._transport.put_bytes('pending-merges', '\n'.join(merges),
751
 
            mode=self._control_files._file_mode)
 
772
            mode=self.bzrdir._get_file_mode())
752
773
 
753
774
    def _filter_parent_ids_by_ancestry(self, revision_ids):
754
775
        """Check that all merged revisions are proper 'heads'.
854
875
        self._must_be_locked()
855
876
        my_file = rio_file(stanzas, header)
856
877
        self._transport.put_file(filename, my_file,
857
 
            mode=self._control_files._file_mode)
 
878
            mode=self.bzrdir._get_file_mode())
858
879
 
859
880
    @needs_write_lock # because merge pulls data into the branch.
860
881
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
951
972
        return file_id
952
973
 
953
974
    def get_symlink_target(self, file_id):
954
 
        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
955
978
 
956
979
    @needs_write_lock
957
980
    def subsume(self, other_tree):
1086
1109
        self._serialize(self._inventory, sio)
1087
1110
        sio.seek(0)
1088
1111
        self._transport.put_file('inventory', sio,
1089
 
            mode=self._control_files._file_mode)
 
1112
            mode=self.bzrdir._get_file_mode())
1090
1113
        self._inventory_is_modified = False
1091
1114
 
1092
1115
    def _kind(self, relpath):
1509
1532
        :raises: NoSuchId if any fileid is not currently versioned.
1510
1533
        """
1511
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:
1512
1538
            if self._inventory.has_id(file_id):
1513
1539
                self._inventory.remove_recursive_id(file_id)
1514
 
            else:
1515
 
                raise errors.NoSuchId(self, file_id)
1516
1540
        if len(file_ids):
1517
1541
            # in the future this should just set a dirty bit to wait for the
1518
1542
            # final unlock. However, until all methods of workingtree start
1537
1561
 
1538
1562
    @needs_write_lock
1539
1563
    def pull(self, source, overwrite=False, stop_revision=None,
1540
 
             change_reporter=None, possible_transports=None):
 
1564
             change_reporter=None, possible_transports=None, local=False):
1541
1565
        top_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1542
1566
        source.lock_read()
1543
1567
        try:
1546
1570
            old_revision_info = self.branch.last_revision_info()
1547
1571
            basis_tree = self.basis_tree()
1548
1572
            count = self.branch.pull(source, overwrite, stop_revision,
1549
 
                                     possible_transports=possible_transports)
 
1573
                                     possible_transports=possible_transports,
 
1574
                                     local=local)
1550
1575
            new_revision_info = self.branch.last_revision_info()
1551
1576
            if new_revision_info != old_revision_info:
1552
1577
                pp.next_phase()
1617
1642
 
1618
1643
            fl = []
1619
1644
            for subf in os.listdir(dirabs):
1620
 
                if subf == '.bzr':
 
1645
                if self.bzrdir.is_control_filename(subf):
1621
1646
                    continue
1622
1647
                if subf not in dir_entry.children:
1623
1648
                    try:
1809
1834
        path = self._basis_inventory_name()
1810
1835
        sio = StringIO(xml)
1811
1836
        self._transport.put_file(path, sio,
1812
 
            mode=self._control_files._file_mode)
 
1837
            mode=self.bzrdir._get_file_mode())
1813
1838
 
1814
1839
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1815
1840
        """Create the text that will be saved in basis-inventory"""
1943
1968
                        tree_delta.unversioned.extend((unknown_file,))
1944
1969
                raise errors.BzrRemoveChangedFilesError(tree_delta)
1945
1970
 
1946
 
        # Build inv_delta and delete files where applicaple,
 
1971
        # Build inv_delta and delete files where applicable,
1947
1972
        # do this before any modifications to inventory.
1948
1973
        for f in files:
1949
1974
            fid = self.path2id(f)
2200
2225
            parent_trees = [(self.branch.last_revision(), to_tree)]
2201
2226
            merges = self.get_parent_ids()[1:]
2202
2227
            # Ideally we ask the tree for the trees here, that way the working
2203
 
            # 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
2204
2229
            # lazy initialised tree. dirstate for instance will have the trees
2205
2230
            # in ram already, whereas a last-revision + basis-inventory tree
2206
2231
            # will not, but also does not need them when setting parents.
2349
2374
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
2350
2375
                        ('.bzr', '.bzr'))
2351
2376
                    if (bzrdir_loc < len(cur_disk_dir_content)
2352
 
                        and cur_disk_dir_content[bzrdir_loc][0] == '.bzr'):
 
2377
                        and self.bzrdir.is_control_filename(
 
2378
                            cur_disk_dir_content[bzrdir_loc][0])):
2353
2379
                        # we dont yield the contents of, or, .bzr itself.
2354
2380
                        del cur_disk_dir_content[bzrdir_loc]
2355
2381
            if inv_finished:
2605
2631
            return False
2606
2632
        else:
2607
2633
            self._transport.put_bytes('last-revision', revision_id,
2608
 
                mode=self._control_files._file_mode)
 
2634
                mode=self.bzrdir._get_file_mode())
2609
2635
            return True
2610
2636
 
2611
2637
    @needs_tree_write_lock
2886
2912
        control_files.create_lock()
2887
2913
        control_files.lock_write()
2888
2914
        transport.put_bytes('format', self.get_format_string(),
2889
 
            mode=control_files._file_mode)
 
2915
            mode=a_bzrdir._get_file_mode())
2890
2916
        if from_branch is not None:
2891
2917
            branch = from_branch
2892
2918
        else:
2962
2988
 
2963
2989
__default_format = WorkingTreeFormat4()
2964
2990
WorkingTreeFormat.register_format(__default_format)
 
2991
WorkingTreeFormat.register_format(WorkingTreeFormat6())
2965
2992
WorkingTreeFormat.register_format(WorkingTreeFormat5())
2966
2993
WorkingTreeFormat.register_format(WorkingTreeFormat3())
2967
2994
WorkingTreeFormat.set_default_format(__default_format)