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

  • Committer: Michael Ellerman
  • Date: 2006-03-09 00:24:48 UTC
  • mto: (1610.1.8 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: michael@ellerman.id.au-20060309002448-70cce15e3d605130
Make the "ignore line" in the commit message editor the "right" width, so
that if you make your message that wide it won't wrap in bzr log output.
Just as a visual aid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 by Aaron Bentley
 
2
 
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
 
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
# TODO: Move this into builtins
 
18
 
 
19
# TODO: 'bzr resolve' should accept a directory name and work from that 
 
20
# point down
 
21
 
 
22
# TODO: bzr revert should resolve; even when reverting the whole tree
 
23
# or particular directories
 
24
 
 
25
import os
 
26
import errno
 
27
 
 
28
import bzrlib.status
 
29
from bzrlib.errors import BzrCommandError, NotConflicted
 
30
from bzrlib.commands import register_command
 
31
from bzrlib.workingtree import CONFLICT_SUFFIXES, WorkingTree
 
32
from bzrlib.osutils import rename
 
33
 
 
34
class cmd_conflicts(bzrlib.commands.Command):
 
35
    """List files with conflicts.
 
36
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 
37
    files.)
 
38
    """
 
39
    def run(self):
 
40
        for path in WorkingTree.open_containing(u'.')[0].iter_conflicts():
 
41
            print path
 
42
 
 
43
class cmd_resolve(bzrlib.commands.Command):
 
44
    """Mark a conflict as resolved.
 
45
    """
 
46
    aliases = ['resolved']
 
47
    takes_args = ['file*']
 
48
    takes_options = ['all']
 
49
    def run(self, file_list=None, all=False):
 
50
        if file_list is None:
 
51
            if not all:
 
52
                raise BzrCommandError(
 
53
                    "command 'resolve' needs one or more FILE, or --all")
 
54
            tree = WorkingTree.open_containing(u'.')[0]
 
55
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
 
56
        else:
 
57
            if all:
 
58
                raise BzrCommandError(
 
59
                    "If --all is specified, no FILE may be provided")
 
60
        for filename in file_list:
 
61
            failures = 0
 
62
            for suffix in CONFLICT_SUFFIXES:
 
63
                try:
 
64
                    os.unlink(filename+suffix)
 
65
                except OSError, e:
 
66
                    if e.errno != errno.ENOENT:
 
67
                        raise
 
68
                    else:
 
69
                        failures += 1
 
70
            if failures == len(CONFLICT_SUFFIXES):
 
71
                if not os.path.exists(filename):
 
72
                    print "%s does not exist" % filename
 
73
                else:
 
74
                    print "%s is not conflicted" % filename
 
75
 
 
76
def restore(filename):
 
77
    """\
 
78
    Restore a conflicted file to the state it was in before merging.
 
79
    Only text restoration supported at present.
 
80
    """
 
81
    conflicted = False
 
82
    try:
 
83
        rename(filename + ".THIS", filename)
 
84
        conflicted = True
 
85
    except OSError, e:
 
86
        if e.errno != errno.ENOENT:
 
87
            raise
 
88
    try:
 
89
        os.unlink(filename + ".BASE")
 
90
        conflicted = True
 
91
    except OSError, e:
 
92
        if e.errno != errno.ENOENT:
 
93
            raise
 
94
    try:
 
95
        os.unlink(filename + ".OTHER")
 
96
        conflicted = True
 
97
    except OSError, e:
 
98
        if e.errno != errno.ENOENT:
 
99
            raise
 
100
    if not conflicted:
 
101
        raise NotConflicted(filename)