Merge lp:~jelmer/brz/changes-from-entries 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/changes-from-entries
Merge into: lp:brz
Diff against target: 128 lines (+28/-23)
2 files modified
breezy/tests/per_intertree/test_file_content_matches.py (+7/-2)
breezy/tree.py (+21/-21)
To merge this branch: bzr merge lp:~jelmer/brz/changes-from-entries
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+341569@code.launchpad.net

Commit message

Avoid id2path calls in Tree.

Description of the change

Avoid id2path calls in Tree.

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

Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/tests/per_intertree/test_file_content_matches.py'
2--- breezy/tests/per_intertree/test_file_content_matches.py 2017-05-21 18:10:28 +0000
3+++ breezy/tests/per_intertree/test_file_content_matches.py 2018-03-18 01:17:08 +0000
4@@ -32,7 +32,9 @@
5 tree2.add('file', 'file-id-2')
6 tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
7 inter = self.intertree_class(tree1, tree2)
8- self.assertTrue(inter.file_content_matches('file-id-1', 'file-id-2'))
9+ self.assertTrue(inter.file_content_matches(
10+ 'file', 'file', 'file-id-1', 'file-id-2'))
11+ self.assertTrue(inter.file_content_matches('file', 'file'))
12
13 def test_different_contents_and_same_verifier(self):
14 tree1 = self.make_branch_and_tree('1')
15@@ -45,4 +47,7 @@
16 tree2.add('file', 'file-id-2')
17 tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
18 inter = self.intertree_class(tree1, tree2)
19- self.assertFalse(inter.file_content_matches('file-id-1', 'file-id-2'))
20+ self.assertFalse(inter.file_content_matches(
21+ 'file', 'file', 'file-id-1', 'file-id-2'))
22+ self.assertFalse(inter.file_content_matches(
23+ 'file', 'file'))
24
25=== modified file 'breezy/tree.py'
26--- breezy/tree.py 2018-03-02 00:38:34 +0000
27+++ breezy/tree.py 2018-03-18 01:17:08 +0000
28@@ -783,16 +783,14 @@
29 # it works for all trees.
30 return True
31
32- def _changes_from_entries(self, source_entry, target_entry,
33- source_path=None, target_path=None):
34+ def _changes_from_entries(self, source_entry, target_entry, source_path,
35+ target_path):
36 """Generate a iter_changes tuple between source_entry and target_entry.
37
38 :param source_entry: An inventory entry from self.source, or None.
39 :param target_entry: An inventory entry from self.target, or None.
40- :param source_path: The path of source_entry, if known. If not known
41- it will be looked up.
42- :param target_path: The path of target_entry, if known. If not known
43- it will be looked up.
44+ :param source_path: The path of source_entry.
45+ :param target_path: The path of target_entry.
46 :return: A tuple, item 0 of which is an iter_changes result tuple, and
47 item 1 is True if there are any changes in the result tuple.
48 """
49@@ -806,8 +804,6 @@
50 source_versioned = True
51 source_name = source_entry.name
52 source_parent = source_entry.parent_id
53- if source_path is None:
54- source_path = self.source.id2path(file_id)
55 source_kind, source_executable, source_stat = \
56 self.source._comparison_data(source_entry, source_path)
57 else:
58@@ -820,8 +816,6 @@
59 target_versioned = True
60 target_name = target_entry.name
61 target_parent = target_entry.parent_id
62- if target_path is None:
63- target_path = self.target.id2path(file_id)
64 target_kind, target_executable, target_stat = \
65 self.target._comparison_data(target_entry, target_path)
66 else:
67@@ -836,8 +830,9 @@
68 if source_kind != target_kind:
69 changed_content = True
70 elif source_kind == 'file':
71- if not self.file_content_matches(file_id, file_id, source_path,
72- target_path, source_stat, target_stat):
73+ if not self.file_content_matches(
74+ source_path, target_path,
75+ file_id, file_id, source_stat, target_stat):
76 changed_content = True
77 elif source_kind == 'symlink':
78 if (self.source.get_symlink_target(source_path, file_id) !=
79@@ -1132,8 +1127,16 @@
80 if result is None:
81 old_entry = self._get_entry(self.source, file_id)
82 new_entry = self._get_entry(self.target, file_id)
83+ try:
84+ source_path = self.source.id2path(file_id)
85+ except errors.NoSuchId:
86+ source_path = None
87+ try:
88+ target_path = self.target.id2path(file_id)
89+ except errors.NoSuchId:
90+ target_path = None
91 result, changes = self._changes_from_entries(
92- old_entry, new_entry)
93+ old_entry, new_entry, source_path, target_path)
94 else:
95 changes = True
96 # Get this parents parent to examine.
97@@ -1153,26 +1156,23 @@
98 yield result
99
100 def file_content_matches(
101- self, source_file_id, target_file_id, source_path=None,
102- target_path=None, source_stat=None, target_stat=None):
103+ self, source_path, target_path,
104+ source_file_id=None, target_file_id=None,
105+ source_stat=None, target_stat=None):
106 """Check if two files are the same in the source and target trees.
107
108 This only checks that the contents of the files are the same,
109 it does not touch anything else.
110
111- :param source_file_id: File id of the file in the source tree
112- :param target_file_id: File id of the file in the target tree
113 :param source_path: Path of the file in the source tree
114 :param target_path: Path of the file in the target tree
115+ :param source_file_id: Optional file id of the file in the source tree
116+ :param target_file_id: Optional file id of the file in the target tree
117 :param source_stat: Optional stat value of the file in the source tree
118 :param target_stat: Optional stat value of the file in the target tree
119 :return: Boolean indicating whether the files have the same contents
120 """
121 with self.lock_read():
122- if source_path is None:
123- source_path = self.source.id2path(source_file_id)
124- if target_path is None:
125- target_path = self.target.id2path(target_file_id)
126 source_verifier_kind, source_verifier_data = (
127 self.source.get_file_verifier(
128 source_path, source_file_id, source_stat))

Subscribers

People subscribed via source and target branches