~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Martin Packman
  • Date: 2012-02-01 13:24:42 UTC
  • mto: (6437.23.4 2.5)
  • mto: This revision was merged to the branch mainline in revision 6462.
  • Revision ID: martin.packman@canonical.com-20120201132442-ela7jc4mxv4b058o
Treat path for .bzr.log as unicode

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
53
from bzrlib.mutabletree import MutableTree
575
574
            # ensure that all children are registered with the transaction
576
575
            list(self.iter_tree_children(parent_id))
577
576
 
 
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
 
578
582
    def _has_named_child(self, name, parent_id, known_children):
579
583
        """Does a parent already have a name child.
580
584
 
1401
1405
        delete_any(self._limbo_name(trans_id))
1402
1406
 
1403
1407
    def new_orphan(self, trans_id, parent_id):
1404
 
        conf = self._tree.get_config_stack()
1405
 
        handle_orphan = conf.get('bzr.transform.orphan_policy')
 
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)
1406
1423
        handle_orphan(self, trans_id, parent_id)
1407
1424
 
1408
1425
 
1471
1488
orphaning_registry._set_default_key('conflict')
1472
1489
 
1473
1490
 
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
 
 
1480
1491
class TreeTransform(DiskTreeTransform):
1481
1492
    """Represent a tree transformation.
1482
1493
 
2051
2062
        pass
2052
2063
 
2053
2064
    @property
2054
 
    @deprecated_method(deprecated_in((2, 5, 0)))
2055
2065
    def inventory(self):
2056
2066
        """This Tree does not use inventory as its backing data."""
2057
2067
        raise NotImplementedError(_PreviewTree.inventory)
2058
2068
 
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
 
 
2064
2069
    def get_root_id(self):
2065
2070
        return self._transform.final_file_id(self._transform.root)
2066
2071
 
2112
2117
        return cur_parent
2113
2118
 
2114
2119
    def path2id(self, path):
2115
 
        if isinstance(path, list):
2116
 
            if path == []:
2117
 
                path = [""]
2118
 
            path = osutils.pathjoin(*path)
2119
2120
        return self._transform.final_file_id(self._path2trans_id(path))
2120
2121
 
2121
2122
    def id2path(self, file_id):
2182
2183
                ordered_ids.append((trans_id, parent_file_id))
2183
2184
        return ordered_ids
2184
2185
 
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
 
 
2193
2186
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
2194
2187
        # This may not be a maximally efficient implementation, but it is
2195
2188
        # reasonably straightforward.  An implementation that grafts the
2832
2825
        tt.set_executability(entry.executable, trans_id)
2833
2826
 
2834
2827
 
 
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
 
2835
2846
def revert(working_tree, target_tree, filenames, backups=False,
2836
2847
           pb=None, change_reporter=None):
2837
2848
    """Revert a working tree's contents to those of a target tree."""