Merge lp:~jelmer/brz/objects-2a 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/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 Approve
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.
Revision history for this message
Martin Packman (gz) wrote :

Looks good, 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 :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/bzr/workingtree.py'
--- breezy/bzr/workingtree.py 2019-06-21 17:35:24 +0000
+++ breezy/bzr/workingtree.py 2019-06-22 10:13:17 +0000
@@ -897,9 +897,12 @@
897897
898 def set_merge_modified(self, modified_hashes):898 def set_merge_modified(self, modified_hashes):
899 def iter_stanzas():899 def iter_stanzas():
900 for file_id in modified_hashes:900 for path, sha1 in modified_hashes.items():
901 file_id = self.path2id(path)
902 if file_id is None:
903 continue
901 yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),904 yield _mod_rio.Stanza(file_id=file_id.decode('utf8'),
902 hash=modified_hashes[file_id])905 hash=sha1)
903 with self.lock_tree_write():906 with self.lock_tree_write():
904 self._put_rio('merge-hashes', iter_stanzas(),907 self._put_rio('merge-hashes', iter_stanzas(),
905 MERGE_MODIFIED_HEADER_1)908 MERGE_MODIFIED_HEADER_1)
@@ -930,12 +933,13 @@
930 # RioReader reads in Unicode, so convert file_ids back to933 # RioReader reads in Unicode, so convert file_ids back to
931 # utf8934 # utf8
932 file_id = cache_utf8.encode(s.get("file_id"))935 file_id = cache_utf8.encode(s.get("file_id"))
933 if not self.has_id(file_id):936 try:
937 path = self.id2path(file_id)
938 except errors.NoSuchId:
934 continue939 continue
935 text_hash = s.get("hash").encode('ascii')940 text_hash = s.get("hash").encode('ascii')
936 path = self.id2path(file_id)
937 if text_hash == self.get_file_sha1(path):941 if text_hash == self.get_file_sha1(path):
938 merge_hashes[file_id] = text_hash942 merge_hashes[path] = text_hash
939 return merge_hashes943 return merge_hashes
940 finally:944 finally:
941 hashfile.close()945 hashfile.close()
942946
=== modified file 'breezy/merge.py'
--- breezy/merge.py 2019-06-21 17:49:36 +0000
+++ breezy/merge.py 2019-06-22 10:13:17 +0000
@@ -1068,13 +1068,12 @@
1068 modified_hashes = {}1068 modified_hashes = {}
1069 for path in results.modified_paths:1069 for path in results.modified_paths:
1070 wt_relpath = self.working_tree.relpath(path)1070 wt_relpath = self.working_tree.relpath(path)
1071 file_id = self.working_tree.path2id(wt_relpath)1071 if not self.working_tree.is_versioned(wt_relpath):
1072 if file_id is None:
1073 continue1072 continue
1074 hash = self.working_tree.get_file_sha1(wt_relpath)1073 hash = self.working_tree.get_file_sha1(wt_relpath)
1075 if hash is None:1074 if hash is None:
1076 continue1075 continue
1077 modified_hashes[file_id] = hash1076 modified_hashes[wt_relpath] = hash
1078 self.working_tree.set_merge_modified(modified_hashes)1077 self.working_tree.set_merge_modified(modified_hashes)
10791078
1080 @staticmethod1079 @staticmethod
10811080
=== modified file 'breezy/tests/per_workingtree/test_workingtree.py'
--- breezy/tests/per_workingtree/test_workingtree.py 2019-06-17 23:01:58 +0000
+++ breezy/tests/per_workingtree/test_workingtree.py 2019-06-22 10:13:17 +0000
@@ -736,7 +736,7 @@
736 self.build_tree_contents([('tree/somefile', b'hello')])736 self.build_tree_contents([('tree/somefile', b'hello')])
737 with tree.lock_write():737 with tree.lock_write():
738 tree.add(['somefile'])738 tree.add(['somefile'])
739 d = {tree.path2id('somefile'): osutils.sha_string(b'hello')}739 d = {'somefile': osutils.sha_string(b'hello')}
740 if tree.supports_merge_modified():740 if tree.supports_merge_modified():
741 tree.set_merge_modified(d)741 tree.set_merge_modified(d)
742 mm = tree.merge_modified()742 mm = tree.merge_modified()
743743
=== modified file 'breezy/tests/test_revert.py'
--- breezy/tests/test_revert.py 2019-06-17 23:01:58 +0000
+++ breezy/tests/test_revert.py 2019-06-22 10:13:17 +0000
@@ -124,11 +124,14 @@
124 tree = self.make_branch_and_tree('.')124 tree = self.make_branch_and_tree('.')
125 self.build_tree(['file'])125 self.build_tree(['file'])
126 tree.add('file')126 tree.add('file')
127 tree.commit('added file', rev_id=b'rev1')127 rev1 = tree.commit('added file')
128 with tree.lock_read():
129 file_sha = tree.get_file_sha1('file')
128 os.unlink('file')130 os.unlink('file')
129 tree.commit('removed file')131 tree.commit('removed file')
130 self.assertPathDoesNotExist('file')132 self.assertPathDoesNotExist('file')
131 tree.revert(old_tree=tree.branch.repository.revision_tree(b'rev1'))133 tree.revert(old_tree=tree.branch.repository.revision_tree(rev1))
134 self.assertEqual({'file': file_sha}, tree.merge_modified())
132 self.assertPathExists('file')135 self.assertPathExists('file')
133 tree.revert()136 tree.revert()
134 self.assertPathDoesNotExist('file')137 self.assertPathDoesNotExist('file')
135138
=== modified file 'breezy/tests/test_transform.py'
--- breezy/tests/test_transform.py 2019-06-15 15:59:17 +0000
+++ breezy/tests/test_transform.py 2019-06-22 10:13:17 +0000
@@ -1816,7 +1816,7 @@
1816 self.assertEqual(this.wt.get_file('i.OTHER').read(),1816 self.assertEqual(this.wt.get_file('i.OTHER').read(),
1817 b'h\ni\nj\nk\n')1817 b'h\ni\nj\nk\n')
1818 self.assertEqual(os.path.exists(this.wt.abspath('i.BASE')), False)1818 self.assertEqual(os.path.exists(this.wt.abspath('i.BASE')), False)
1819 modified = [b'a', b'b', b'c', b'h', b'i']1819 modified = ['a', 'b', 'c', 'h', 'i']
1820 merge_modified = this.wt.merge_modified()1820 merge_modified = this.wt.merge_modified()
1821 self.assertSubset(merge_modified, modified)1821 self.assertSubset(merge_modified, modified)
1822 self.assertEqual(len(merge_modified), len(modified))1822 self.assertEqual(len(merge_modified), len(modified))
18231823
=== modified file 'breezy/transform.py'
--- breezy/transform.py 2019-06-18 00:22:26 +0000
+++ breezy/transform.py 2019-06-22 10:13:17 +0000
@@ -2965,7 +2965,7 @@
2965 keep_content = False2965 keep_content = False
2966 if wt_kind == 'file' and (backups or target_kind is None):2966 if wt_kind == 'file' and (backups or target_kind is None):
2967 wt_sha1 = working_tree.get_file_sha1(wt_path)2967 wt_sha1 = working_tree.get_file_sha1(wt_path)
2968 if merge_modified.get(file_id) != wt_sha1:2968 if merge_modified.get(wt_path) != wt_sha1:
2969 # acquire the basis tree lazily to prevent the2969 # acquire the basis tree lazily to prevent the
2970 # expense of accessing it when it's not needed ?2970 # expense of accessing it when it's not needed ?
2971 # (Guessing, RBC, 200702)2971 # (Guessing, RBC, 200702)
@@ -3015,10 +3015,12 @@
3015 basis_path = find_previous_path(target_tree, basis_tree, target_path)3015 basis_path = find_previous_path(target_tree, basis_tree, target_path)
3016 if (basis_path is not None and3016 if (basis_path is not None and
3017 new_sha1 == basis_tree.get_file_sha1(basis_path)):3017 new_sha1 == basis_tree.get_file_sha1(basis_path)):
3018 if file_id in merge_modified:3018 # If the new contents of the file match what is in basis,
3019 del merge_modified[file_id]3019 # then there is no need to store in merge_modified.
3020 if basis_path in merge_modified:
3021 del merge_modified[basis_path]
3020 else:3022 else:
3021 merge_modified[file_id] = new_sha13023 merge_modified[target_path] = new_sha1
30223024
3023 # preserve the execute bit when backing up3025 # preserve the execute bit when backing up
3024 if keep_content and wt_executable == target_executable:3026 if keep_content and wt_executable == target_executable:

Subscribers

People subscribed via source and target branches