Merge lp:~jelmer/brz/use-find-previous-path into lp:brz

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/use-find-previous-path
Merge into: lp:brz
Diff against target: 160 lines (+34/-22)
4 files modified
breezy/bzr/dirstate.py (+1/-1)
breezy/bzr/workingtree_4.py (+4/-1)
breezy/tests/test_workingtree_4.py (+5/-1)
breezy/tree.py (+24/-19)
To merge this branch: bzr merge lp:~jelmer/brz/use-find-previous-path
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+368861@code.launchpad.net

Commit message

Use find_previous_path in InterTree.iter_changes.

Description of the change

Use find_previous_path in InterTree.iter_changes.

This allows future rename detection to happen using something other than file ids.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks!

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

A single test is failing:

Traceback (most recent call last):
  File "/workspace/brz/brz/brz-land/work/breezy/tests/test_workingtree_4.py", line 245, in test_dirstate_doesnt_read_from_repo_when_returning_cache_tree
    self.assertTreesEqual(rev1_tree, result_rev1_tree)
  File "/workspace/brz/brz/brz-land/work/breezy/tests/__init__.py", line 3102, in assertTreesEqual
    differences = left.changes_from(right)
  File "/workspace/brz/brz/brz-land/work/breezy/tree.py", line 240, in changes_from
    want_unversioned=want_unversioned,
  File "/workspace/brz/brz/brz-land/work/breezy/tree.py", line 855, in compare
    want_unversioned=want_unversioned)
  File "/workspace/brz/brz/brz-land/work/breezy/delta.py", line 131, in _compare_trees
    want_unversioned=want_unversioned):
  File "/workspace/brz/brz/brz-land/work/breezy/tree.py", line 934, in iter_changes
    self.target, self.source, [p for p, e in to_entries_by_dir])
  File "/workspace/brz/brz/brz-land/work/breezy/tree.py", line 1176, in find_previous_paths
    ret[path] = find_previous_path(from_tree, to_tree, path)
  File "/workspace/brz/brz/brz-land/work/breezy/tree.py", line 1189, in find_previous_path
    file_id = from_tree.path2id(path)
  File "/workspace/brz/brz/brz-land/work/breezy/bzr/workingtree_4.py", line 2055, in path2id
    entry = self._get_entry(path=path)
  File "/workspace/brz/brz/brz-land/work/breezy/bzr/workingtree_4.py", line 1788, in _get_entry
    parent_index = self._get_parent_index()
  File "/workspace/brz/brz/brz-land/work/breezy/bzr/workingtree_4.py", line 1771, in _get_parent_index
    return self._dirstate.get_parent_ids().index(self._revision_id) + 1
