/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: Vincent Ladeuil
  • Date: 2009-09-08 16:45:11 UTC
  • mto: (4681.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4682.
  • Revision ID: v.ladeuil+lp@free.fr-20090908164511-5e7eupewxycwaue4
Don't allow remove-tree to succeed with pending merges unless
--force is used.

* bzrlib/tests/blackbox/test_remove_tree.py:
(TestRemoveTree.test_remove_tree_pending_merges,
TestRemoveTree.test_remove_tree_pending_merges_force): Test with
and without --force and pending merges.

* bzrlib/builtins.py:
(cmd_remove_tree.run): Check pending merges too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
53
53
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
54
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
55
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
 
56
import bzrlib.mutabletree
56
57
from bzrlib.mutabletree import needs_tree_write_lock
57
58
from bzrlib.osutils import (
58
59
    file_kind,
567
568
            return _mod_revision.NULL_REVISION
568
569
 
569
570
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock.
571
 
 
572
 
        :return: An object with an unlock method which will release the lock
573
 
            obtained.
574
 
        """
 
571
        """See Branch.lock_read, and WorkingTree.unlock."""
575
572
        self.branch.lock_read()
576
573
        try:
577
574
            self._control_files.lock_read()
590
587
        except:
591
588
            self.branch.unlock()
592
589
            raise
593
 
        return self
594
590
 
595
591
    def _lock_self_write(self):
596
592
        """This should be called after the branch is locked."""
611
607
        except:
612
608
            self.branch.unlock()
613
609
            raise
614
 
        return self
615
610
 
616
611
    def lock_tree_write(self):
617
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
 
 
619
 
        :return: An object with an unlock method which will release the lock
620
 
            obtained.
621
 
        """
 
612
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
622
613
        self.branch.lock_read()
623
 
        return self._lock_self_write()
 
614
        self._lock_self_write()
624
615
 
625
616
    def lock_write(self):
626
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
627
 
 
628
 
        :return: An object with an unlock method which will release the lock
629
 
            obtained.
630
 
        """
 
617
        """See MutableTree.lock_write, and WorkingTree.unlock."""
631
618
        self.branch.lock_write()
632
 
        return self._lock_self_write()
 
619
        self._lock_self_write()
633
620
 
634
621
    @needs_tree_write_lock
635
622
    def move(self, from_paths, to_dir, after=False):
1280
1267
        if self._dirty:
1281
1268
            raise AssertionError("attempting to write an inventory when the "
1282
1269
                "dirstate is dirty will lose pending changes")
1283
 
        had_inventory = self._inventory is not None
1284
 
        # Setting self._inventory = None forces the dirstate to regenerate the
1285
 
        # working inventory. We do this because self.inventory may be inv, or
1286
 
        # may have been modified, and either case would prevent a clean delta
1287
 
        # being created.
1288
 
        self._inventory = None
1289
 
        # generate a delta,
1290
 
        delta = inv._make_delta(self.inventory)
1291
 
        # and apply it.
1292
 
        self.apply_inventory_delta(delta)
1293
 
        if had_inventory:
 
1270
        self.current_dirstate().set_state_from_inventory(inv)
 
1271
        self._make_dirty(reset_inventory=False)
 
1272
        if self._inventory is not None:
1294
1273
            self._inventory = inv
1295
1274
        self.flush()
1296
1275
 
1385
1364
 
1386
1365
 
1387
1366
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1388
 
 
1389
1367
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1390
1368
                   accelerator_tree=None, hardlink=False):
1391
1369
        """See WorkingTreeFormat.initialize().
1461
1439
                if basis_root_id is not None:
1462
1440
                    wt._set_root_id(basis_root_id)
1463
1441
                    wt.flush()
 
1442
                # If content filtering is supported, do not use the accelerator
 
1443
                # tree - the cost of transforming the content both ways and
 
1444
                # checking for changed content can outweight the gains it gives.
 
1445
                # Note: do NOT move this logic up higher - using the basis from
 
1446
                # the accelerator tree is still desirable because that can save
 
1447
                # a minute or more of processing on large trees!
 
1448
                # The original tree may not have the same content filters
 
1449
                # applied so we can't safely build the inventory delta from
 
1450
                # the source tree.
1464
1451
                if wt.supports_content_filtering():
1465
 
                    # The original tree may not have the same content filters
1466
 
                    # applied so we can't safely build the inventory delta from
1467
 
                    # the source tree.
 
1452
                    if hardlink:
 
1453
                        # see https://bugs.edge.launchpad.net/bzr/+bug/408193
 
1454
                        trace.warning("hardlinking working copy files is not currently "
 
1455
                            "supported in %r" % (wt,))
 
1456
                    accelerator_tree = None
1468
1457
                    delta_from_tree = False
1469
1458
                else:
1470
1459
                    delta_from_tree = True
1769
1758
            return None
1770
1759
        parent_index = self._get_parent_index()
1771
1760
        last_changed_revision = entry[1][parent_index][4]
1772
 
        try:
1773
 
            rev = self._repository.get_revision(last_changed_revision)
1774
 
        except errors.NoSuchRevision:
1775
 
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
1776
 
        return rev.timestamp
 
1761
        return self._repository.get_revision(last_changed_revision).timestamp
1777
1762
 
1778
1763
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1779
1764
        entry = self._get_entry(file_id=file_id, path=path)
1846
1831
        entry = self._get_entry(file_id=file_id)[1]
1847
1832
        if entry is None:
1848
1833
            raise errors.NoSuchId(tree=self, file_id=file_id)
1849
 
        parent_index = self._get_parent_index()
1850
 
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
 
1834
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1851
1835
 
1852
1836
    def stored_kind(self, file_id):
1853
1837
        """See Tree.stored_kind"""
1873
1857
            return None
1874
1858
        return ie.executable
1875
1859
 
1876
 
    def is_locked(self):
1877
 
        return self._locked
1878
 
 
1879
1860
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1880
1861
        # We use a standard implementation, because DirStateRevisionTree is
1881
1862
        # dealing with one of the parents of the current state
1894
1875
            yield path, 'V', entry.kind, entry.file_id, entry
1895
1876
 
1896
1877
    def lock_read(self):
1897
 
        """Lock the tree for a set of operations.
1898
 
 
1899
 
        :return: An object with an unlock method which will release the lock
1900
 
            obtained.
1901
 
        """
 
1878
        """Lock the tree for a set of operations."""
1902
1879
        if not self._locked:
1903
1880
            self._repository.lock_read()
1904
1881
            if self._dirstate._lock_token is None:
1905
1882
                self._dirstate.lock_read()
1906
1883
                self._dirstate_locked = True
1907
1884
        self._locked += 1
1908
 
        return self
1909
1885
 
1910
1886
    def _must_be_locked(self):
1911
1887
        if not self._locked:
2001
1977
        return result
2002
1978
 
2003
1979
    @classmethod
2004
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
2005
 
                                                  target):
 
1980
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
2006
1981
        from bzrlib.tests.test__dirstate_helpers import \
2007
 
            compiled_dirstate_helpers_feature
2008
 
        test_case.requireFeature(compiled_dirstate_helpers_feature)
 
1982
            CompiledDirstateHelpersFeature
 
1983
        if not CompiledDirstateHelpersFeature.available():
 
1984
            from bzrlib.tests import UnavailableFeature
 
1985
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
2009
1986
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
2010
1987
        result = klass.make_source_parent_tree(source, target)
2011
1988
        result[1]._iter_changes = ProcessEntryC
2042
2019
            output. An unversioned file is defined as one with (False, False)
2043
2020
            for the versioned pair.
2044
2021
        """
 
2022
        # NB: show_status depends on being able to pass in non-versioned files
 
2023
        # and report them as unknown
2045
2024
        # TODO: handle extra trees in the dirstate.
2046
2025
        if (extra_trees or specific_files == []):
2047
2026
            # we can't fast-path these cases (yet)