~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

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
"""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 (
84
 
    WorkingTreeFormat4,
85
 
    WorkingTreeFormat5,
86
 
    WorkingTreeFormat6,
87
 
    )
 
83
from bzrlib.workingtree_4 import WorkingTreeFormat4, WorkingTreeFormat5
88
84
""")
89
85
 
90
86
from bzrlib import symbol_versioning
107
103
    splitpath,
108
104
    supports_executable,
109
105
    )
110
 
from bzrlib.filters import filtered_input_file
111
106
from bzrlib.trace import mutter, note
112
107
from bzrlib.transport.local import LocalTransport
113
108
from bzrlib.progress import DummyProgress, ProgressPhase
235
230
        wt_trans = self.bzrdir.get_workingtree_transport(None)
236
231
        cache_filename = wt_trans.local_abspath('stat-cache')
237
232
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
238
 
            self.bzrdir._get_file_mode(),
239
 
            self._content_filter_stack_provider())
 
233
            self.bzrdir._get_file_mode())
240
234
        hc = self._hashcache
241
235
        hc.read()
242
236
        # is this scan needed ? it makes things kinda slow.
419
413
            return self.branch.repository.revision_tree(revision_id)
420
414
        except (errors.RevisionNotPresent, errors.NoSuchRevision):
421
415
            # the basis tree *may* be a ghost or a low level error may have
422
 
            # occurred. If the revision is present, its a problem, if its not
 
416
            # occured. If the revision is present, its a problem, if its not
423
417
            # its a ghost.
424
418
            if self.branch.repository.has_revision(revision_id):
425
419
                raise
441
435
    def has_filename(self, filename):
442
436
        return osutils.lexists(self.abspath(filename))
443
437
 
444
 
    def get_file(self, file_id, path=None, filtered=True):
445
 
        return self.get_file_with_stat(file_id, path, filtered=filtered)[0]
 
438
    def get_file(self, file_id, path=None):
 
439
        return self.get_file_with_stat(file_id, path)[0]
446
440
 
447
 
    def get_file_with_stat(self, file_id, path=None, filtered=True,
448
 
        _fstat=os.fstat):
 
441
    def get_file_with_stat(self, file_id, path=None, _fstat=os.fstat):
449
442
        """See MutableTree.get_file_with_stat."""
450
443
        if path is None:
451
444
            path = self.id2path(file_id)
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):
 
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):
472
452
        """See Tree.get_file_lines()"""
473
 
        file = self.get_file(file_id, path, filtered=filtered)
 
453
        file = self.get_file(file_id, path)
474
454
        try:
475
455
            return file.readlines()
476
456
        finally:
561
541
 
562
542
        revision
563
543
            If not None, the cloned tree will have its last revision set to
564
 
            revision, and difference between the source trees last revision
 
544
            revision, and and difference between the source trees last revision
565
545
            and this one merged in.
566
546
        """
567
547
        # assumes the target bzr dir format is compatible.
749
729
                kind = 'tree-reference'
750
730
            return kind, None, None, None
751
731
        elif kind == 'symlink':
752
 
            return ('symlink', None, None,
753
 
                    os.readlink(abspath.encode(osutils._fs_enc)
754
 
                                ).decode(osutils._fs_enc))
 
732
            return ('symlink', None, None, os.readlink(abspath.encode(osutils._fs_enc)))
755
733
        else:
756
734
            return (kind, None, None, None)
757
735
 
770
748
    def _set_merges_from_parent_ids(self, parent_ids):
771
749
        merges = parent_ids[1:]
772
750
        self._transport.put_bytes('pending-merges', '\n'.join(merges),
773
 
            mode=self.bzrdir._get_file_mode())
 
751
            mode=self._control_files._file_mode)
774
752
 
775
753
    def _filter_parent_ids_by_ancestry(self, revision_ids):
776
754
        """Check that all merged revisions are proper 'heads'.
876
854
        self._must_be_locked()
877
855
        my_file = rio_file(stanzas, header)
878
856
        self._transport.put_file(filename, my_file,
879
 
            mode=self.bzrdir._get_file_mode())
 
