/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

 * The internal storage of history, and logical branch identity have now
   been split into Branch, and Repository. The common locking and file 
   management routines are now in bzrlib.lockablefiles. 
   (Aaron Bentley, Robert Collins, Martin Pool)

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.branch import Branch
 
30
from bzrlib.errors import BzrCommandError, NotConflicted
 
31
from bzrlib.commands import register_command
 
32
from bzrlib.workingtree import CONFLICT_SUFFIXES
 
33
from bzrlib.osutils import rename
 
34
 
 
35
class cmd_conflicts(bzrlib.commands.Command):
 
36
    """List files with conflicts.
 
37
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 
38
    files.)
 
39
    """
 
40
    def run(self):
 
41
        for path in Branch.open_containing(u'.')[0].working_tree().iter_conflicts():
 
42
            print path
 
43
 
 
44
class cmd_resolve(bzrlib.commands.Command):
 
45
    """Mark a conflict as resolved.
 
46
    """
 
47
    aliases = ['resolved']
 
48
    takes_args = ['file*']
 
49
    takes_options = ['all']
 
50
    def run(self, file_list=None, all=False):
 
51
        if file_list is None:
 
52
            if not all:
 
53
                raise BzrCommandError(
 
54
                    "command 'resolve' needs one or more FILE, or --all")
 
55
            tree = Branch.open_containing(u'.')[0].working_tree()
 
56
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
 
57
        else:
 
58
            if all:
 
59
                raise BzrCommandError(
 
60
                    "If --all is specified, no FILE may be provided")
 
61
        for filename in file_list:
 
62
            failures = 0
 
63
            for suffix in CONFLICT_SUFFIXES:
 
64
                try:
 
65
                    os.unlink(filename+suffix)
 
66
                except OSError, e:
 
67
                    if e.errno != errno.ENOENT:
 
68
                        raise
 
69
                    else:
 
70
                        failures += 1
 
71
            if failures == len(CONFLICT_SUFFIXES):
 
72
                if not os.path.exists(filename):
 
73
                    print "%s does not exist" % filename
 
74
                else:
 
75
                    print "%s is not conflicted" % filename
 
76
 
 
77
def restore(filename):
 
78
    """\
 
79
    Restore a conflicted file to the state it was in before merging.
 
80
    Only text restoration supported at present.
 
81
    """
 
82
    conflicted = False
 
83
    try:
 
84
        rename(filename + ".THIS", filename)
 
85
        conflicted = True
 
86
    except OSError, e:
 
87
        if e.errno != errno.ENOENT:
 
88
            raise
 
89
    try:
 
90
        os.unlink(filename + ".BASE")
 
91
        conflicted = True
 
92
    except OSError, e:
 
93
        if e.errno != errno.ENOENT:
 
94
            raise
 
95
    try:
 
96
        os.unlink(filename + ".OTHER")
 
97
        conflicted = True
 
98
    except OSError, e:
 
99
        if e.errno != errno.ENOENT:
 
100
            raise
 
101
    if not conflicted:
 
102
        raise NotConflicted(filename)