/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

Store-escaping must quote uppercase characters too, so that they're safely 
stored on Windows.  We can't use urllib.quote anymore but must have our own 
version that can do this.  Test.

Make KnitRepository use escaped stores.

Update existing storage-escaping tests.

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.commands import register_command
 
30
from bzrlib.errors import BzrCommandError, NotConflicted
 
31
from bzrlib.option import Option
 
32
from bzrlib.workingtree import CONFLICT_SUFFIXES, WorkingTree
 
33
from bzrlib.osutils import rename
 
34
 
 
35
class cmd_conflicts(bzrlib.commands.Command):
 
36
    """List files with conflicts.
 
37
 
 
38
    Merge will do its best to combine the changes in two branches, but there
 
39
    are some kinds of problems only a human can fix.  When it encounters those,
 
40
    it will mark a conflict.  A conflict means that you need to fix something,
 
41
    before you should commit.
 
42
 
 
43
    Use bzr resolve when you have fixed a problem.
 
44
 
 
45
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 
46
    files.)
 
47
 
 
48
    See also bzr resolve.
 
49
    """
 
50
    def run(self):
 
51
        for path in WorkingTree.open_containing(u'.')[0].iter_conflicts():
 
52
            print path
 
53
 
 
54
class cmd_resolve(bzrlib.commands.Command):
 
55
    """Mark a conflict as resolved.
 
56
 
 
57
    Merge will do its best to combine the changes in two branches, but there
 
58
    are some kinds of problems only a human can fix.  When it encounters those,
 
59
    it will mark a conflict.  A conflict means that you need to fix something,
 
60
    before you should commit.
 
61
 
 
62
    Once you have fixed a problem, use "bzr resolve FILE.." to mark
 
63
    individual files as fixed, or "bzr resolve --all" to mark all conflicts as
 
64
    resolved.
 
65
 
 
66
    See also bzr conflicts.
 
67
    """
 
68
    aliases = ['resolved']
 
69
    takes_args = ['file*']
 
70
    takes_options = [Option('all', help='Resolve all conflicts in this tree')]
 
71
    def run(self, file_list=None, all=False):
 
72
        if file_list is None:
 
73
            if not all:
 
74
                raise BzrCommandError(
 
75
                    "command 'resolve' needs one or more FILE, or --all")
 
76
            tree = WorkingTree.open_containing(u'.')[0]
 
77
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
 
78
        else:
 
79
            if all:
 
80
                raise BzrCommandError(
 
81
                    "If --all is specified, no FILE may be provided")
 
82
        for filename in file_list:
 
83
            failures = 0
 
84
            for suffix in CONFLICT_SUFFIXES:
 
85
                try:
 
86
                    os.unlink(filename+suffix)
 
87
                except OSError, e:
 
88
                    if e.errno != errno.ENOENT:
 
89
                        raise
 
90
                    else:
 
91
                        failures += 1
 
92
            if failures == len(CONFLICT_SUFFIXES):
 
93
                if not os.path.exists(filename):
 
94
                    print "%s does not exist" % filename
 
95
                else:
 
96
                    print "%s is not conflicted" % filename
 
97
 
 
98
def restore(filename):
 
99
    """\
 
100
    Restore a conflicted file to the state it was in before merging.
 
101
    Only text restoration supported at present.
 
102
    """
 
103
    conflicted = False
 
104
    try:
 
105
        rename(filename + ".THIS", filename)
 
106
        conflicted = True
 
107
    except OSError, e:
 
108
        if e.errno != errno.ENOENT:
 
109
            raise
 
110
    try:
 
111
        os.unlink(filename + ".BASE")
 
112
        conflicted = True
 
113
    except OSError, e:
 
114
        if e.errno != errno.ENOENT:
 
115
            raise
 
116
    try:
 
117
        os.unlink(filename + ".OTHER")
 
118
        conflicted = True
 
119
    except OSError, e:
 
120
        if e.errno != errno.ENOENT:
 
121
            raise
 
122
    if not conflicted:
 
123
        raise NotConflicted(filename)