ValueError: '<email address hidden>' is not in list

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/dirstate.py'
2--- breezy/bzr/dirstate.py 2019-06-15 15:59:17 +0000
3+++ breezy/bzr/dirstate.py 2019-06-16 23:55:10 +0000
4@@ -166,7 +166,7 @@
5
6 vector of all directories, and vector of the childen ?
7 i.e.
8- root_entrie = (direntry for root, [parent_direntries_for_root]),
9+ root_entries = (direntry for root, [parent_direntries_for_root]),
10 dirblocks = [
11 ('', ['data for achild', 'data for bchild', 'data for cchild'])
12 ('dir', ['achild', 'cchild', 'echild'])
13
14=== modified file 'breezy/bzr/workingtree_4.py'
15--- breezy/bzr/workingtree_4.py 2019-03-04 00:16:27 +0000
16+++ breezy/bzr/workingtree_4.py 2019-06-16 23:55:10 +0000
17@@ -1785,7 +1785,10 @@
18 raise errors.BzrError('must supply file_id or path')
19 if path is not None:
20 path = path.encode('utf8')
21- parent_index = self._get_parent_index()
22+ try:
23+ parent_index = self._get_parent_index()
24+ except ValueError:
25+ raise errors.NoSuchRevisionInTree(self._dirstate, self._revision_id)
26 return self._dirstate._get_entry(parent_index, fileid_utf8=file_id,
27 path_utf8=path)
28
29
30=== modified file 'breezy/tests/test_workingtree_4.py'
31--- breezy/tests/test_workingtree_4.py 2018-11-16 18:35:30 +0000
32+++ breezy/tests/test_workingtree_4.py 2019-06-16 23:55:10 +0000
33@@ -214,11 +214,13 @@
34 rev1 = subtree.commit('commit in subdir')
35 rev1_tree = subtree.basis_tree()
36 rev1_tree.lock_read()
37+ # Trigger reading of inventory
38 rev1_tree.root_inventory
39 self.addCleanup(rev1_tree.unlock)
40 rev2 = subtree.commit('second commit in subdir', allow_pointless=True)
41 rev2_tree = subtree.basis_tree()
42 rev2_tree.lock_read()
43+ # Trigger reading of inventory
44 rev2_tree.root_inventory
45 self.addCleanup(rev2_tree.unlock)
46
47@@ -242,8 +244,10 @@
48 result_rev2_tree = tree.revision_tree(rev2)
49 # compare - there should be no differences between the handed and
50 # returned trees
51- self.assertTreesEqual(rev1_tree, result_rev1_tree)
52 self.assertTreesEqual(rev2_tree, result_rev2_tree)
53+ self.assertRaises(
54+ errors.NoSuchRevisionInTree, self.assertTreesEqual, rev1_tree,
55+ result_rev1_tree)
56
57 def test_dirstate_doesnt_cache_non_parent_trees(self):
58 """Getting parent trees from a dirstate tree does not read from the
59
60=== modified file 'breezy/tree.py'
61--- breezy/tree.py 2019-06-15 17:53:40 +0000
62+++ breezy/tree.py 2019-06-16 23:55:10 +0000
63@@ -161,6 +161,9 @@
64 return tuple(self).__getitem__(i)
65 return getattr(self, self.__slots__[i])
66
67+ def is_reparented(self):
68+ return self.parent_id[0] != self.parent_id[1]
69+
70 def discard_new(self):
71 return self.__class__(
72 self.file_id, (self.path[0], None), self.changed_content,
73@@ -924,9 +927,11 @@
74 to_paths = {}
75 from_entries_by_dir = list(self.source.iter_entries_by_dir(
76 specific_files=source_specific_files))
77- from_data = dict((e.file_id, (p, e)) for p, e in from_entries_by_dir)
78+ from_data = dict(from_entries_by_dir)
79 to_entries_by_dir = list(self.target.iter_entries_by_dir(
80 specific_files=target_specific_files))
81+ path_equivs = find_previous_paths(
82+ self.target, self.source, [p for p, e in to_entries_by_dir])
83 num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
84 entry_count = 0
85 # the unversioned path lookup only occurs on real trees - where there
86@@ -946,32 +951,32 @@
87 (None, unversioned_path[0][-1]),
88 (None, target_kind),
89 (None, target_executable))
90- source_path, source_entry = from_data.get(target_entry.file_id,
91- (None, None))
92- result, changes = self._changes_from_entries(source_entry,
93- target_entry, source_path=source_path, target_path=target_path)
94- to_paths[result[0]] = result[1][1]
95+ source_path = path_equivs[target_path]
96+ if source_path is not None:
97+ source_entry = from_data.get(source_path)
98+ else:
99+ source_entry = None
100+ result, changes = self._changes_from_entries(
101+ source_entry, target_entry, source_path=source_path, target_path=target_path)
102+ to_paths[result.file_id] = result.path[1]
103 entry_count += 1
104- if result[3][0]:
105+ if result.versioned[0]:
106 entry_count += 1
107 if pb is not None:
108 pb.update('comparing files', entry_count, num_entries)
109 if changes or include_unchanged:
110 if specific_files is not None:
111- new_parent_id = result[4][1]
112- precise_file_ids.add(new_parent_id)
113- changed_file_ids.append(result[0])
114+ precise_file_ids.add(result.parent_id[1])
115+ changed_file_ids.append(result.file_id)
116 yield result
117 # Ensure correct behaviour for reparented/added specific files.
118 if specific_files is not None:
119 # Record output dirs
120- if result[6][1] == 'directory':
121- seen_dirs.add(result[0])
122+ if result.kind[1] == 'directory':
123+ seen_dirs.add(result.file_id)
124 # Record parents of reparented/added entries.
125- versioned = result[3]
126- parents = result[4]
127- if not versioned[0] or parents[0] != parents[1]:
128- seen_parents.add(parents[1])
129+ if not result.versioned[0] or result.is_reparented():
130+ seen_parents.add(result.parent_id[1])
131 while all_unversioned:
132 # yield any trailing unversioned paths
133 unversioned_path = all_unversioned.popleft()
134@@ -1101,7 +1106,7 @@
135 else:
136 changes = True
137 # Get this parents parent to examine.
138- new_parent_id = result[4][1]
139+ new_parent_id = result.parent_id[1]
140 precise_file_ids.add(new_parent_id)
141 if changes:
142 if (result.kind[0] == 'directory' and
143@@ -1162,7 +1167,7 @@
144
145 :param from_tree: From tree
146 :param to_tree: To tree
147- :param paths: Iterable over paths to search for
148+ :param paths: Iterable over paths in from_tree to search for
149 :return: Dictionary mapping from from_tree paths to paths in to_tree, or
150 None if there is no equivalent path.
151 """
152@@ -1177,7 +1182,7 @@
153
154 :param from_tree: From tree
155 :param to_tree: To tree
156- :param path: Path to search for
157+ :param path: Path to search for (exists in from_tree)
158 :return: path in to_tree, or None if there is no equivalent path.
159 """
160 if file_id is None:

Subscribers

People subscribed via source and target branches