~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Refactored conflict handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 
110
110
    def find_conflicts(self):
111
111
        """Find any violations of inventory of filesystem invariants"""
112
 
        # No directory may have two entries with the same name
113
112
        by_parent = {}
114
113
        conflicts = []
115
114
        for trans_id, parent_id in self._new_parent.iteritems():
116
115
            if parent_id not in by_parent:
117
116
                by_parent[parent_id] = set()
118
117
            by_parent[parent_id].add(trans_id)
 
118
 
 
119
        conflicts.extend(self._duplicate_entries(by_parent))
 
120
        conflicts.extend(self._parent_type_conflicts(by_parent))
 
121
        return conflicts
 
122
 
 
123
    def _duplicate_entries(self, by_parent):
 
124
        """No directory may have two entries with the same name."""
 
125
        conflicts = []
119
126
        for children in by_parent.itervalues():
120
127
            name_ids = [(self._new_name[t], t) for t in children]
121
128
            name_ids.sort()
126
133
                    conflicts.append(('duplicate', last_trans_id, trans_id))
127
134
                last_name = name
128
135
                last_trans_id = trans_id
 
136
        return conflicts
 
137
 
 
138
    def _parent_type_conflicts(self, by_parent):
 
139
        """parents must have directory 'contents'."""
 
140
        conflicts = []
129
141
        for parent_id in by_parent.iterkeys():
130
142
            try:
131
143
                kind = self.final_kind(parent_id)
135
147
                conflicts.append(('missing parent', parent_id))
136
148
            elif kind != "directory":
137
149
                conflicts.append(('non-directory parent', parent_id))
138
 
                
139
150
        return conflicts
140
151
            
141
152
    def apply(self):