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

Split out bzr-specific Conflicts code.

Merged from https://code.launchpad.net/~jelmer/brz/conflict-refactor/+merge/388964

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from stat import S_ISREG
23
23
import time
24
24
 
25
 
from .. import errors, multiparent, osutils, trace, ui, urlutils
 
25
from .. import conflicts, errors, multiparent, osutils, trace, ui, urlutils
26
26
from ..i18n import gettext
27
27
from ..mutabletree import MutableTree
28
28
from ..sixish import viewitems, viewvalues
282
282
            if value == trans_id:
283
283
                return key
284
284
 
285
 
    def find_conflicts(self):
 
285
    def find_raw_conflicts(self):
286
286
        """Find any violations of inventory or filesystem invariants"""
287
287
        if self._done is True:
288
288
            raise ReusingTransform()
291
291
        # all children of non-existent parents are known, by definition.
292
292
        self._add_tree_children()
293
293
        by_parent = self.by_parent()
294
 
        conflicts.extend(self._unversioned_parents(by_parent))
295
294
        conflicts.extend(self._parent_loops())
296
295
        conflicts.extend(self._duplicate_entries(by_parent))
297
296
        conflicts.extend(self._parent_type_conflicts(by_parent))
301
300
        return conflicts
302
301
 
303
302
    def _check_malformed(self):
304
 
        conflicts = self.find_conflicts()
 
303
        conflicts = self.find_raw_conflicts()
305
304
        if len(conflicts) != 0:
306
305
            raise MalformedTransform(conflicts=conflicts)
307
306
 
387
386
                    break
388
387
        return conflicts
389
388
 
390
 
    def _unversioned_parents(self, by_parent):
391
 
        """If parent directories are versioned, children must be versioned."""
392
 
        conflicts = []
393
 
        for parent_id, children in viewitems(by_parent):
394
 
            if parent_id == ROOT_PARENT:
395
 
                continue
396
 
            if self.final_is_versioned(parent_id):
397
 
                continue
398
 
            for child_id in children:
399
 
                if self.final_is_versioned(child_id):
400
 
                    conflicts.append(('unversioned parent', parent_id))
401
 
                    break
402
 
        return conflicts
403
 
 
404
389
    def _improper_versioning(self):
405
390
        """Cannot version a file with no contents, or a bad type.
406
391
 
689
674
        """Produce output in the same format as Tree.iter_changes.
690
675
 
691
676
        Will produce nonsensical results if invoked while inventory/filesystem
692
 
        conflicts (as reported by TreeTransform.find_conflicts()) are present.
 
677
        conflicts (as reported by TreeTransform.find_raw_conflicts()) are present.
693
678
 
694
679
        This reads the Transform, but only reproduces changes involving a
695
680
        file_id.  Files that are not versioned in either of the FROM or TO
996
981
        """
997
982
        raise NotImplementedError(self.apply)
998
983
 
 
984
    def cook_conflicts(self, raw_conflicts):
 
985
        """Generate a list of cooked conflicts, sorted by file path"""
 
986
        if not raw_conflicts:
 
987
            return
 
988
        fp = FinalPaths(self)
 
989
        from .workingtree import TextConflict
 
990
        for c in raw_conflicts:
 
991
            if c[0] == 'text conflict':
 
992
                yield TextConflict(fp.get_path(c[1]))
 
993
            elif c[0] == 'duplicate':
 
994
                yield TextConflict(fp.get_path(c[2]))
 
995
            elif c[0] == 'contents conflict':
 
996
                yield TextConflict(fp.get_path(c[1][0]))
 
997
            elif c[0] == 'missing parent':
 
998
                # TODO(jelmer): This should not make it to here
 
999
                yield TextConflict(fp.get_path(c[2]))
 
1000
            else:
 
1001
                raise AssertionError('unknown conflict %s' % c[0])
 
1002
 
999
1003
 
1000
1004
class DiskTreeTransform(TreeTransformBase):
1001
1005
    """Tree transform storing its contents on disk."""