/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/transform.py

Added conflict handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
 
from bzrlib.errors import DuplicateKey
 
2
from bzrlib.errors import DuplicateKey, MalformedTransform
3
3
def unique_add(map, key, value):
4
4
    if key in map:
5
5
        raise DuplicateKey(key=key)
41
41
        unique_add(self._new_parent, trans_id, parent)
42
42
        return trans_id
43
43
 
 
44
    def adjust_path(self, name, parent, trans_id):
 
45
        self._new_name[trans_id] = name
 
46
        self._new_parent[trans_id] = parent
 
47
 
44
48
    def get_id_tree(self, inventory_id):
45
49
        """Determine the transaction id of a working tree file.
46
50
        
71
75
        new_paths = [(fp.get_path(t), t) for t in new_ids]
72
76
        new_paths.sort()
73
77
        return new_paths
 
78
 
 
79
    def find_conflicts(self):
 
80
        """Find any violations of inventory of filesystem invariants"""
 
81
        # No directory may have two entries with the same name
 
82
        by_parent = {}
 
83
        conflicts = []
 
84
        for trans_id, parent_id in self._new_parent.iteritems():
 
85
            if parent_id not in by_parent:
 
86
                by_parent[parent_id] = set()
 
87
            by_parent[parent_id].add(trans_id)
 
88
        for children in by_parent.itervalues():
 
89
            name_ids = [(self._new_name[t], t) for t in children]
 
90
            name_ids.sort()
 
91
            last_name = None
 
92
            last_trans_id = None
 
93
            for name, trans_id in name_ids:
 
94
                if name == last_name:
 
95
                    conflicts.append(('duplicate', last_trans_id, trans_id))
 
96
                last_name = name
 
97
                last_trans_id = trans_id
 
98
        return conflicts
 
99
            
74
100
            
75
101
    def apply(self):
 
102
        if len(self.find_conflicts()) != 0:
 
103
            raise MalformedTransform()
76
104
        inv = self._tree.inventory
77
105
        for path, trans_id in self.new_paths():
78
106
            try: