Merge lp:~jelmer/brz/cook-conflicts-split into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/cook-conflicts-split
Merge into: lp:brz/3.1
Diff against target: 128 lines (+61/-49)
1 file modified
breezy/merge.py (+61/-49)
To merge this branch: bzr merge lp:~jelmer/brz/cook-conflicts-split
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+388956@code.launchpad.net

Commit message

Factor out conflict cookers.

Description of the change

Factor out conflict cookers.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/merge.py'
2--- breezy/merge.py 2020-07-05 13:18:03 +0000
3+++ breezy/merge.py 2020-08-08 18:04:48 +0000
4@@ -689,6 +689,61 @@
5 return other is self
6
7
8+
9+def cook_path_conflict(
10+ tt, fp, conflict_type, trans_id, file_id, this_parent, this_name,
11+ other_parent, other_name):
12+ if this_parent is None or this_name is None:
13+ this_path = '<deleted>'
14+ else:
15+ parent_path = fp.get_path(tt.trans_id_file_id(this_parent))
16+ this_path = osutils.pathjoin(parent_path, this_name)
17+ if other_parent is None or other_name is None:
18+ other_path = '<deleted>'
19+ else:
20+ try:
21+ parent_path = fp.get_path(tt.trans_id_file_id(other_parent))
22+ except transform.NoFinalPath:
23+ # The other entry was in a path that doesn't exist in our tree.
24+ # Put it in the root.
25+ parent_path = ''
26+ other_path = osutils.pathjoin(parent_path, other_name)
27+ return _mod_conflicts.Conflict.factory(
28+ 'path conflict', path=this_path,
29+ conflict_path=other_path,
30+ file_id=file_id)
31+
32+
33+def cook_content_conflict(tt, fp, conflict_type, trans_ids):
34+ for trans_id in trans_ids:
35+ file_id = tt.final_file_id(trans_id)
36+ if file_id is not None:
37+ # Ok we found the relevant file-id
38+ break
39+ path = fp.get_path(trans_id)
40+ for suffix in ('.BASE', '.THIS', '.OTHER'):
41+ if path.endswith(suffix):
42+ # Here is the raw path
43+ path = path[:-len(suffix)]
44+ break
45+ return _mod_conflicts.Conflict.factory(
46+ conflict_type, path=path, file_id=file_id)
47+
48+
49+def cook_text_conflict(tt, fp, conflict_type, trans_id):
50+ path = fp.get_path(trans_id)
51+ file_id = tt.final_file_id(trans_id)
52+ return _mod_conflicts.Conflict.factory(
53+ conflict_type, path=path, file_id=file_id)
54+
55+
56+CONFLICT_COOKERS = {
57+ 'path conflict': cook_path_conflict,
58+ 'text conflict': cook_text_conflict,
59+ 'contents conflict': cook_content_conflict,
60+}
61+
62+
63 _none_entry = _InventoryNoneEntry()
64
65
66@@ -1527,56 +1582,13 @@
67 cooked_conflicts = transform.cook_conflicts(fs_conflicts, self.tt)
68 fp = transform.FinalPaths(self.tt)
69 for conflict in self._raw_conflicts:
70- conflict_type = conflict[0]
71- if conflict_type == 'path conflict':
72- (trans_id, file_id,
73- this_parent, this_name,
74- other_parent, other_name) = conflict[1:]
75- if this_parent is None or this_name is None:
76- this_path = '<deleted>'
77- else:
78- parent_path = fp.get_path(
79- self.tt.trans_id_file_id(this_parent))
80- this_path = osutils.pathjoin(parent_path, this_name)
81- if other_parent is None or other_name is None:
82- other_path = '<deleted>'
83- else:
84- if other_parent == self.other_tree.path2id(''):
85- # The tree transform doesn't know about the other root,
86- # so we special case here to avoid a NoFinalPath
87- # exception
88- parent_path = ''
89- else:
90- parent_path = fp.get_path(
91- self.tt.trans_id_file_id(other_parent))
92- other_path = osutils.pathjoin(parent_path, other_name)
93- c = _mod_conflicts.Conflict.factory(
94- 'path conflict', path=this_path,
95- conflict_path=other_path,
96- file_id=file_id)
97- elif conflict_type == 'contents conflict':
98- for trans_id in conflict[1]:
99- file_id = self.tt.final_file_id(trans_id)
100- if file_id is not None:
101- # Ok we found the relevant file-id
102- break
103- path = fp.get_path(trans_id)
104- for suffix in ('.BASE', '.THIS', '.OTHER'):
105- if path.endswith(suffix):
106- # Here is the raw path
107- path = path[:-len(suffix)]
108- break
109- c = _mod_conflicts.Conflict.factory(conflict_type,
110- path=path, file_id=file_id)
111- content_conflict_file_ids.add(file_id)
112- elif conflict_type == 'text conflict':
113- trans_id = conflict[1]
114- path = fp.get_path(trans_id)
115- file_id = self.tt.final_file_id(trans_id)
116- c = _mod_conflicts.Conflict.factory(conflict_type,
117- path=path, file_id=file_id)
118- else:
119+ try:
120+ cooker = CONFLICT_COOKERS[conflict[0]]
121+ except KeyError:
122 raise AssertionError('bad conflict type: %r' % (conflict,))
123+ c = cooker(self.tt, fp, *conflict)
124+ if conflict[0] == 'contents conflict':
125+ content_conflict_file_ids.add(c.file_id)
126 cooked_conflicts.append(c)
127
128 self.cooked_conflicts = []

Subscribers

People subscribed via source and target branches