~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Vincent Ladeuil
  • Date: 2011-12-16 16:38:33 UTC
  • mto: This revision was merged to the branch mainline in revision 6387.
  • Revision ID: v.ladeuil+lp@free.fr-20111216163833-4igwmwi1dmxbbebw
Migrate add.maximum_file_size to the new config scheme

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
WorkingTree.open(dir).
23
23
"""
24
24
 
25
 
from __future__ import absolute_import
26
 
 
27
25
from cStringIO import StringIO
28
26
import os
29
27
import sys
57
55
from bzrlib.lock import LogicalLockResult
58
56
from bzrlib.lockable_files import LockableFiles
59
57
from bzrlib.lockdir import LockDir
60
 
from bzrlib.mutabletree import (
61
 
    MutableTree,
62
 
    needs_tree_write_lock,
63
 
    )
 
58
from bzrlib.mutabletree import needs_tree_write_lock
64
59
from bzrlib.osutils import (
65
60
    file_kind,
66
61
    isdir,
68
63
    realpath,
69
64
    safe_unicode,
70
65
    )
71
 
from bzrlib.symbol_versioning import (
72
 
    deprecated_in,
73
 
    deprecated_method,
74
 
    )
75
66
from bzrlib.transport.local import LocalTransport
76
67
from bzrlib.tree import (
77
68
    InterTree,
259
250
 
260
251
        :return: an integer. -1 means never save.
261
252
        """
262
 
        conf = self.get_config_stack()
 
253
        # FIXME: We want a WorkingTreeStack here -- vila 20110812
 
254
        conf = config.BranchStack(self.branch)
263
255
        return conf.get('bzr.workingtree.worth_saving_limit')
264
256
 
265
257
    def filter_unversioned_files(self, paths):
418
410
                return link_or_sha1
419
411
        return None
420
412
 
421
 
    def _get_root_inventory(self):
 
413
    def _get_inventory(self):
422
414
        """Get the inventory for the tree. This is only valid within a lock."""
423
415
        if 'evil' in debug.debug_flags:
