28
28
import bzrlib.status
29
29
from bzrlib.commands import register_command
30
from bzrlib.errors import BzrCommandError, NotConflicted
30
from bzrlib.errors import BzrCommandError, NotConflicted, UnsupportedOperation
31
31
from bzrlib.option import Option
32
32
from bzrlib.osutils import rename
33
33
from bzrlib.rio import Stanza
82
82
raise BzrCommandError(
83
83
"command 'resolve' needs one or more FILE, or --all")
84
tree = WorkingTree.open_containing(u'.')[0]
85
file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
88
86
raise BzrCommandError(
89
87
"If --all is specified, no FILE may be provided")
90
for filename in file_list:
88
tree = WorkingTree.open_containing(u'.')[0]
89
resolve(tree, file_list)
92
def resolve(tree, paths=None):
95
tree_conflicts = list(tree.conflict_lines())
98
selected_conflicts = tree_conflicts
100
new_conflicts, selected_conflicts = \
101
select_conflicts(tree, paths, tree_conflicts)
103
tree.set_conflict_lines(new_conflicts)
104
except UnsupportedOperation:
106
remove_conflict_files(tree, selected_conflicts)
111
def select_conflicts(tree, paths, tree_conflicts):
112
path_set = set(paths)
114
selected_paths = set()
116
selected_conflicts = []
118
file_id = tree.path2id(path)
119
if file_id is not None:
122
for conflict, stanza in zip(tree_conflicts,
123
conflict_stanzas(tree_conflicts)):
125
for key in ('path', 'conflict_path'):
130
if cpath in path_set:
132
selected_paths.add(cpath)
133
for key in ('file_id', 'conflict_file_id'):
135
cfile_id = stanza[key]
139
cpath = ids[cfile_id]
143
selected_paths.add(cpath)
145
selected_conflicts.append(conflict)
147
new_conflicts.append(conflict)
148
for path in [p for p in paths if p not in selected_paths]:
149
if not os.path.exists(tree.abspath(filename)):
150
print "%s does not exist" % path
152
print "%s is not conflicted" % path
153
return new_conflicts, selected_conflicts
155
def remove_conflict_files(tree, conflicts):
156
for stanza in conflict_stanzas(conflicts):
157
if stanza['type'] in ("text conflict", "contents conflict"):
92
158
for suffix in CONFLICT_SUFFIXES:
94
os.unlink(filename+suffix)
160
os.unlink(stanza['path']+suffix)
95
161
except OSError, e:
96
162
if e.errno != errno.ENOENT:
100
if failures == len(CONFLICT_SUFFIXES):
101
if not os.path.exists(filename):
102
print "%s does not exist" % filename
104
print "%s is not conflicted" % filename
106
168
def restore(filename):