/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

(jelmer) Update tests for no user identity being configured so they work
 when one can be inferred. (Martin Pool)

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,
46
45
    transform,
47
46
    views,
48
47
    )
49
 
import bzrlib.branch
50
 
import bzrlib.ui
51
48
""")
52
49
 
53
50
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
51
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
52
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
 
53
from bzrlib.lock import LogicalLockResult
56
54
from bzrlib.mutabletree import needs_tree_write_lock
57
55
from bzrlib.osutils import (
58
56
    file_kind,
61
59
    realpath,
62
60
    safe_unicode,
63
61
    )
64
 
from bzrlib.trace import mutter
65
62
from bzrlib.transport.local import LocalTransport
66
63
from bzrlib.tree import InterTree
67
64
from bzrlib.tree import Tree
84
81
        self._format = _format
85
82
        self.bzrdir = _bzrdir
86
83
        basedir = safe_unicode(basedir)
87
 
        mutter("opening working tree %r", basedir)
 
84
        trace.mutter("opening working tree %r", basedir)
88
85
        self._branch = branch
89
86
        self.basedir = realpath(basedir)
90
87
        # if branch is at our basedir and is a format 6 or less
368
365
        state = self.current_dirstate()
369
366
        if stat_value is None:
370
367
            try:
371
 
                stat_value = os.lstat(file_abspath)
 
368
                stat_value = osutils.lstat(file_abspath)
372
369
            except OSError, e:
373
370
                if e.errno == errno.ENOENT:
374
371
                    return None
477
474
            self._must_be_locked()
478
475
            if not path:
479
476
                path = self.id2path(file_id)
480
 
            mode = os.lstat(self.abspath(path)).st_mode
 
477
            mode = osutils.lstat(self.abspath(path)).st_mode
481
478
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
482
479
 
483
480
    def all_file_ids(self):
567
564
            return _mod_revision.NULL_REVISION
568
565
 
569
566
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
567
        """See Branch.lock_read, and WorkingTree.unlock.
 
568
 
 
569
        :return: A bzrlib.lock.LogicalLockResult.
 
570
        """
571
571
        self.branch.lock_read()
572
572
        try:
573
573
            self._control_files.lock_read()
586
586
        except:
587
587
            self.branch.unlock()
588
588
            raise
 
589
        return LogicalLockResult(self.unlock)
589
590
 
590
591
    def _lock_self_write(self):
591
592
        """This should be called after the branch is locked."""
606
607
        except:
607
608
            self.branch.unlock()
608
609
            raise
 
610
        return LogicalLockResult(self.unlock)
609
611
 
610
612
    def lock_tree_write(self):
611
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
613
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
614
 
 
615
        :return: A bzrlib.lock.LogicalLockResult.
 
616
        """
612
617
        self.branch.lock_read()
613
 
        self._lock_self_write()
 
618
        return self._lock_self_write()
614
619
 
615
620
    def lock_write(self):
616
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
621
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
622
 
 
623
        :return: A bzrlib.lock.LogicalLockResult.
 
624
        """
617
625
        self.branch.lock_write()
618
 
        self._lock_self_write()
 
626
        return self._lock_self_write()
619
627
 
620
628
    @needs_tree_write_lock
621
629
    def move(self, from_paths, to_dir, after=False):
1235
1243
        # have to change the legacy inventory too.
1236
1244
        if self._inventory is not None:
1237
1245
            for file_id in file_ids:
1238
 
                self._inventory.remove_recursive_id(file_id)
 
1246
                if self._inventory.has_id(file_id):
 
1247
                    self._inventory.remove_recursive_id(file_id)
1239
1248
 
1240
1249
    @needs_tree_write_lock
1241
1250
    def rename_one(self, from_rel, to_rel, after=False):
1280
1289
            self._inventory = inv
1281
1290
        self.flush()
1282
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
 
1283
1313
 
1284
1314
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1285
1315
 
1317
1347
    def _file_content_summary(self, path, stat_result):
1318
1348
        # This is to support the somewhat obsolete path_content_summary method
1319
1349
        # with content filtering: see
1320
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1350
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1321
1351
        #
1322
1352
        # If the dirstate cache is up to date and knows the hash and size,
1323
1353
        # return that.
1372
1402
 
1373
1403
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1374
1404
 
 
1405
    missing_parent_conflicts = True
 
1406
 
1375
1407
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1376
1408
                   accelerator_tree=None, hardlink=False):
1377
1409
        """See WorkingTreeFormat.initialize().
1725
1757
                elif kind == 'directory':
1726
1758
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1727
1759
                elif kind == 'symlink':
1728
 
                    inv_entry.executable = False
1729
 
                    inv_entry.text_size = None
1730
1760
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1731
1761
                elif kind == 'tree-reference':
1732
1762
                    inv_entry.reference_revision = fingerprint or None
1856
1886
    def is_executable(self, file_id, path=None):
1857
1887
        ie = self.inventory[file_id]
1858
1888
        if ie.kind != "file":
1859
 
            return None
 
1889
            return False
1860
1890
        return ie.executable
1861
1891
 
 
1892
    def is_locked(self):
 
1893
        return self._locked
 
1894
 
1862
1895
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1863
1896
        # We use a standard implementation, because DirStateRevisionTree is
1864
1897
        # dealing with one of the parents of the current state
1877
1910
            yield path, 'V', entry.kind, entry.file_id, entry
1878
1911
 
1879
1912
    def lock_read(self):
1880
 
        """Lock the tree for a set of operations."""
 
1913
        """Lock the tree for a set of operations.
 
1914
 
 
1915
        :return: A bzrlib.lock.LogicalLockResult.
 
1916
        """
1881
1917
        if not self._locked:
1882
1918
            self._repository.lock_read()
1883
1919
            if self._dirstate._lock_token is None:
1884
1920
                self._dirstate.lock_read()
1885
1921
                self._dirstate_locked = True
1886
1922
        self._locked += 1
 
1923
        return LogicalLockResult(self.unlock)
1887
1924
 
1888
1925
    def _must_be_locked(self):
1889
1926
        if not self._locked: