~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-05 01:12:15 UTC
  • mto: This revision was merged to the branch mainline in revision 5757.
  • Revision ID: jelmer@samba.org-20110405011215-8g6izwf3uz8v4174
Remove some unnecessary imports, clean up lazy imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib import (
35
35
    bzrdir,
36
36
    cache_utf8,
37
 
    conflicts as _mod_conflicts,
38
37
    debug,
39
38
    dirstate,
40
39
    errors,
41
 
    filters as _mod_filters,
42
40
    generate_ids,
43
41
    osutils,
44
42
    revision as _mod_revision,
45
43
    revisiontree,
46
 
    trace,
47
44
    transform,
48
45
    views,
49
46
    )
50
47
""")
51
48
 
52
49
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
50
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
53
51
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
54
52
from bzrlib.lock import LogicalLockResult
55
 
from bzrlib.lockable_files import LockableFiles
56
 
from bzrlib.lockdir import LockDir
57
53
from bzrlib.mutabletree import needs_tree_write_lock
58
54
from bzrlib.osutils import (
59
55
    file_kind,
62
58
    realpath,
63
59
    safe_unicode,
64
60
    )
 
61
from bzrlib.trace import mutter, mutter_callsite
65
62
from bzrlib.transport.local import LocalTransport
66
 
from bzrlib.tree import (
67
 
    InterTree,
68
 
    InventoryTree,
69
 
    )
70
 
from bzrlib.workingtree import (
71
 
    InventoryWorkingTree,
72
 
    WorkingTree,
73
 
    WorkingTreeFormat,
74
 
    )
75
 
 
76
 
 
77
 
class DirStateWorkingTree(InventoryWorkingTree):
78
 
 
 
63
from bzrlib.tree import InterTree
 
64
from bzrlib.tree import Tree
 
65
from bzrlib.workingtree import WorkingTree, WorkingTree3, WorkingTreeFormat3
 
66
 
 
67
 
 
68
class DirStateWorkingTree(WorkingTree3):
79
69
    def __init__(self, basedir,
80
70
                 branch,
81
71
                 _control_files=None,
91
81
        self._format = _format
92
82
        self.bzrdir = _bzrdir
93
83
        basedir = safe_unicode(basedir)
94
 
        trace.mutter("opening working tree %r", basedir)
 
84
        mutter("opening working tree %r", basedir)
95
85
        self._branch = branch
96
86
        self.basedir = realpath(basedir)
97
87
        # if branch is at our basedir and is a format 6 or less
131
121
            state.add(f, file_id, kind, None, '')
132
122
        self._make_dirty(reset_inventory=True)
133
123
 
134
 
    def _get_check_refs(self):
135
 
        """Return the references needed to perform a check of this tree."""
136
 
        return [('trees', self.last_revision())]
137
 
 
138
124
    def _make_dirty(self, reset_inventory):
139
125
        """Make the tree state dirty.
140
126
 
192
178
 
193
179
    def _comparison_data(self, entry, path):
194
180
        kind, executable, stat_value = \
195
 
            WorkingTree._comparison_data(self, entry, path)
 
181
            WorkingTree3._comparison_data(self, entry, path)
196
182
        # it looks like a plain directory, but it's really a reference -- see
197
183
        # also kind()
