Merge lp:~jelmer/brz/objects-2a into lp:brz

Proposed by Jelmer Vernooij on 2019-06-17
Status: Merged
Approved by: Jelmer Vernooij on 2019-06-22
Approved revision: 7353
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/objects-2a
Merge into: lp:brz
Diff against target: 131 lines (+24/-16)
6 files modified
breezy/bzr/workingtree.py (+9/-5)
breezy/merge.py (+2/-3)
breezy/tests/per_workingtree/test_workingtree.py (+1/-1)
breezy/tests/test_revert.py (+5/-2)
breezy/tests/test_transform.py (+1/-1)
breezy/transform.py (+6/-4)
To merge this branch: bzr merge lp:~jelmer/brz/objects-2a
Reviewer Review Type Date Requested Status
Martin Packman 2019-06-17 Approve on 2019-06-21
Review via email: mp+368929@code.launchpad.net

Commit message

Use paths as keys in merge_modified dictionary.

Description of the change

Use paths as keys in merge_modified dictionary.

This brings us one step closer to not having file ids in public APIs.

To post a comment you must log in.
Martin Packman (gz) wrote :

Looks good, thanks!

review: Approve
lp:~jelmer/brz/objects-2a updated on 2019-06-22
7352. By Jelmer Vernooij on 2019-06-21

Fix merge modified test on python3.

7353. By Jelmer Vernooij on 2019-06-22

Fix tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/workingtree.py'
2--- breezy/bzr/workingtree.py 2019-06-21 17:35:24 +0000
3+++ breezy/bzr/workingtree.py 2019-06-22 10:13:17 +0000
4@@ -897,9 +897,12 @@
5
6 def set_merge_modified(self, modified_hashes):
7 def iter_stanzas():
8- for file_id in modified_hashes:
9+ for path, sha1 in modified_hashes.items():
10+ file_id = self.path2id(path)
11+ if file_id is None:
12+ continue
13 yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
14- hash=modified_hashes[file_id])
15+ hash=sha1)
16 with self.lock_tree_write():
17 self._put_rio('merge-hashes', iter_stanzas(),
18 MERGE_MODIFIED_HEADER_1)
19@@ -930,12 +933,13 @@
20 # RioReader reads in Unicode, so convert file_ids back to
21 # utf8
22 file_id = cache_utf8.encode(s.get("file_id"))
23- if not self.has_id(file_id):
24+ try:
25+ path = self.id2path(file_id)
26+ except errors.NoSuchId:
27 continue
28 text_hash = s.get("hash").encode('ascii')
29- path = self.id2path(file_id)
30 if text_hash == self.get_file_sha1(path):
31- merge_hashes[file_id] = text_hash
32+ merge_hashes[path] = text_hash
33 return merge_hashes
34 finally:
35 hashfile.close()
36
37=== modified file 'breezy/merge.py'
38--- breezy/merge.py 2019-06-21 17:49:36 +0000
39+++ breezy/merge.py 2019-06-22 10:13:17 +0000
40@@ -1068,13 +1068,12 @@
41 modified_hashes = {}
42 for path in results.modified_paths:
43 wt_relpath = self.working_tree.relpath(path)
44- file_id = self.working_tree.path2id(wt_relpath)
45- if file_id is None:
46+ if not self.working_tree.is_versioned(wt_relpath):
47 continue
48 hash = self.working_tree.get_file_sha1(wt_relpath)
49 if hash is None:
50 continue
51- modified_hashes[file_id] = hash
52+ modified_hashes[wt_relpath] = hash
53 self.working_tree.set_merge_modified(modified_hashes)
54
55 @staticmethod
56
57=== modified file 'breezy/tests/per_workingtree/test_workingtree.py'
58--- breezy/tests/per_workingtree/test_workingtree.py 2019-06-17 23:01:58 +0000
59+++ breezy/tests/per_workingtree/test_workingtree.py 2019-06-22 10:13:17 +0000
60@@ -736,7 +736,7 @@
61 self.build_tree_contents([('tree/somefile', b'hello')])
62 with tree.lock_write():
63 tree.add(['somefile'])
64- d = {tree.path2id('somefile'): osutils.sha_string(b'hello')}
65+ d = {'somefile': osutils.sha_string(b'hello')}
66 if tree.supports_merge_modified():
67 tree.set_merge_modified(d)
68 mm = tree.merge_modified()
69
70=== modified file 'breezy/tests/test_revert.py'
71--- breezy/tests/test_revert.py 2019-06-17 23:01:58 +0000
72+++ breezy/tests/test_revert.py 2019-06-22 10:13:17 +0000
73@@ -124,11 +124,14 @@
74 tree = self.make_branch_and_tree('.')
75 self.build_tree(['file'])
76 tree.add('file')
77- tree.commit('added file', rev_id=b'rev1')
78+ rev1 = tree.commit('added file')
79+ with tree.lock_read():
80+ file_sha = tree.get_file_sha1('file')
81 os.unlink('file')
82 tree.commit('removed file')
83 self.assertPathDoesNotExist('file')
84- tree.revert(old_tree=tree.branch.repository.revision_tree(b'rev1'))
85+ tree.revert(old_tree=tree.branch.repository.revision_tree(rev1))
86+ self.assertEqual({'file': file_sha}, tree.merge_modified())
87 self.assertPathExists('file')
88 tree.revert()
89 self.assertPathDoesNotExist('file')
90
91=== modified file 'breezy/tests/test_transform.py'
92--- breezy/tests/test_transform.py 2019-06-15 15:59:17 +0000
93+++ breezy/tests/test_transform.py 2019-06-22 10:13:17 +0000
94@@ -1816,7 +1816,7 @@
95 self.assertEqual(this.wt.get_file('i.OTHER').read(),
96 b'h\ni\nj\nk\n')
97 self.assertEqual(os.path.exists(this.wt.abspath('i.BASE')), False)
98- modified = [b'a', b'b', b'c', b'h', b'i']
99+ modified = ['a', 'b', 'c', 'h', 'i']
100 merge_modified = this.wt.merge_modified()
101 self.assertSubset(merge_modified, modified)
102 self.assertEqual(len(merge_modified), len(modified))
103
104=== modified file 'breezy/transform.py'
105--- breezy/transform.py 2019-06-18 00:22:26 +0000
106+++ breezy/transform.py 2019-06-22 10:13:17 +0000
107@@ -2965,7 +2965,7 @@
108 keep_content = False
109 if wt_kind == 'file' and (backups or target_kind is None):
110 wt_sha1 = working_tree.get_file_sha1(wt_path)
111- if merge_modified.get(file_id) != wt_sha1:
112+ if merge_modified.get(wt_path) != wt_sha1:
113 # acquire the basis tree lazily to prevent the
114 # expense of accessing it when it's not needed ?
115 # (Guessing, RBC, 200702)
116@@ -3015,10 +3015,12 @@
117 basis_path = find_previous_path(target_tree, basis_tree, target_path)
118 if (basis_path is not None and
119 new_sha1 == basis_tree.get_file_sha1(basis_path)):
120- if file_id in merge_modified:
121- del merge_modified[file_id]
122+ # If the new contents of the file match what is in basis,
123+ # then there is no need to store in merge_modified.
124+ if basis_path in merge_modified:
125+ del merge_modified[basis_path]
126 else:
127- merge_modified[file_id] = new_sha1
128+ merge_modified[target_path] = new_sha1
129
130 # preserve the execute bit when backing up
131 if keep_content and wt_executable == target_executable:

Subscribers

People subscribed via source and target branches