~lifeless/bzr/dirstate2

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Robert Collins
  • Date: 2009-09-29 05:21:38 UTC
  • Revision ID: robertc@robertcollins.net-20090929052138-u2po4lj409sohiqa
Hook up IndirectedDirState to --development-rich-root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
                 branch,
75
75
                 _control_files=None,
76
76
                 _format=None,
77
 
                 _bzrdir=None):
 
77
                 _bzrdir=None,
 
78
                 _dirstate_class=None):
78
79
        """Construct a WorkingTree for basedir.
79
80
 
80
81
        If the branch is not supplied, it is opened automatically.
81
82
        If the branch is supplied, it must be the branch for this basedir.
82
83
        (branch.base is not cross checked, because for remote branches that
83
84
        would be meaningless).
 
85
 
 
86
        :ivar _dirstate_class: The class of 'DirState' to be used for this
 
87
            tree.
84
88
        """
85
89
        self._format = _format
86
90
        self.bzrdir = _bzrdir
 
91
        self._dirstate_class = _dirstate_class
87
92
        basedir = safe_unicode(basedir)
88
93
        mutter("opening working tree %r", basedir)
89
94
        self._branch = branch
159
164
            else:
160
165
                clear = False
161
166
            state = self._current_dirstate()
162
 
            if state._lock_token is not None:
 
167
            if state._lock_state is not None:
163
168
                # we already have it locked. sheese, cant break our own lock.
164
169
                raise errors.LockActive(self.basedir)
165
170
            else:
218
223
            return self._dirstate
219
224
        local_path = self.bzrdir.get_workingtree_transport(None
220
225
            ).local_abspath('dirstate')
221
 
        self._dirstate = dirstate.DirState.on_file(local_path,
 
226
        self._dirstate = self._dirstate_class.on_file(local_path,
222
227
            self._sha1_provider())
223
228
        return self._dirstate
224
229
 
574
579
            self._control_files.lock_read()
575
580
            try:
576
581
                state = self.current_dirstate()
577
 
                if not state._lock_token:
 
582
                if not state._lock_state:
578
583
                    state.lock_read()
579
584
                # set our support for tree references from the repository in
580
585
                # use.
594
599
            self._control_files.lock_write()
595
600
            try:
596
601
                state = self.current_dirstate()
597
 
                if not state._lock_token:
 
602
                if not state._lock_state:
598
603
                    state.lock_write()
599
604
                # set our support for tree references from the repository in
600
605
                # use.
1364
1369
 
1365
1370
 
1366
1371
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
 
1372
 
 
1373
    # what dirstate class should be used for a given format.
 
1374
    _dirstate_class = dirstate.DirState
 
1375
 
1367
1376
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1368
1377
                   accelerator_tree=None, hardlink=False):
1369
1378
        """See WorkingTreeFormat.initialize().
1396
1405
            revision_id = branch.last_revision()
1397
1406
        local_path = transport.local_abspath('dirstate')
1398
1407
        # write out new dirstate (must exist when we create the tree)
1399
 
        state = dirstate.DirState.initialize(local_path)
 
1408
        state = self._dirstate_class.initialize(local_path)
1400
1409
        state.unlock()
1401
1410
        del state
1402
1411
        wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
1403
1412
                         branch,
1404
1413
                         _format=self,
1405
1414
                         _bzrdir=a_bzrdir,
1406
 
                         _control_files=control_files)
 
1415
                         _control_files=control_files,
 
1416
                         _dirstate_class=self._dirstate_class)
1407
1417
        wt._new_tree()
1408
1418
        wt.lock_tree_write()
1409
1419
        try:
1489
1499
                           branch=a_bzrdir.open_branch(),
1490
1500
                           _format=self,
1491
1501
                           _bzrdir=a_bzrdir,
1492
 
                           _control_files=control_files)
 
1502
                           _control_files=control_files,
 
1503
                           _dirstate_class=self._dirstate_class)
1493
1504
 
1494
1505
    def __get_matchingbzrdir(self):
1495
1506
        return self._get_matchingbzrdir()
1548
1559
        return True
1549
1560
 
1550
1561
 
1551
 
class WorkingTreeFormat6(DirStateWorkingTreeFormat):
1552
 
    """WorkingTree format supporting views.
 
1562
class WorkingTreeFormat7(DirStateWorkingTreeFormat):
 
1563
    """WorkingTree with:
 
1564
        - views
 
1565
        - IndirectedDirState
1553
1566
    """
1554
1567
 
 
1568
    _dirstate_class = dirstate.IndirectedDirState
1555
1569
    upgrade_recommended = False
1556
1570
 
1557
1571
    _tree_class = WorkingTree6
1558
1572
 
1559
1573
    def get_format_string(self):
1560
1574
        """See WorkingTreeFormat.get_format_string()."""
1561
 
        return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
 
1575
        return "Bazaar Working Tree Format 7 (bzr 2.1)\n"
1562
1576
 
1563
1577
    def get_format_description(self):
1564
1578
        """See WorkingTreeFormat.get_format_description()."""
1565
 
        return "Working tree format 6"
 
1579
        return "Working tree format 7"
1566
1580
 
1567
1581
    def _init_custom_control_files(self, wt):
1568
1582
        """Subclasses with custom control files should override this method."""
1575
1589
        return True
1576
1590
 
1577
1591
 
 
1592
class WorkingTreeFormat6(WorkingTreeFormat7):
 
1593
    """WorkingTree with:
 
1594
        - views
 
1595
        - single file dirstate (OSLocks needed)
 
1596
    """
 
1597
 
 
1598
    _dirstate_class = dirstate.DirState
 
1599
 
 
1600
    def get_format_string(self):
 
1601
        """See WorkingTreeFormat.get_format_string()."""
 
1602
        return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
 
1603
 
 
1604
    def get_format_description(self):
 
1605
        """See WorkingTreeFormat.get_format_description()."""
 
1606
        return "Working tree format 6"
 
1607
 
 
1608
 
 
1609
 
1578
1610
class DirStateRevisionTree(Tree):
1579
1611
    """A revision tree pulling the inventory from a dirstate.
1580
1612
    
1878
1910
        """Lock the tree for a set of operations."""
1879
1911
        if not self._locked:
1880
1912
            self._repository.lock_read()
1881
 
            if self._dirstate._lock_token is None:
 
1913
            if self._dirstate._lock_state is None:
1882
1914
                self._dirstate.lock_read()
1883
1915
                self._dirstate_locked = True
1884
1916
        self._locked += 1
2136
2168
        """Create the dirstate based data for tree."""
2137
2169
        local_path = tree.bzrdir.get_workingtree_transport(None
2138
2170
            ).local_abspath('dirstate')
2139
 
        state = dirstate.DirState.from_tree(tree, local_path)
 
2171
        state = self._dirstate_class.from_tree(tree, local_path)
2140
2172
        state.save()
2141
2173
        state.unlock()
2142
2174