~abentley/bzrtools/bzrtools.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright (C) 2005 by Aaron Bentley

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import bzrlib.status
from bzrlib.branch import Branch

SUFFIXES = ('.TREE', '.BASE', '.OTHER')
def get_conflicted_stem(path):
    for suffix in SUFFIXES:
        if path.endswith(suffix):
            return path[:-len(suffix)]

def iter_conflicts(tree):
    conflicted = set()
    for path in (s[0] for s in tree.list_files()):
        stem = get_conflicted_stem(path)
        if stem is None:
            continue
        if stem not in conflicted:
            conflicted.add(stem)
            yield stem

class cmd_conflicts(bzrlib.commands.Command):
    """List files with conflicts.
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
    files.)
    """
    def run(self):
        for path in iter_conflicts(Branch('.').working_tree()):
            print path

# monkey-patch the standard 'status' to give us conflicts, too.
def _show_status(branch, **kwargs):
    old_show_status(branch, **kwargs)
    conflicted = list(iter_conflicts(branch.working_tree()))
    if len(conflicted) > 0:
        print "conflicts:"
        for f in conflicted:
            print " ", f

old_show_status = bzrlib.status.show_status
bzrlib.status.show_status = _show_status