Merge lp:~jelmer/brz/lca-merge-git into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7303
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/lca-merge-git
Merge into: lp:brz
Prerequisite: lp:~jelmer/brz/split-multiwalker
Diff against target: 169 lines (+25/-27)
3 files modified
breezy/merge.py (+9/-11)
breezy/multiwalker.py (+14/-14)
breezy/tests/test_multiwalker.py (+2/-2)
To merge this branch: bzr merge lp:~jelmer/brz/lca-merge-git
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+367321@code.launchpad.net

Commit message

Avoid using inventories in breezy.merge when encountering lcas.

Description of the change

Avoid using inventories in breezy.merge when encountering lcas.

This fixes merge for git when encountering lcas.

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve
lp:~jelmer/brz/lca-merge-git updated
7303. By Jelmer Vernooij on 2019-06-02

Fix syntax.

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 2019-06-02 18:45:38 +0000
3+++ breezy/merge.py 2019-06-02 18:45:39 +0000
4@@ -908,8 +908,6 @@
5 from .multiwalker import MultiWalker
6 walker = MultiWalker(self.other_tree, self._lca_trees)
7
8- base_inventory = self.base_tree.root_inventory
9- this_inventory = self.this_tree.root_inventory
10 for other_path, file_id, other_ie, lca_values in walker.iter_all():
11 # Is this modified at all from any of the other trees?
12 if other_ie is None:
13@@ -948,20 +946,20 @@
14 lca_paths.append(lca_path)
15
16 try:
17- base_ie = base_inventory.get_entry(file_id)
18+ base_path = self.base_tree.id2path(file_id)
19 except errors.NoSuchId:
20+ base_path = None
21 base_ie = _none_entry
22- base_path = None
23 else:
24- base_path = self.base_tree.id2path(file_id)
25+ base_ie = next(self.base_tree.iter_entries_by_dir(specific_files=[base_path]))[1]
26
27 try:
28- this_ie = this_inventory.get_entry(file_id)
29+ this_path = self.this_tree.id2path(file_id)
30 except errors.NoSuchId:
31 this_ie = _none_entry
32 this_path = None
33 else:
34- this_path = self.this_tree.id2path(file_id)
35+ this_ie = next(self.this_tree.iter_entries_by_dir(specific_files=[this_path]))[1]
36
37 lca_kinds = []
38 lca_parent_ids = []
39@@ -1865,13 +1863,13 @@
40
41 def _entries_to_incorporate(self):
42 """Yields pairs of (inventory_entry, new_parent)."""
43- other_inv = self.other_tree.root_inventory
44- subdir_id = other_inv.path2id(self._source_subpath)
45+ subdir_id = self.other_tree.path2id(self._source_subpath)
46 if subdir_id is None:
47 # XXX: The error would be clearer if it gave the URL of the source
48 # branch, but we don't have a reference to that here.
49 raise PathNotInTree(self._source_subpath, "Source tree")
50- subdir = other_inv.get_entry(subdir_id)
51+ subdir = next(self.other_tree.iter_entries_by_dir(
52+ specific_files=[self._source_subpath]))[1]
53 parent_in_target = osutils.dirname(self._target_subdir)
54 target_id = self.this_tree.path2id(parent_in_target)
55 if target_id is None:
56@@ -1893,7 +1891,7 @@
57 if subdir.kind != 'directory':
58 # No children, so we are done.
59 return
60- for path, entry in other_inv.iter_entries_by_dir(subdir_id):
61+ for path, entry in self.other_tree.root_inventory.iter_entries_by_dir(subdir_id):
62 parent_id = entry.parent_id
63 if parent_id == subdir.file_id:
64 # The root's parent ID has changed, so make sure children of
65
66=== modified file 'breezy/multiwalker.py'
67--- breezy/multiwalker.py 2019-06-02 18:45:38 +0000
68+++ breezy/multiwalker.py 2019-06-02 18:45:39 +0000
69@@ -108,6 +108,11 @@
70 dirname, basename = osutils.split(path)
71 return (dirname.split(u'/'), basename)
72
73+ def _lookup_by_master_path(self, extra_entries, other_tree, master_path):
74+ return self._lookup_by_file_id(
75+ extra_entries, other_tree,
76+ self._master_tree.path2id(master_path))
77+
78 def _lookup_by_file_id(self, extra_entries, other_tree, file_id):
79 """Lookup an inventory entry by file_id.
80
81@@ -127,8 +132,6 @@
82 """
83 if file_id in extra_entries:
84 return extra_entries.pop(file_id)
85- # TODO: Is id2path better as the first call, or is
86- # inventory[file_id] better as a first check?
87 try:
88 cur_path = other_tree.id2path(file_id)
89 except errors.NoSuchId:
90@@ -137,7 +140,8 @@
91 return (None, None)
92 else:
93 self._out_of_order_processed.add(file_id)
94- cur_ie = other_tree.root_inventory.get_entry(file_id)
95+ cur_ie = next(other_tree.iter_entries_by_dir(
96+ specific_files=[cur_path]))[1]
97 return (cur_path, cur_ie)
98
99 def iter_all(self):
100@@ -176,17 +180,16 @@
101 if not master_has_more:
102 break
103
104- file_id = master_ie.file_id
105 other_values = []
106 other_values_append = other_values.append
107 next_other_entries = []
108 next_other_entries_append = next_other_entries.append
109 for idx, (other_has_more, other_path, other_ie) in enumerate(other_entries):
110 if not other_has_more:
111- other_values_append(lookup_by_file_id(
112- others_extra[idx], self._other_trees[idx], file_id))
113+ other_values_append(self._lookup_by_master_path(
114+ others_extra[idx], self._other_trees[idx], path))
115 next_other_entries_append((False, None, None))
116- elif file_id == other_ie.file_id:
117+ elif master_ie.file_id == other_ie.file_id:
118 # This is the critical code path, as most of the entries
119 # should match between most trees.
120 other_values_append((other_path, other_ie))
121@@ -203,7 +206,7 @@
122 other_extra[other_file_id] = (other_path, other_ie)
123 other_has_more, other_path, other_ie = \
124 step_one(other_walker)
125- if other_has_more and other_ie.file_id == file_id:
126+ if other_has_more and other_ie.file_id == master_ie.file_id:
127 # We ended up walking to this point, match and step
128 # again
129 other_values_append((other_path, other_ie))
130@@ -212,14 +215,14 @@
131 else:
132 # This record isn't in the normal order, see if it
133 # exists at all.
134- other_values_append(lookup_by_file_id(
135- other_extra, self._other_trees[idx], file_id))
136+ other_values_append(self._lookup_by_master_path(
137+ other_extra, self._other_trees[idx], path))
138 next_other_entries_append((other_has_more, other_path,
139 other_ie))
140 other_entries = next_other_entries
141
142 # We've matched all the walkers, yield this datapoint
143- yield path, file_id, master_ie, other_values
144+ yield path, master_ie.file_id, master_ie, other_values
145 self._other_walkers = other_walkers
146 self._other_entries = other_entries
147 self._others_extra = others_extra
148@@ -261,6 +264,3 @@
149 other_values.append(self._lookup_by_file_id(
150 alt_extra, alt_tree, file_id))
151 yield other_path, file_id, None, other_values
152-
153-
154-
155
156=== modified file 'breezy/tests/test_multiwalker.py'
157--- breezy/tests/test_multiwalker.py 2019-06-02 18:45:38 +0000
158+++ breezy/tests/test_multiwalker.py 2019-06-02 18:45:39 +0000
159@@ -229,8 +229,8 @@
160 basis_tree, root_id = self.lock_and_get_basis_and_root_id(tree)
161 first_tree = tree.branch.repository.revision_tree(b'first-rev-id')
162 second_tree = tree.branch.repository.revision_tree(b'second-rev-id')
163- walker = multiwalker.MultiWalker(tree, [basis_tree, first_tree,
164- second_tree])
165+ walker = multiwalker.MultiWalker(
166+ tree, [basis_tree, first_tree, second_tree])
167 iterator = walker.iter_all()
168 self.assertWalkerNext(u'', root_id, True, [u'', u'', u''], iterator)
169 self.assertWalkerNext(u'a', b'a-id', True,

Subscribers

People subscribed via source and target branches