~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 06:48:25 UTC
  • mfrom: (4070.8.6 debug-config)
  • Revision ID: pqm@pqm.ubuntu.com-20090306064825-kbpwggw21dygeix6
(mbp) debug_flags configuration option

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""WorkingTree4 format and implementation.
18
18
 
69
69
 
70
70
from bzrlib import symbol_versioning
71
71
from bzrlib.decorators import needs_read_lock, needs_write_lock
72
 
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
73
72
from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, entry_factory
74
73
import bzrlib.mutabletree
75
74
from bzrlib.mutabletree import needs_tree_write_lock
214
213
            WorkingTree3._comparison_data(self, entry, path)
215
214
        # it looks like a plain directory, but it's really a reference -- see
216
215
        # also kind()
217
 
        if (self._repo_supports_tree_reference and kind == 'directory'
218
 
            and entry is not None and entry.kind == 'tree-reference'):
 
216
        if (self._repo_supports_tree_reference and
 
217
            kind == 'directory' and
 
218
            self._directory_is_tree_reference(path)):
219
219
            kind = 'tree-reference'
220
220
        return kind, executable, stat_value
221
221
 
247
247
            return self._dirstate
248
248
        local_path = self.bzrdir.get_workingtree_transport(None
249
249
            ).local_abspath('dirstate')
250
 
        self._dirstate = dirstate.DirState.on_file(local_path,
251
 
            self._sha1_provider())
 
250
        self._dirstate = dirstate.DirState.on_file(local_path)
252
251
        return self._dirstate
253
252
 
254
 
    def _sha1_provider(self):
255
 
        """A function that returns a SHA1Provider suitable for this tree.
256
 
 
257
 
        :return: None if content filtering is not supported by this tree.
258
 
          Otherwise, a SHA1Provider is returned that sha's the canonical
259
 
          form of files, i.e. after read filters are applied.
260
 
        """
261
 
        if self.supports_content_filtering():
262
 
            return ContentFilterAwareSHA1Provider(self)
263
 
        else:
264
 
            return None
265
 
 
266
253
    def filter_unversioned_files(self, paths):
267
254
        """Filter out paths that are versioned.
268
255
 
351
338
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
352
339
                elif kind == 'tree-reference':
353
340
                    if not self._repo_supports_tree_reference:
354
 
                        raise errors.UnsupportedOperation(
355
 
                            self._generate_inventory,
356
 
                            self.branch.repository)
 
341
                        raise AssertionError(
 
342
                            "repository of %r "
 
343
                            "doesn't support tree references "
 
344
                            "required by entry %r"
 
345
                            % (self, name))
357
346
                    inv_entry.reference_revision = link_or_sha1 or None
358
347
                elif kind != 'symlink':
359
348
                    raise AssertionError("unknown kind %r" % kind)
575
564
    def _kind(self, relpath):
576
565
        abspath = self.abspath(relpath)
577
566
        kind = file_kind(abspath)
578
 
        if (self._repo_supports_tree_reference and kind == 'directory'):
579
 
            entry = self._get_entry(path=relpath)
580
 
            if entry[1] is not None:
581
 
                if entry[1][0][0] == 't':
582
 
                    kind = 'tree-reference'
 
567
        if (self._repo_supports_tree_reference and
 
568
            kind == 'directory' and
 
569
            self._directory_is_tree_reference(relpath)):
 
570
            kind = 'tree-reference'
583
571
        return kind
584
572
 
585
573
    @needs_read_lock
1295
1283
        self.flush()
1296
1284
 
1297
1285
 
1298
 
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1299
 
 
1300
 
    def __init__(self, tree):
1301
 
        self.tree = tree
1302
 
 
1303
 
    def sha1(self, abspath):
1304
 
        """Return the sha1 of a file given its absolute path."""
1305
 
        filters = self.tree._content_filter_stack(self.tree.relpath(abspath))
1306
 
        return internal_size_sha_file_byname(abspath, filters)[1]
1307
 
 
1308
 
    def stat_and_sha1(self, abspath):
1309
 
        """Return the stat and sha1 of a file given its absolute path."""
1310
 
        filters = self.tree._content_filter_stack(self.tree.relpath(abspath))
1311
 
        file_obj = file(abspath, 'rb', 65000)
1312
 
        try:
1313
 
            statvalue = os.fstat(file_obj.fileno())
1314
 
            if filters:
1315
 
                file_obj = filtered_input_file(file_obj, filters)
1316
 
            sha1 = osutils.size_sha_file(file_obj)[1]
1317
 
        finally:
1318
 
            file_obj.close()
1319
 
        return statvalue, sha1
1320
 
 
1321
 
 
1322
1286
class WorkingTree4(DirStateWorkingTree):
1323
1287
    """This is the Format 4 working tree.
1324
1288
 
1337
1301
 
1338
1302
    This differs from WorkingTree4 by:
1339
1303
     - Supporting content filtering.
