~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-16 11:08:11 UTC
  • mfrom: (6521 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6522.
  • Revision ID: jelmer@samba.org-20120416110811-0y996ihqy9o2bb1t
Merge bzr.dev.

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,
25
26
    errors,
26
27
    lazy_import,
27
28
    registry,
47
48
""")
48
49
from bzrlib.errors import (DuplicateKey, MalformedTransform,
49
50
                           ReusingTransform, CantMoveRoot,
50
 
                           ExistingLimbo, ImmortalLimbo, NoFinalPath,
 
51
                           ImmortalLimbo, NoFinalPath,
51
52
                           UnableCreateSymlink)
52
53
from bzrlib.filters import filtered_output_bytes, ContentFilterContext
53
54
from bzrlib.mutabletree import MutableTree
574
575
            # ensure that all children are registered with the transaction
575
576
            list(self.iter_tree_children(parent_id))
576
577
 
577
 
    @deprecated_method(deprecated_in((2, 3, 0)))
578
 
    def has_named_child(self, by_parent, parent_id, name):
579
 
        return self._has_named_child(
580
 
            name, parent_id, known_children=by_parent.get(parent_id, []))
581
 
 
582
578
    def _has_named_child(self, name, parent_id, known_children):
583
579
        """Does a parent already have a name child.
584
580
 
1405
1401
        delete_any(self._limbo_name(trans_id))
1406
1402
 
1407
1403
    def new_orphan(self, trans_id, parent_id):
1408
 
        # FIXME: There is no tree config, so we use the branch one (it's weird
1409
 
        # to define it this way as orphaning can only occur in a working tree,
1410
 
        # but that's all we have (for now). It will find the option in
1411
 
        # locations.conf or bazaar.conf though) -- vila 20100916
1412
 
        conf = self._tree.branch.get_config()
1413
 
        conf_var_name = 'bzr.transform.orphan_policy'
1414
 
        orphan_policy = conf.get_user_option(conf_var_name)
1415
 
        default_policy = orphaning_registry.default_key
1416
 
        if orphan_policy is None:
1417
 
            orphan_policy = default_policy
1418
 
        if orphan_policy not in orphaning_registry:
1419
 
            trace.warning('%s (from %s) is not a known policy, defaulting '
1420
 
                'to %s' % (orphan_policy, conf_var_name, default_policy))
1421
 
            orphan_policy = default_policy
1422
 
        handle_orphan = orphaning_registry.get(orphan_policy)
 
1404
        conf = self._tree.get_config_stack()
 
1405
        handle_orphan = conf.get('bzr.transform.orphan_policy')
1423
1406
        handle_orphan(self, trans_id, parent_id)
1424
1407
 
1425
1408
 
1488
1471
orphaning_registry._set_default_key('conflict')
1489
1472
 
1490
1473
 
 
1474
opt_transform_orphan = _mod_config.RegistryOption(
 
1475
    'bzr.transform.orphan_policy', orphaning_registry,
 
1476
    help='Policy for orphaned files during transform operations.',
 
1477
    invalid='warning')
 
1478
 
 
1479
 
1491
1480
class TreeTransform(DiskTreeTransform):
1492
1481
    """Represent a tree transformation.
1493
1482
 
2062
2051
        pass
2063
2052
 
2064
2053
    @property
 
2054
    @deprecated_method(deprecated_in((2, 5, 0)))
2065
2055
    def inventory(self):
2066
2056
        """This Tree does not use inventory as its backing data."""
2067
2057
        raise NotImplementedError(_PreviewTree.inventory)
2068
2058
 
 
2059
    @property
 
2060
    def root_inventory(self):
 
2061
        """This Tree does not use inventory as its backing data."""
 
2062
        raise NotImplementedError(_PreviewTree.root_inventory)
 
2063
 
2069
2064
    def get_root_id(self):
2070
2065
        return self._transform.final_file_id(self._transform.root)
2071
2066
 
2117
2112
        return cur_parent
2118
2113
 
2119
2114
    def path2id(self, path):
 
2115
        if isinstance(path, list):
 
2116
            if path == []:
 
2117
                path = [""]
 
2118
            path = osutils.pathjoin(*path)
2120
2119
        return self._transform.final_file_id(self._path2trans_id(path))
2121
2120
 
2122
2121
    def id2path(self, file_id):
2183
2182
                ordered_ids.append((trans_id, parent_file_id))
2184
2183
        return ordered_ids
2185
2184
 
 
2185
    def iter_child_entries(self, file_id, path=None):
 
2186
        self.id2path(file_id)
 
2187
        trans_id = self._transform.trans_id_file_id(file_id)
 
2188
        todo = [(child_trans_id, trans_id) for child_trans_id in
 
2189
                self._all_children(trans_id)]
 
2190
        for entry, trans_id in self._make_inv_entries(todo):
 
2191
            yield entry
 
2192
 
2186
2193
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
2187
2194
        # This may not be a maximally efficient implementation, but it is
2188
2195
        # reasonably straightforward.  An implementation that grafts the
2825
2832
        tt.set_executability(entry.executable, trans_id)
2826
2833
 
2827
2834
 
2828
 
@deprecated_function(deprecated_in((2, 3, 0)))
2829
 
def get_backup_name(entry, by_parent, parent_trans_id, tt):
2830
 
    return _get_backup_name(entry.name, by_parent, parent_trans_id, tt)
2831
 
 
2832
 
 
2833
 
@deprecated_function(deprecated_in((2, 3, 0)))
2834
 
def _get_backup_name(name, by_parent, parent_trans_id, tt):
2835
 
    """Produce a backup-style name that appears to be available"""
2836
 
    def name_gen():
2837
 
        counter = 1
2838
 
        while True:
2839
 
            yield "%s.~%d~" % (name, counter)
2840
 
            counter += 1
2841
 
    for new_name in name_gen():
2842
 
        if not tt.has_named_child(by_parent, parent_trans_id, new_name):
2843
 
            return new_name
2844
 
 
2845
 
 
2846
2835
def revert(working_tree, target_tree, filenames, backups=False,
2847
2836
           pb=None, change_reporter=None):
2848
2837
    """Revert a working tree's contents to those of a target tree."""