~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

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
 
25
27
from cStringIO import StringIO
26
28
import os
27
29
import sys
34
36
from bzrlib import (
35
37
    bzrdir,
36
38
    cache_utf8,
 
39
    config,
37
40
    conflicts as _mod_conflicts,
38
41
    debug,
39
42
    dirstate,
70
73
from bzrlib.workingtree import (
71
74
    InventoryWorkingTree,
72
75
    WorkingTree,
73
 
    WorkingTreeFormat,
 
76
    WorkingTreeFormatMetaDir,
74
77
    )
75
78
 
76
79
 
77
80
class DirStateWorkingTree(InventoryWorkingTree):
78
81
 
79
 
    _DEFAULT_WORTH_SAVING_LIMIT = 10
80
 
 
81
82
    def __init__(self, basedir,
82
83
                 branch,
83
84
                 _control_files=None,
251
252
 
252
253
        :return: an integer. -1 means never save.
253
254
        """
254
 
        config = self.branch.get_config()
255
 
        val = config.get_user_option('bzr.workingtree.worth_saving_limit')
256
 
        if val is None:
257
 
            val = self._DEFAULT_WORTH_SAVING_LIMIT
258
 
        else:
259
 
            try:
260
 
                val = int(val)
261
 
            except ValueError, e:
262
 
                trace.warning('Invalid config value for'
263
 
                              ' "bzr.workingtree.worth_saving_limit"'
264
 
                              ' value %r is not an integer.'
265
 
                              % (val,))
266
 
                val = self._DEFAULT_WORTH_SAVING_LIMIT
267
 
        return val
 
255
        # FIXME: We want a WorkingTreeStack here -- vila 20110812
 
256
        conf = config.BranchStack(self.branch)
 
257
        return conf.get('bzr.workingtree.worth_saving_limit')
268
258
 
269
259
    def filter_unversioned_files(self, paths):
270
260
        """Filter out paths that are versioned.
488
478
            return False # Missing entries are not executable
489
479
        return entry[1][0][3] # Executable?
490
480
 
491
 
    if not osutils.supports_executable():
492
 
        def is_executable(self, file_id, path=None):
493
 
            """Test if a file is executable or not.
 
481
    def is_executable(self, file_id, path=None):
 
482
        """Test if a file is executable or not.
494
483
 
495
 
            Note: The caller is expected to take a read-lock before calling this.
496
 
            """
 
484
        Note: The caller is expected to take a read-lock before calling this.
 
485
        """
 
486
        if not self._supports_executable():
497
487
            entry = self._get_entry(file_id=file_id, path=path)
498
488
            if entry == (None, None):
499
489
                return False
500
490
            return entry[1][0][3]
501
 
 
502
 
        _is_executable_from_path_and_stat = \
503
 
            _is_executable_from_path_and_stat_from_basis
504
 
    else:
505
 
        def is_executable(self, file_id, path=None):
506
 
            """Test if a file is executable or not.
507
 
 
508
 
            Note: The caller is expected to take a read-lock before calling this.
509
 
            """
 
491
        else:
510
492
            self._must_be_locked()
511
493
            if not path:
512
494
                path = self.id2path(file_id)
981
963
                    all_versioned = False
982
964
                    break
983
965
            if not all_versioned:
984
 
                raise errors.PathsNotVersionedError(paths)
 
966
                raise errors.PathsNotVersionedError(
 
967
                    [p.decode('utf-8') for p in paths])
985
968
        # -- remove redundancy in supplied paths to prevent over-scanning --
986
969
        search_paths = osutils.minimum_path_selection(paths)
987
970
        # sketch:
1036
1019
            found_dir_names = set(dir_name_id[:2] for dir_name_id in found)
1037
1020
            for dir_name in split_paths:
1038
1021
                if dir_name not in found_dir_names:
1039
 
                    raise errors.PathsNotVersionedError(paths)
 
1022
                    raise errors.PathsNotVersionedError(
 
1023
                        [p.decode('utf-8') for p in paths])
1040
1024
 
1041
1025
        for dir_name_id, trees_info in found.iteritems():
1042
1026
            for index in search_indexes:
1458
1442
        return views.PathBasedViews(self)
1459
1443
 
1460
1444
 
1461
 
class DirStateWorkingTreeFormat(WorkingTreeFormat):
 
1445
class DirStateWorkingTreeFormat(WorkingTreeFormatMetaDir):
1462
1446
 
1463
1447
    missing_parent_conflicts = True
1464
1448
 
 
1449
    supports_versioned_directories = True
 
1450
 
1465
1451
    _lock_class = LockDir
1466
1452
    _lock_file_name = 'lock'
1467
1453
 
1492
1478
        control_files = self._open_control_files(a_bzrdir)
1493
1479
        control_files.create_lock()
1494
1480
        control_files.lock_write()
1495
 
        transport.put_bytes('format', self.get_format_string(),
 
1481
        transport.put_bytes('format', self.as_string(),
1496
1482
            mode=a_bzrdir._get_file_mode())
1497
1483
        if from_branch is not None:
1498
1484
            branch = from_branch
1618
1604
    This format:
1619
1605
        - exists within a metadir controlling .bzr
1620
1606
        - includes an explicit version marker for the workingtree control
1621
 
          files, separate from the BzrDir format
 
1607
          files, separate from the ControlDir format
1622
1608
        - modifies the hash cache format
1623
1609
        - is new in bzr 0.15
1624
1610
        - uses a LockDir to guard access to it.
1628
1614
 
1629
1615
    _tree_class = WorkingTree4
1630
1616
 
1631
 
    def get_format_string(self):
 
1617
    @classmethod
 
1618
    def get_format_string(cls):
1632
1619
        """See WorkingTreeFormat.get_format_string()."""
1633
1620
        return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1634
1621
 
1645
1632
 
1646
1633
    _tree_class = WorkingTree5
1647
1634
 
1648
 
    def get_format_string(self):
 
1635
    @classmethod
 
1636
    def get_format_string(cls):
1649
1637
        """See WorkingTreeFormat.get_format_string()."""
1650
1638
        return "Bazaar Working Tree Format 5 (bzr 1.11)\n"
1651
1639
 
1665
1653
 
1666
1654
    _tree_class = WorkingTree6
1667
1655
 
1668
 
    def get_format_string(self):
 
1656
    @classmethod
 
1657
    def get_format_string(cls):
1669
1658
        """See WorkingTreeFormat.get_format_string()."""
1670
1659
        return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
1671
1660
 
1713
1702
        annotations = self._repository.texts.annotate(text_key)
1714
1703
        return [(key[-1], line) for (key, line) in annotations]
1715
1704
 
1716
 
    def _get_ancestors(self, default_revision):
1717
 
        return set(self._repository.get_ancestry(self._revision_id,
1718
 
                                                 topo_sorted=False))
1719
1705
    def _comparison_data(self, entry, path):
1720
1706
        """See Tree._comparison_data."""
1721
1707
        if entry is None:
1862
1848
        # Make sure the file exists
1863
1849
        entry = self._get_entry(file_id, path=path)
1864
1850
        if entry == (None, None): # do we raise?
1865
 
            return None
 
1851
            raise errors.NoSuchId(self, file_id)
1866
1852
        parent_index = self._get_parent_index()
1867
1853
        last_changed_revision = entry[1][parent_index][4]
1868
1854
        try:
2187
2173
                path_entries = state._entries_for_path(path)
2188
2174
                if not path_entries:
2189
2175
                    # this specified path is not present at all: error
2190
 
                    not_versioned.append(path)
 
2176
                    not_versioned.append(path.decode('utf-8'))
2191
2177
                    continue
2192
2178
                found_versioned = False
2193
2179
                # for each id at this path
2201
2187
                if not found_versioned:
2202
2188
                    # none of the indexes was not 'absent' at all ids for this
2203
2189
                    # path.
2204
 
                    not_versioned.append(path)
 
2190
                    not_versioned.append(path.decode('utf-8'))
2205
2191
            if len(not_versioned) > 0:
2206
2192
                raise errors.PathsNotVersionedError(not_versioned)
2207
2193
        # -- remove redundancy in supplied specific_files to prevent over-scanning --
2274
2260
    def update_format(self, tree):
2275
2261
        """Change the format marker."""
2276
2262
        tree._transport.put_bytes('format',
2277
 
            self.target_format.get_format_string(),
 
2263
            self.target_format.as_string(),
2278
2264
            mode=tree.bzrdir._get_file_mode())
2279
2265
 
2280
2266
 
2297
2283
    def update_format(self, tree):
2298
2284
        """Change the format marker."""
2299
2285
        tree._transport.put_bytes('format',
2300
 
            self.target_format.get_format_string(),
 
2286
            self.target_format.as_string(),
2301
2287
            mode=tree.bzrdir._get_file_mode())
2302
2288
 
2303
2289
 
2326
2312
    def update_format(self, tree):
2327
2313
        """Change the format marker."""
2328
2314
        tree._transport.put_bytes('format',
2329
 
            self.target_format.get_format_string(),
 
2315
            self.target_format.as_string(),
2330
2316
            mode=tree.bzrdir._get_file_mode())