198
184
        if (self._repo_supports_tree_reference and kind == 'directory'
204
190
    def commit(self, message=None, revprops=None, *args, **kwargs):
205
191
        # mark the tree as dirty post commit - commit
206
192
        # can change the current versioned list by doing deletes.
207
 
        result = WorkingTree.commit(self, message, revprops, *args, **kwargs)
 
193
        result = WorkingTree3.commit(self, message, revprops, *args, **kwargs)
208
194
        self._make_dirty(reset_inventory=True)
209
195
        return result
210
196
 
379
365
        state = self.current_dirstate()
380
366
        if stat_value is None:
381
367
            try:
382
 
                stat_value = osutils.lstat(file_abspath)
 
368
                stat_value = os.lstat(file_abspath)
383
369
            except OSError, e:
384
370
                if e.errno == errno.ENOENT:
385
371
                    return None
403
389
    def _get_inventory(self):
404
390
        """Get the inventory for the tree. This is only valid within a lock."""
405
391
        if 'evil' in debug.debug_flags:
406
 
            trace.mutter_callsite(2,
 
392
            mutter_callsite(2,
407
393
                "accessing .inventory forces a size of tree translation.")
408
394
        if self._inventory is not None:
409
395
            return self._inventory
488
474
            self._must_be_locked()
489
475
            if not path:
490
476
                path = self.id2path(file_id)
491
 
            mode = osutils.lstat(self.abspath(path)).st_mode
 
477
            mode = os.lstat(self.abspath(path)).st_mode
492
478
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
493
479
 
494
480
    def all_file_ids(self):
1264
1250
    def rename_one(self, from_rel, to_rel, after=False):
1265
1251
        """See WorkingTree.rename_one"""
1266
1252
        self.flush()
1267
 
        super(DirStateWorkingTree, self).rename_one(from_rel, to_rel, after)
 
1253
        WorkingTree.rename_one(self, from_rel, to_rel, after)
1268
1254
 
1269
1255
    @needs_tree_write_lock
1270
1256
    def apply_inventory_delta(self, changes):
1334
1320
        """See dirstate.SHA1Provider.sha1()."""
1335
1321
        filters = self.tree._content_filter_stack(
1336
1322
            self.tree.relpath(osutils.safe_unicode(abspath)))
1337
 
        return _mod_filters.internal_size_sha_file_byname(abspath, filters)[1]
 
1323
        return internal_size_sha_file_byname(abspath, filters)[1]
1338
1324
 
1339
1325
    def stat_and_sha1(self, abspath):
1340
1326
        """See dirstate.SHA1Provider.stat_and_sha1()."""
1344
1330
        try:
1345
1331
            statvalue = os.fstat(file_obj.fileno())
1346
1332
            if filters:
1347
 
                file_obj = _mod_filters.filtered_input_file(file_obj, filters)
 
1333
                file_obj = filtered_input_file(file_obj, filters)
1348
1334
            sha1 = osutils.size_sha_file(file_obj)[1]
1349
1335
        finally:
1350
1336
            file_obj.close()
1380
1366
class WorkingTree4(DirStateWorkingTree):
1381
1367
    """This is the Format 4 working tree.
1382
1368
 
1383
 
    This differs from WorkingTree by:
 
1369
    This differs from WorkingTree3 by:
1384
1370
     - Having a consolidated internal dirstate, stored in a
1385
1371
       randomly-accessible sorted file on disk.
1386
1372
     - Not having a regular inventory attribute.  One can be synthesized
1414
1400
        return views.PathBasedViews(self)
1415
1401
 
1416
1402
 
1417
 
class DirStateWorkingTreeFormat(WorkingTreeFormat):
 
1403
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1418
1404
 
1419
1405
    missing_parent_conflicts = True
1420
1406
 
1421
 
    _lock_class = LockDir
1422
 
    _lock_file_name = 'lock'
1423
 
 
1424
 
    def _open_control_files(self, a_bzrdir):
1425
 
        transport = a_bzrdir.get_workingtree_transport(None)
1426
 
        return LockableFiles(transport, self._lock_file_name,
1427
 
                             self._lock_class)
1428
 
 
1429
1407
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1430
1408
                   accelerator_tree=None, hardlink=False):
1431
1409
        """See WorkingTreeFormat.initialize().
1530
1508
        :param wt: the WorkingTree object
1531
1509
        """
1532
1510
 
1533
 
    def open(self, a_bzrdir, _found=False):
1534
 
        """Return the WorkingTree object for a_bzrdir
1535
 
 
1536
 
        _found is a private parameter, do not use it. It is used to indicate
1537
 
               if format probing has already been done.
1538
 
        """
1539
 
        if not _found:
1540
 
            # we are being called directly and must probe.
1541
 
            raise NotImplementedError
1542
 
        if not isinstance(a_bzrdir.transport, LocalTransport):
1543
 
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1544
 
        wt = self._open(a_bzrdir, self._open_control_files(a_bzrdir))
1545
 
        return wt
1546
 
 
1547
1511
    def _open(self, a_bzrdir, control_files):
1548
1512
        """Open the tree itself.
1549
1513
 
1640
1604
        return True
1641
1605
 
1642
1606
 
1643
 
class DirStateRevisionTree(InventoryTree):
 
1607
class DirStateRevisionTree(Tree):
1644
1608
    """A revision tree pulling the inventory from a dirstate.
1645
1609
    
1646
1610
    Note that this is one of the historical (ie revision) trees cached in the
1665
1629
    def annotate_iter(self, file_id,
1666
1630
                      default_revision=_mod_revision.CURRENT_REVISION):
1667
1631
        """See Tree.annotate_iter"""
1668
 
        text_key = (file_id, self.get_file_revision(file_id))
 
1632
        text_key = (file_id, self.inventory[file_id].revision)
1669
1633
        annotations = self._repository.texts.annotate(text_key)
1670
1634
        return [(key[-1], line) for (key, line) in annotations]
1671
1635
 
1835
1799
            return parent_details[1]
1836
1800
        return None
1837
1801
 
1838
 
    @needs_read_lock
1839
 
    def get_file_revision(self, file_id):
1840
 
        return self.inventory[file_id].revision
1841
 
 
1842
1802
    def get_file(self, file_id, path=None):
1843
1803
        return StringIO(self.get_file_text(file_id))
1844
1804
 
2045
2005
    def make_source_parent_tree(source, target):
2046
2006
        """Change the source tree into a parent of the target."""
2047
2007
        revid = source.commit('record tree')
2048
 
        target.branch.fetch(source.branch, revid)
 
2008
        target.branch.repository.fetch(source.branch.repository, revid)
2049
2009
        target.set_parent_ids([revid])
2050
2010
        return target.basis_tree(), target
2051
2011