1340
 
 
1341
 
    This is new in bzr 1.11.
1342
 
    """
1343
 
 
1344
 
 
1345
 
class WorkingTree6(DirStateWorkingTree):
1346
 
    """This is the Format 6 working tree.
1347
 
 
1348
 
    This differs from WorkingTree5 by:
1349
1304
     - Supporting a current view that may mask the set of files in a tree
1350
1305
       impacted by most user operations.
1351
1306
 
1352
 
    This is new in bzr 1.14.
 
1307
    This is new in bzr 1.11.
1353
1308
    """
1354
1309
 
1355
1310
    def _make_views(self):
1466
1421
                           _control_files=control_files)
1467
1422
 
1468
1423
    def __get_matchingbzrdir(self):
1469
 
        return self._get_matchingbzrdir()
1470
 
 
1471
 
    def _get_matchingbzrdir(self):
1472
 
        """Overrideable method to get a bzrdir for testing."""
1473
1424
        # please test against something that will let us do tree references
1474
1425
        return bzrdir.format_registry.make_bzrdir(
1475
1426
            'dirstate-with-subtree')
1503
1454
 
1504
1455
 
1505
1456
class WorkingTreeFormat5(DirStateWorkingTreeFormat):
1506
 
    """WorkingTree format supporting content filtering.
 
1457
    """WorkingTree format supporting views.
1507
1458
    """
1508
1459
 
1509
1460
    upgrade_recommended = False
1518
1469
        """See WorkingTreeFormat.get_format_description()."""
1519
1470
        return "Working tree format 5"
1520
1471
 
1521
 
    def supports_content_filtering(self):
1522
 
        return True
1523
 
 
1524
 
 
1525
 
class WorkingTreeFormat6(DirStateWorkingTreeFormat):
1526
 
    """WorkingTree format supporting views.
1527
 
    """
1528
 
 
1529
 
    upgrade_recommended = False
1530
 
 
1531
 
    _tree_class = WorkingTree6
1532
 
 
1533
 
    def get_format_string(self):
1534
 
        """See WorkingTreeFormat.get_format_string()."""
1535
 
        return "Bazaar Working Tree Format 6 (bzr 1.14)\n"
1536
 
 
1537
 
    def get_format_description(self):
1538
 
        """See WorkingTreeFormat.get_format_description()."""
1539
 
        return "Working tree format 6"
1540
 
 
1541
1472
    def _init_custom_control_files(self, wt):
1542
1473
        """Subclasses with custom control files should override this method."""
1543
1474
        wt._transport.put_bytes('views', '', mode=wt.bzrdir._get_file_mode())
1746
1677
        return self.inventory[file_id].text_size
1747
1678
 
1748
1679
    def get_file_text(self, file_id, path=None):
1749
 
        _, content = list(self.iter_files_bytes([(file_id, None)]))[0]
1750
 
        return ''.join(content)
 
1680
        return list(self.iter_files_bytes([(file_id, None)]))[0][1]
1751
1681
 
1752
1682
    def get_reference_revision(self, file_id, path=None):
1753
1683
        return self.inventory[file_id].reference_revision
1772
1702
        if entry[1][parent_index][0] != 'l':
1773
1703
            return None
1774
1704
        else:
1775
 
            target = entry[1][parent_index][1]
1776
 
            target = target.decode('utf8')
1777
 
            return target
 
1705
            # At present, none of the tree implementations supports non-ascii
 
1706
            # symlink targets. So we will just assume that the dirstate path is
 
1707
            # correct.
 
1708
            return entry[1][parent_index][1]
1778
1709
 
1779
1710
    def get_revision_id(self):
1780
1711
        """Return the revision id for this tree."""
2138
2069
        # tree during upgrade.
2139
2070
        tree._control_files.lock_write()
2140
2071
        try:
2141
 
            self.update_format(tree)
2142
 
        finally:
2143
 
            tree._control_files.unlock()
2144
 
 
2145
 
    def update_format(self, tree):
2146
 
        """Change the format marker."""
2147
 
        tree._transport.put_bytes('format',
2148
 
            self.target_format.get_format_string(),
2149
 
            mode=tree.bzrdir._get_file_mode())
2150
 
 
2151
 
 
2152
 
class Converter4or5to6(object):
2153
 
    """Perform an in-place upgrade of format 4 or 5 to format 6 trees."""
2154
 
 
2155
 
    def __init__(self):
2156
 
        self.target_format = WorkingTreeFormat6()
2157
 
 
2158
 
    def convert(self, tree):
2159
 
        # lock the control files not the tree, so that we don't get tree
2160
 
        # on-unlock behaviours, and so that no-one else diddles with the
2161
 
        # tree during upgrade.
2162
 
        tree._control_files.lock_write()
2163
 
        try:
2164
2072
            self.init_custom_control_files(tree)
2165
2073
            self.update_format(tree)
2166
2074
        finally: