~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-19 17:14:34 UTC
  • mfrom: (6378.1.5 config-si-unit)
  • Revision ID: pqm@pqm.ubuntu.com-20111219171434-i0b4ir0invs9il2v
(vila) Migrate add.maximum_file_size configuration option. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import time
23
23
 
24
24
from bzrlib import (
25
 
    config as _mod_config,
26
25
    errors,
27
26
    lazy_import,
28
27
    registry,
48
47
""")
49
48
from bzrlib.errors import (DuplicateKey, MalformedTransform,
50
49
                           ReusingTransform, CantMoveRoot,
51
 
                           ImmortalLimbo, NoFinalPath,
 
50
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
52
51
                           UnableCreateSymlink)
53
52
from bzrlib.filters import filtered_output_bytes, ContentFilterContext
54
 
from bzrlib.mutabletree import MutableTree
55
53
from bzrlib.osutils import (
56
54
    delete_any,
57
55
    file_kind,
59
57
    pathjoin,
60
58
    sha_file,
61
59
    splitpath,
 
60
    supports_executable,
62
61
    )
63
62
from bzrlib.progress import ProgressPhase
64
63
from bzrlib.symbol_versioning import (
157
156
        """
158
157
        if self._tree is None:
159
158
            return
160
 
        for hook in MutableTree.hooks['post_transform']:
161
 
            hook(self._tree, self)
162
159
        self._tree.unlock()
163
160
        self._tree = None
164
161
 
233
230
        irrelevant.
234
231
 
235
232
        """
236
 
        new_roots = [k for k, v in self._new_parent.iteritems() if v ==
 
233
        new_roots = [k for k, v in self._new_parent.iteritems() if v is
237
234
                     ROOT_PARENT]
238
235
        if len(new_roots) < 1:
239
236
            return
629
626
        for trans_id in self._new_parent:
630
627
            seen = set()
631
628
            parent_id = trans_id
632
 
            while parent_id != ROOT_PARENT:
 
629
            while parent_id is not ROOT_PARENT:
633
630
                seen.add(parent_id)
634
631
                try:
635
632
                    parent_id = self.final_parent(parent_id)
645
642
        """If parent directories are versioned, children must be versioned."""
646
643
        conflicts = []
647
644
        for parent_id, children in by_parent.iteritems():
648
 
            if parent_id == ROOT_PARENT:
 
645
            if parent_id is ROOT_PARENT:
649
646
                continue
650
647
            if self.final_file_id(parent_id) is not None:
651
648
                continue
744
741
        """Children must have a directory parent"""
745
742
        conflicts = []
746
743
        for parent_id, children in by_parent.iteritems():
747
 
            if parent_id == ROOT_PARENT:
 
744
            if parent_id is ROOT_PARENT:
748
745
                continue
749
746
            no_children = True
750
747
            for child_id in children:
766
763
 
767
764
    def _set_executability(self, path, trans_id):
768
765
        """Set the executability of versioned files """
769
 
        if self._tree._supports_executable():
 
766
        if supports_executable():
770
767
            new_executability = self._new_executability[trans_id]
771
768
            abspath = self._tree.abspath(path)
772
769
            current_mode = os.stat(abspath).st_mode
1236
1233
        finally:
1237
1234
            TreeTransformBase.finalize(self)
1238
1235
 
1239
 
    def _limbo_supports_executable(self):
1240
 
        """Check if the limbo path supports the executable bit."""
1241
 
        # FIXME: Check actual file system capabilities of limbodir
1242
 
        return osutils.supports_executable()
1243
 
 
1244
1236
    def _limbo_name(self, trans_id):
1245
1237
        """Generate the limbo name of a file"""
1246
1238
        limbo_name = self._limbo_files.get(trans_id)
1406
1398
        delete_any(self._limbo_name(trans_id))
1407
1399
 
1408
1400
    def new_orphan(self, trans_id, parent_id):
1409
 
        conf = self._tree.get_config_stack()
1410
 
        handle_orphan = conf.get('bzr.transform.orphan_policy')
 
1401
        # FIXME: There is no tree config, so we use the branch one (it's weird
 
1402
        # to define it this way as orphaning can only occur in a working tree,
 
1403
        # but that's all we have (for now). It will find the option in
 
1404
        # locations.conf or bazaar.conf though) -- vila 20100916
 
1405
        conf = self._tree.branch.get_config()
 
1406
        conf_var_name = 'bzr.transform.orphan_policy'
 
1407
        orphan_policy = conf.get_user_option(conf_var_name)
 
1408
        default_policy = orphaning_registry.default_key
 
1409
        if orphan_policy is None:
 
1410
            orphan_policy = default_policy
 
1411
        if orphan_policy not in orphaning_registry:
 
1412
            trace.warning('%s (from %s) is not a known policy, defaulting '
 
1413
                'to %s' % (orphan_policy, conf_var_name, default_policy))
 
1414
            orphan_policy = default_policy
 
1415
        handle_orphan = orphaning_registry.get(orphan_policy)
1411
1416
        handle_orphan(self, trans_id, parent_id)
1412
1417
 
1413
1418
 
1476
1481
orphaning_registry._set_default_key('conflict')
1477
1482
 
1478
1483
 
1479
 
opt_transform_orphan = _mod_config.RegistryOption(
1480
 
    'bzr.transform.orphan_policy', orphaning_registry,
1481
 
    help='Policy for orphaned files during transform operations.',
1482
 
    invalid='warning')
1483
 
 
1484
 
 
1485
1484
class TreeTransform(DiskTreeTransform):
1486
1485
    """Represent a tree transformation.
1487
1486
 
1718
1717
            calculating one.
1719
1718
        :param _mover: Supply an alternate FileMover, for testing
1720
1719
        """
1721
 
        for hook in MutableTree.hooks['pre_transform']:
1722
 
            hook(self._tree, self)
1723
1720
        if not no_conflicts:
1724
1721
            self._check_malformed()
1725
1722
        child_pb = ui.ui_factory.nested_progress_bar()
2056
2053
        pass
2057
2054
 
2058
2055
    @property
2059
 
    @deprecated_method(deprecated_in((2, 5, 0)))
2060
2056
    def inventory(self):
2061
2057
        """This Tree does not use inventory as its backing data."""
2062
2058
        raise NotImplementedError(_PreviewTree.inventory)
2063
2059
 
2064
 
    @property
2065
 
    def root_inventory(self):
2066
 
        """This Tree does not use inventory as its backing data."""
2067
 
        raise NotImplementedError(_PreviewTree.root_inventory)
2068
 
 
2069
2060
    def get_root_id(self):
2070
2061
        return self._transform.final_file_id(self._transform.root)
2071
2062
 
2330
2321
            if kind == 'file':
2331
2322
                statval = os.lstat(limbo_name)
2332
2323
                size = statval.st_size
2333
 
                if not tt._limbo_supports_executable():
 
2324
                if not supports_executable():
2334
2325
                    executable = False
2335
2326
                else:
2336
2327
                    executable = statval.st_mode & S_IEXEC