/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: mbp at sourcefrog
  • Date: 2011-04-11 01:23:58 UTC
  • mfrom: (5777 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5802.
  • Revision ID: mbp@sourcefrog.net-20110411012358-gl07rdtxydlq7fh1
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
31
31
import errno
32
32
import stat
33
33
 
34
 
import bzrlib
35
34
from bzrlib import (
36
35
    bzrdir,
37
36
    cache_utf8,
38
37
    debug,
39
38
    dirstate,
40
39
    errors,
 
40
    filters as _mod_filters,
41
41
    generate_ids,
42
42
    osutils,
43
43
    revision as _mod_revision,
46
46
    transform,
47
47
    views,
48
48
    )
49
 
import bzrlib.branch
50
 
import bzrlib.ui
51
49
""")
52
50
 
53
51
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
 
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
52
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
56
53
from bzrlib.lock import LogicalLockResult
57
54
from bzrlib.mutabletree import needs_tree_write_lock
62
59
    realpath,
63
60
    safe_unicode,
64
61
    )
65
 
from bzrlib.trace import mutter
66
62
from bzrlib.transport.local import LocalTransport
67
63
from bzrlib.tree import InterTree
68
64
from bzrlib.tree import Tree
85
81
        self._format = _format
86
82
        self.bzrdir = _bzrdir
87
83
        basedir = safe_unicode(basedir)
88
 
        mutter("opening working tree %r", basedir)
 
84
        trace.mutter("opening working tree %r", basedir)
89
85
        self._branch = branch
90
86
        self.basedir = realpath(basedir)
91
87
        # if branch is at our basedir and is a format 6 or less
369
365
        state = self.current_dirstate()
370
366
        if stat_value is None:
371
367
            try:
372
 
                stat_value = os.lstat(file_abspath)
 
368
                stat_value = osutils.lstat(file_abspath)
373
369
            except OSError, e:
374
370
                if e.errno == errno.ENOENT:
375
371
                    return None
478
474
            self._must_be_locked()
479
475
            if not path:
480
476
                path = self.id2path(file_id)
481
 
            mode = os.lstat(self.abspath(path)).st_mode
 
477
            mode = osutils.lstat(self.abspath(path)).st_mode
482
478
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
483
479
 
484
480
    def all_file_ids(self):
1247
1243
        # have to change the legacy inventory too.
1248
1244
        if self._inventory is not None:
1249
1245
            for file_id in file_ids:
1250
 
                self._inventory.remove_recursive_id(file_id)
 
1246
                if self._inventory.has_id(file_id):
 
1247
                    self._inventory.remove_recursive_id(file_id)
1251
1248
 
1252
1249
    @needs_tree_write_lock
1253
1250
    def rename_one(self, from_rel, to_rel, after=False):
1292
1289
            self._inventory = inv
1293
1290
        self.flush()
1294
1291
 
 
1292
    @needs_tree_write_lock
 
1293
    def reset_state(self, revision_ids=None):
 
1294
        """Reset the state of the working tree.
 
1295
 
 
1296
        This does a hard-reset to a last-known-good state. This is a way to
 
1297
        fix if something got corrupted (like the .bzr/checkout/dirstate file)
 
1298
        """
 
1299
        if revision_ids is None:
 
1300
            revision_ids = self.get_parent_ids()
 
1301
        if not revision_ids:
 
1302
            base_tree = self.branch.repository.revision_tree(
 
1303
                _mod_revision.NULL_REVISION)
 
1304
            trees = []
 
1305
        else:
 
1306
            trees = zip(revision_ids,
 
1307
                        self.branch.repository.revision_trees(revision_ids))
 
1308
            base_tree = trees[0][1]
 
1309
        state = self.current_dirstate()
 
1310
        # We don't support ghosts yet
 
1311
        state.set_state_from_scratch(base_tree.inventory, trees, [])
 
1312
 
1295
1313
 
1296
1314
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1297
1315
 
1302
1320
        """See dirstate.SHA1Provider.sha1()."""
1303
1321
        filters = self.tree._content_filter_stack(
1304
1322
            self.tree.relpath(osutils.safe_unicode(abspath)))
1305
 
        return internal_size_sha_file_byname(abspath, filters)[1]
 
1323
        return _mod_filters.internal_size_sha_file_byname(abspath, filters)[1]
1306
1324
 
1307
1325
    def stat_and_sha1(self, abspath):
1308
1326
        """See dirstate.SHA1Provider.stat_and_sha1()."""
1312
1330
        try:
1313
1331
            statvalue = os.fstat(file_obj.fileno())
1314
1332
            if filters:
1315
 
                file_obj = filtered_input_file(file_obj, filters)
 
1333
                file_obj = _mod_filters.filtered_input_file(file_obj, filters)
1316
1334
            sha1 = osutils.size_sha_file(file_obj)[1]
1317
1335
        finally:
1318
1336
            file_obj.close()
1329
1347
    def _file_content_summary(self, path, stat_result):
1330
1348
        # This is to support the somewhat obsolete path_content_summary method
1331
1349
        # with content filtering: see
1332
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1350
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1333
1351
        #
1334
1352
        # If the dirstate cache is up to date and knows the hash and size,
1335
1353
        # return that.
1384
1402
 
1385
1403
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1386
1404
 
 
1405
    missing_parent_conflicts = True
 
1406
 
1387
1407
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1388
1408
                   accelerator_tree=None, hardlink=False):
1389
1409
        """See WorkingTreeFormat.initialize().
1737
1757
                elif kind == 'directory':
1738
1758
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1739
1759
                elif kind == 'symlink':
1740
 
                    inv_entry.executable = False
1741
 
                    inv_entry.text_size = None
1742
1760
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1743
1761
                elif kind == 'tree-reference':
1744
1762
                    inv_entry.reference_revision = fingerprint or None
1868
1886
    def is_executable(self, file_id, path=None):
1869
1887
        ie = self.inventory[file_id]
1870
1888
        if ie.kind != "file":
1871
 
            return None
 
1889
            return False
1872
1890
        return ie.executable
1873
1891
 
1874
1892
    def is_locked(self):