~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Martin Pool
  • Date: 2011-11-18 05:13:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6277.
  • Revision ID: mbp@canonical.com-20111118051319-9cj53bg5e06zl7rw
Remove more lzma related code

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,
80
71
from bzrlib.workingtree import (
81
72
    InventoryWorkingTree,
82
73
    WorkingTree,
83
 
    WorkingTreeFormatMetaDir,
 
74
    WorkingTreeFormat,
84
75
    )
85
76
 
86
77
 
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:
976
969
                    all_versioned = False
977
970
                    break
978
971
            if not all_versioned:
979
 
                raise errors.PathsNotVersionedError(
980
 
                    [p.decode('utf-8') for p in paths])
 
972
                raise errors.PathsNotVersionedError(paths)
981
973
        # -- remove redundancy in supplied paths to prevent over-scanning --
982
974
        search_paths = osutils.minimum_path_selection(paths)
983
975
        # sketch:
1032
1024
            found_dir_names = set(dir_name_id[:2] for dir_name_id in found)
1033
1025
            for dir_name in split_paths:
1034
1026
                if dir_name not in found_dir_names:
1035
 
                    raise errors.PathsNotVersionedError(
1036
 
                        [p.decode('utf-8') for p in paths])
 
1027
                    raise errors.PathsNotVersionedError(paths)
1037
1028
 
1038
1029
        for dir_name_id, trees_info in found.iteritems():
1039
1030
            for index in search_indexes:
1046
1037
 
1047
1038
        This is a meaningless operation for dirstate, but we obey it anyhow.
1048
1039
        """
1049
 
        return self.root_inventory
 
1040
        return self.inventory
1050
1041
 
1051
1042
    @needs_read_lock
1052
1043
    def revision_tree(self, revision_id):
1160
1151
                # _make_delta if we can't get the RevisionTree
1161
1152
                pass
1162
1153
            else:
1163
 
                delta = rev_tree.root_inventory._make_delta(
1164
 
                    basis_tree.root_inventory)
 
1154
                delta = rev_tree.inventory._make_delta(basis_tree.inventory)
1165
1155
                dirstate.update_basis_by_delta(delta, rev_id)
1166
1156
                updated = True
1167
1157
        if not updated:
1338
1328
        # being created.
1339
1329
        self._inventory = None
1340
1330
        # generate a delta,
1341
 
        delta = inv._make_delta(self.root_inventory)
 
1331
        delta = inv._make_delta(self.inventory)
1342
1332
        # and apply it.
1343
1333
        self.apply_inventory_delta(delta)
1344
1334
        if had_inventory:
1364
1354
            base_tree = trees[0][1]
1365
1355
        state = self.current_dirstate()
1366
1356
        # We don't support ghosts yet
1367
 
        state.set_state_from_scratch(base_tree.root_inventory, trees, [])
 
1357
        state.set_state_from_scratch(base_tree.inventory, trees, [])
1368
1358
 
1369
1359
 
1370
1360
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1456
1446
        return views.PathBasedViews(self)
1457
1447
 
1458
1448
 
1459
 
class DirStateWorkingTreeFormat(WorkingTreeFormatMetaDir):
 
1449
class DirStateWorkingTreeFormat(WorkingTreeFormat):
1460
1450
 
1461
1451
    missing_parent_conflicts = True
1462
1452
 
1492
1482
        control_files = self._open_control_files(a_bzrdir)
1493
1483
        control_files.create_lock()
1494
1484
        control_files.lock_write()
1495
 
        transport.put_bytes('format', self.as_string(),
 
1485
        transport.put_bytes('format', self.get_format_string(),
1496
1486
            mode=a_bzrdir._get_file_mode())
1497
1487
        if from_branch is not None:
1498
1488
            branch = from_branch
1558
1548
                transform.build_tree(basis, wt, accelerator_tree,
1559
1549
                                     hardlink=hardlink,
1560
1550
                                     delta_from_tree=delta_from_tree)
1561
 
                for hook in MutableTree.hooks['post_build_tree']:
1562
 
                    hook(wt)
1563
1551
            finally:
1564
1552
                basis.unlock()
1565
1553
        finally:
1609
1597
        """Overrideable method to get a bzrdir for testing."""
1610
1598
        # please test against something that will let us do tree references
1611
1599
        return bzrdir.format_registry.make_bzrdir(
1612
 
            'development-subtree')
 
1600
            'dirstate-with-subtree')
1613
1601
 
1614
1602
    _matchingbzrdir = property(__get_matchingbzrdir)
1615
1603
 
1630
1618
 
1631
1619
    _tree_class = WorkingTree4
1632
1620
 
1633
 
    @classmethod
1634
 
    def get_format_string(cls):
 
1621
    def get_format_string(self):
1635
1622
        """See WorkingTreeFormat.get_format_string()."""
1636
1623
        return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1637
1624
 
1648
1635
 
1649
1636
    _tree_class = WorkingTree5
1650
1637
 
1651
 
    @classmethod
1652
 
    def get_format_string(cls):
 
1638
    def get_format_string(self):
1653
1639
        """See WorkingTreeFormat.get_format_string()."""
1654
1640
        return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
1655
1641
 
1669
1655
 
1670
1656
    _tree_class = WorkingTree6
1671
1657
 
1672
 
    @classmethod
1673
 
    def get_format_string(cls):
 
1658
    def get_format_string(self):
1674
1659
        """See WorkingTreeFormat.get_format_string()."""
1675
1660
        return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
1676
1661
 
1883
1868
 
1884
1869
    @needs_read_lock
1885
1870
    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
 
1871
        return self.inventory[file_id].revision
1888
1872
 
1889
1873
    def get_file(self, file_id, path=None):
1890
1874
        return StringIO(self.get_file_text(file_id))
1891
1875
 
1892
1876
    def get_file_size(self, file_id):
1893
1877
        """See Tree.get_file_size"""
1894
 
        inv, inv_file_id = self._unpack_file_id(file_id)
1895
 
        return inv[inv_file_id].text_size
 
1878
        return self.inventory[file_id].text_size
1896
1879
 
1897
1880
    def get_file_text(self, file_id, path=None):
1898
1881
        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
1899
1882
        return ''.join(content)
1900
1883
 
1901
1884
    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
 
1885
        return self.inventory[file_id].reference_revision
1904
1886
 
1905
1887
    def iter_files_bytes(self, desired_files):
1906
1888
        """See Tree.iter_files_bytes.
1930
1912
        """Return the revision id for this tree."""
1931
1913
        return self._revision_id
1932
1914
 
1933
 
    def _get_root_inventory(self):
 
1915
    def _get_inventory(self):
1934
1916
        if self._inventory is not None:
1935
1917
            return self._inventory
1936
1918
        self._must_be_locked()
1937
1919
        self._generate_inventory()
1938
1920
        return self._inventory
1939
1921
 
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
1922
    inventory = property(_get_inventory,
1948
1923
                         doc="Inventory of this Tree")
1949
1924
 
1967
1942
 
1968
1943
    def path_content_summary(self, path):
1969
1944
        """See Tree.path_content_summary."""
1970
 
        inv, inv_file_id = self._path2inv_file_id(path)
1971
 
        if inv_file_id is None:
 
1945
        id = self.inventory.path2id(path)
 
1946
        if id is None:
1972
1947
            return ('missing', None, None, None)
1973
 
        entry = inv[inv_file_id]
 
1948
        entry = self._inventory[id]
1974
1949
        kind = entry.kind
1975
1950
        if kind == 'file':
1976
1951
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
1980
1955
            return (kind, None, None, None)
1981
1956
 
1982
1957
    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]
 
1958
        ie = self.inventory[file_id]
1985
1959
        if ie.kind != "file":
1986
1960
            return False
1987
1961
        return ie.executable
1992
1966
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1993
1967
        # We use a standard implementation, because DirStateRevisionTree is
1994
1968
        # dealing with one of the parents of the current state
 
1969
        inv = self._get_inventory()
1995
1970
        if from_dir is None:
1996
 
            inv = self.root_inventory
1997
1971
            from_dir_id = None
1998
1972
        else:
1999
 
            inv, from_dir_id = self._path2inv_file_id(from_dir)
 
1973
            from_dir_id = inv.path2id(from_dir)
2000
1974
            if from_dir_id is None:
2001
1975
                # Directory not versioned
2002
1976
                return
2003
 
        # FIXME: Support nested trees
2004
1977
        entries = inv.iter_entries(from_dir=from_dir_id, recursive=recursive)
2005
1978
        if inv.root is not None and not include_root and from_dir is None:
2006
1979
            entries.next()
2056
2029
        # So for now, we just build up the parent inventory, and extract
2057
2030
        # it the same way RevisionTree does.
2058
2031
        _directory = 'directory'
2059
 
        inv = self._get_root_inventory()
 
2032
        inv = self._get_inventory()
2060
2033
        top_id = inv.path2id(prefix)
2061
2034
        if top_id is None:
2062
2035
            pending = []
2201
2174
                path_entries = state._entries_for_path(path)
2202
2175
                if not path_entries:
2203
2176
                    # this specified path is not present at all: error
2204
 
                    not_versioned.append(path.decode('utf-8'))
 
2177
                    not_versioned.append(path)
2205
2178
                    continue
2206
2179
                found_versioned = False
2207
2180
                # for each id at this path
2215
2188
                if not found_versioned:
2216
2189
                    # none of the indexes was not 'absent' at all ids for this
2217
2190
                    # path.
2218
 
                    not_versioned.append(path.decode('utf-8'))
 
2191
                    not_versioned.append(path)
2219
2192
            if len(not_versioned) > 0:
2220
2193
                raise errors.PathsNotVersionedError(not_versioned)
2221
2194
        # -- remove redundancy in supplied specific_files to prevent over-scanning --
2288
2261
    def update_format(self, tree):
2289
2262
        """Change the format marker."""
2290
2263
        tree._transport.put_bytes('format',
2291
 
            self.target_format.as_string(),
 
2264
            self.target_format.get_format_string(),
2292
2265
            mode=tree.bzrdir._get_file_mode())
2293
2266
 
2294
2267
 
2311
2284
    def update_format(self, tree):
2312
2285
        """Change the format marker."""
2313
2286
        tree._transport.put_bytes('format',
2314
 
            self.target_format.as_string(),
 
2287
            self.target_format.get_format_string(),
2315
2288
            mode=tree.bzrdir._get_file_mode())
2316
2289
 
2317
2290
 
2340
2313
    def update_format(self, tree):
2341
2314
        """Change the format marker."""
2342
2315
        tree._transport.put_bytes('format',
2343
 
            self.target_format.as_string(),
 
2316
            self.target_format.get_format_string(),
2344
2317
            mode=tree.bzrdir._get_file_mode())