Merge lp:~jelmer/brz/extra-fields into lp:brz
- extra-fields
- Merge into trunk
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/extra-fields |
Merge into: | lp:brz |
Diff against target: |
253 lines (+44/-44) 5 files modified
breezy/git/errors.py (+0/-18) breezy/git/fetch.py (+5/-4) breezy/git/mapping.py (+23/-7) breezy/git/repository.py (+1/-1) breezy/git/tests/test_mapping.py (+15/-14) |
To merge this branch: | bzr merge lp:~jelmer/brz/extra-fields |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jelmer Vernooij | Approve | ||
Review via email: mp+374765@code.launchpad.net |
Commit message
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
Description of the change
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) : | # |
review:
Approve
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
1 | === modified file 'breezy/git/errors.py' | |||
2 | --- breezy/git/errors.py 2019-01-13 14:16:35 +0000 | |||
3 | +++ breezy/git/errors.py 2019-11-03 00:18:07 +0000 | |||
4 | @@ -61,21 +61,3 @@ | |||
5 | 61 | 61 | ||
6 | 62 | class GitSmartRemoteNotSupported(brz_errors.UnsupportedOperation): | 62 | class GitSmartRemoteNotSupported(brz_errors.UnsupportedOperation): |
7 | 63 | _fmt = "This operation is not supported by the Git smart server protocol." | 63 | _fmt = "This operation is not supported by the Git smart server protocol." |
8 | 64 | |||
9 | 65 | |||
10 | 66 | class UnknownCommitExtra(brz_errors.BzrError): | ||
11 | 67 | _fmt = "Unknown extra fields in %(object)r: %(fields)r." | ||
12 | 68 | |||
13 | 69 | def __init__(self, object, fields): | ||
14 | 70 | brz_errors.BzrError.__init__(self) | ||
15 | 71 | self.object = object | ||
16 | 72 | self.fields = ",".join(fields) | ||
17 | 73 | |||
18 | 74 | |||
19 | 75 | class UnknownMercurialCommitExtra(brz_errors.BzrError): | ||
20 | 76 | _fmt = "Unknown mercurial extra fields in %(object)r: %(fields)r." | ||
21 | 77 | |||
22 | 78 | def __init__(self, object, fields): | ||
23 | 79 | brz_errors.BzrError.__init__(self) | ||
24 | 80 | self.object = object | ||
25 | 81 | self.fields = b",".join(fields) | ||
26 | 82 | 64 | ||
27 | === modified file 'breezy/git/fetch.py' | |||
28 | --- breezy/git/fetch.py 2019-06-29 15:50:22 +0000 | |||
29 | +++ breezy/git/fetch.py 2019-11-03 00:18:07 +0000 | |||
30 | @@ -378,13 +378,13 @@ | |||
31 | 378 | 378 | ||
32 | 379 | 379 | ||
33 | 380 | def import_git_commit(repo, mapping, head, lookup_object, | 380 | def import_git_commit(repo, mapping, head, lookup_object, |
35 | 381 | target_git_object_retriever, trees_cache): | 381 | target_git_object_retriever, trees_cache, strict): |
36 | 382 | o = lookup_object(head) | 382 | o = lookup_object(head) |
37 | 383 | # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents | 383 | # Note that this uses mapping.revision_id_foreign_to_bzr. If the parents |
38 | 384 | # were bzr roundtripped revisions they would be specified in the | 384 | # were bzr roundtripped revisions they would be specified in the |
39 | 385 | # roundtrip data. | 385 | # roundtrip data. |
40 | 386 | rev, roundtrip_revid, verifiers = mapping.import_commit( | 386 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
42 | 387 | o, mapping.revision_id_foreign_to_bzr) | 387 | o, mapping.revision_id_foreign_to_bzr, strict) |
43 | 388 | if roundtrip_revid is not None: | 388 | if roundtrip_revid is not None: |
44 | 389 | original_revid = rev.revision_id | 389 | original_revid = rev.revision_id |
45 | 390 | rev.revision_id = roundtrip_revid | 390 | rev.revision_id = roundtrip_revid |
46 | @@ -482,7 +482,7 @@ | |||
47 | 482 | continue | 482 | continue |
48 | 483 | if isinstance(o, Commit): | 483 | if isinstance(o, Commit): |
49 | 484 | rev, roundtrip_revid, verifiers = mapping.import_commit( | 484 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
51 | 485 | o, mapping.revision_id_foreign_to_bzr) | 485 | o, mapping.revision_id_foreign_to_bzr, strict=True) |
52 | 486 | if (repo.has_revision(rev.revision_id) | 486 | if (repo.has_revision(rev.revision_id) |
53 | 487 | or (roundtrip_revid and | 487 | or (roundtrip_revid and |
54 | 488 | repo.has_revision(roundtrip_revid))): | 488 | repo.has_revision(roundtrip_revid))): |
55 | @@ -515,7 +515,8 @@ | |||
56 | 515 | pb.update("fetching revisions", offset + i, | 515 | pb.update("fetching revisions", offset + i, |
57 | 516 | len(revision_ids)) | 516 | len(revision_ids)) |
58 | 517 | import_git_commit(repo, mapping, head, lookup_object, | 517 | import_git_commit(repo, mapping, head, lookup_object, |
60 | 518 | target_git_object_retriever, trees_cache) | 518 | target_git_object_retriever, trees_cache, |
61 | 519 | strict=True) | ||
62 | 519 | last_imported = head | 520 | last_imported = head |
63 | 520 | except BaseException: | 521 | except BaseException: |
64 | 521 | repo.abort_write_group() | 522 | repo.abort_write_group() |
65 | 522 | 523 | ||
66 | === modified file 'breezy/git/mapping.py' | |||
67 | --- breezy/git/mapping.py 2019-06-29 15:50:22 +0000 | |||
68 | +++ breezy/git/mapping.py 2019-11-03 00:18:07 +0000 | |||
69 | @@ -46,8 +46,6 @@ | |||
70 | 46 | ) | 46 | ) |
71 | 47 | from .errors import ( | 47 | from .errors import ( |
72 | 48 | NoPushSupport, | 48 | NoPushSupport, |
73 | 49 | UnknownCommitExtra, | ||
74 | 50 | UnknownMercurialCommitExtra, | ||
75 | 51 | ) | 49 | ) |
76 | 52 | from .hg import ( | 50 | from .hg import ( |
77 | 53 | format_hg_metadata, | 51 | format_hg_metadata, |
78 | @@ -73,6 +71,24 @@ | |||
79 | 73 | ROOT_ID = b"TREE_ROOT" | 71 | ROOT_ID = b"TREE_ROOT" |
80 | 74 | 72 | ||
81 | 75 | 73 | ||
82 | 74 | class UnknownCommitExtra(errors.BzrError): | ||
83 | 75 | _fmt = "Unknown extra fields in %(object)r: %(fields)r." | ||
84 | 76 | |||
85 | 77 | def __init__(self, object, fields): | ||
86 | 78 | errors.BzrError.__init__(self) | ||
87 | 79 | self.object = object | ||
88 | 80 | self.fields = ",".join(fields) | ||
89 | 81 | |||
90 | 82 | |||
91 | 83 | class UnknownMercurialCommitExtra(errors.BzrError): | ||
92 | 84 | _fmt = "Unknown mercurial extra fields in %(object)r: %(fields)r." | ||
93 | 85 | |||
94 | 86 | def __init__(self, object, fields): | ||
95 | 87 | errors.BzrError.__init__(self) | ||
96 | 88 | self.object = object | ||
97 | 89 | self.fields = b",".join(fields) | ||
98 | 90 | |||
99 | 91 | |||
100 | 76 | def escape_file_id(file_id): | 92 | def escape_file_id(file_id): |
101 | 77 | file_id = file_id.replace(b'_', b'__') | 93 | file_id = file_id.replace(b'_', b'__') |
102 | 78 | file_id = file_id.replace(b' ', b'_s') | 94 | file_id = file_id.replace(b' ', b'_s') |
103 | @@ -370,7 +386,7 @@ | |||
104 | 370 | return metadata.revision_id | 386 | return metadata.revision_id |
105 | 371 | return self.revision_id_foreign_to_bzr(commit.id) | 387 | return self.revision_id_foreign_to_bzr(commit.id) |
106 | 372 | 388 | ||
108 | 373 | def import_commit(self, commit, lookup_parent_revid): | 389 | def import_commit(self, commit, lookup_parent_revid, strict=True): |
109 | 374 | """Convert a git commit to a bzr revision. | 390 | """Convert a git commit to a bzr revision. |
110 | 375 | 391 | ||
111 | 376 | :return: a `breezy.revision.Revision` object, foreign revid and a | 392 | :return: a `breezy.revision.Revision` object, foreign revid and a |
112 | @@ -444,12 +460,12 @@ | |||
113 | 444 | extra_lines.append(k + b' ' + v + b'\n') | 460 | extra_lines.append(k + b' ' + v + b'\n') |
114 | 445 | elif k == HG_EXTRA: | 461 | elif k == HG_EXTRA: |
115 | 446 | hgk, hgv = v.split(b':', 1) | 462 | hgk, hgv = v.split(b':', 1) |
117 | 447 | if hgk not in (HG_EXTRA_AMEND_SOURCE, ): | 463 | if hgk not in (HG_EXTRA_AMEND_SOURCE, ) and strict: |
118 | 448 | raise UnknownMercurialCommitExtra(commit, [hgk]) | 464 | raise UnknownMercurialCommitExtra(commit, [hgk]) |
119 | 449 | extra_lines.append(k + b' ' + v + b'\n') | 465 | extra_lines.append(k + b' ' + v + b'\n') |
120 | 450 | else: | 466 | else: |
121 | 451 | unknown_extra_fields.append(k) | 467 | unknown_extra_fields.append(k) |
123 | 452 | if unknown_extra_fields: | 468 | if unknown_extra_fields and strict: |
124 | 453 | raise UnknownCommitExtra( | 469 | raise UnknownCommitExtra( |
125 | 454 | commit, | 470 | commit, |
126 | 455 | [f.decode('ascii', 'replace') for f in unknown_extra_fields]) | 471 | [f.decode('ascii', 'replace') for f in unknown_extra_fields]) |
127 | @@ -487,10 +503,10 @@ | |||
128 | 487 | ret += self._generate_git_svn_metadata(rev, encoding) | 503 | ret += self._generate_git_svn_metadata(rev, encoding) |
129 | 488 | return ret | 504 | return ret |
130 | 489 | 505 | ||
132 | 490 | def import_commit(self, commit, lookup_parent_revid): | 506 | def import_commit(self, commit, lookup_parent_revid, strict=True): |
133 | 491 | rev, roundtrip_revid, verifiers = super( | 507 | rev, roundtrip_revid, verifiers = super( |
134 | 492 | BzrGitMappingExperimental, self).import_commit( | 508 | BzrGitMappingExperimental, self).import_commit( |
136 | 493 | commit, lookup_parent_revid) | 509 | commit, lookup_parent_revid, strict) |
137 | 494 | rev.properties[u'converted_revision'] = "git %s\n" % commit.id | 510 | rev.properties[u'converted_revision'] = "git %s\n" % commit.id |
138 | 495 | return rev, roundtrip_revid, verifiers | 511 | return rev, roundtrip_revid, verifiers |
139 | 496 | 512 | ||
140 | 497 | 513 | ||
141 | === modified file 'breezy/git/repository.py' | |||
142 | --- breezy/git/repository.py 2019-06-02 02:35:46 +0000 | |||
143 | +++ breezy/git/repository.py 2019-11-03 00:18:07 +0000 | |||
144 | @@ -539,7 +539,7 @@ | |||
145 | 539 | except KeyError: | 539 | except KeyError: |
146 | 540 | raise errors.NoSuchRevision(self, revision_id) | 540 | raise errors.NoSuchRevision(self, revision_id) |
147 | 541 | revision, roundtrip_revid, verifiers = mapping.import_commit( | 541 | revision, roundtrip_revid, verifiers = mapping.import_commit( |
149 | 542 | commit, self.lookup_foreign_revision_id) | 542 | commit, self.lookup_foreign_revision_id, strict=False) |
150 | 543 | if revision is None: | 543 | if revision is None: |
151 | 544 | raise AssertionError | 544 | raise AssertionError |
152 | 545 | # FIXME: check verifiers ? | 545 | # FIXME: check verifiers ? |
153 | 546 | 546 | ||
154 | === modified file 'breezy/git/tests/test_mapping.py' | |||
155 | --- breezy/git/tests/test_mapping.py 2019-06-02 05:34:26 +0000 | |||
156 | +++ breezy/git/tests/test_mapping.py 2019-11-03 00:18:07 +0000 | |||
157 | @@ -34,15 +34,13 @@ | |||
158 | 34 | ) | 34 | ) |
159 | 35 | 35 | ||
160 | 36 | from .. import tests | 36 | from .. import tests |
161 | 37 | from ..errors import ( | ||
162 | 38 | UnknownCommitExtra, | ||
163 | 39 | UnknownMercurialCommitExtra, | ||
164 | 40 | ) | ||
165 | 41 | from ..mapping import ( | 37 | from ..mapping import ( |
166 | 42 | BzrGitMappingv1, | 38 | BzrGitMappingv1, |
167 | 43 | escape_file_id, | 39 | escape_file_id, |
168 | 44 | fix_person_identifier, | 40 | fix_person_identifier, |
169 | 45 | unescape_file_id, | 41 | unescape_file_id, |
170 | 42 | UnknownCommitExtra, | ||
171 | 43 | UnknownMercurialCommitExtra, | ||
172 | 46 | ) | 44 | ) |
173 | 47 | 45 | ||
174 | 48 | 46 | ||
175 | @@ -111,8 +109,8 @@ | |||
176 | 111 | c.author_timezone = 60 * 3 | 109 | c.author_timezone = 60 * 3 |
177 | 112 | c.author = b"Author" | 110 | c.author = b"Author" |
178 | 113 | mapping = BzrGitMappingv1() | 111 | mapping = BzrGitMappingv1() |
181 | 114 | rev, roundtrip_revid, verifiers = mapping.import_commit(c, | 112 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
182 | 115 | mapping.revision_id_foreign_to_bzr) | 113 | c, mapping.revision_id_foreign_to_bzr) |
183 | 116 | self.assertEqual(None, roundtrip_revid) | 114 | self.assertEqual(None, roundtrip_revid) |
184 | 117 | self.assertEqual({}, verifiers) | 115 | self.assertEqual({}, verifiers) |
185 | 118 | self.assertEqual(u"Some message", rev.message) | 116 | self.assertEqual(u"Some message", rev.message) |
186 | @@ -136,8 +134,8 @@ | |||
187 | 136 | c.author = u"Authér".encode("iso8859-1") | 134 | c.author = u"Authér".encode("iso8859-1") |
188 | 137 | c.encoding = b"iso8859-1" | 135 | c.encoding = b"iso8859-1" |
189 | 138 | mapping = BzrGitMappingv1() | 136 | mapping = BzrGitMappingv1() |
192 | 139 | rev, roundtrip_revid, verifiers = mapping.import_commit(c, | 137 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
193 | 140 | mapping.revision_id_foreign_to_bzr) | 138 | c, mapping.revision_id_foreign_to_bzr) |
194 | 141 | self.assertEqual(None, roundtrip_revid) | 139 | self.assertEqual(None, roundtrip_revid) |
195 | 142 | self.assertEqual({}, verifiers) | 140 | self.assertEqual({}, verifiers) |
196 | 143 | self.assertEqual(u"Authér", rev.properties[u'author']) | 141 | self.assertEqual(u"Authér", rev.properties[u'author']) |
197 | @@ -155,8 +153,8 @@ | |||
198 | 155 | c.author_timezone = 60 * 3 | 153 | c.author_timezone = 60 * 3 |
199 | 156 | c.author = u"Authér".encode("latin1") | 154 | c.author = u"Authér".encode("latin1") |
200 | 157 | mapping = BzrGitMappingv1() | 155 | mapping = BzrGitMappingv1() |
203 | 158 | rev, roundtrip_revid, verifiers = mapping.import_commit(c, | 156 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
204 | 159 | mapping.revision_id_foreign_to_bzr) | 157 | c, mapping.revision_id_foreign_to_bzr) |
205 | 160 | self.assertEqual(None, roundtrip_revid) | 158 | self.assertEqual(None, roundtrip_revid) |
206 | 161 | self.assertEqual({}, verifiers) | 159 | self.assertEqual({}, verifiers) |
207 | 162 | self.assertEqual(u"Authér", rev.properties[u'author']) | 160 | self.assertEqual(u"Authér", rev.properties[u'author']) |
208 | @@ -174,8 +172,8 @@ | |||
209 | 174 | c.author_timezone = 60 * 3 | 172 | c.author_timezone = 60 * 3 |
210 | 175 | c.author = u"Authér".encode("utf-8") | 173 | c.author = u"Authér".encode("utf-8") |
211 | 176 | mapping = BzrGitMappingv1() | 174 | mapping = BzrGitMappingv1() |
214 | 177 | rev, roundtrip_revid, verifiers = mapping.import_commit(c, | 175 | rev, roundtrip_revid, verifiers = mapping.import_commit( |
215 | 178 | mapping.revision_id_foreign_to_bzr) | 176 | c, mapping.revision_id_foreign_to_bzr) |
216 | 179 | self.assertEqual(None, roundtrip_revid) | 177 | self.assertEqual(None, roundtrip_revid) |
217 | 180 | self.assertEqual({}, verifiers) | 178 | self.assertEqual({}, verifiers) |
218 | 181 | self.assertEqual(u"Authér", rev.properties[u'author']) | 179 | self.assertEqual(u"Authér", rev.properties[u'author']) |
219 | @@ -196,6 +194,7 @@ | |||
220 | 196 | mapping = BzrGitMappingv1() | 194 | mapping = BzrGitMappingv1() |
221 | 197 | self.assertRaises(UnknownCommitExtra, mapping.import_commit, c, | 195 | self.assertRaises(UnknownCommitExtra, mapping.import_commit, c, |
222 | 198 | mapping.revision_id_foreign_to_bzr) | 196 | mapping.revision_id_foreign_to_bzr) |
223 | 197 | mapping.import_commit(c, mapping.revision_id_foreign_to_bzr, strict=False) | ||
224 | 199 | 198 | ||
225 | 200 | def test_mergetag(self): | 199 | def test_mergetag(self): |
226 | 201 | c = Commit() | 200 | c = Commit() |
227 | @@ -235,6 +234,8 @@ | |||
228 | 235 | self.assertRaises( | 234 | self.assertRaises( |
229 | 236 | UnknownMercurialCommitExtra, | 235 | UnknownMercurialCommitExtra, |
230 | 237 | mapping.import_commit, c, mapping.revision_id_foreign_to_bzr) | 236 | mapping.import_commit, c, mapping.revision_id_foreign_to_bzr) |
231 | 237 | mapping.import_commit( | ||
232 | 238 | c, mapping.revision_id_foreign_to_bzr, strict=False) | ||
233 | 238 | self.assertEqual( | 239 | self.assertEqual( |
234 | 239 | mapping.revision_id_foreign_to_bzr(c.id), | 240 | mapping.revision_id_foreign_to_bzr(c.id), |
235 | 240 | mapping.get_revision_id(c)) | 241 | mapping.get_revision_id(c)) |
236 | @@ -267,7 +268,7 @@ | |||
237 | 267 | commit = self.mapping.export_commit(orig_rev, b"mysha", | 268 | commit = self.mapping.export_commit(orig_rev, b"mysha", |
238 | 268 | self._lookup_parent, True, b"testamentsha") | 269 | self._lookup_parent, True, b"testamentsha") |
239 | 269 | rev, roundtrip_revid, verifiers = self.mapping.import_commit( | 270 | rev, roundtrip_revid, verifiers = self.mapping.import_commit( |
241 | 270 | commit, self.mapping.revision_id_foreign_to_bzr) | 271 | commit, self.mapping.revision_id_foreign_to_bzr, strict=True) |
242 | 271 | self.assertEqual(rev.revision_id, | 272 | self.assertEqual(rev.revision_id, |
243 | 272 | self.mapping.revision_id_foreign_to_bzr(commit.id)) | 273 | self.mapping.revision_id_foreign_to_bzr(commit.id)) |
244 | 273 | if self.mapping.roundtripping: | 274 | if self.mapping.roundtripping: |
245 | @@ -338,7 +339,7 @@ | |||
246 | 338 | 339 | ||
247 | 339 | def assertRoundtripCommit(self, commit1): | 340 | def assertRoundtripCommit(self, commit1): |
248 | 340 | rev, roundtrip_revid, verifiers = self.mapping.import_commit( | 341 | rev, roundtrip_revid, verifiers = self.mapping.import_commit( |
250 | 341 | commit1, self.mapping.revision_id_foreign_to_bzr) | 342 | commit1, self.mapping.revision_id_foreign_to_bzr, strict=True) |
251 | 342 | commit2 = self.mapping.export_commit(rev, "12341212121212", None, | 343 | commit2 = self.mapping.export_commit(rev, "12341212121212", None, |
252 | 343 | True, None) | 344 | True, None) |
253 | 344 | self.assertEqual(commit1.committer, commit2.committer) | 345 | self.assertEqual(commit1.committer, commit2.committer) |
Running landing tests failed /ci.breezy- vcs.org/ job/brz/ job/brz- land/534/
https:/