~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/conflicts.py

  • Committer: Aaron Bentley
  • Date: 2005-10-01 06:48:01 UTC
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051001064801-7400c2ed0fe26080
Made iter_conflicts a WorkingTree method

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from bzrlib.branch import Branch
19
19
from bzrlib.errors import BzrCommandError
20
20
from bzrlib.commands import register_command
 
21
from bzrlib.workingtree import CONFLICT_SUFFIXES
21
22
import os
22
23
import errno
23
24
 
24
 
SUFFIXES = ('.THIS', '.BASE', '.OTHER')
25
 
def get_conflicted_stem(path):
26
 
    for suffix in SUFFIXES:
27
 
        if path.endswith(suffix):
28
 
            return path[:-len(suffix)]
29
 
 
30
 
def iter_conflicts(tree):
31
 
    conflicted = set()
32
 
    for path in (s[0] for s in tree.list_files()):
33
 
        stem = get_conflicted_stem(path)
34
 
        if stem is None:
35
 
            continue
36
 
        if stem not in conflicted:
37
 
            conflicted.add(stem)
38
 
            yield stem
39
 
 
40
25
class cmd_conflicts(bzrlib.commands.Command):
41
26
    """List files with conflicts.
42
27
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
43
28
    files.)
44
29
    """
45
30
    def run(self):
46
 
        for path in iter_conflicts(Branch.open_containing('.').working_tree()):
 
31
        for path in Branch.open_containing('.').working_tree().iter_conflicts():
47
32
            print path
48
33
 
49
34
register_command(cmd_conflicts)
59
44
                raise BzrCommandError(
60
45
                    "command 'resolve' needs one or more FILE, or --all")
61
46
            tree = Branch.open_containing('.').working_tree()
62
 
            file_list = list(tree.abspath(f) for f in iter_conflicts(tree))
 
47
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
63
48
        else:
64
49
            if all:
65
50
                raise BzrCommandError(
66
51
                    "If --all is specified, no FILE may be provided")
67
52
        for filename in file_list:
68
53
            failures = 0
69
 
            for suffix in SUFFIXES:
 
54
            for suffix in CONFLICT_SUFFIXES:
70
55
                try:
71
56
                    os.unlink(filename+suffix)
72
57
                except OSError, e:
74
59
                        raise
75
60
                    else:
76
61
                        failures += 1
77
 
            if failures == len(SUFFIXES):
 
62
            if failures == len(CONFLICT_SUFFIXES):
78
63
                if not os.path.exists(filename):
79
64
                    print "%s does not exist" % filename
80
65
                else:
85
70
# monkey-patch the standard 'status' to give us conflicts, too.
86
71
def _show_status(branch, **kwargs):
87
72
    old_show_status(branch, **kwargs)
88
 
    conflicted = list(iter_conflicts(branch.working_tree()))
 
73
    conflicted = list(branch.working_tree().iter_conflicts())
89
74
    if len(conflicted) > 0:
90
75
        print "conflicts:"
91
76
        for f in conflicted: