~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-11 05:06:26 UTC
  • mto: (5050.45.2 2.2)
  • mto: This revision was merged to the branch mainline in revision 5524.
  • Revision ID: andrew.bennetts@canonical.com-20101011050626-kql01ndwvploy97a
Suppress unexpected errors during NotBranchError's call to open_repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    revisiontree,
62
62
    trace,
63
63
    transform,
 
64
    transport,
64
65
    ui,
65
66
    views,
66
67
    xml5,
67
68
    xml7,
68
69
    )
69
 
import bzrlib.branch
70
 
from bzrlib.transport import get_transport
71
70
from bzrlib.workingtree_4 import (
72
71
    WorkingTreeFormat4,
73
72
    WorkingTreeFormat5,
77
76
 
78
77
from bzrlib import symbol_versioning
79
78
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
79
from bzrlib.lock import LogicalLockResult
80
80
from bzrlib.lockable_files import LockableFiles
81
81
from bzrlib.lockdir import LockDir
82
82
import bzrlib.mutabletree
176
176
 
177
177
    It is possible for a `WorkingTree` to have a filename which is
178
178
    not listed in the Inventory and vice versa.
 
179
 
 
180
    :ivar basedir: The root of the tree on disk. This is a unicode path object
 
181
        (as opposed to a URL).
179
182
    """
180
183
 
181
184
    # override this to set the strategy for storing views
368
371
                return True, None
369
372
            else:
370
373
                return True, tree
371
 
        transport = get_transport(location)
372
 
        iterator = bzrdir.BzrDir.find_bzrdirs(transport, evaluate=evaluate,
 
374
        t = transport.get_transport(location)
 
375
        iterator = bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate,
373
376
                                              list_current=list_current)
374
 
        return [t for t in iterator if t is not None]
 
377
        return [tr for tr in iterator if tr is not None]
375
378
 
376
379
    # should be deprecated - this is slow and in any case treating them as a
377
380
    # container is (we now know) bad style -- mbp 20070302
462
465
        return (file_obj, stat_value)
463
466
 
464
467
    def get_file_text(self, file_id, path=None, filtered=True):
465
 
        return self.get_file(file_id, path=path, filtered=filtered).read()
 
468
        my_file = self.get_file(file_id, path=path, filtered=filtered)
 
469
        try:
 
470
            return my_file.read()
 
471
        finally:
 
472
            my_file.close()
466
473
 
467
474
    def get_file_byname(self, filename, filtered=True):
468
475
        path = self.abspath(filename)
522
529
 
523
530
        # Now we have the parents of this content
524
531
        annotator = self.branch.repository.texts.get_annotator()
525
 
        text = self.get_file(file_id).read()
 
532
        text = self.get_file_text(file_id)
526
533
        this_key =(file_id, default_revision)
527
534
        annotator.add_special_text(this_key, file_parent_keys, text)
528
535
        annotations = [(key[-1], line)
1202
1209
                # absolute path
1203
1210
                fap = from_dir_abspath + '/' + f
1204
1211
 
1205
 
                f_ie = inv.get_child(from_dir_id, f)
 
1212
                dir_ie = inv[from_dir_id]
 
1213
                if dir_ie.kind == 'directory':
 
1214
                    f_ie = dir_ie.children.get(f)
 
1215
                else:
 
1216
                    f_ie = None
1206
1217
                if f_ie:
1207
1218
                    c = 'V'
1208
1219
                elif self.is_ignored(fp[1:]):
1209
1220
                    c = 'I'
1210
1221
                else:
1211
 
                    # we may not have found this file, because of a unicode issue
 
1222
                    # we may not have found this file, because of a unicode
 
1223
                    # issue, or because the directory was actually a symlink.
1212
1224
                    f_norm, can_access = osutils.normalized_filename(f)
1213
1225
                    if f == f_norm or not can_access:
1214
1226
                        # No change, so treat this file normally
1802
1814
 
1803
1815
        This also locks the branch, and can be unlocked via self.unlock().
1804
1816
 
1805
 
        :return: An object with an unlock method which will release the lock
1806
 
            obtained.
 
1817
        :return: A bzrlib.lock.LogicalLockResult.
1807
1818
        """
1808
1819
        if not self.is_locked():
1809
1820
            self._reset_data()
1810
1821
        self.branch.lock_read()
1811
1822
        try:
1812
1823
            self._control_files.lock_read()
1813
 
            return self
 
1824
            return LogicalLockResult(self.unlock)
1814
1825
        except:
1815
1826
            self.branch.unlock()
1816
1827
            raise
1818
1829
    def lock_tree_write(self):
1819
1830
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1820
1831
 
1821
 
        :return: An object with an unlock method which will release the lock
1822
 
            obtained.
 
1832
        :return: A bzrlib.lock.LogicalLockResult.
1823
1833
        """
1824
1834
        if not self.is_locked():
1825
1835
            self._reset_data()
1826
1836
        self.branch.lock_read()
1827
1837
        try:
1828
1838
            self._control_files.lock_write()
1829
 
            return self
 
1839
            return LogicalLockResult(self.unlock)
1830
1840
        except:
1831
1841
            self.branch.unlock()
1832
1842
            raise
1834
1844
    def lock_write(self):
1835
1845
        """See MutableTree.lock_write, and WorkingTree.unlock.
1836
1846
 
1837
 
        :return: An object with an unlock method which will release the lock
1838
 
            obtained.
 
1847
        :return: A bzrlib.lock.LogicalLockResult.
1839
1848
        """
1840
1849
        if not self.is_locked():
1841
1850
            self._reset_data()
1842
1851
        self.branch.lock_write()
1843
1852
        try:
1844
1853
            self._control_files.lock_write()
1845
 
            return self
 
1854
            return LogicalLockResult(self.unlock)
1846
1855
        except:
1847
1856
            self.branch.unlock()
1848
1857
            raise
1973
1982
        def recurse_directory_to_add_files(directory):
1974
1983
            # Recurse directory and add all files
1975
1984
            # so we can check if they have changed.
1976
 
            for parent_info, file_infos in\
1977
 
                self.walkdirs(directory):
 
1985
            for parent_info, file_infos in self.walkdirs(directory):
1978
1986
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
1979
1987
                    # Is it versioned or ignored?
1980
1988
                    if self.path2id(relpath) or self.is_ignored(relpath):
2015
2023
                            # ... but not ignored
2016
2024
                            has_changed_files = True
2017
2025
                            break
2018
 
                    elif content_change and (kind[1] is not None):
2019
 
                        # Versioned and changed, but not deleted
 
2026
                    elif (content_change and (kind[1] is not None) and
 
2027
                            osutils.is_inside_any(files, path[1])):
 
2028
                        # Versioned and changed, but not deleted, and still
 
2029
                        # in one of the dirs to be deleted.
2020
2030
                        has_changed_files = True
2021
2031
                        break
2022
2032