857
            mode=self._control_files._file_mode)
880
858
 
881
859
    @needs_write_lock # because merge pulls data into the branch.
882
860
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
973
951
        return file_id
974
952
 
975
953
    def get_symlink_target(self, file_id):
976
 
        return os.readlink(self.id2abspath(file_id).encode(osutils._fs_enc)
977
 
            ).decode(osutils._fs_enc)
 
954
        return os.readlink(self.id2abspath(file_id).encode(osutils._fs_enc))
978
955
 
979
956
    @needs_write_lock
980
957
    def subsume(self, other_tree):
1109
1086
        self._serialize(self._inventory, sio)
1110
1087
        sio.seek(0)
1111
1088
        self._transport.put_file('inventory', sio,
1112
 
            mode=self.bzrdir._get_file_mode())
 
1089
            mode=self._control_files._file_mode)
1113
1090
        self._inventory_is_modified = False
1114
1091
 
1115
1092
    def _kind(self, relpath):
1532
1509
        :raises: NoSuchId if any fileid is not currently versioned.
1533
1510
        """
1534
1511
        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:
1538
1512
            if self._inventory.has_id(file_id):
1539
1513
                self._inventory.remove_recursive_id(file_id)
 
1514
            else:
 
1515
                raise errors.NoSuchId(self, file_id)
1540
1516
        if len(file_ids):
1541
1517
            # in the future this should just set a dirty bit to wait for the
1542
1518
            # final unlock. However, until all methods of workingtree start
1833
1809
        path = self._basis_inventory_name()
1834
1810
        sio = StringIO(xml)
1835
1811
        self._transport.put_file(path, sio,
1836
 
            mode=self.bzrdir._get_file_mode())
 
1812
            mode=self._control_files._file_mode)
1837
1813
 
1838
1814
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1839
1815
        """Create the text that will be saved in basis-inventory"""
1967
1943
                        tree_delta.unversioned.extend((unknown_file,))
1968
1944
                raise errors.BzrRemoveChangedFilesError(tree_delta)
1969
1945
 
1970
 
        # Build inv_delta and delete files where applicable,
 
1946
        # Build inv_delta and delete files where applicaple,
1971
1947
        # do this before any modifications to inventory.
1972
1948
        for f in files:
1973
1949
            fid = self.path2id(f)
2224
2200
            parent_trees = [(self.branch.last_revision(), to_tree)]
2225
2201
            merges = self.get_parent_ids()[1:]
2226
2202
            # Ideally we ask the tree for the trees here, that way the working
2227
 
            # tree can decide whether to give us the entire tree or give us a
 
2203
            # tree can decide whether to give us teh entire tree or give us a
2228
2204
            # lazy initialised tree. dirstate for instance will have the trees
2229
2205
            # in ram already, whereas a last-revision + basis-inventory tree
2230
2206
            # will not, but also does not need them when setting parents.
2629
2605
            return False
2630
2606
        else:
2631
2607
            self._transport.put_bytes('last-revision', revision_id,
2632
 
                mode=self.bzrdir._get_file_mode())
 
2608
                mode=self._control_files._file_mode)
2633
2609
            return True
2634
2610
 
2635
2611
    @needs_tree_write_lock
2910
2886
        control_files.create_lock()
2911
2887
        control_files.lock_write()
2912
2888
        transport.put_bytes('format', self.get_format_string(),
2913
 
            mode=a_bzrdir._get_file_mode())
 
2889
            mode=control_files._file_mode)
2914
2890
        if from_branch is not None:
2915
2891
            branch = from_branch
2916
2892
        else:
2986
2962
 
2987
2963
__default_format = WorkingTreeFormat4()
2988
2964
WorkingTreeFormat.register_format(__default_format)
2989
 
WorkingTreeFormat.register_format(WorkingTreeFormat6())
2990
2965
WorkingTreeFormat.register_format(WorkingTreeFormat5())
2991
2966
WorkingTreeFormat.register_format(WorkingTreeFormat3())
2992
2967
WorkingTreeFormat.set_default_format(__default_format)