~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Benoît Pierre
  • Date: 2011-10-10 20:55:52 UTC
  • mto: This revision was merged to the branch mainline in revision 6215.
  • Revision ID: benoit.pierre@gmail.com-20111010205552-7o6qoaiihy31hhxb
Avoid prompt duplication for shelf_ui tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
    generate_ids,
55
55
    globbing,
56
56
    graph as _mod_graph,
57
 
    hashcache,
58
57
    ignores,
59
58
    inventory,
60
59
    merge,
72
71
 
73
72
from bzrlib import symbol_versioning
74
73
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
74
from bzrlib.i18n import gettext
75
75
from bzrlib.lock import LogicalLockResult
76
76
import bzrlib.mutabletree
77
77
from bzrlib.mutabletree import needs_tree_write_lock
194
194
        self.basedir = realpath(basedir)
195
195
        self._control_files = _control_files
196
196
        self._transport = self._control_files._transport
197
 
        # update the whole cache up front and write to disk if anything changed;
198
 
        # in the future we might want to do this more selectively
199
 
        # two possible ways offer themselves : in self._unlock, write the cache
200
 
        # if needed, or, when the cache sees a change, append it to the hash
201
 
        # cache file, and have the parser take the most recent entry for a
202
 
        # given path only.
203
 
        wt_trans = self.bzrdir.get_workingtree_transport(None)
204
 
        cache_filename = wt_trans.local_abspath('stat-cache')
205
 
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
206
 
            self.bzrdir._get_file_mode(),
207
 
            self._content_filter_stack_provider())
208
 
        hc = self._hashcache
209
 
        hc.read()
210
 
        # is this scan needed ? it makes things kinda slow.
211
 
        #hc.scan()
212
 
 
213
 
        if hc.needs_write:
214
 
            mutter("write hc")
215
 
            hc.write()
216
 
 
217
 
        self._detect_case_handling()
218
197
        self._rules_searcher = None
219
198
        self.views = self._make_views()
220
199
 
238
217
        """
239
218
        return self.bzrdir.is_control_filename(filename)
240
219
 
241
 
    def _detect_case_handling(self):
242
 
        wt_trans = self.bzrdir.get_workingtree_transport(None)
243
 
        try:
244
 
            wt_trans.stat(self._format.case_sensitive_filename)
245
 
        except errors.NoSuchFile:
246
 
            self.case_sensitive = True
247
 
        else:
248
 
            self.case_sensitive = False
249
 
 
250
 
        self._setup_directory_is_tree_reference()
251
 
 
252
220
    branch = property(
253
221
        fget=lambda self: self._branch,
254
222
        doc="""The branch this WorkingTree is connected to.
257
225
            the working tree has been constructed from.
258
226
            """)
259
227
 
 
228
    def has_versioned_directories(self):
 
229
        """See `Tree.has_versioned_directories`."""
 
230
        return self._format.supports_versioned_directories
 
231
 
260
232
    def break_lock(self):
261
233
        """Break a lock if one is present from another instance.
262
234
 
331
303
                if view_files:
332
304
                    file_list = view_files
333
305
                    view_str = views.view_display_str(view_files)
334
 
                    note("Ignoring files outside view. View is %s" % view_str)
 
306
                    note(gettext("Ignoring files outside view. View is %s") % view_str)
335
307
            return tree, file_list
336
308
        if default_directory == u'.':
337
309
            seed = file_list[0]
595
567
            else:
596
568
                return None
597
569
 
598
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
599
 
        # FIXME: Shouldn't this be in Tree?
600
 
        raise NotImplementedError(self.get_file_sha1)
601
 
 
602
570
    @needs_tree_write_lock
603
571
    def _gather_kinds(self, files, kinds):
604
572
        """See MutableTree._gather_kinds."""
1066
1034
            stream.write(bytes)
1067
1035
        finally:
1068
1036
            stream.close()
1069
 
        # TODO: update the hashcache here ?
1070
1037
 
1071
1038
    def extras(self):