424
416
            trace.mutter_callsite(2,
429
421
        self._generate_inventory()
430
422
        return self._inventory
431
423
 
432
 
    @deprecated_method(deprecated_in((2, 5, 0)))
433
 
    def _get_inventory(self):
434
 
        return self.root_inventory
435
 
 
436
424
    inventory = property(_get_inventory,
437
425
                         doc="Inventory of this Tree")
438
426
 
439
 
    root_inventory = property(_get_root_inventory,
440
 
        "Root inventory of this tree")
441
 
 
442
427
    @needs_read_lock
443
428
    def get_parent_ids(self):
444
429
        """See Tree.get_parent_ids.
491
476
            return False # Missing entries are not executable
492
477
        return entry[1][0][3] # Executable?
493
478
 
494
 
    def is_executable(self, file_id, path=None):
495
 
        """Test if a file is executable or not.
 
479
    if not osutils.supports_executable():
 
480
        def is_executable(self, file_id, path=None):
 
481
            """Test if a file is executable or not.
496
482
 
497
 
        Note: The caller is expected to take a read-lock before calling this.
498
 
        """
499
 
        if not self._supports_executable():
 
483
            Note: The caller is expected to take a read-lock before calling this.
 
484
            """
500
485
            entry = self._get_entry(file_id=file_id, path=path)
501
486
            if entry == (None, None):
502
487
                return False
503
488
            return entry[1][0][3]
504
 
        else:
 
489
 
 
490
        _is_executable_from_path_and_stat = \
 
491
            _is_executable_from_path_and_stat_from_basis
 
492
    else:
 
493
        def is_executable(self, file_id, path=None):
 
494
            """Test if a file is executable or not.
 
495
 
 
496
            Note: The caller is expected to take a read-lock before calling this.
 
497
            """
505
498
            self._must_be_locked()
506
499
            if not path:
507
500
                path = self.id2path(file_id)
691
684
 
692
685
        if self._inventory is not None:
693
686
            update_inventory = True
694
 
            inv = self.root_inventory
 
687
            inv = self.inventory
695
688
            to_dir_id = to_entry[0][2]
696
689
            to_dir_ie = inv[to_dir_id]
697
690
        else:
1046
1039
 
1047
1040
        This is a meaningless operation for dirstate, but we obey it anyhow.
1048
1041
        """
1049
 
        return self.root_inventory
 
1042
        return self.inventory
1050
1043
 
1051
1044
    @needs_read_lock
1052
1045
    def revision_tree(self, revision_id):
1160
1153
                # _make_delta if we can't get the RevisionTree
1161
1154
                pass
1162
1155
            else:
1163
 
                delta = rev_tree.root_inventory._make_delta(
1164
 
                    basis_tree.root_inventory)
 
1156
                delta = rev_tree.inventory._make_delta(basis_tree.inventory)
1165
1157
                dirstate.update_basis_by_delta(delta, rev_id)
1166
1158
                updated = True
1167
1159
        if not updated:
1338
1330
        # being created.
1339
1331
        self._inventory = None
1340
1332
        # generate a delta,
1341
 
        delta = inv._make_delta(self.root_inventory)
 
1333
        delta = inv._make_delta(self.inventory)
1342
1334
        # and apply it.
1343
1335
        self.apply_inventory_delta(delta)
1344
1336
        if had_inventory:
1364
1356
            base_tree = trees[0][1]
1365
1357
        state = self.current_dirstate()
1366
1358
        # We don't support ghosts yet
1367
 
        state.set_state_from_scratch(base_tree.root_inventory, trees, [])
 
1359
        state.set_state_from_scratch(base_tree.inventory, trees, [])
1368
1360
 
1369
1361
 
1370
1362
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1492
1484
        control_files = self._open_control_files(a_bzrdir)
1493
1485
        control_files.create_lock()
1494
1486
        control_files.lock_write()
1495
 
        transport.put_bytes('format', self.as_string(),
 
1487
        transport.put_bytes('format', self.get_format_string(),
1496
1488
            mode=a_bzrdir._get_file_mode())
1497
1489
        if from_branch is not None:
1498
1490
            branch = from_branch
1558
1550
                transform.build_tree(basis, wt, accelerator_tree,
1559
1551
                                     hardlink=hardlink,
1560
1552
                                     delta_from_tree=delta_from_tree)
1561
 
                for hook in MutableTree.hooks['post_build_tree']:
1562
 
                    hook(wt)
1563
1553
            finally:
1564
1554
                basis.unlock()
1565
1555
        finally:
1609
1599
        """Overrideable method to get a bzrdir for testing."""
1610
1600
        # please test against something that will let us do tree references
1611
1601
        return bzrdir.format_registry.make_bzrdir(
1612
 
            'development-subtree')
 
1602
            'dirstate-with-subtree')
1613
1603
 
1614
1604
    _matchingbzrdir = property(__get_matchingbzrdir)
1615
1605
 
1883
1873
 
1884
1874
    @needs_read_lock
1885
1875
    def get_file_revision(self, file_id):
1886
 
        inv, inv_file_id = self._unpack_file_id(file_id)
1887
 
        return inv[inv_file_id].revision
 
1876
        return self.inventory[file_id].revision
1888
1877
 
1889
1878
    def get_file(self, file_id, path=None):
1890
1879
        return StringIO(self.get_file_text(file_id))
1891
1880
 
1892
1881
    def get_file_size(self, file_id):
1893
1882
        """See Tree.get_file_size"""
1894
 
        inv, inv_file_id = self._unpack_file_id(file_id)
1895
 
        return inv[inv_file_id].text_size
 
1883
        return self.inventory[file_id].text_size
1896
1884
 
1897
1885
    def get_file_text(self, file_id, path=None):
1898
1886
        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
1899
1887
        return ''.join(content)
1900
1888
 
1901
1889
    def get_reference_revision(self, file_id, path=None):
1902
 
        inv, inv_file_id = self._unpack_file_id(file_id)
1903
 
        return inv[inv_file_id].reference_revision
 
1890
        return self.inventory[file_id].reference_revision
1904
1891
 
1905
1892
    def iter_files_bytes(self, desired_files):
1906
1893
        """See Tree.iter_files_bytes.
1930
1917
        """Return the revision id for this tree."""
1931
1918
        return self._revision_id
1932
1919
 
1933
 
    def _get_root_inventory(self):
 
1920
    def _get_inventory(self):
1934
1921
        if self._inventory is not None:
1935
1922
            return self._inventory
1936
1923
        self._must_be_locked()
1937
1924
        self._generate_inventory()
1938
1925
        return self._inventory
1939
1926
 
1940
 
    root_inventory = property(_get_root_inventory,
1941
 
                         doc="Inventory of this Tree")
1942
 
 
1943
 
    @deprecated_method(deprecated_in((2, 5, 0)))
1944
 
    def _get_inventory(self):
1945
 
        return self.root_inventory
1946
 
 
1947
1927
    inventory = property(_get_inventory,
1948
1928
                         doc="Inventory of this Tree")
1949
1929
 
1967
1947
 
1968
1948
    def path_content_summary(self, path):
1969
1949
        """See Tree.path_content_summary."""
1970
 
        inv, inv_file_id = self._path2inv_file_id(path)
1971
 
        if inv_file_id is None:
 
1950
        id = self.inventory.path2id(path)
 
1951
        if id is None:
1972
1952
            return ('missing', None, None, None)
1973
 
        entry = inv[inv_file_id]
 
1953
        entry = self._inventory[id]
1974
1954
        kind = entry.kind
1975
1955
        if kind == 'file':
1976
1956
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
1980
1960
            return (kind, None, None, None)
1981
1961
 
1982
1962
    def is_executable(self, file_id, path=None):
1983
 
        inv, inv_file_id = self._unpack_file_id(file_id)
1984
 
        ie = inv[inv_file_id]
 
1963
        ie = self.inventory[file_id]
1985
1964
        if ie.kind != "file":
1986
1965
            return False
1987
1966
        return ie.executable
1992
1971
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1993
1972
        # We use a standard implementation, because DirStateRevisionTree is
1994
1973
        # dealing with one of the parents of the current state
 
1974
        inv = self._get_inventory()
1995
1975
        if from_dir is None:
1996
 
            inv = self.root_inventory
1997
1976
            from_dir_id = None
1998
1977
        else:
1999
 
            inv, from_dir_id = self._path2inv_file_id(from_dir)
 
1978
            from_dir_id = inv.path2id(from_dir)
2000
1979
            if from_dir_id is None:
2001
1980
                # Directory not versioned
2002
1981
                return
2003
 
        # FIXME: Support nested trees
2004
1982
        entries = inv.iter_entries(from_dir=from_dir_id, recursive=recursive)
2005
1983
        if inv.root is not None and not include_root and from_dir is None:
2006
1984
            entries.next()
2056
2034
        # So for now, we just build up the parent inventory, and extract
2057
2035
        # it the same way RevisionTree does.
2058
2036
        _directory = 'directory'
2059
 
        inv = self._get_root_inventory()
 
2037
        inv = self._get_inventory()
2060
2038
        top_id = inv.path2id(prefix)
2061
2039
        if top_id is None:
2062
2040
            pending = []
2288
2266
    def update_format(self, tree):
2289
2267
        """Change the format marker."""
2290
2268
        tree._transport.put_bytes('format',
2291
 
            self.target_format.as_string(),
 
2269
            self.target_format.get_format_string(),
2292
2270
            mode=tree.bzrdir._get_file_mode())
2293
2271
 
2294
2272
 
2311
2289
    def update_format(self, tree):
2312
2290
        """Change the format marker."""
2313
2291
        tree._transport.put_bytes('format',
2314
 
            self.target_format.as_string(),
 
2292
            self.target_format.get_format_string(),
2315
2293
            mode=tree.bzrdir._get_file_mode())
2316
2294
 
2317
2295
 
2340
2318
    def update_format(self, tree):
2341
2319
        """Change the format marker."""
2342
2320
        tree._transport.put_bytes('format',
2343
 
            self.target_format.as_string(),
 
2321
            self.target_format.get_format_string(),
2344
2322
            mode=tree.bzrdir._get_file_mode())