1072
1039
        """Yield all unversioned files in this WorkingTree.
1532
1499
                                             show_base=show_base)
1533
1500
            if nb_conflicts:
1534
1501
                self.add_parent_tree((old_tip, other_tree))
1535
 
                note('Rerun update after fixing the conflicts.')
 
1502
                note(gettext('Rerun update after fixing the conflicts.'))
1536
1503
                return nb_conflicts
1537
1504
 
1538
1505
        if last_rev != _mod_revision.ensure_null(revision):
1580
1547
            last_rev = parent_trees[0][0]
1581
1548
        return nb_conflicts
1582
1549
 
1583
 
    def _write_hashcache_if_dirty(self):
1584
 
        """Write out the hashcache if it is dirty."""
1585
 
        if self._hashcache.needs_write:
1586
 
            try:
1587
 
                self._hashcache.write()
1588
 
            except OSError, e:
1589
 
                if e.errno not in (errno.EPERM, errno.EACCES):
1590
 
                    raise
1591
 
                # TODO: jam 20061219 Should this be a warning? A single line
1592
 
                #       warning might be sufficient to let the user know what
1593
 
                #       is going on.
1594
 
                mutter('Could not write hashcache for %s\nError: %s',
1595
 
                              self._hashcache.cache_file_name(), e)
1596
 
 
1597
1550
    def set_conflicts(self, arg):
1598
1551
        raise errors.UnsupportedOperation(self.set_conflicts, self)
1599
1552
 
1831
1784
            branch=branch, _control_files=_control_files, _internal=_internal,
1832
1785
            _format=_format, _bzrdir=_bzrdir)
1833
1786
 
 
1787
        self._detect_case_handling()
 
1788
 
1834
1789
        if _inventory is None:
1835
1790
            # This will be acquired on lock_read() or lock_write()
1836
1791
            self._inventory_is_modified = False
1855
1810
        self._inventory = inv
1856
1811
        self._inventory_is_modified = dirty
1857
1812
 
 
1813
    def _detect_case_handling(self):
 
1814
        wt_trans = self.bzrdir.get_workingtree_transport(None)
 
1815
        try:
 
1816
            wt_trans.stat(self._format.case_sensitive_filename)
 
1817
        except errors.NoSuchFile:
 
1818
            self.case_sensitive = True
 
1819
        else:
 
1820
            self.case_sensitive = False
 
1821
 
 
1822
        self._setup_directory_is_tree_reference()
 
1823
 
1858
1824
    def _serialize(self, inventory, out_file):
1859
1825
        xml5.serializer_v5.write_inventory(self._inventory, out_file,
1860
1826
            working=True)
2164
2130
            mode=self.bzrdir._get_file_mode())
2165
2131
        self._inventory_is_modified = False
2166
2132
 
2167
 
    @needs_read_lock
2168
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
2169
 
        if not path:
2170
 
            path = self._inventory.id2path(file_id)
2171
 
        return self._hashcache.get_sha1(path, stat_value)
2172
 
 
2173
2133
    def get_file_mtime(self, file_id, path=None):
2174
2134
        """See Tree.get_file_mtime."""
2175
2135
        if not path:
2176
2136
            path = self.inventory.id2path(file_id)
2177
 
        return os.lstat(self.abspath(path)).st_mtime
 
2137
        try:
 
2138
            return os.lstat(self.abspath(path)).st_mtime
 
2139
        except OSError, e:
 
2140
            if e.errno == errno.ENOENT:
 
2141
                raise errors.FileTimestampUnavailable(path)
 
2142
            raise
2178
2143
 
2179
2144
    def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
2180
2145
        file_id = self.path2id(path)
3126
3091
    def unregister_format(klass, format):
3127
3092
        format_registry.remove(format)
3128
3093
 
 
3094
    def get_controldir_for_branch(self):
 
3095
        """Get the control directory format for creating branches.
 
3096
 
 
3097
        This is to support testing of working tree formats that can not exist
 
3098
        in the same control directory as a branch.
 
3099
        """
 
3100
        return self._matchingbzrdir
 
3101
 
3129
3102
 
3130
3103
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
3131
3104
    "bzrlib.workingtree_4", "WorkingTreeFormat4")