##// END OF EJS Templates
py3: use bytes() to byte-stringify Abort message in handleremotechangegroup()
Yuya Nishihara -
r38723:f016eac2 default
parent child Browse files
Show More
@@ -1,541 +1,542
1 test-abort-checkin.t
1 test-abort-checkin.t
2 test-add.t
2 test-add.t
3 test-addremove-similar.t
3 test-addremove-similar.t
4 test-addremove.t
4 test-addremove.t
5 test-alias.t
5 test-alias.t
6 test-amend-subrepo.t
6 test-amend-subrepo.t
7 test-amend.t
7 test-amend.t
8 test-ancestor.py
8 test-ancestor.py
9 test-annotate.py
9 test-annotate.py
10 test-annotate.t
10 test-annotate.t
11 test-archive-symlinks.t
11 test-archive-symlinks.t
12 test-atomictempfile.py
12 test-atomictempfile.py
13 test-audit-path.t
13 test-audit-path.t
14 test-audit-subrepo.t
14 test-audit-subrepo.t
15 test-automv.t
15 test-automv.t
16 test-backout.t
16 test-backout.t
17 test-backwards-remove.t
17 test-backwards-remove.t
18 test-bad-pull.t
18 test-bad-pull.t
19 test-basic.t
19 test-basic.t
20 test-bheads.t
20 test-bheads.t
21 test-bisect.t
21 test-bisect.t
22 test-bisect2.t
22 test-bisect2.t
23 test-bisect3.t
23 test-bisect3.t
24 test-blackbox.t
24 test-blackbox.t
25 test-bookmarks-current.t
25 test-bookmarks-current.t
26 test-bookmarks-merge.t
26 test-bookmarks-merge.t
27 test-bookmarks-pushpull.t
27 test-bookmarks-pushpull.t
28 test-bookmarks-rebase.t
28 test-bookmarks-rebase.t
29 test-bookmarks-strip.t
29 test-bookmarks-strip.t
30 test-bookmarks.t
30 test-bookmarks.t
31 test-branch-change.t
31 test-branch-change.t
32 test-branch-option.t
32 test-branch-option.t
33 test-branch-tag-confict.t
33 test-branch-tag-confict.t
34 test-branches.t
34 test-branches.t
35 test-bundle-phases.t
35 test-bundle-phases.t
36 test-bundle-r.t
36 test-bundle-r.t
37 test-bundle-type.t
37 test-bundle-type.t
38 test-bundle-vs-outgoing.t
38 test-bundle-vs-outgoing.t
39 test-bundle.t
39 test-bundle.t
40 test-bundle2-exchange.t
40 test-bundle2-exchange.t
41 test-bundle2-format.t
41 test-bundle2-format.t
42 test-bundle2-multiple-changegroups.t
42 test-bundle2-multiple-changegroups.t
43 test-bundle2-pushback.t
43 test-bundle2-pushback.t
44 test-bundle2-remote-changegroup.t
44 test-cappedreader.py
45 test-cappedreader.py
45 test-casecollision.t
46 test-casecollision.t
46 test-cat.t
47 test-cat.t
47 test-cbor.py
48 test-cbor.py
48 test-censor.t
49 test-censor.t
49 test-changelog-exec.t
50 test-changelog-exec.t
50 test-check-commit.t
51 test-check-commit.t
51 test-check-execute.t
52 test-check-execute.t
52 test-check-interfaces.py
53 test-check-interfaces.py
53 test-check-module-imports.t
54 test-check-module-imports.t
54 test-check-pyflakes.t
55 test-check-pyflakes.t
55 test-check-pylint.t
56 test-check-pylint.t
56 test-check-shbang.t
57 test-check-shbang.t
57 test-children.t
58 test-children.t
58 test-clone-cgi.t
59 test-clone-cgi.t
59 test-clone-pull-corruption.t
60 test-clone-pull-corruption.t
60 test-clone-r.t
61 test-clone-r.t
61 test-clone-update-order.t
62 test-clone-update-order.t
62 test-clonebundles.t
63 test-clonebundles.t
63 test-commit-amend.t
64 test-commit-amend.t
64 test-commit-interactive.t
65 test-commit-interactive.t
65 test-commit-multiple.t
66 test-commit-multiple.t
66 test-commit-unresolved.t
67 test-commit-unresolved.t
67 test-commit.t
68 test-commit.t
68 test-committer.t
69 test-committer.t
69 test-completion.t
70 test-completion.t
70 test-config-env.py
71 test-config-env.py
71 test-config.t
72 test-config.t
72 test-conflict.t
73 test-conflict.t
73 test-confused-revert.t
74 test-confused-revert.t
74 test-context.py
75 test-context.py
75 test-contrib-check-code.t
76 test-contrib-check-code.t
76 test-contrib-check-commit.t
77 test-contrib-check-commit.t
77 test-convert-authormap.t
78 test-convert-authormap.t
78 test-convert-clonebranches.t
79 test-convert-clonebranches.t
79 test-convert-cvs-branch.t
80 test-convert-cvs-branch.t
80 test-convert-cvs-detectmerge.t
81 test-convert-cvs-detectmerge.t
81 test-convert-cvs-synthetic.t
82 test-convert-cvs-synthetic.t
82 test-convert-cvs.t
83 test-convert-cvs.t
83 test-convert-cvsnt-mergepoints.t
84 test-convert-cvsnt-mergepoints.t
84 test-convert-datesort.t
85 test-convert-datesort.t
85 test-convert-filemap.t
86 test-convert-filemap.t
86 test-convert-hg-sink.t
87 test-convert-hg-sink.t
87 test-convert-hg-source.t
88 test-convert-hg-source.t
88 test-convert-hg-startrev.t
89 test-convert-hg-startrev.t
89 test-convert-splicemap.t
90 test-convert-splicemap.t
90 test-convert-tagsbranch-topology.t
91 test-convert-tagsbranch-topology.t
91 test-copy-move-merge.t
92 test-copy-move-merge.t
92 test-copy.t
93 test-copy.t
93 test-copytrace-heuristics.t
94 test-copytrace-heuristics.t
94 test-debugbuilddag.t
95 test-debugbuilddag.t
95 test-debugbundle.t
96 test-debugbundle.t
96 test-debugextensions.t
97 test-debugextensions.t
97 test-debugindexdot.t
98 test-debugindexdot.t
98 test-debugrename.t
99 test-debugrename.t
99 test-default-push.t
100 test-default-push.t
100 test-diff-antipatience.t
101 test-diff-antipatience.t
101 test-diff-binary-file.t
102 test-diff-binary-file.t
102 test-diff-change.t
103 test-diff-change.t
103 test-diff-copy-depth.t
104 test-diff-copy-depth.t
104 test-diff-hashes.t
105 test-diff-hashes.t
105 test-diff-ignore-whitespace.t
106 test-diff-ignore-whitespace.t
106 test-diff-indent-heuristic.t
107 test-diff-indent-heuristic.t
107 test-diff-issue2761.t
108 test-diff-issue2761.t
108 test-diff-newlines.t
109 test-diff-newlines.t
109 test-diff-reverse.t
110 test-diff-reverse.t
110 test-diff-subdir.t
111 test-diff-subdir.t
111 test-diff-unified.t
112 test-diff-unified.t
112 test-diff-upgrade.t
113 test-diff-upgrade.t
113 test-diffdir.t
114 test-diffdir.t
114 test-diffstat.t
115 test-diffstat.t
115 test-directaccess.t
116 test-directaccess.t
116 test-dirstate-backup.t
117 test-dirstate-backup.t
117 test-dirstate-nonnormalset.t
118 test-dirstate-nonnormalset.t
118 test-dirstate.t
119 test-dirstate.t
119 test-dispatch.py
120 test-dispatch.py
120 test-doctest.py
121 test-doctest.py
121 test-double-merge.t
122 test-double-merge.t
122 test-drawdag.t
123 test-drawdag.t
123 test-duplicateoptions.py
124 test-duplicateoptions.py
124 test-editor-filename.t
125 test-editor-filename.t
125 test-empty-dir.t
126 test-empty-dir.t
126 test-empty-file.t
127 test-empty-file.t
127 test-empty-group.t
128 test-empty-group.t
128 test-empty.t
129 test-empty.t
129 test-encode.t
130 test-encode.t
130 test-encoding-func.py
131 test-encoding-func.py
131 test-encoding.t
132 test-encoding.t
132 test-eol-add.t
133 test-eol-add.t
133 test-eol-clone.t
134 test-eol-clone.t
134 test-eol-hook.t
135 test-eol-hook.t
135 test-eol-patch.t
136 test-eol-patch.t
136 test-eol-tag.t
137 test-eol-tag.t
137 test-eol-update.t
138 test-eol-update.t
138 test-eol.t
139 test-eol.t
139 test-eolfilename.t
140 test-eolfilename.t
140 test-excessive-merge.t
141 test-excessive-merge.t
141 test-exchange-obsmarkers-case-A1.t
142 test-exchange-obsmarkers-case-A1.t
142 test-exchange-obsmarkers-case-A2.t
143 test-exchange-obsmarkers-case-A2.t
143 test-exchange-obsmarkers-case-A3.t
144 test-exchange-obsmarkers-case-A3.t
144 test-exchange-obsmarkers-case-A4.t
145 test-exchange-obsmarkers-case-A4.t
145 test-exchange-obsmarkers-case-A5.t
146 test-exchange-obsmarkers-case-A5.t
146 test-exchange-obsmarkers-case-A6.t
147 test-exchange-obsmarkers-case-A6.t
147 test-exchange-obsmarkers-case-A7.t
148 test-exchange-obsmarkers-case-A7.t
148 test-exchange-obsmarkers-case-B1.t
149 test-exchange-obsmarkers-case-B1.t
149 test-exchange-obsmarkers-case-B2.t
150 test-exchange-obsmarkers-case-B2.t
150 test-exchange-obsmarkers-case-B3.t
151 test-exchange-obsmarkers-case-B3.t
151 test-exchange-obsmarkers-case-B4.t
152 test-exchange-obsmarkers-case-B4.t
152 test-exchange-obsmarkers-case-B5.t
153 test-exchange-obsmarkers-case-B5.t
153 test-exchange-obsmarkers-case-B6.t
154 test-exchange-obsmarkers-case-B6.t
154 test-exchange-obsmarkers-case-B7.t
155 test-exchange-obsmarkers-case-B7.t
155 test-exchange-obsmarkers-case-C1.t
156 test-exchange-obsmarkers-case-C1.t
156 test-exchange-obsmarkers-case-C2.t
157 test-exchange-obsmarkers-case-C2.t
157 test-exchange-obsmarkers-case-C3.t
158 test-exchange-obsmarkers-case-C3.t
158 test-exchange-obsmarkers-case-C4.t
159 test-exchange-obsmarkers-case-C4.t
159 test-exchange-obsmarkers-case-D1.t
160 test-exchange-obsmarkers-case-D1.t
160 test-exchange-obsmarkers-case-D2.t
161 test-exchange-obsmarkers-case-D2.t
161 test-exchange-obsmarkers-case-D3.t
162 test-exchange-obsmarkers-case-D3.t
162 test-exchange-obsmarkers-case-D4.t
163 test-exchange-obsmarkers-case-D4.t
163 test-execute-bit.t
164 test-execute-bit.t
164 test-export.t
165 test-export.t
165 test-extdata.t
166 test-extdata.t
166 test-extdiff.t
167 test-extdiff.t
167 test-extensions-afterloaded.t
168 test-extensions-afterloaded.t
168 test-extensions-wrapfunction.py
169 test-extensions-wrapfunction.py
169 test-extra-filelog-entry.t
170 test-extra-filelog-entry.t
170 test-fetch.t
171 test-fetch.t
171 test-filebranch.t
172 test-filebranch.t
172 test-filecache.py
173 test-filecache.py
173 test-filelog.py
174 test-filelog.py
174 test-fileset-generated.t
175 test-fileset-generated.t
175 test-fileset.t
176 test-fileset.t
176 test-fix-topology.t
177 test-fix-topology.t
177 test-flags.t
178 test-flags.t
178 test-generaldelta.t
179 test-generaldelta.t
179 test-getbundle.t
180 test-getbundle.t
180 test-git-export.t
181 test-git-export.t
181 test-glog-topological.t
182 test-glog-topological.t
182 test-gpg.t
183 test-gpg.t
183 test-graft.t
184 test-graft.t
184 test-hg-parseurl.py
185 test-hg-parseurl.py
185 test-hghave.t
186 test-hghave.t
186 test-hgignore.t
187 test-hgignore.t
187 test-hgk.t
188 test-hgk.t
188 test-hgrc.t
189 test-hgrc.t
189 test-hgweb-bundle.t
190 test-hgweb-bundle.t
190 test-hgweb-descend-empties.t
191 test-hgweb-descend-empties.t
191 test-hgweb-empty.t
192 test-hgweb-empty.t
192 test-hgweb-removed.t
193 test-hgweb-removed.t
193 test-hgwebdir-paths.py
194 test-hgwebdir-paths.py
194 test-hgwebdirsym.t
195 test-hgwebdirsym.t
195 test-histedit-arguments.t
196 test-histedit-arguments.t
196 test-histedit-base.t
197 test-histedit-base.t
197 test-histedit-bookmark-motion.t
198 test-histedit-bookmark-motion.t
198 test-histedit-commute.t
199 test-histedit-commute.t
199 test-histedit-drop.t
200 test-histedit-drop.t
200 test-histedit-edit.t
201 test-histedit-edit.t
201 test-histedit-fold-non-commute.t
202 test-histedit-fold-non-commute.t
202 test-histedit-fold.t
203 test-histedit-fold.t
203 test-histedit-no-backup.t
204 test-histedit-no-backup.t
204 test-histedit-no-change.t
205 test-histedit-no-change.t
205 test-histedit-non-commute-abort.t
206 test-histedit-non-commute-abort.t
206 test-histedit-non-commute.t
207 test-histedit-non-commute.t
207 test-histedit-obsolete.t
208 test-histedit-obsolete.t
208 test-histedit-outgoing.t
209 test-histedit-outgoing.t
209 test-histedit-templates.t
210 test-histedit-templates.t
210 test-http-branchmap.t
211 test-http-branchmap.t
211 test-http-bundle1.t
212 test-http-bundle1.t
212 test-http-clone-r.t
213 test-http-clone-r.t
213 test-http.t
214 test-http.t
214 test-hybridencode.py
215 test-hybridencode.py
215 test-identify.t
216 test-identify.t
216 test-impexp-branch.t
217 test-impexp-branch.t
217 test-import-bypass.t
218 test-import-bypass.t
218 test-import-eol.t
219 test-import-eol.t
219 test-import-merge.t
220 test-import-merge.t
220 test-import-unknown.t
221 test-import-unknown.t
221 test-import.t
222 test-import.t
222 test-imports-checker.t
223 test-imports-checker.t
223 test-incoming-outgoing.t
224 test-incoming-outgoing.t
224 test-inherit-mode.t
225 test-inherit-mode.t
225 test-init.t
226 test-init.t
226 test-issue1089.t
227 test-issue1089.t
227 test-issue1102.t
228 test-issue1102.t
228 test-issue1175.t
229 test-issue1175.t
229 test-issue1306.t
230 test-issue1306.t
230 test-issue1438.t
231 test-issue1438.t
231 test-issue1502.t
232 test-issue1502.t
232 test-issue1802.t
233 test-issue1802.t
233 test-issue1877.t
234 test-issue1877.t
234 test-issue1993.t
235 test-issue1993.t
235 test-issue2137.t
236 test-issue2137.t
236 test-issue3084.t
237 test-issue3084.t
237 test-issue4074.t
238 test-issue4074.t
238 test-issue522.t
239 test-issue522.t
239 test-issue586.t
240 test-issue586.t
240 test-issue612.t
241 test-issue612.t
241 test-issue619.t
242 test-issue619.t
242 test-issue660.t
243 test-issue660.t
243 test-issue672.t
244 test-issue672.t
244 test-issue842.t
245 test-issue842.t
245 test-journal-exists.t
246 test-journal-exists.t
246 test-journal-share.t
247 test-journal-share.t
247 test-journal.t
248 test-journal.t
248 test-known.t
249 test-known.t
249 test-largefiles-cache.t
250 test-largefiles-cache.t
250 test-largefiles-misc.t
251 test-largefiles-misc.t
251 test-largefiles-small-disk.t
252 test-largefiles-small-disk.t
252 test-largefiles-update.t
253 test-largefiles-update.t
253 test-largefiles.t
254 test-largefiles.t
254 test-lfs-largefiles.t
255 test-lfs-largefiles.t
255 test-lfs-pointer.py
256 test-lfs-pointer.py
256 test-linerange.py
257 test-linerange.py
257 test-locate.t
258 test-locate.t
258 test-lock-badness.t
259 test-lock-badness.t
259 test-log-linerange.t
260 test-log-linerange.t
260 test-log.t
261 test-log.t
261 test-logexchange.t
262 test-logexchange.t
262 test-lrucachedict.py
263 test-lrucachedict.py
263 test-mactext.t
264 test-mactext.t
264 test-mailmap.t
265 test-mailmap.t
265 test-manifest-merging.t
266 test-manifest-merging.t
266 test-manifest.py
267 test-manifest.py
267 test-manifest.t
268 test-manifest.t
268 test-match.py
269 test-match.py
269 test-mdiff.py
270 test-mdiff.py
270 test-merge-changedelete.t
271 test-merge-changedelete.t
271 test-merge-closedheads.t
272 test-merge-closedheads.t
272 test-merge-commit.t
273 test-merge-commit.t
273 test-merge-criss-cross.t
274 test-merge-criss-cross.t
274 test-merge-default.t
275 test-merge-default.t
275 test-merge-force.t
276 test-merge-force.t
276 test-merge-halt.t
277 test-merge-halt.t
277 test-merge-internal-tools-pattern.t
278 test-merge-internal-tools-pattern.t
278 test-merge-local.t
279 test-merge-local.t
279 test-merge-remove.t
280 test-merge-remove.t
280 test-merge-revert.t
281 test-merge-revert.t
281 test-merge-revert2.t
282 test-merge-revert2.t
282 test-merge-subrepos.t
283 test-merge-subrepos.t
283 test-merge-symlinks.t
284 test-merge-symlinks.t
284 test-merge-tools.t
285 test-merge-tools.t
285 test-merge-types.t
286 test-merge-types.t
286 test-merge1.t
287 test-merge1.t
287 test-merge10.t
288 test-merge10.t
288 test-merge2.t
289 test-merge2.t
289 test-merge4.t
290 test-merge4.t
290 test-merge5.t
291 test-merge5.t
291 test-merge6.t
292 test-merge6.t
292 test-merge7.t
293 test-merge7.t
293 test-merge8.t
294 test-merge8.t
294 test-merge9.t
295 test-merge9.t
295 test-minifileset.py
296 test-minifileset.py
296 test-minirst.py
297 test-minirst.py
297 test-mq-git.t
298 test-mq-git.t
298 test-mq-header-date.t
299 test-mq-header-date.t
299 test-mq-header-from.t
300 test-mq-header-from.t
300 test-mq-merge.t
301 test-mq-merge.t
301 test-mq-pull-from-bundle.t
302 test-mq-pull-from-bundle.t
302 test-mq-qclone-http.t
303 test-mq-qclone-http.t
303 test-mq-qdelete.t
304 test-mq-qdelete.t
304 test-mq-qdiff.t
305 test-mq-qdiff.t
305 test-mq-qfold.t
306 test-mq-qfold.t
306 test-mq-qgoto.t
307 test-mq-qgoto.t
307 test-mq-qimport-fail-cleanup.t
308 test-mq-qimport-fail-cleanup.t
308 test-mq-qnew.t
309 test-mq-qnew.t
309 test-mq-qpush-exact.t
310 test-mq-qpush-exact.t
310 test-mq-qqueue.t
311 test-mq-qqueue.t
311 test-mq-qrefresh-interactive.t
312 test-mq-qrefresh-interactive.t
312 test-mq-qrefresh-replace-log-message.t
313 test-mq-qrefresh-replace-log-message.t
313 test-mq-qrefresh.t
314 test-mq-qrefresh.t
314 test-mq-qrename.t
315 test-mq-qrename.t
315 test-mq-qsave.t
316 test-mq-qsave.t
316 test-mq-safety.t
317 test-mq-safety.t
317 test-mq-subrepo.t
318 test-mq-subrepo.t
318 test-mq-symlinks.t
319 test-mq-symlinks.t
319 test-mv-cp-st-diff.t
320 test-mv-cp-st-diff.t
320 test-narrow-archive.t
321 test-narrow-archive.t
321 test-narrow-clone-no-ellipsis.t
322 test-narrow-clone-no-ellipsis.t
322 test-narrow-clone-non-narrow-server.t
323 test-narrow-clone-non-narrow-server.t
323 test-narrow-clone-nonlinear.t
324 test-narrow-clone-nonlinear.t
324 test-narrow-clone.t
325 test-narrow-clone.t
325 test-narrow-commit.t
326 test-narrow-commit.t
326 test-narrow-copies.t
327 test-narrow-copies.t
327 test-narrow-debugcommands.t
328 test-narrow-debugcommands.t
328 test-narrow-debugrebuilddirstate.t
329 test-narrow-debugrebuilddirstate.t
329 test-narrow-exchange-merges.t
330 test-narrow-exchange-merges.t
330 test-narrow-exchange.t
331 test-narrow-exchange.t
331 test-narrow-expanddirstate.t
332 test-narrow-expanddirstate.t
332 test-narrow-merge.t
333 test-narrow-merge.t
333 test-narrow-patch.t
334 test-narrow-patch.t
334 test-narrow-patterns.t
335 test-narrow-patterns.t
335 test-narrow-pull.t
336 test-narrow-pull.t
336 test-narrow-rebase.t
337 test-narrow-rebase.t
337 test-narrow-shallow-merges.t
338 test-narrow-shallow-merges.t
338 test-narrow-shallow.t
339 test-narrow-shallow.t
339 test-narrow-strip.t
340 test-narrow-strip.t
340 test-narrow-update.t
341 test-narrow-update.t
341 test-narrow-widen.t
342 test-narrow-widen.t
342 test-narrow.t
343 test-narrow.t
343 test-nested-repo.t
344 test-nested-repo.t
344 test-newbranch.t
345 test-newbranch.t
345 test-nointerrupt.t
346 test-nointerrupt.t
346 test-obshistory.t
347 test-obshistory.t
347 test-obsmarker-template.t
348 test-obsmarker-template.t
348 test-obsmarkers-effectflag.t
349 test-obsmarkers-effectflag.t
349 test-obsolete-bundle-strip.t
350 test-obsolete-bundle-strip.t
350 test-obsolete-changeset-exchange.t
351 test-obsolete-changeset-exchange.t
351 test-obsolete-checkheads.t
352 test-obsolete-checkheads.t
352 test-obsolete-distributed.t
353 test-obsolete-distributed.t
353 test-obsolete-divergent.t
354 test-obsolete-divergent.t
354 test-obsolete-tag-cache.t
355 test-obsolete-tag-cache.t
355 test-pager.t
356 test-pager.t
356 test-parents.t
357 test-parents.t
357 test-parseindex2.py
358 test-parseindex2.py
358 test-patch-offset.t
359 test-patch-offset.t
359 test-patch.t
360 test-patch.t
360 test-pathconflicts-merge.t
361 test-pathconflicts-merge.t
361 test-pathconflicts-update.t
362 test-pathconflicts-update.t
362 test-pathencode.py
363 test-pathencode.py
363 test-pending.t
364 test-pending.t
364 test-permissions.t
365 test-permissions.t
365 test-phases.t
366 test-phases.t
366 test-pull-branch.t
367 test-pull-branch.t
367 test-pull-http.t
368 test-pull-http.t
368 test-pull-permission.t
369 test-pull-permission.t
369 test-pull-pull-corruption.t
370 test-pull-pull-corruption.t
370 test-pull-r.t
371 test-pull-r.t
371 test-pull-update.t
372 test-pull-update.t
372 test-pull.t
373 test-pull.t
373 test-purge.t
374 test-purge.t
374 test-push-checkheads-partial-C1.t
375 test-push-checkheads-partial-C1.t
375 test-push-checkheads-partial-C2.t
376 test-push-checkheads-partial-C2.t
376 test-push-checkheads-partial-C3.t
377 test-push-checkheads-partial-C3.t
377 test-push-checkheads-partial-C4.t
378 test-push-checkheads-partial-C4.t
378 test-push-checkheads-pruned-B1.t
379 test-push-checkheads-pruned-B1.t
379 test-push-checkheads-pruned-B2.t
380 test-push-checkheads-pruned-B2.t
380 test-push-checkheads-pruned-B3.t
381 test-push-checkheads-pruned-B3.t
381 test-push-checkheads-pruned-B4.t
382 test-push-checkheads-pruned-B4.t
382 test-push-checkheads-pruned-B5.t
383 test-push-checkheads-pruned-B5.t
383 test-push-checkheads-pruned-B6.t
384 test-push-checkheads-pruned-B6.t
384 test-push-checkheads-pruned-B7.t
385 test-push-checkheads-pruned-B7.t
385 test-push-checkheads-pruned-B8.t
386 test-push-checkheads-pruned-B8.t
386 test-push-checkheads-superceed-A1.t
387 test-push-checkheads-superceed-A1.t
387 test-push-checkheads-superceed-A2.t
388 test-push-checkheads-superceed-A2.t
388 test-push-checkheads-superceed-A3.t
389 test-push-checkheads-superceed-A3.t
389 test-push-checkheads-superceed-A4.t
390 test-push-checkheads-superceed-A4.t
390 test-push-checkheads-superceed-A5.t
391 test-push-checkheads-superceed-A5.t
391 test-push-checkheads-superceed-A6.t
392 test-push-checkheads-superceed-A6.t
392 test-push-checkheads-superceed-A7.t
393 test-push-checkheads-superceed-A7.t
393 test-push-checkheads-superceed-A8.t
394 test-push-checkheads-superceed-A8.t
394 test-push-checkheads-unpushed-D1.t
395 test-push-checkheads-unpushed-D1.t
395 test-push-checkheads-unpushed-D2.t
396 test-push-checkheads-unpushed-D2.t
396 test-push-checkheads-unpushed-D3.t
397 test-push-checkheads-unpushed-D3.t
397 test-push-checkheads-unpushed-D4.t
398 test-push-checkheads-unpushed-D4.t
398 test-push-checkheads-unpushed-D5.t
399 test-push-checkheads-unpushed-D5.t
399 test-push-checkheads-unpushed-D6.t
400 test-push-checkheads-unpushed-D6.t
400 test-push-checkheads-unpushed-D7.t
401 test-push-checkheads-unpushed-D7.t
401 test-push-http.t
402 test-push-http.t
402 test-push-warn.t
403 test-push-warn.t
403 test-push.t
404 test-push.t
404 test-pushvars.t
405 test-pushvars.t
405 test-qrecord.t
406 test-qrecord.t
406 test-rebase-abort.t
407 test-rebase-abort.t
407 test-rebase-base-flag.t
408 test-rebase-base-flag.t
408 test-rebase-bookmarks.t
409 test-rebase-bookmarks.t
409 test-rebase-brute-force.t
410 test-rebase-brute-force.t
410 test-rebase-cache.t
411 test-rebase-cache.t
411 test-rebase-check-restore.t
412 test-rebase-check-restore.t
412 test-rebase-collapse.t
413 test-rebase-collapse.t
413 test-rebase-conflicts.t
414 test-rebase-conflicts.t
414 test-rebase-dest.t
415 test-rebase-dest.t
415 test-rebase-detach.t
416 test-rebase-detach.t
416 test-rebase-emptycommit.t
417 test-rebase-emptycommit.t
417 test-rebase-inmemory.t
418 test-rebase-inmemory.t
418 test-rebase-interruptions.t
419 test-rebase-interruptions.t
419 test-rebase-issue-noparam-single-rev.t
420 test-rebase-issue-noparam-single-rev.t
420 test-rebase-legacy.t
421 test-rebase-legacy.t
421 test-rebase-mq-skip.t
422 test-rebase-mq-skip.t
422 test-rebase-mq.t
423 test-rebase-mq.t
423 test-rebase-named-branches.t
424 test-rebase-named-branches.t
424 test-rebase-newancestor.t
425 test-rebase-newancestor.t
425 test-rebase-obsolete.t
426 test-rebase-obsolete.t
426 test-rebase-parameters.t
427 test-rebase-parameters.t
427 test-rebase-partial.t
428 test-rebase-partial.t
428 test-rebase-pull.t
429 test-rebase-pull.t
429 test-rebase-rename.t
430 test-rebase-rename.t
430 test-rebase-scenario-global.t
431 test-rebase-scenario-global.t
431 test-rebase-templates.t
432 test-rebase-templates.t
432 test-rebase-transaction.t
433 test-rebase-transaction.t
433 test-rebuildstate.t
434 test-rebuildstate.t
434 test-record.t
435 test-record.t
435 test-relink.t
436 test-relink.t
436 test-remove.t
437 test-remove.t
437 test-removeemptydirs.t
438 test-removeemptydirs.t
438 test-rename-after-merge.t
439 test-rename-after-merge.t
439 test-rename-dir-merge.t
440 test-rename-dir-merge.t
440 test-rename-merge1.t
441 test-rename-merge1.t
441 test-rename.t
442 test-rename.t
442 test-repair-strip.t
443 test-repair-strip.t
443 test-repo-compengines.t
444 test-repo-compengines.t
444 test-resolve.t
445 test-resolve.t
445 test-revert-flags.t
446 test-revert-flags.t
446 test-revert-interactive.t
447 test-revert-interactive.t
447 test-revert-unknown.t
448 test-revert-unknown.t
448 test-revlog-ancestry.py
449 test-revlog-ancestry.py
449 test-revlog-group-emptyiter.t
450 test-revlog-group-emptyiter.t
450 test-revlog-mmapindex.t
451 test-revlog-mmapindex.t
451 test-revlog-packentry.t
452 test-revlog-packentry.t
452 test-revlog-raw.py
453 test-revlog-raw.py
453 test-revlog-v2.t
454 test-revlog-v2.t
454 test-revset-dirstate-parents.t
455 test-revset-dirstate-parents.t
455 test-revset-legacy-lookup.t
456 test-revset-legacy-lookup.t
456 test-revset-outgoing.t
457 test-revset-outgoing.t
457 test-rollback.t
458 test-rollback.t
458 test-run-tests.py
459 test-run-tests.py
459 test-run-tests.t
460 test-run-tests.t
460 test-schemes.t
461 test-schemes.t
461 test-serve.t
462 test-serve.t
462 test-setdiscovery.t
463 test-setdiscovery.t
463 test-share.t
464 test-share.t
464 test-shelve.t
465 test-shelve.t
465 test-show-stack.t
466 test-show-stack.t
466 test-show-work.t
467 test-show-work.t
467 test-show.t
468 test-show.t
468 test-simple-update.t
469 test-simple-update.t
469 test-simplekeyvaluefile.py
470 test-simplekeyvaluefile.py
470 test-simplemerge.py
471 test-simplemerge.py
471 test-single-head.t
472 test-single-head.t
472 test-sparse-clear.t
473 test-sparse-clear.t
473 test-sparse-clone.t
474 test-sparse-clone.t
474 test-sparse-import.t
475 test-sparse-import.t
475 test-sparse-merges.t
476 test-sparse-merges.t
476 test-sparse-profiles.t
477 test-sparse-profiles.t
477 test-sparse-requirement.t
478 test-sparse-requirement.t
478 test-sparse-verbose-json.t
479 test-sparse-verbose-json.t
479 test-sparse.t
480 test-sparse.t
480 test-split.t
481 test-split.t
481 test-ssh-bundle1.t
482 test-ssh-bundle1.t
482 test-ssh-clone-r.t
483 test-ssh-clone-r.t
483 test-ssh-proto-unbundle.t
484 test-ssh-proto-unbundle.t
484 test-ssh-proto.t
485 test-ssh-proto.t
485 test-ssh.t
486 test-ssh.t
486 test-sshserver.py
487 test-sshserver.py
487 test-stack.t
488 test-stack.t
488 test-status-inprocess.py
489 test-status-inprocess.py
489 test-status-rev.t
490 test-status-rev.t
490 test-status-terse.t
491 test-status-terse.t
491 test-strict.t
492 test-strict.t
492 test-strip-cross.t
493 test-strip-cross.t
493 test-strip.t
494 test-strip.t
494 test-subrepo-deep-nested-change.t
495 test-subrepo-deep-nested-change.t
495 test-subrepo-missing.t
496 test-subrepo-missing.t
496 test-subrepo-paths.t
497 test-subrepo-paths.t
497 test-subrepo-recursion.t
498 test-subrepo-recursion.t
498 test-subrepo-relative-path.t
499 test-subrepo-relative-path.t
499 test-subrepo.t
500 test-subrepo.t
500 test-symlink-os-yes-fs-no.py
501 test-symlink-os-yes-fs-no.py
501 test-symlink-placeholder.t
502 test-symlink-placeholder.t
502 test-symlinks.t
503 test-symlinks.t
503 test-tag.t
504 test-tag.t
504 test-tags.t
505 test-tags.t
505 test-template-basic.t
506 test-template-basic.t
506 test-template-functions.t
507 test-template-functions.t
507 test-template-keywords.t
508 test-template-keywords.t
508 test-template-map.t
509 test-template-map.t
509 test-transplant.t
510 test-transplant.t
510 test-treemanifest.t
511 test-treemanifest.t
511 test-ui-color.py
512 test-ui-color.py
512 test-ui-config.py
513 test-ui-config.py
513 test-ui-verbosity.py
514 test-ui-verbosity.py
514 test-unamend.t
515 test-unamend.t
515 test-unbundlehash.t
516 test-unbundlehash.t
516 test-uncommit.t
517 test-uncommit.t
517 test-unified-test.t
518 test-unified-test.t
518 test-unionrepo.t
519 test-unionrepo.t
519 test-unrelated-pull.t
520 test-unrelated-pull.t
520 test-up-local-change.t
521 test-up-local-change.t
521 test-update-branches.t
522 test-update-branches.t
522 test-update-dest.t
523 test-update-dest.t
523 test-update-issue1456.t
524 test-update-issue1456.t
524 test-update-names.t
525 test-update-names.t
525 test-update-reverse.t
526 test-update-reverse.t
526 test-upgrade-repo.t
527 test-upgrade-repo.t
527 test-url-download.t
528 test-url-download.t
528 test-url-rev.t
529 test-url-rev.t
529 test-url.py
530 test-url.py
530 test-username-newline.t
531 test-username-newline.t
531 test-verify.t
532 test-verify.t
532 test-walk.t
533 test-walk.t
533 test-walkrepo.py
534 test-walkrepo.py
534 test-websub.t
535 test-websub.t
535 test-win32text.t
536 test-win32text.t
536 test-wireproto-clientreactor.py
537 test-wireproto-clientreactor.py
537 test-wireproto-framing.py
538 test-wireproto-framing.py
538 test-wireproto-serverreactor.py
539 test-wireproto-serverreactor.py
539 test-wireproto.py
540 test-wireproto.py
540 test-wsgirequest.py
541 test-wsgirequest.py
541 test-xdg.t
542 test-xdg.t
@@ -1,2265 +1,2265
1 # bundle2.py - generic container format to transmit arbitrary data.
1 # bundle2.py - generic container format to transmit arbitrary data.
2 #
2 #
3 # Copyright 2013 Facebook, Inc.
3 # Copyright 2013 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7 """Handling of the new bundle2 format
7 """Handling of the new bundle2 format
8
8
9 The goal of bundle2 is to act as an atomically packet to transmit a set of
9 The goal of bundle2 is to act as an atomically packet to transmit a set of
10 payloads in an application agnostic way. It consist in a sequence of "parts"
10 payloads in an application agnostic way. It consist in a sequence of "parts"
11 that will be handed to and processed by the application layer.
11 that will be handed to and processed by the application layer.
12
12
13
13
14 General format architecture
14 General format architecture
15 ===========================
15 ===========================
16
16
17 The format is architectured as follow
17 The format is architectured as follow
18
18
19 - magic string
19 - magic string
20 - stream level parameters
20 - stream level parameters
21 - payload parts (any number)
21 - payload parts (any number)
22 - end of stream marker.
22 - end of stream marker.
23
23
24 the Binary format
24 the Binary format
25 ============================
25 ============================
26
26
27 All numbers are unsigned and big-endian.
27 All numbers are unsigned and big-endian.
28
28
29 stream level parameters
29 stream level parameters
30 ------------------------
30 ------------------------
31
31
32 Binary format is as follow
32 Binary format is as follow
33
33
34 :params size: int32
34 :params size: int32
35
35
36 The total number of Bytes used by the parameters
36 The total number of Bytes used by the parameters
37
37
38 :params value: arbitrary number of Bytes
38 :params value: arbitrary number of Bytes
39
39
40 A blob of `params size` containing the serialized version of all stream level
40 A blob of `params size` containing the serialized version of all stream level
41 parameters.
41 parameters.
42
42
43 The blob contains a space separated list of parameters. Parameters with value
43 The blob contains a space separated list of parameters. Parameters with value
44 are stored in the form `<name>=<value>`. Both name and value are urlquoted.
44 are stored in the form `<name>=<value>`. Both name and value are urlquoted.
45
45
46 Empty name are obviously forbidden.
46 Empty name are obviously forbidden.
47
47
48 Name MUST start with a letter. If this first letter is lower case, the
48 Name MUST start with a letter. If this first letter is lower case, the
49 parameter is advisory and can be safely ignored. However when the first
49 parameter is advisory and can be safely ignored. However when the first
50 letter is capital, the parameter is mandatory and the bundling process MUST
50 letter is capital, the parameter is mandatory and the bundling process MUST
51 stop if he is not able to proceed it.
51 stop if he is not able to proceed it.
52
52
53 Stream parameters use a simple textual format for two main reasons:
53 Stream parameters use a simple textual format for two main reasons:
54
54
55 - Stream level parameters should remain simple and we want to discourage any
55 - Stream level parameters should remain simple and we want to discourage any
56 crazy usage.
56 crazy usage.
57 - Textual data allow easy human inspection of a bundle2 header in case of
57 - Textual data allow easy human inspection of a bundle2 header in case of
58 troubles.
58 troubles.
59
59
60 Any Applicative level options MUST go into a bundle2 part instead.
60 Any Applicative level options MUST go into a bundle2 part instead.
61
61
62 Payload part
62 Payload part
63 ------------------------
63 ------------------------
64
64
65 Binary format is as follow
65 Binary format is as follow
66
66
67 :header size: int32
67 :header size: int32
68
68
69 The total number of Bytes used by the part header. When the header is empty
69 The total number of Bytes used by the part header. When the header is empty
70 (size = 0) this is interpreted as the end of stream marker.
70 (size = 0) this is interpreted as the end of stream marker.
71
71
72 :header:
72 :header:
73
73
74 The header defines how to interpret the part. It contains two piece of
74 The header defines how to interpret the part. It contains two piece of
75 data: the part type, and the part parameters.
75 data: the part type, and the part parameters.
76
76
77 The part type is used to route an application level handler, that can
77 The part type is used to route an application level handler, that can
78 interpret payload.
78 interpret payload.
79
79
80 Part parameters are passed to the application level handler. They are
80 Part parameters are passed to the application level handler. They are
81 meant to convey information that will help the application level object to
81 meant to convey information that will help the application level object to
82 interpret the part payload.
82 interpret the part payload.
83
83
84 The binary format of the header is has follow
84 The binary format of the header is has follow
85
85
86 :typesize: (one byte)
86 :typesize: (one byte)
87
87
88 :parttype: alphanumerical part name (restricted to [a-zA-Z0-9_:-]*)
88 :parttype: alphanumerical part name (restricted to [a-zA-Z0-9_:-]*)
89
89
90 :partid: A 32bits integer (unique in the bundle) that can be used to refer
90 :partid: A 32bits integer (unique in the bundle) that can be used to refer
91 to this part.
91 to this part.
92
92
93 :parameters:
93 :parameters:
94
94
95 Part's parameter may have arbitrary content, the binary structure is::
95 Part's parameter may have arbitrary content, the binary structure is::
96
96
97 <mandatory-count><advisory-count><param-sizes><param-data>
97 <mandatory-count><advisory-count><param-sizes><param-data>
98
98
99 :mandatory-count: 1 byte, number of mandatory parameters
99 :mandatory-count: 1 byte, number of mandatory parameters
100
100
101 :advisory-count: 1 byte, number of advisory parameters
101 :advisory-count: 1 byte, number of advisory parameters
102
102
103 :param-sizes:
103 :param-sizes:
104
104
105 N couple of bytes, where N is the total number of parameters. Each
105 N couple of bytes, where N is the total number of parameters. Each
106 couple contains (<size-of-key>, <size-of-value) for one parameter.
106 couple contains (<size-of-key>, <size-of-value) for one parameter.
107
107
108 :param-data:
108 :param-data:
109
109
110 A blob of bytes from which each parameter key and value can be
110 A blob of bytes from which each parameter key and value can be
111 retrieved using the list of size couples stored in the previous
111 retrieved using the list of size couples stored in the previous
112 field.
112 field.
113
113
114 Mandatory parameters comes first, then the advisory ones.
114 Mandatory parameters comes first, then the advisory ones.
115
115
116 Each parameter's key MUST be unique within the part.
116 Each parameter's key MUST be unique within the part.
117
117
118 :payload:
118 :payload:
119
119
120 payload is a series of `<chunksize><chunkdata>`.
120 payload is a series of `<chunksize><chunkdata>`.
121
121
122 `chunksize` is an int32, `chunkdata` are plain bytes (as much as
122 `chunksize` is an int32, `chunkdata` are plain bytes (as much as
123 `chunksize` says)` The payload part is concluded by a zero size chunk.
123 `chunksize` says)` The payload part is concluded by a zero size chunk.
124
124
125 The current implementation always produces either zero or one chunk.
125 The current implementation always produces either zero or one chunk.
126 This is an implementation limitation that will ultimately be lifted.
126 This is an implementation limitation that will ultimately be lifted.
127
127
128 `chunksize` can be negative to trigger special case processing. No such
128 `chunksize` can be negative to trigger special case processing. No such
129 processing is in place yet.
129 processing is in place yet.
130
130
131 Bundle processing
131 Bundle processing
132 ============================
132 ============================
133
133
134 Each part is processed in order using a "part handler". Handler are registered
134 Each part is processed in order using a "part handler". Handler are registered
135 for a certain part type.
135 for a certain part type.
136
136
137 The matching of a part to its handler is case insensitive. The case of the
137 The matching of a part to its handler is case insensitive. The case of the
138 part type is used to know if a part is mandatory or advisory. If the Part type
138 part type is used to know if a part is mandatory or advisory. If the Part type
139 contains any uppercase char it is considered mandatory. When no handler is
139 contains any uppercase char it is considered mandatory. When no handler is
140 known for a Mandatory part, the process is aborted and an exception is raised.
140 known for a Mandatory part, the process is aborted and an exception is raised.
141 If the part is advisory and no handler is known, the part is ignored. When the
141 If the part is advisory and no handler is known, the part is ignored. When the
142 process is aborted, the full bundle is still read from the stream to keep the
142 process is aborted, the full bundle is still read from the stream to keep the
143 channel usable. But none of the part read from an abort are processed. In the
143 channel usable. But none of the part read from an abort are processed. In the
144 future, dropping the stream may become an option for channel we do not care to
144 future, dropping the stream may become an option for channel we do not care to
145 preserve.
145 preserve.
146 """
146 """
147
147
148 from __future__ import absolute_import, division
148 from __future__ import absolute_import, division
149
149
150 import collections
150 import collections
151 import errno
151 import errno
152 import os
152 import os
153 import re
153 import re
154 import string
154 import string
155 import struct
155 import struct
156 import sys
156 import sys
157
157
158 from .i18n import _
158 from .i18n import _
159 from . import (
159 from . import (
160 bookmarks,
160 bookmarks,
161 changegroup,
161 changegroup,
162 encoding,
162 encoding,
163 error,
163 error,
164 node as nodemod,
164 node as nodemod,
165 obsolete,
165 obsolete,
166 phases,
166 phases,
167 pushkey,
167 pushkey,
168 pycompat,
168 pycompat,
169 streamclone,
169 streamclone,
170 tags,
170 tags,
171 url,
171 url,
172 util,
172 util,
173 )
173 )
174 from .utils import (
174 from .utils import (
175 stringutil,
175 stringutil,
176 )
176 )
177
177
178 urlerr = util.urlerr
178 urlerr = util.urlerr
179 urlreq = util.urlreq
179 urlreq = util.urlreq
180
180
181 _pack = struct.pack
181 _pack = struct.pack
182 _unpack = struct.unpack
182 _unpack = struct.unpack
183
183
184 _fstreamparamsize = '>i'
184 _fstreamparamsize = '>i'
185 _fpartheadersize = '>i'
185 _fpartheadersize = '>i'
186 _fparttypesize = '>B'
186 _fparttypesize = '>B'
187 _fpartid = '>I'
187 _fpartid = '>I'
188 _fpayloadsize = '>i'
188 _fpayloadsize = '>i'
189 _fpartparamcount = '>BB'
189 _fpartparamcount = '>BB'
190
190
191 preferedchunksize = 32768
191 preferedchunksize = 32768
192
192
193 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
193 _parttypeforbidden = re.compile('[^a-zA-Z0-9_:-]')
194
194
195 def outdebug(ui, message):
195 def outdebug(ui, message):
196 """debug regarding output stream (bundling)"""
196 """debug regarding output stream (bundling)"""
197 if ui.configbool('devel', 'bundle2.debug'):
197 if ui.configbool('devel', 'bundle2.debug'):
198 ui.debug('bundle2-output: %s\n' % message)
198 ui.debug('bundle2-output: %s\n' % message)
199
199
200 def indebug(ui, message):
200 def indebug(ui, message):
201 """debug on input stream (unbundling)"""
201 """debug on input stream (unbundling)"""
202 if ui.configbool('devel', 'bundle2.debug'):
202 if ui.configbool('devel', 'bundle2.debug'):
203 ui.debug('bundle2-input: %s\n' % message)
203 ui.debug('bundle2-input: %s\n' % message)
204
204
205 def validateparttype(parttype):
205 def validateparttype(parttype):
206 """raise ValueError if a parttype contains invalid character"""
206 """raise ValueError if a parttype contains invalid character"""
207 if _parttypeforbidden.search(parttype):
207 if _parttypeforbidden.search(parttype):
208 raise ValueError(parttype)
208 raise ValueError(parttype)
209
209
210 def _makefpartparamsizes(nbparams):
210 def _makefpartparamsizes(nbparams):
211 """return a struct format to read part parameter sizes
211 """return a struct format to read part parameter sizes
212
212
213 The number parameters is variable so we need to build that format
213 The number parameters is variable so we need to build that format
214 dynamically.
214 dynamically.
215 """
215 """
216 return '>'+('BB'*nbparams)
216 return '>'+('BB'*nbparams)
217
217
218 parthandlermapping = {}
218 parthandlermapping = {}
219
219
220 def parthandler(parttype, params=()):
220 def parthandler(parttype, params=()):
221 """decorator that register a function as a bundle2 part handler
221 """decorator that register a function as a bundle2 part handler
222
222
223 eg::
223 eg::
224
224
225 @parthandler('myparttype', ('mandatory', 'param', 'handled'))
225 @parthandler('myparttype', ('mandatory', 'param', 'handled'))
226 def myparttypehandler(...):
226 def myparttypehandler(...):
227 '''process a part of type "my part".'''
227 '''process a part of type "my part".'''
228 ...
228 ...
229 """
229 """
230 validateparttype(parttype)
230 validateparttype(parttype)
231 def _decorator(func):
231 def _decorator(func):
232 lparttype = parttype.lower() # enforce lower case matching.
232 lparttype = parttype.lower() # enforce lower case matching.
233 assert lparttype not in parthandlermapping
233 assert lparttype not in parthandlermapping
234 parthandlermapping[lparttype] = func
234 parthandlermapping[lparttype] = func
235 func.params = frozenset(params)
235 func.params = frozenset(params)
236 return func
236 return func
237 return _decorator
237 return _decorator
238
238
239 class unbundlerecords(object):
239 class unbundlerecords(object):
240 """keep record of what happens during and unbundle
240 """keep record of what happens during and unbundle
241
241
242 New records are added using `records.add('cat', obj)`. Where 'cat' is a
242 New records are added using `records.add('cat', obj)`. Where 'cat' is a
243 category of record and obj is an arbitrary object.
243 category of record and obj is an arbitrary object.
244
244
245 `records['cat']` will return all entries of this category 'cat'.
245 `records['cat']` will return all entries of this category 'cat'.
246
246
247 Iterating on the object itself will yield `('category', obj)` tuples
247 Iterating on the object itself will yield `('category', obj)` tuples
248 for all entries.
248 for all entries.
249
249
250 All iterations happens in chronological order.
250 All iterations happens in chronological order.
251 """
251 """
252
252
253 def __init__(self):
253 def __init__(self):
254 self._categories = {}
254 self._categories = {}
255 self._sequences = []
255 self._sequences = []
256 self._replies = {}
256 self._replies = {}
257
257
258 def add(self, category, entry, inreplyto=None):
258 def add(self, category, entry, inreplyto=None):
259 """add a new record of a given category.
259 """add a new record of a given category.
260
260
261 The entry can then be retrieved in the list returned by
261 The entry can then be retrieved in the list returned by
262 self['category']."""
262 self['category']."""
263 self._categories.setdefault(category, []).append(entry)
263 self._categories.setdefault(category, []).append(entry)
264 self._sequences.append((category, entry))
264 self._sequences.append((category, entry))
265 if inreplyto is not None:
265 if inreplyto is not None:
266 self.getreplies(inreplyto).add(category, entry)
266 self.getreplies(inreplyto).add(category, entry)
267
267
268 def getreplies(self, partid):
268 def getreplies(self, partid):
269 """get the records that are replies to a specific part"""
269 """get the records that are replies to a specific part"""
270 return self._replies.setdefault(partid, unbundlerecords())
270 return self._replies.setdefault(partid, unbundlerecords())
271
271
272 def __getitem__(self, cat):
272 def __getitem__(self, cat):
273 return tuple(self._categories.get(cat, ()))
273 return tuple(self._categories.get(cat, ()))
274
274
275 def __iter__(self):
275 def __iter__(self):
276 return iter(self._sequences)
276 return iter(self._sequences)
277
277
278 def __len__(self):
278 def __len__(self):
279 return len(self._sequences)
279 return len(self._sequences)
280
280
281 def __nonzero__(self):
281 def __nonzero__(self):
282 return bool(self._sequences)
282 return bool(self._sequences)
283
283
284 __bool__ = __nonzero__
284 __bool__ = __nonzero__
285
285
286 class bundleoperation(object):
286 class bundleoperation(object):
287 """an object that represents a single bundling process
287 """an object that represents a single bundling process
288
288
289 Its purpose is to carry unbundle-related objects and states.
289 Its purpose is to carry unbundle-related objects and states.
290
290
291 A new object should be created at the beginning of each bundle processing.
291 A new object should be created at the beginning of each bundle processing.
292 The object is to be returned by the processing function.
292 The object is to be returned by the processing function.
293
293
294 The object has very little content now it will ultimately contain:
294 The object has very little content now it will ultimately contain:
295 * an access to the repo the bundle is applied to,
295 * an access to the repo the bundle is applied to,
296 * a ui object,
296 * a ui object,
297 * a way to retrieve a transaction to add changes to the repo,
297 * a way to retrieve a transaction to add changes to the repo,
298 * a way to record the result of processing each part,
298 * a way to record the result of processing each part,
299 * a way to construct a bundle response when applicable.
299 * a way to construct a bundle response when applicable.
300 """
300 """
301
301
302 def __init__(self, repo, transactiongetter, captureoutput=True, source=''):
302 def __init__(self, repo, transactiongetter, captureoutput=True, source=''):
303 self.repo = repo
303 self.repo = repo
304 self.ui = repo.ui
304 self.ui = repo.ui
305 self.records = unbundlerecords()
305 self.records = unbundlerecords()
306 self.reply = None
306 self.reply = None
307 self.captureoutput = captureoutput
307 self.captureoutput = captureoutput
308 self.hookargs = {}
308 self.hookargs = {}
309 self._gettransaction = transactiongetter
309 self._gettransaction = transactiongetter
310 # carries value that can modify part behavior
310 # carries value that can modify part behavior
311 self.modes = {}
311 self.modes = {}
312 self.source = source
312 self.source = source
313
313
314 def gettransaction(self):
314 def gettransaction(self):
315 transaction = self._gettransaction()
315 transaction = self._gettransaction()
316
316
317 if self.hookargs:
317 if self.hookargs:
318 # the ones added to the transaction supercede those added
318 # the ones added to the transaction supercede those added
319 # to the operation.
319 # to the operation.
320 self.hookargs.update(transaction.hookargs)
320 self.hookargs.update(transaction.hookargs)
321 transaction.hookargs = self.hookargs
321 transaction.hookargs = self.hookargs
322
322
323 # mark the hookargs as flushed. further attempts to add to
323 # mark the hookargs as flushed. further attempts to add to
324 # hookargs will result in an abort.
324 # hookargs will result in an abort.
325 self.hookargs = None
325 self.hookargs = None
326
326
327 return transaction
327 return transaction
328
328
329 def addhookargs(self, hookargs):
329 def addhookargs(self, hookargs):
330 if self.hookargs is None:
330 if self.hookargs is None:
331 raise error.ProgrammingError('attempted to add hookargs to '
331 raise error.ProgrammingError('attempted to add hookargs to '
332 'operation after transaction started')
332 'operation after transaction started')
333 self.hookargs.update(hookargs)
333 self.hookargs.update(hookargs)
334
334
335 class TransactionUnavailable(RuntimeError):
335 class TransactionUnavailable(RuntimeError):
336 pass
336 pass
337
337
338 def _notransaction():
338 def _notransaction():
339 """default method to get a transaction while processing a bundle
339 """default method to get a transaction while processing a bundle
340
340
341 Raise an exception to highlight the fact that no transaction was expected
341 Raise an exception to highlight the fact that no transaction was expected
342 to be created"""
342 to be created"""
343 raise TransactionUnavailable()
343 raise TransactionUnavailable()
344
344
345 def applybundle(repo, unbundler, tr, source, url=None, **kwargs):
345 def applybundle(repo, unbundler, tr, source, url=None, **kwargs):
346 # transform me into unbundler.apply() as soon as the freeze is lifted
346 # transform me into unbundler.apply() as soon as the freeze is lifted
347 if isinstance(unbundler, unbundle20):
347 if isinstance(unbundler, unbundle20):
348 tr.hookargs['bundle2'] = '1'
348 tr.hookargs['bundle2'] = '1'
349 if source is not None and 'source' not in tr.hookargs:
349 if source is not None and 'source' not in tr.hookargs:
350 tr.hookargs['source'] = source
350 tr.hookargs['source'] = source
351 if url is not None and 'url' not in tr.hookargs:
351 if url is not None and 'url' not in tr.hookargs:
352 tr.hookargs['url'] = url
352 tr.hookargs['url'] = url
353 return processbundle(repo, unbundler, lambda: tr, source=source)
353 return processbundle(repo, unbundler, lambda: tr, source=source)
354 else:
354 else:
355 # the transactiongetter won't be used, but we might as well set it
355 # the transactiongetter won't be used, but we might as well set it
356 op = bundleoperation(repo, lambda: tr, source=source)
356 op = bundleoperation(repo, lambda: tr, source=source)
357 _processchangegroup(op, unbundler, tr, source, url, **kwargs)
357 _processchangegroup(op, unbundler, tr, source, url, **kwargs)
358 return op
358 return op
359
359
360 class partiterator(object):
360 class partiterator(object):
361 def __init__(self, repo, op, unbundler):
361 def __init__(self, repo, op, unbundler):
362 self.repo = repo
362 self.repo = repo
363 self.op = op
363 self.op = op
364 self.unbundler = unbundler
364 self.unbundler = unbundler
365 self.iterator = None
365 self.iterator = None
366 self.count = 0
366 self.count = 0
367 self.current = None
367 self.current = None
368
368
369 def __enter__(self):
369 def __enter__(self):
370 def func():
370 def func():
371 itr = enumerate(self.unbundler.iterparts())
371 itr = enumerate(self.unbundler.iterparts())
372 for count, p in itr:
372 for count, p in itr:
373 self.count = count
373 self.count = count
374 self.current = p
374 self.current = p
375 yield p
375 yield p
376 p.consume()
376 p.consume()
377 self.current = None
377 self.current = None
378 self.iterator = func()
378 self.iterator = func()
379 return self.iterator
379 return self.iterator
380
380
381 def __exit__(self, type, exc, tb):
381 def __exit__(self, type, exc, tb):
382 if not self.iterator:
382 if not self.iterator:
383 return
383 return
384
384
385 # Only gracefully abort in a normal exception situation. User aborts
385 # Only gracefully abort in a normal exception situation. User aborts
386 # like Ctrl+C throw a KeyboardInterrupt which is not a base Exception,
386 # like Ctrl+C throw a KeyboardInterrupt which is not a base Exception,
387 # and should not gracefully cleanup.
387 # and should not gracefully cleanup.
388 if isinstance(exc, Exception):
388 if isinstance(exc, Exception):
389 # Any exceptions seeking to the end of the bundle at this point are
389 # Any exceptions seeking to the end of the bundle at this point are
390 # almost certainly related to the underlying stream being bad.
390 # almost certainly related to the underlying stream being bad.
391 # And, chances are that the exception we're handling is related to
391 # And, chances are that the exception we're handling is related to
392 # getting in that bad state. So, we swallow the seeking error and
392 # getting in that bad state. So, we swallow the seeking error and
393 # re-raise the original error.
393 # re-raise the original error.
394 seekerror = False
394 seekerror = False
395 try:
395 try:
396 if self.current:
396 if self.current:
397 # consume the part content to not corrupt the stream.
397 # consume the part content to not corrupt the stream.
398 self.current.consume()
398 self.current.consume()
399
399
400 for part in self.iterator:
400 for part in self.iterator:
401 # consume the bundle content
401 # consume the bundle content
402 part.consume()
402 part.consume()
403 except Exception:
403 except Exception:
404 seekerror = True
404 seekerror = True
405
405
406 # Small hack to let caller code distinguish exceptions from bundle2
406 # Small hack to let caller code distinguish exceptions from bundle2
407 # processing from processing the old format. This is mostly needed
407 # processing from processing the old format. This is mostly needed
408 # to handle different return codes to unbundle according to the type
408 # to handle different return codes to unbundle according to the type
409 # of bundle. We should probably clean up or drop this return code
409 # of bundle. We should probably clean up or drop this return code
410 # craziness in a future version.
410 # craziness in a future version.
411 exc.duringunbundle2 = True
411 exc.duringunbundle2 = True
412 salvaged = []
412 salvaged = []
413 replycaps = None
413 replycaps = None
414 if self.op.reply is not None:
414 if self.op.reply is not None:
415 salvaged = self.op.reply.salvageoutput()
415 salvaged = self.op.reply.salvageoutput()
416 replycaps = self.op.reply.capabilities
416 replycaps = self.op.reply.capabilities
417 exc._replycaps = replycaps
417 exc._replycaps = replycaps
418 exc._bundle2salvagedoutput = salvaged
418 exc._bundle2salvagedoutput = salvaged
419
419
420 # Re-raising from a variable loses the original stack. So only use
420 # Re-raising from a variable loses the original stack. So only use
421 # that form if we need to.
421 # that form if we need to.
422 if seekerror:
422 if seekerror:
423 raise exc
423 raise exc
424
424
425 self.repo.ui.debug('bundle2-input-bundle: %i parts total\n' %
425 self.repo.ui.debug('bundle2-input-bundle: %i parts total\n' %
426 self.count)
426 self.count)
427
427
428 def processbundle(repo, unbundler, transactiongetter=None, op=None, source=''):
428 def processbundle(repo, unbundler, transactiongetter=None, op=None, source=''):
429 """This function process a bundle, apply effect to/from a repo
429 """This function process a bundle, apply effect to/from a repo
430
430
431 It iterates over each part then searches for and uses the proper handling
431 It iterates over each part then searches for and uses the proper handling
432 code to process the part. Parts are processed in order.
432 code to process the part. Parts are processed in order.
433
433
434 Unknown Mandatory part will abort the process.
434 Unknown Mandatory part will abort the process.
435
435
436 It is temporarily possible to provide a prebuilt bundleoperation to the
436 It is temporarily possible to provide a prebuilt bundleoperation to the
437 function. This is used to ensure output is properly propagated in case of
437 function. This is used to ensure output is properly propagated in case of
438 an error during the unbundling. This output capturing part will likely be
438 an error during the unbundling. This output capturing part will likely be
439 reworked and this ability will probably go away in the process.
439 reworked and this ability will probably go away in the process.
440 """
440 """
441 if op is None:
441 if op is None:
442 if transactiongetter is None:
442 if transactiongetter is None:
443 transactiongetter = _notransaction
443 transactiongetter = _notransaction
444 op = bundleoperation(repo, transactiongetter, source=source)
444 op = bundleoperation(repo, transactiongetter, source=source)
445 # todo:
445 # todo:
446 # - replace this is a init function soon.
446 # - replace this is a init function soon.
447 # - exception catching
447 # - exception catching
448 unbundler.params
448 unbundler.params
449 if repo.ui.debugflag:
449 if repo.ui.debugflag:
450 msg = ['bundle2-input-bundle:']
450 msg = ['bundle2-input-bundle:']
451 if unbundler.params:
451 if unbundler.params:
452 msg.append(' %i params' % len(unbundler.params))
452 msg.append(' %i params' % len(unbundler.params))
453 if op._gettransaction is None or op._gettransaction is _notransaction:
453 if op._gettransaction is None or op._gettransaction is _notransaction:
454 msg.append(' no-transaction')
454 msg.append(' no-transaction')
455 else:
455 else:
456 msg.append(' with-transaction')
456 msg.append(' with-transaction')
457 msg.append('\n')
457 msg.append('\n')
458 repo.ui.debug(''.join(msg))
458 repo.ui.debug(''.join(msg))
459
459
460 processparts(repo, op, unbundler)
460 processparts(repo, op, unbundler)
461
461
462 return op
462 return op
463
463
464 def processparts(repo, op, unbundler):
464 def processparts(repo, op, unbundler):
465 with partiterator(repo, op, unbundler) as parts:
465 with partiterator(repo, op, unbundler) as parts:
466 for part in parts:
466 for part in parts:
467 _processpart(op, part)
467 _processpart(op, part)
468
468
469 def _processchangegroup(op, cg, tr, source, url, **kwargs):
469 def _processchangegroup(op, cg, tr, source, url, **kwargs):
470 ret = cg.apply(op.repo, tr, source, url, **kwargs)
470 ret = cg.apply(op.repo, tr, source, url, **kwargs)
471 op.records.add('changegroup', {
471 op.records.add('changegroup', {
472 'return': ret,
472 'return': ret,
473 })
473 })
474 return ret
474 return ret
475
475
476 def _gethandler(op, part):
476 def _gethandler(op, part):
477 status = 'unknown' # used by debug output
477 status = 'unknown' # used by debug output
478 try:
478 try:
479 handler = parthandlermapping.get(part.type)
479 handler = parthandlermapping.get(part.type)
480 if handler is None:
480 if handler is None:
481 status = 'unsupported-type'
481 status = 'unsupported-type'
482 raise error.BundleUnknownFeatureError(parttype=part.type)
482 raise error.BundleUnknownFeatureError(parttype=part.type)
483 indebug(op.ui, 'found a handler for part %s' % part.type)
483 indebug(op.ui, 'found a handler for part %s' % part.type)
484 unknownparams = part.mandatorykeys - handler.params
484 unknownparams = part.mandatorykeys - handler.params
485 if unknownparams:
485 if unknownparams:
486 unknownparams = list(unknownparams)
486 unknownparams = list(unknownparams)
487 unknownparams.sort()
487 unknownparams.sort()
488 status = 'unsupported-params (%s)' % ', '.join(unknownparams)
488 status = 'unsupported-params (%s)' % ', '.join(unknownparams)
489 raise error.BundleUnknownFeatureError(parttype=part.type,
489 raise error.BundleUnknownFeatureError(parttype=part.type,
490 params=unknownparams)
490 params=unknownparams)
491 status = 'supported'
491 status = 'supported'
492 except error.BundleUnknownFeatureError as exc:
492 except error.BundleUnknownFeatureError as exc:
493 if part.mandatory: # mandatory parts
493 if part.mandatory: # mandatory parts
494 raise
494 raise
495 indebug(op.ui, 'ignoring unsupported advisory part %s' % exc)
495 indebug(op.ui, 'ignoring unsupported advisory part %s' % exc)
496 return # skip to part processing
496 return # skip to part processing
497 finally:
497 finally:
498 if op.ui.debugflag:
498 if op.ui.debugflag:
499 msg = ['bundle2-input-part: "%s"' % part.type]
499 msg = ['bundle2-input-part: "%s"' % part.type]
500 if not part.mandatory:
500 if not part.mandatory:
501 msg.append(' (advisory)')
501 msg.append(' (advisory)')
502 nbmp = len(part.mandatorykeys)
502 nbmp = len(part.mandatorykeys)
503 nbap = len(part.params) - nbmp
503 nbap = len(part.params) - nbmp
504 if nbmp or nbap:
504 if nbmp or nbap:
505 msg.append(' (params:')
505 msg.append(' (params:')
506 if nbmp:
506 if nbmp:
507 msg.append(' %i mandatory' % nbmp)
507 msg.append(' %i mandatory' % nbmp)
508 if nbap:
508 if nbap:
509 msg.append(' %i advisory' % nbmp)
509 msg.append(' %i advisory' % nbmp)
510 msg.append(')')
510 msg.append(')')
511 msg.append(' %s\n' % status)
511 msg.append(' %s\n' % status)
512 op.ui.debug(''.join(msg))
512 op.ui.debug(''.join(msg))
513
513
514 return handler
514 return handler
515
515
516 def _processpart(op, part):
516 def _processpart(op, part):
517 """process a single part from a bundle
517 """process a single part from a bundle
518
518
519 The part is guaranteed to have been fully consumed when the function exits
519 The part is guaranteed to have been fully consumed when the function exits
520 (even if an exception is raised)."""
520 (even if an exception is raised)."""
521 handler = _gethandler(op, part)
521 handler = _gethandler(op, part)
522 if handler is None:
522 if handler is None:
523 return
523 return
524
524
525 # handler is called outside the above try block so that we don't
525 # handler is called outside the above try block so that we don't
526 # risk catching KeyErrors from anything other than the
526 # risk catching KeyErrors from anything other than the
527 # parthandlermapping lookup (any KeyError raised by handler()
527 # parthandlermapping lookup (any KeyError raised by handler()
528 # itself represents a defect of a different variety).
528 # itself represents a defect of a different variety).
529 output = None
529 output = None
530 if op.captureoutput and op.reply is not None:
530 if op.captureoutput and op.reply is not None:
531 op.ui.pushbuffer(error=True, subproc=True)
531 op.ui.pushbuffer(error=True, subproc=True)
532 output = ''
532 output = ''
533 try:
533 try:
534 handler(op, part)
534 handler(op, part)
535 finally:
535 finally:
536 if output is not None:
536 if output is not None:
537 output = op.ui.popbuffer()
537 output = op.ui.popbuffer()
538 if output:
538 if output:
539 outpart = op.reply.newpart('output', data=output,
539 outpart = op.reply.newpart('output', data=output,
540 mandatory=False)
540 mandatory=False)
541 outpart.addparam(
541 outpart.addparam(
542 'in-reply-to', pycompat.bytestr(part.id), mandatory=False)
542 'in-reply-to', pycompat.bytestr(part.id), mandatory=False)
543
543
544 def decodecaps(blob):
544 def decodecaps(blob):
545 """decode a bundle2 caps bytes blob into a dictionary
545 """decode a bundle2 caps bytes blob into a dictionary
546
546
547 The blob is a list of capabilities (one per line)
547 The blob is a list of capabilities (one per line)
548 Capabilities may have values using a line of the form::
548 Capabilities may have values using a line of the form::
549
549
550 capability=value1,value2,value3
550 capability=value1,value2,value3
551
551
552 The values are always a list."""
552 The values are always a list."""
553 caps = {}
553 caps = {}
554 for line in blob.splitlines():
554 for line in blob.splitlines():
555 if not line:
555 if not line:
556 continue
556 continue
557 if '=' not in line:
557 if '=' not in line:
558 key, vals = line, ()
558 key, vals = line, ()
559 else:
559 else:
560 key, vals = line.split('=', 1)
560 key, vals = line.split('=', 1)
561 vals = vals.split(',')
561 vals = vals.split(',')
562 key = urlreq.unquote(key)
562 key = urlreq.unquote(key)
563 vals = [urlreq.unquote(v) for v in vals]
563 vals = [urlreq.unquote(v) for v in vals]
564 caps[key] = vals
564 caps[key] = vals
565 return caps
565 return caps
566
566
567 def encodecaps(caps):
567 def encodecaps(caps):
568 """encode a bundle2 caps dictionary into a bytes blob"""
568 """encode a bundle2 caps dictionary into a bytes blob"""
569 chunks = []
569 chunks = []
570 for ca in sorted(caps):
570 for ca in sorted(caps):
571 vals = caps[ca]
571 vals = caps[ca]
572 ca = urlreq.quote(ca)
572 ca = urlreq.quote(ca)
573 vals = [urlreq.quote(v) for v in vals]
573 vals = [urlreq.quote(v) for v in vals]
574 if vals:
574 if vals:
575 ca = "%s=%s" % (ca, ','.join(vals))
575 ca = "%s=%s" % (ca, ','.join(vals))
576 chunks.append(ca)
576 chunks.append(ca)
577 return '\n'.join(chunks)
577 return '\n'.join(chunks)
578
578
579 bundletypes = {
579 bundletypes = {
580 "": ("", 'UN'), # only when using unbundle on ssh and old http servers
580 "": ("", 'UN'), # only when using unbundle on ssh and old http servers
581 # since the unification ssh accepts a header but there
581 # since the unification ssh accepts a header but there
582 # is no capability signaling it.
582 # is no capability signaling it.
583 "HG20": (), # special-cased below
583 "HG20": (), # special-cased below
584 "HG10UN": ("HG10UN", 'UN'),
584 "HG10UN": ("HG10UN", 'UN'),
585 "HG10BZ": ("HG10", 'BZ'),
585 "HG10BZ": ("HG10", 'BZ'),
586 "HG10GZ": ("HG10GZ", 'GZ'),
586 "HG10GZ": ("HG10GZ", 'GZ'),
587 }
587 }
588
588
589 # hgweb uses this list to communicate its preferred type
589 # hgweb uses this list to communicate its preferred type
590 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
590 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
591
591
592 class bundle20(object):
592 class bundle20(object):
593 """represent an outgoing bundle2 container
593 """represent an outgoing bundle2 container
594
594
595 Use the `addparam` method to add stream level parameter. and `newpart` to
595 Use the `addparam` method to add stream level parameter. and `newpart` to
596 populate it. Then call `getchunks` to retrieve all the binary chunks of
596 populate it. Then call `getchunks` to retrieve all the binary chunks of
597 data that compose the bundle2 container."""
597 data that compose the bundle2 container."""
598
598
599 _magicstring = 'HG20'
599 _magicstring = 'HG20'
600
600
601 def __init__(self, ui, capabilities=()):
601 def __init__(self, ui, capabilities=()):
602 self.ui = ui
602 self.ui = ui
603 self._params = []
603 self._params = []
604 self._parts = []
604 self._parts = []
605 self.capabilities = dict(capabilities)
605 self.capabilities = dict(capabilities)
606 self._compengine = util.compengines.forbundletype('UN')
606 self._compengine = util.compengines.forbundletype('UN')
607 self._compopts = None
607 self._compopts = None
608 # If compression is being handled by a consumer of the raw
608 # If compression is being handled by a consumer of the raw
609 # data (e.g. the wire protocol), unsetting this flag tells
609 # data (e.g. the wire protocol), unsetting this flag tells
610 # consumers that the bundle is best left uncompressed.
610 # consumers that the bundle is best left uncompressed.
611 self.prefercompressed = True
611 self.prefercompressed = True
612
612
613 def setcompression(self, alg, compopts=None):
613 def setcompression(self, alg, compopts=None):
614 """setup core part compression to <alg>"""
614 """setup core part compression to <alg>"""
615 if alg in (None, 'UN'):
615 if alg in (None, 'UN'):
616 return
616 return
617 assert not any(n.lower() == 'compression' for n, v in self._params)
617 assert not any(n.lower() == 'compression' for n, v in self._params)
618 self.addparam('Compression', alg)
618 self.addparam('Compression', alg)
619 self._compengine = util.compengines.forbundletype(alg)
619 self._compengine = util.compengines.forbundletype(alg)
620 self._compopts = compopts
620 self._compopts = compopts
621
621
622 @property
622 @property
623 def nbparts(self):
623 def nbparts(self):
624 """total number of parts added to the bundler"""
624 """total number of parts added to the bundler"""
625 return len(self._parts)
625 return len(self._parts)
626
626
627 # methods used to defines the bundle2 content
627 # methods used to defines the bundle2 content
628 def addparam(self, name, value=None):
628 def addparam(self, name, value=None):
629 """add a stream level parameter"""
629 """add a stream level parameter"""
630 if not name:
630 if not name:
631 raise error.ProgrammingError(b'empty parameter name')
631 raise error.ProgrammingError(b'empty parameter name')
632 if name[0:1] not in pycompat.bytestr(string.ascii_letters):
632 if name[0:1] not in pycompat.bytestr(string.ascii_letters):
633 raise error.ProgrammingError(b'non letter first character: %s'
633 raise error.ProgrammingError(b'non letter first character: %s'
634 % name)
634 % name)
635 self._params.append((name, value))
635 self._params.append((name, value))
636
636
637 def addpart(self, part):
637 def addpart(self, part):
638 """add a new part to the bundle2 container
638 """add a new part to the bundle2 container
639
639
640 Parts contains the actual applicative payload."""
640 Parts contains the actual applicative payload."""
641 assert part.id is None
641 assert part.id is None
642 part.id = len(self._parts) # very cheap counter
642 part.id = len(self._parts) # very cheap counter
643 self._parts.append(part)
643 self._parts.append(part)
644
644
645 def newpart(self, typeid, *args, **kwargs):
645 def newpart(self, typeid, *args, **kwargs):
646 """create a new part and add it to the containers
646 """create a new part and add it to the containers
647
647
648 As the part is directly added to the containers. For now, this means
648 As the part is directly added to the containers. For now, this means
649 that any failure to properly initialize the part after calling
649 that any failure to properly initialize the part after calling
650 ``newpart`` should result in a failure of the whole bundling process.
650 ``newpart`` should result in a failure of the whole bundling process.
651
651
652 You can still fall back to manually create and add if you need better
652 You can still fall back to manually create and add if you need better
653 control."""
653 control."""
654 part = bundlepart(typeid, *args, **kwargs)
654 part = bundlepart(typeid, *args, **kwargs)
655 self.addpart(part)
655 self.addpart(part)
656 return part
656 return part
657
657
658 # methods used to generate the bundle2 stream
658 # methods used to generate the bundle2 stream
659 def getchunks(self):
659 def getchunks(self):
660 if self.ui.debugflag:
660 if self.ui.debugflag:
661 msg = ['bundle2-output-bundle: "%s",' % self._magicstring]
661 msg = ['bundle2-output-bundle: "%s",' % self._magicstring]
662 if self._params:
662 if self._params:
663 msg.append(' (%i params)' % len(self._params))
663 msg.append(' (%i params)' % len(self._params))
664 msg.append(' %i parts total\n' % len(self._parts))
664 msg.append(' %i parts total\n' % len(self._parts))
665 self.ui.debug(''.join(msg))
665 self.ui.debug(''.join(msg))
666 outdebug(self.ui, 'start emission of %s stream' % self._magicstring)
666 outdebug(self.ui, 'start emission of %s stream' % self._magicstring)
667 yield self._magicstring
667 yield self._magicstring
668 param = self._paramchunk()
668 param = self._paramchunk()
669 outdebug(self.ui, 'bundle parameter: %s' % param)
669 outdebug(self.ui, 'bundle parameter: %s' % param)
670 yield _pack(_fstreamparamsize, len(param))
670 yield _pack(_fstreamparamsize, len(param))
671 if param:
671 if param:
672 yield param
672 yield param
673 for chunk in self._compengine.compressstream(self._getcorechunk(),
673 for chunk in self._compengine.compressstream(self._getcorechunk(),
674 self._compopts):
674 self._compopts):
675 yield chunk
675 yield chunk
676
676
677 def _paramchunk(self):
677 def _paramchunk(self):
678 """return a encoded version of all stream parameters"""
678 """return a encoded version of all stream parameters"""
679 blocks = []
679 blocks = []
680 for par, value in self._params:
680 for par, value in self._params:
681 par = urlreq.quote(par)
681 par = urlreq.quote(par)
682 if value is not None:
682 if value is not None:
683 value = urlreq.quote(value)
683 value = urlreq.quote(value)
684 par = '%s=%s' % (par, value)
684 par = '%s=%s' % (par, value)
685 blocks.append(par)
685 blocks.append(par)
686 return ' '.join(blocks)
686 return ' '.join(blocks)
687
687
688 def _getcorechunk(self):
688 def _getcorechunk(self):
689 """yield chunk for the core part of the bundle
689 """yield chunk for the core part of the bundle
690
690
691 (all but headers and parameters)"""
691 (all but headers and parameters)"""
692 outdebug(self.ui, 'start of parts')
692 outdebug(self.ui, 'start of parts')
693 for part in self._parts:
693 for part in self._parts:
694 outdebug(self.ui, 'bundle part: "%s"' % part.type)
694 outdebug(self.ui, 'bundle part: "%s"' % part.type)
695 for chunk in part.getchunks(ui=self.ui):
695 for chunk in part.getchunks(ui=self.ui):
696 yield chunk
696 yield chunk
697 outdebug(self.ui, 'end of bundle')
697 outdebug(self.ui, 'end of bundle')
698 yield _pack(_fpartheadersize, 0)
698 yield _pack(_fpartheadersize, 0)
699
699
700
700
701 def salvageoutput(self):
701 def salvageoutput(self):
702 """return a list with a copy of all output parts in the bundle
702 """return a list with a copy of all output parts in the bundle
703
703
704 This is meant to be used during error handling to make sure we preserve
704 This is meant to be used during error handling to make sure we preserve
705 server output"""
705 server output"""
706 salvaged = []
706 salvaged = []
707 for part in self._parts:
707 for part in self._parts:
708 if part.type.startswith('output'):
708 if part.type.startswith('output'):
709 salvaged.append(part.copy())
709 salvaged.append(part.copy())
710 return salvaged
710 return salvaged
711
711
712
712
713 class unpackermixin(object):
713 class unpackermixin(object):
714 """A mixin to extract bytes and struct data from a stream"""
714 """A mixin to extract bytes and struct data from a stream"""
715
715
716 def __init__(self, fp):
716 def __init__(self, fp):
717 self._fp = fp
717 self._fp = fp
718
718
719 def _unpack(self, format):
719 def _unpack(self, format):
720 """unpack this struct format from the stream
720 """unpack this struct format from the stream
721
721
722 This method is meant for internal usage by the bundle2 protocol only.
722 This method is meant for internal usage by the bundle2 protocol only.
723 They directly manipulate the low level stream including bundle2 level
723 They directly manipulate the low level stream including bundle2 level
724 instruction.
724 instruction.
725
725
726 Do not use it to implement higher-level logic or methods."""
726 Do not use it to implement higher-level logic or methods."""
727 data = self._readexact(struct.calcsize(format))
727 data = self._readexact(struct.calcsize(format))
728 return _unpack(format, data)
728 return _unpack(format, data)
729
729
730 def _readexact(self, size):
730 def _readexact(self, size):
731 """read exactly <size> bytes from the stream
731 """read exactly <size> bytes from the stream
732
732
733 This method is meant for internal usage by the bundle2 protocol only.
733 This method is meant for internal usage by the bundle2 protocol only.
734 They directly manipulate the low level stream including bundle2 level
734 They directly manipulate the low level stream including bundle2 level
735 instruction.
735 instruction.
736
736
737 Do not use it to implement higher-level logic or methods."""
737 Do not use it to implement higher-level logic or methods."""
738 return changegroup.readexactly(self._fp, size)
738 return changegroup.readexactly(self._fp, size)
739
739
740 def getunbundler(ui, fp, magicstring=None):
740 def getunbundler(ui, fp, magicstring=None):
741 """return a valid unbundler object for a given magicstring"""
741 """return a valid unbundler object for a given magicstring"""
742 if magicstring is None:
742 if magicstring is None:
743 magicstring = changegroup.readexactly(fp, 4)
743 magicstring = changegroup.readexactly(fp, 4)
744 magic, version = magicstring[0:2], magicstring[2:4]
744 magic, version = magicstring[0:2], magicstring[2:4]
745 if magic != 'HG':
745 if magic != 'HG':
746 ui.debug(
746 ui.debug(
747 "error: invalid magic: %r (version %r), should be 'HG'\n"
747 "error: invalid magic: %r (version %r), should be 'HG'\n"
748 % (magic, version))
748 % (magic, version))
749 raise error.Abort(_('not a Mercurial bundle'))
749 raise error.Abort(_('not a Mercurial bundle'))
750 unbundlerclass = formatmap.get(version)
750 unbundlerclass = formatmap.get(version)
751 if unbundlerclass is None:
751 if unbundlerclass is None:
752 raise error.Abort(_('unknown bundle version %s') % version)
752 raise error.Abort(_('unknown bundle version %s') % version)
753 unbundler = unbundlerclass(ui, fp)
753 unbundler = unbundlerclass(ui, fp)
754 indebug(ui, 'start processing of %s stream' % magicstring)
754 indebug(ui, 'start processing of %s stream' % magicstring)
755 return unbundler
755 return unbundler
756
756
757 class unbundle20(unpackermixin):
757 class unbundle20(unpackermixin):
758 """interpret a bundle2 stream
758 """interpret a bundle2 stream
759
759
760 This class is fed with a binary stream and yields parts through its
760 This class is fed with a binary stream and yields parts through its
761 `iterparts` methods."""
761 `iterparts` methods."""
762
762
763 _magicstring = 'HG20'
763 _magicstring = 'HG20'
764
764
765 def __init__(self, ui, fp):
765 def __init__(self, ui, fp):
766 """If header is specified, we do not read it out of the stream."""
766 """If header is specified, we do not read it out of the stream."""
767 self.ui = ui
767 self.ui = ui
768 self._compengine = util.compengines.forbundletype('UN')
768 self._compengine = util.compengines.forbundletype('UN')
769 self._compressed = None
769 self._compressed = None
770 super(unbundle20, self).__init__(fp)
770 super(unbundle20, self).__init__(fp)
771
771
772 @util.propertycache
772 @util.propertycache
773 def params(self):
773 def params(self):
774 """dictionary of stream level parameters"""
774 """dictionary of stream level parameters"""
775 indebug(self.ui, 'reading bundle2 stream parameters')
775 indebug(self.ui, 'reading bundle2 stream parameters')
776 params = {}
776 params = {}
777 paramssize = self._unpack(_fstreamparamsize)[0]
777 paramssize = self._unpack(_fstreamparamsize)[0]
778 if paramssize < 0:
778 if paramssize < 0:
779 raise error.BundleValueError('negative bundle param size: %i'
779 raise error.BundleValueError('negative bundle param size: %i'
780 % paramssize)
780 % paramssize)
781 if paramssize:
781 if paramssize:
782 params = self._readexact(paramssize)
782 params = self._readexact(paramssize)
783 params = self._processallparams(params)
783 params = self._processallparams(params)
784 return params
784 return params
785
785
786 def _processallparams(self, paramsblock):
786 def _processallparams(self, paramsblock):
787 """"""
787 """"""
788 params = util.sortdict()
788 params = util.sortdict()
789 for p in paramsblock.split(' '):
789 for p in paramsblock.split(' '):
790 p = p.split('=', 1)
790 p = p.split('=', 1)
791 p = [urlreq.unquote(i) for i in p]
791 p = [urlreq.unquote(i) for i in p]
792 if len(p) < 2:
792 if len(p) < 2:
793 p.append(None)
793 p.append(None)
794 self._processparam(*p)
794 self._processparam(*p)
795 params[p[0]] = p[1]
795 params[p[0]] = p[1]
796 return params
796 return params
797
797
798
798
799 def _processparam(self, name, value):
799 def _processparam(self, name, value):
800 """process a parameter, applying its effect if needed
800 """process a parameter, applying its effect if needed
801
801
802 Parameter starting with a lower case letter are advisory and will be
802 Parameter starting with a lower case letter are advisory and will be
803 ignored when unknown. Those starting with an upper case letter are
803 ignored when unknown. Those starting with an upper case letter are
804 mandatory and will this function will raise a KeyError when unknown.
804 mandatory and will this function will raise a KeyError when unknown.
805
805
806 Note: no option are currently supported. Any input will be either
806 Note: no option are currently supported. Any input will be either
807 ignored or failing.
807 ignored or failing.
808 """
808 """
809 if not name:
809 if not name:
810 raise ValueError(r'empty parameter name')
810 raise ValueError(r'empty parameter name')
811 if name[0:1] not in pycompat.bytestr(string.ascii_letters):
811 if name[0:1] not in pycompat.bytestr(string.ascii_letters):
812 raise ValueError(r'non letter first character: %s' % name)
812 raise ValueError(r'non letter first character: %s' % name)
813 try:
813 try:
814 handler = b2streamparamsmap[name.lower()]
814 handler = b2streamparamsmap[name.lower()]
815 except KeyError:
815 except KeyError:
816 if name[0:1].islower():
816 if name[0:1].islower():
817 indebug(self.ui, "ignoring unknown parameter %s" % name)
817 indebug(self.ui, "ignoring unknown parameter %s" % name)
818 else:
818 else:
819 raise error.BundleUnknownFeatureError(params=(name,))
819 raise error.BundleUnknownFeatureError(params=(name,))
820 else:
820 else:
821 handler(self, name, value)
821 handler(self, name, value)
822
822
823 def _forwardchunks(self):
823 def _forwardchunks(self):
824 """utility to transfer a bundle2 as binary
824 """utility to transfer a bundle2 as binary
825
825
826 This is made necessary by the fact the 'getbundle' command over 'ssh'
826 This is made necessary by the fact the 'getbundle' command over 'ssh'
827 have no way to know then the reply end, relying on the bundle to be
827 have no way to know then the reply end, relying on the bundle to be
828 interpreted to know its end. This is terrible and we are sorry, but we
828 interpreted to know its end. This is terrible and we are sorry, but we
829 needed to move forward to get general delta enabled.
829 needed to move forward to get general delta enabled.
830 """
830 """
831 yield self._magicstring
831 yield self._magicstring
832 assert 'params' not in vars(self)
832 assert 'params' not in vars(self)
833 paramssize = self._unpack(_fstreamparamsize)[0]
833 paramssize = self._unpack(_fstreamparamsize)[0]
834 if paramssize < 0:
834 if paramssize < 0:
835 raise error.BundleValueError('negative bundle param size: %i'
835 raise error.BundleValueError('negative bundle param size: %i'
836 % paramssize)
836 % paramssize)
837 yield _pack(_fstreamparamsize, paramssize)
837 yield _pack(_fstreamparamsize, paramssize)
838 if paramssize:
838 if paramssize:
839 params = self._readexact(paramssize)
839 params = self._readexact(paramssize)
840 self._processallparams(params)
840 self._processallparams(params)
841 yield params
841 yield params
842 assert self._compengine.bundletype == 'UN'
842 assert self._compengine.bundletype == 'UN'
843 # From there, payload might need to be decompressed
843 # From there, payload might need to be decompressed
844 self._fp = self._compengine.decompressorreader(self._fp)
844 self._fp = self._compengine.decompressorreader(self._fp)
845 emptycount = 0
845 emptycount = 0
846 while emptycount < 2:
846 while emptycount < 2:
847 # so we can brainlessly loop
847 # so we can brainlessly loop
848 assert _fpartheadersize == _fpayloadsize
848 assert _fpartheadersize == _fpayloadsize
849 size = self._unpack(_fpartheadersize)[0]
849 size = self._unpack(_fpartheadersize)[0]
850 yield _pack(_fpartheadersize, size)
850 yield _pack(_fpartheadersize, size)
851 if size:
851 if size:
852 emptycount = 0
852 emptycount = 0
853 else:
853 else:
854 emptycount += 1
854 emptycount += 1
855 continue
855 continue
856 if size == flaginterrupt:
856 if size == flaginterrupt:
857 continue
857 continue
858 elif size < 0:
858 elif size < 0:
859 raise error.BundleValueError('negative chunk size: %i')
859 raise error.BundleValueError('negative chunk size: %i')
860 yield self._readexact(size)
860 yield self._readexact(size)
861
861
862
862
863 def iterparts(self, seekable=False):
863 def iterparts(self, seekable=False):
864 """yield all parts contained in the stream"""
864 """yield all parts contained in the stream"""
865 cls = seekableunbundlepart if seekable else unbundlepart
865 cls = seekableunbundlepart if seekable else unbundlepart
866 # make sure param have been loaded
866 # make sure param have been loaded
867 self.params
867 self.params
868 # From there, payload need to be decompressed
868 # From there, payload need to be decompressed
869 self._fp = self._compengine.decompressorreader(self._fp)
869 self._fp = self._compengine.decompressorreader(self._fp)
870 indebug(self.ui, 'start extraction of bundle2 parts')
870 indebug(self.ui, 'start extraction of bundle2 parts')
871 headerblock = self._readpartheader()
871 headerblock = self._readpartheader()
872 while headerblock is not None:
872 while headerblock is not None:
873 part = cls(self.ui, headerblock, self._fp)
873 part = cls(self.ui, headerblock, self._fp)
874 yield part
874 yield part
875 # Ensure part is fully consumed so we can start reading the next
875 # Ensure part is fully consumed so we can start reading the next
876 # part.
876 # part.
877 part.consume()
877 part.consume()
878
878
879 headerblock = self._readpartheader()
879 headerblock = self._readpartheader()
880 indebug(self.ui, 'end of bundle2 stream')
880 indebug(self.ui, 'end of bundle2 stream')
881
881
882 def _readpartheader(self):
882 def _readpartheader(self):
883 """reads a part header size and return the bytes blob
883 """reads a part header size and return the bytes blob
884
884
885 returns None if empty"""
885 returns None if empty"""
886 headersize = self._unpack(_fpartheadersize)[0]
886 headersize = self._unpack(_fpartheadersize)[0]
887 if headersize < 0:
887 if headersize < 0:
888 raise error.BundleValueError('negative part header size: %i'
888 raise error.BundleValueError('negative part header size: %i'
889 % headersize)
889 % headersize)
890 indebug(self.ui, 'part header size: %i' % headersize)
890 indebug(self.ui, 'part header size: %i' % headersize)
891 if headersize:
891 if headersize:
892 return self._readexact(headersize)
892 return self._readexact(headersize)
893 return None
893 return None
894
894
895 def compressed(self):
895 def compressed(self):
896 self.params # load params
896 self.params # load params
897 return self._compressed
897 return self._compressed
898
898
899 def close(self):
899 def close(self):
900 """close underlying file"""
900 """close underlying file"""
901 if util.safehasattr(self._fp, 'close'):
901 if util.safehasattr(self._fp, 'close'):
902 return self._fp.close()
902 return self._fp.close()
903
903
904 formatmap = {'20': unbundle20}
904 formatmap = {'20': unbundle20}
905
905
906 b2streamparamsmap = {}
906 b2streamparamsmap = {}
907
907
908 def b2streamparamhandler(name):
908 def b2streamparamhandler(name):
909 """register a handler for a stream level parameter"""
909 """register a handler for a stream level parameter"""
910 def decorator(func):
910 def decorator(func):
911 assert name not in formatmap
911 assert name not in formatmap
912 b2streamparamsmap[name] = func
912 b2streamparamsmap[name] = func
913 return func
913 return func
914 return decorator
914 return decorator
915
915
916 @b2streamparamhandler('compression')
916 @b2streamparamhandler('compression')
917 def processcompression(unbundler, param, value):
917 def processcompression(unbundler, param, value):
918 """read compression parameter and install payload decompression"""
918 """read compression parameter and install payload decompression"""
919 if value not in util.compengines.supportedbundletypes:
919 if value not in util.compengines.supportedbundletypes:
920 raise error.BundleUnknownFeatureError(params=(param,),
920 raise error.BundleUnknownFeatureError(params=(param,),
921 values=(value,))
921 values=(value,))
922 unbundler._compengine = util.compengines.forbundletype(value)
922 unbundler._compengine = util.compengines.forbundletype(value)
923 if value is not None:
923 if value is not None:
924 unbundler._compressed = True
924 unbundler._compressed = True
925
925
926 class bundlepart(object):
926 class bundlepart(object):
927 """A bundle2 part contains application level payload
927 """A bundle2 part contains application level payload
928
928
929 The part `type` is used to route the part to the application level
929 The part `type` is used to route the part to the application level
930 handler.
930 handler.
931
931
932 The part payload is contained in ``part.data``. It could be raw bytes or a
932 The part payload is contained in ``part.data``. It could be raw bytes or a
933 generator of byte chunks.
933 generator of byte chunks.
934
934
935 You can add parameters to the part using the ``addparam`` method.
935 You can add parameters to the part using the ``addparam`` method.
936 Parameters can be either mandatory (default) or advisory. Remote side
936 Parameters can be either mandatory (default) or advisory. Remote side
937 should be able to safely ignore the advisory ones.
937 should be able to safely ignore the advisory ones.
938
938
939 Both data and parameters cannot be modified after the generation has begun.
939 Both data and parameters cannot be modified after the generation has begun.
940 """
940 """
941
941
942 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
942 def __init__(self, parttype, mandatoryparams=(), advisoryparams=(),
943 data='', mandatory=True):
943 data='', mandatory=True):
944 validateparttype(parttype)
944 validateparttype(parttype)
945 self.id = None
945 self.id = None
946 self.type = parttype
946 self.type = parttype
947 self._data = data
947 self._data = data
948 self._mandatoryparams = list(mandatoryparams)
948 self._mandatoryparams = list(mandatoryparams)
949 self._advisoryparams = list(advisoryparams)
949 self._advisoryparams = list(advisoryparams)
950 # checking for duplicated entries
950 # checking for duplicated entries
951 self._seenparams = set()
951 self._seenparams = set()
952 for pname, __ in self._mandatoryparams + self._advisoryparams:
952 for pname, __ in self._mandatoryparams + self._advisoryparams:
953 if pname in self._seenparams:
953 if pname in self._seenparams:
954 raise error.ProgrammingError('duplicated params: %s' % pname)
954 raise error.ProgrammingError('duplicated params: %s' % pname)
955 self._seenparams.add(pname)
955 self._seenparams.add(pname)
956 # status of the part's generation:
956 # status of the part's generation:
957 # - None: not started,
957 # - None: not started,
958 # - False: currently generated,
958 # - False: currently generated,
959 # - True: generation done.
959 # - True: generation done.
960 self._generated = None
960 self._generated = None
961 self.mandatory = mandatory
961 self.mandatory = mandatory
962
962
963 def __repr__(self):
963 def __repr__(self):
964 cls = "%s.%s" % (self.__class__.__module__, self.__class__.__name__)
964 cls = "%s.%s" % (self.__class__.__module__, self.__class__.__name__)
965 return ('<%s object at %x; id: %s; type: %s; mandatory: %s>'
965 return ('<%s object at %x; id: %s; type: %s; mandatory: %s>'
966 % (cls, id(self), self.id, self.type, self.mandatory))
966 % (cls, id(self), self.id, self.type, self.mandatory))
967
967
968 def copy(self):
968 def copy(self):
969 """return a copy of the part
969 """return a copy of the part
970
970
971 The new part have the very same content but no partid assigned yet.
971 The new part have the very same content but no partid assigned yet.
972 Parts with generated data cannot be copied."""
972 Parts with generated data cannot be copied."""
973 assert not util.safehasattr(self.data, 'next')
973 assert not util.safehasattr(self.data, 'next')
974 return self.__class__(self.type, self._mandatoryparams,
974 return self.__class__(self.type, self._mandatoryparams,
975 self._advisoryparams, self._data, self.mandatory)
975 self._advisoryparams, self._data, self.mandatory)
976
976
977 # methods used to defines the part content
977 # methods used to defines the part content
978 @property
978 @property
979 def data(self):
979 def data(self):
980 return self._data
980 return self._data
981
981
982 @data.setter
982 @data.setter
983 def data(self, data):
983 def data(self, data):
984 if self._generated is not None:
984 if self._generated is not None:
985 raise error.ReadOnlyPartError('part is being generated')
985 raise error.ReadOnlyPartError('part is being generated')
986 self._data = data
986 self._data = data
987
987
988 @property
988 @property
989 def mandatoryparams(self):
989 def mandatoryparams(self):
990 # make it an immutable tuple to force people through ``addparam``
990 # make it an immutable tuple to force people through ``addparam``
991 return tuple(self._mandatoryparams)
991 return tuple(self._mandatoryparams)
992
992
993 @property
993 @property
994 def advisoryparams(self):
994 def advisoryparams(self):
995 # make it an immutable tuple to force people through ``addparam``
995 # make it an immutable tuple to force people through ``addparam``
996 return tuple(self._advisoryparams)
996 return tuple(self._advisoryparams)
997
997
998 def addparam(self, name, value='', mandatory=True):
998 def addparam(self, name, value='', mandatory=True):
999 """add a parameter to the part
999 """add a parameter to the part
1000
1000
1001 If 'mandatory' is set to True, the remote handler must claim support
1001 If 'mandatory' is set to True, the remote handler must claim support
1002 for this parameter or the unbundling will be aborted.
1002 for this parameter or the unbundling will be aborted.
1003
1003
1004 The 'name' and 'value' cannot exceed 255 bytes each.
1004 The 'name' and 'value' cannot exceed 255 bytes each.
1005 """
1005 """
1006 if self._generated is not None:
1006 if self._generated is not None:
1007 raise error.ReadOnlyPartError('part is being generated')
1007 raise error.ReadOnlyPartError('part is being generated')
1008 if name in self._seenparams:
1008 if name in self._seenparams:
1009 raise ValueError('duplicated params: %s' % name)
1009 raise ValueError('duplicated params: %s' % name)
1010 self._seenparams.add(name)
1010 self._seenparams.add(name)
1011 params = self._advisoryparams
1011 params = self._advisoryparams
1012 if mandatory:
1012 if mandatory:
1013 params = self._mandatoryparams
1013 params = self._mandatoryparams
1014 params.append((name, value))
1014 params.append((name, value))
1015
1015
1016 # methods used to generates the bundle2 stream
1016 # methods used to generates the bundle2 stream
1017 def getchunks(self, ui):
1017 def getchunks(self, ui):
1018 if self._generated is not None:
1018 if self._generated is not None:
1019 raise error.ProgrammingError('part can only be consumed once')
1019 raise error.ProgrammingError('part can only be consumed once')
1020 self._generated = False
1020 self._generated = False
1021
1021
1022 if ui.debugflag:
1022 if ui.debugflag:
1023 msg = ['bundle2-output-part: "%s"' % self.type]
1023 msg = ['bundle2-output-part: "%s"' % self.type]
1024 if not self.mandatory:
1024 if not self.mandatory:
1025 msg.append(' (advisory)')
1025 msg.append(' (advisory)')
1026 nbmp = len(self.mandatoryparams)
1026 nbmp = len(self.mandatoryparams)
1027 nbap = len(self.advisoryparams)
1027 nbap = len(self.advisoryparams)
1028 if nbmp or nbap:
1028 if nbmp or nbap:
1029 msg.append(' (params:')
1029 msg.append(' (params:')
1030 if nbmp:
1030 if nbmp:
1031 msg.append(' %i mandatory' % nbmp)
1031 msg.append(' %i mandatory' % nbmp)
1032 if nbap:
1032 if nbap:
1033 msg.append(' %i advisory' % nbmp)
1033 msg.append(' %i advisory' % nbmp)
1034 msg.append(')')
1034 msg.append(')')
1035 if not self.data:
1035 if not self.data:
1036 msg.append(' empty payload')
1036 msg.append(' empty payload')
1037 elif (util.safehasattr(self.data, 'next')
1037 elif (util.safehasattr(self.data, 'next')
1038 or util.safehasattr(self.data, '__next__')):
1038 or util.safehasattr(self.data, '__next__')):
1039 msg.append(' streamed payload')
1039 msg.append(' streamed payload')
1040 else:
1040 else:
1041 msg.append(' %i bytes payload' % len(self.data))
1041 msg.append(' %i bytes payload' % len(self.data))
1042 msg.append('\n')
1042 msg.append('\n')
1043 ui.debug(''.join(msg))
1043 ui.debug(''.join(msg))
1044
1044
1045 #### header
1045 #### header
1046 if self.mandatory:
1046 if self.mandatory:
1047 parttype = self.type.upper()
1047 parttype = self.type.upper()
1048 else:
1048 else:
1049 parttype = self.type.lower()
1049 parttype = self.type.lower()
1050 outdebug(ui, 'part %s: "%s"' % (pycompat.bytestr(self.id), parttype))
1050 outdebug(ui, 'part %s: "%s"' % (pycompat.bytestr(self.id), parttype))
1051 ## parttype
1051 ## parttype
1052 header = [_pack(_fparttypesize, len(parttype)),
1052 header = [_pack(_fparttypesize, len(parttype)),
1053 parttype, _pack(_fpartid, self.id),
1053 parttype, _pack(_fpartid, self.id),
1054 ]
1054 ]
1055 ## parameters
1055 ## parameters
1056 # count
1056 # count
1057 manpar = self.mandatoryparams
1057 manpar = self.mandatoryparams
1058 advpar = self.advisoryparams
1058 advpar = self.advisoryparams
1059 header.append(_pack(_fpartparamcount, len(manpar), len(advpar)))
1059 header.append(_pack(_fpartparamcount, len(manpar), len(advpar)))
1060 # size
1060 # size
1061 parsizes = []
1061 parsizes = []
1062 for key, value in manpar:
1062 for key, value in manpar:
1063 parsizes.append(len(key))
1063 parsizes.append(len(key))
1064 parsizes.append(len(value))
1064 parsizes.append(len(value))
1065 for key, value in advpar:
1065 for key, value in advpar:
1066 parsizes.append(len(key))
1066 parsizes.append(len(key))
1067 parsizes.append(len(value))
1067 parsizes.append(len(value))
1068 paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes)
1068 paramsizes = _pack(_makefpartparamsizes(len(parsizes) // 2), *parsizes)
1069 header.append(paramsizes)
1069 header.append(paramsizes)
1070 # key, value
1070 # key, value
1071 for key, value in manpar:
1071 for key, value in manpar:
1072 header.append(key)
1072 header.append(key)
1073 header.append(value)
1073 header.append(value)
1074 for key, value in advpar:
1074 for key, value in advpar:
1075 header.append(key)
1075 header.append(key)
1076 header.append(value)
1076 header.append(value)
1077 ## finalize header
1077 ## finalize header
1078 try:
1078 try:
1079 headerchunk = ''.join(header)
1079 headerchunk = ''.join(header)
1080 except TypeError:
1080 except TypeError:
1081 raise TypeError(r'Found a non-bytes trying to '
1081 raise TypeError(r'Found a non-bytes trying to '
1082 r'build bundle part header: %r' % header)
1082 r'build bundle part header: %r' % header)
1083 outdebug(ui, 'header chunk size: %i' % len(headerchunk))
1083 outdebug(ui, 'header chunk size: %i' % len(headerchunk))
1084 yield _pack(_fpartheadersize, len(headerchunk))
1084 yield _pack(_fpartheadersize, len(headerchunk))
1085 yield headerchunk
1085 yield headerchunk
1086 ## payload
1086 ## payload
1087 try:
1087 try:
1088 for chunk in self._payloadchunks():
1088 for chunk in self._payloadchunks():
1089 outdebug(ui, 'payload chunk size: %i' % len(chunk))
1089 outdebug(ui, 'payload chunk size: %i' % len(chunk))
1090 yield _pack(_fpayloadsize, len(chunk))
1090 yield _pack(_fpayloadsize, len(chunk))
1091 yield chunk
1091 yield chunk
1092 except GeneratorExit:
1092 except GeneratorExit:
1093 # GeneratorExit means that nobody is listening for our
1093 # GeneratorExit means that nobody is listening for our
1094 # results anyway, so just bail quickly rather than trying
1094 # results anyway, so just bail quickly rather than trying
1095 # to produce an error part.
1095 # to produce an error part.
1096 ui.debug('bundle2-generatorexit\n')
1096 ui.debug('bundle2-generatorexit\n')
1097 raise
1097 raise
1098 except BaseException as exc:
1098 except BaseException as exc:
1099 bexc = stringutil.forcebytestr(exc)
1099 bexc = stringutil.forcebytestr(exc)
1100 # backup exception data for later
1100 # backup exception data for later
1101 ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
1101 ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
1102 % bexc)
1102 % bexc)
1103 tb = sys.exc_info()[2]
1103 tb = sys.exc_info()[2]
1104 msg = 'unexpected error: %s' % bexc
1104 msg = 'unexpected error: %s' % bexc
1105 interpart = bundlepart('error:abort', [('message', msg)],
1105 interpart = bundlepart('error:abort', [('message', msg)],
1106 mandatory=False)
1106 mandatory=False)
1107 interpart.id = 0
1107 interpart.id = 0
1108 yield _pack(_fpayloadsize, -1)
1108 yield _pack(_fpayloadsize, -1)
1109 for chunk in interpart.getchunks(ui=ui):
1109 for chunk in interpart.getchunks(ui=ui):
1110 yield chunk
1110 yield chunk
1111 outdebug(ui, 'closing payload chunk')
1111 outdebug(ui, 'closing payload chunk')
1112 # abort current part payload
1112 # abort current part payload
1113 yield _pack(_fpayloadsize, 0)
1113 yield _pack(_fpayloadsize, 0)
1114 pycompat.raisewithtb(exc, tb)
1114 pycompat.raisewithtb(exc, tb)
1115 # end of payload
1115 # end of payload
1116 outdebug(ui, 'closing payload chunk')
1116 outdebug(ui, 'closing payload chunk')
1117 yield _pack(_fpayloadsize, 0)
1117 yield _pack(_fpayloadsize, 0)
1118 self._generated = True
1118 self._generated = True
1119
1119
1120 def _payloadchunks(self):
1120 def _payloadchunks(self):
1121 """yield chunks of a the part payload
1121 """yield chunks of a the part payload
1122
1122
1123 Exists to handle the different methods to provide data to a part."""
1123 Exists to handle the different methods to provide data to a part."""
1124 # we only support fixed size data now.
1124 # we only support fixed size data now.
1125 # This will be improved in the future.
1125 # This will be improved in the future.
1126 if (util.safehasattr(self.data, 'next')
1126 if (util.safehasattr(self.data, 'next')
1127 or util.safehasattr(self.data, '__next__')):
1127 or util.safehasattr(self.data, '__next__')):
1128 buff = util.chunkbuffer(self.data)
1128 buff = util.chunkbuffer(self.data)
1129 chunk = buff.read(preferedchunksize)
1129 chunk = buff.read(preferedchunksize)
1130 while chunk:
1130 while chunk:
1131 yield chunk
1131 yield chunk
1132 chunk = buff.read(preferedchunksize)
1132 chunk = buff.read(preferedchunksize)
1133 elif len(self.data):
1133 elif len(self.data):
1134 yield self.data
1134 yield self.data
1135
1135
1136
1136
1137 flaginterrupt = -1
1137 flaginterrupt = -1
1138
1138
1139 class interrupthandler(unpackermixin):
1139 class interrupthandler(unpackermixin):
1140 """read one part and process it with restricted capability
1140 """read one part and process it with restricted capability
1141
1141
1142 This allows to transmit exception raised on the producer size during part
1142 This allows to transmit exception raised on the producer size during part
1143 iteration while the consumer is reading a part.
1143 iteration while the consumer is reading a part.
1144
1144
1145 Part processed in this manner only have access to a ui object,"""
1145 Part processed in this manner only have access to a ui object,"""
1146
1146
1147 def __init__(self, ui, fp):
1147 def __init__(self, ui, fp):
1148 super(interrupthandler, self).__init__(fp)
1148 super(interrupthandler, self).__init__(fp)
1149 self.ui = ui
1149 self.ui = ui
1150
1150
1151 def _readpartheader(self):
1151 def _readpartheader(self):
1152 """reads a part header size and return the bytes blob
1152 """reads a part header size and return the bytes blob
1153
1153
1154 returns None if empty"""
1154 returns None if empty"""
1155 headersize = self._unpack(_fpartheadersize)[0]
1155 headersize = self._unpack(_fpartheadersize)[0]
1156 if headersize < 0:
1156 if headersize < 0:
1157 raise error.BundleValueError('negative part header size: %i'
1157 raise error.BundleValueError('negative part header size: %i'
1158 % headersize)
1158 % headersize)
1159 indebug(self.ui, 'part header size: %i\n' % headersize)
1159 indebug(self.ui, 'part header size: %i\n' % headersize)
1160 if headersize:
1160 if headersize:
1161 return self._readexact(headersize)
1161 return self._readexact(headersize)
1162 return None
1162 return None
1163
1163
1164 def __call__(self):
1164 def __call__(self):
1165
1165
1166 self.ui.debug('bundle2-input-stream-interrupt:'
1166 self.ui.debug('bundle2-input-stream-interrupt:'
1167 ' opening out of band context\n')
1167 ' opening out of band context\n')
1168 indebug(self.ui, 'bundle2 stream interruption, looking for a part.')
1168 indebug(self.ui, 'bundle2 stream interruption, looking for a part.')
1169 headerblock = self._readpartheader()
1169 headerblock = self._readpartheader()
1170 if headerblock is None:
1170 if headerblock is None:
1171 indebug(self.ui, 'no part found during interruption.')
1171 indebug(self.ui, 'no part found during interruption.')
1172 return
1172 return
1173 part = unbundlepart(self.ui, headerblock, self._fp)
1173 part = unbundlepart(self.ui, headerblock, self._fp)
1174 op = interruptoperation(self.ui)
1174 op = interruptoperation(self.ui)
1175 hardabort = False
1175 hardabort = False
1176 try:
1176 try:
1177 _processpart(op, part)
1177 _processpart(op, part)
1178 except (SystemExit, KeyboardInterrupt):
1178 except (SystemExit, KeyboardInterrupt):
1179 hardabort = True
1179 hardabort = True
1180 raise
1180 raise
1181 finally:
1181 finally:
1182 if not hardabort:
1182 if not hardabort:
1183 part.consume()
1183 part.consume()
1184 self.ui.debug('bundle2-input-stream-interrupt:'
1184 self.ui.debug('bundle2-input-stream-interrupt:'
1185 ' closing out of band context\n')
1185 ' closing out of band context\n')
1186
1186
1187 class interruptoperation(object):
1187 class interruptoperation(object):
1188 """A limited operation to be use by part handler during interruption
1188 """A limited operation to be use by part handler during interruption
1189
1189
1190 It only have access to an ui object.
1190 It only have access to an ui object.
1191 """
1191 """
1192
1192
1193 def __init__(self, ui):
1193 def __init__(self, ui):
1194 self.ui = ui
1194 self.ui = ui
1195 self.reply = None
1195 self.reply = None
1196 self.captureoutput = False
1196 self.captureoutput = False
1197
1197
1198 @property
1198 @property
1199 def repo(self):
1199 def repo(self):
1200 raise error.ProgrammingError('no repo access from stream interruption')
1200 raise error.ProgrammingError('no repo access from stream interruption')
1201
1201
1202 def gettransaction(self):
1202 def gettransaction(self):
1203 raise TransactionUnavailable('no repo access from stream interruption')
1203 raise TransactionUnavailable('no repo access from stream interruption')
1204
1204
1205 def decodepayloadchunks(ui, fh):
1205 def decodepayloadchunks(ui, fh):
1206 """Reads bundle2 part payload data into chunks.
1206 """Reads bundle2 part payload data into chunks.
1207
1207
1208 Part payload data consists of framed chunks. This function takes
1208 Part payload data consists of framed chunks. This function takes
1209 a file handle and emits those chunks.
1209 a file handle and emits those chunks.
1210 """
1210 """
1211 dolog = ui.configbool('devel', 'bundle2.debug')
1211 dolog = ui.configbool('devel', 'bundle2.debug')
1212 debug = ui.debug
1212 debug = ui.debug
1213
1213
1214 headerstruct = struct.Struct(_fpayloadsize)
1214 headerstruct = struct.Struct(_fpayloadsize)
1215 headersize = headerstruct.size
1215 headersize = headerstruct.size
1216 unpack = headerstruct.unpack
1216 unpack = headerstruct.unpack
1217
1217
1218 readexactly = changegroup.readexactly
1218 readexactly = changegroup.readexactly
1219 read = fh.read
1219 read = fh.read
1220
1220
1221 chunksize = unpack(readexactly(fh, headersize))[0]
1221 chunksize = unpack(readexactly(fh, headersize))[0]
1222 indebug(ui, 'payload chunk size: %i' % chunksize)
1222 indebug(ui, 'payload chunk size: %i' % chunksize)
1223
1223
1224 # changegroup.readexactly() is inlined below for performance.
1224 # changegroup.readexactly() is inlined below for performance.
1225 while chunksize:
1225 while chunksize:
1226 if chunksize >= 0:
1226 if chunksize >= 0:
1227 s = read(chunksize)
1227 s = read(chunksize)
1228 if len(s) < chunksize:
1228 if len(s) < chunksize:
1229 raise error.Abort(_('stream ended unexpectedly '
1229 raise error.Abort(_('stream ended unexpectedly '
1230 ' (got %d bytes, expected %d)') %
1230 ' (got %d bytes, expected %d)') %
1231 (len(s), chunksize))
1231 (len(s), chunksize))
1232
1232
1233 yield s
1233 yield s
1234 elif chunksize == flaginterrupt:
1234 elif chunksize == flaginterrupt:
1235 # Interrupt "signal" detected. The regular stream is interrupted
1235 # Interrupt "signal" detected. The regular stream is interrupted
1236 # and a bundle2 part follows. Consume it.
1236 # and a bundle2 part follows. Consume it.
1237 interrupthandler(ui, fh)()
1237 interrupthandler(ui, fh)()
1238 else:
1238 else:
1239 raise error.BundleValueError(
1239 raise error.BundleValueError(
1240 'negative payload chunk size: %s' % chunksize)
1240 'negative payload chunk size: %s' % chunksize)
1241
1241
1242 s = read(headersize)
1242 s = read(headersize)
1243 if len(s) < headersize:
1243 if len(s) < headersize:
1244 raise error.Abort(_('stream ended unexpectedly '
1244 raise error.Abort(_('stream ended unexpectedly '
1245 ' (got %d bytes, expected %d)') %
1245 ' (got %d bytes, expected %d)') %
1246 (len(s), chunksize))
1246 (len(s), chunksize))
1247
1247
1248 chunksize = unpack(s)[0]
1248 chunksize = unpack(s)[0]
1249
1249
1250 # indebug() inlined for performance.
1250 # indebug() inlined for performance.
1251 if dolog:
1251 if dolog:
1252 debug('bundle2-input: payload chunk size: %i\n' % chunksize)
1252 debug('bundle2-input: payload chunk size: %i\n' % chunksize)
1253
1253
1254 class unbundlepart(unpackermixin):
1254 class unbundlepart(unpackermixin):
1255 """a bundle part read from a bundle"""
1255 """a bundle part read from a bundle"""
1256
1256
1257 def __init__(self, ui, header, fp):
1257 def __init__(self, ui, header, fp):
1258 super(unbundlepart, self).__init__(fp)
1258 super(unbundlepart, self).__init__(fp)
1259 self._seekable = (util.safehasattr(fp, 'seek') and
1259 self._seekable = (util.safehasattr(fp, 'seek') and
1260 util.safehasattr(fp, 'tell'))
1260 util.safehasattr(fp, 'tell'))
1261 self.ui = ui
1261 self.ui = ui
1262 # unbundle state attr
1262 # unbundle state attr
1263 self._headerdata = header
1263 self._headerdata = header
1264 self._headeroffset = 0
1264 self._headeroffset = 0
1265 self._initialized = False
1265 self._initialized = False
1266 self.consumed = False
1266 self.consumed = False
1267 # part data
1267 # part data
1268 self.id = None
1268 self.id = None
1269 self.type = None
1269 self.type = None
1270 self.mandatoryparams = None
1270 self.mandatoryparams = None
1271 self.advisoryparams = None
1271 self.advisoryparams = None
1272 self.params = None
1272 self.params = None
1273 self.mandatorykeys = ()
1273 self.mandatorykeys = ()
1274 self._readheader()
1274 self._readheader()
1275 self._mandatory = None
1275 self._mandatory = None
1276 self._pos = 0
1276 self._pos = 0
1277
1277
1278 def _fromheader(self, size):
1278 def _fromheader(self, size):
1279 """return the next <size> byte from the header"""
1279 """return the next <size> byte from the header"""
1280 offset = self._headeroffset
1280 offset = self._headeroffset
1281 data = self._headerdata[offset:(offset + size)]
1281 data = self._headerdata[offset:(offset + size)]
1282 self._headeroffset = offset + size
1282 self._headeroffset = offset + size
1283 return data
1283 return data
1284
1284
1285 def _unpackheader(self, format):
1285 def _unpackheader(self, format):
1286 """read given format from header
1286 """read given format from header
1287
1287
1288 This automatically compute the size of the format to read."""
1288 This automatically compute the size of the format to read."""
1289 data = self._fromheader(struct.calcsize(format))
1289 data = self._fromheader(struct.calcsize(format))
1290 return _unpack(format, data)
1290 return _unpack(format, data)
1291
1291
1292 def _initparams(self, mandatoryparams, advisoryparams):
1292 def _initparams(self, mandatoryparams, advisoryparams):
1293 """internal function to setup all logic related parameters"""
1293 """internal function to setup all logic related parameters"""
1294 # make it read only to prevent people touching it by mistake.
1294 # make it read only to prevent people touching it by mistake.
1295 self.mandatoryparams = tuple(mandatoryparams)
1295 self.mandatoryparams = tuple(mandatoryparams)
1296 self.advisoryparams = tuple(advisoryparams)
1296 self.advisoryparams = tuple(advisoryparams)
1297 # user friendly UI
1297 # user friendly UI
1298 self.params = util.sortdict(self.mandatoryparams)
1298 self.params = util.sortdict(self.mandatoryparams)
1299 self.params.update(self.advisoryparams)
1299 self.params.update(self.advisoryparams)
1300 self.mandatorykeys = frozenset(p[0] for p in mandatoryparams)
1300 self.mandatorykeys = frozenset(p[0] for p in mandatoryparams)
1301
1301
1302 def _readheader(self):
1302 def _readheader(self):
1303 """read the header and setup the object"""
1303 """read the header and setup the object"""
1304 typesize = self._unpackheader(_fparttypesize)[0]
1304 typesize = self._unpackheader(_fparttypesize)[0]
1305 self.type = self._fromheader(typesize)
1305 self.type = self._fromheader(typesize)
1306 indebug(self.ui, 'part type: "%s"' % self.type)
1306 indebug(self.ui, 'part type: "%s"' % self.type)
1307 self.id = self._unpackheader(_fpartid)[0]
1307 self.id = self._unpackheader(_fpartid)[0]
1308 indebug(self.ui, 'part id: "%s"' % pycompat.bytestr(self.id))
1308 indebug(self.ui, 'part id: "%s"' % pycompat.bytestr(self.id))
1309 # extract mandatory bit from type
1309 # extract mandatory bit from type
1310 self.mandatory = (self.type != self.type.lower())
1310 self.mandatory = (self.type != self.type.lower())
1311 self.type = self.type.lower()
1311 self.type = self.type.lower()
1312 ## reading parameters
1312 ## reading parameters
1313 # param count
1313 # param count
1314 mancount, advcount = self._unpackheader(_fpartparamcount)
1314 mancount, advcount = self._unpackheader(_fpartparamcount)
1315 indebug(self.ui, 'part parameters: %i' % (mancount + advcount))
1315 indebug(self.ui, 'part parameters: %i' % (mancount + advcount))
1316 # param size
1316 # param size
1317 fparamsizes = _makefpartparamsizes(mancount + advcount)
1317 fparamsizes = _makefpartparamsizes(mancount + advcount)
1318 paramsizes = self._unpackheader(fparamsizes)
1318 paramsizes = self._unpackheader(fparamsizes)
1319 # make it a list of couple again
1319 # make it a list of couple again
1320 paramsizes = list(zip(paramsizes[::2], paramsizes[1::2]))
1320 paramsizes = list(zip(paramsizes[::2], paramsizes[1::2]))
1321 # split mandatory from advisory
1321 # split mandatory from advisory
1322 mansizes = paramsizes[:mancount]
1322 mansizes = paramsizes[:mancount]
1323 advsizes = paramsizes[mancount:]
1323 advsizes = paramsizes[mancount:]
1324 # retrieve param value
1324 # retrieve param value
1325 manparams = []
1325 manparams = []
1326 for key, value in mansizes:
1326 for key, value in mansizes:
1327 manparams.append((self._fromheader(key), self._fromheader(value)))
1327 manparams.append((self._fromheader(key), self._fromheader(value)))
1328 advparams = []
1328 advparams = []
1329 for key, value in advsizes:
1329 for key, value in advsizes:
1330 advparams.append((self._fromheader(key), self._fromheader(value)))
1330 advparams.append((self._fromheader(key), self._fromheader(value)))
1331 self._initparams(manparams, advparams)
1331 self._initparams(manparams, advparams)
1332 ## part payload
1332 ## part payload
1333 self._payloadstream = util.chunkbuffer(self._payloadchunks())
1333 self._payloadstream = util.chunkbuffer(self._payloadchunks())
1334 # we read the data, tell it
1334 # we read the data, tell it
1335 self._initialized = True
1335 self._initialized = True
1336
1336
1337 def _payloadchunks(self):
1337 def _payloadchunks(self):
1338 """Generator of decoded chunks in the payload."""
1338 """Generator of decoded chunks in the payload."""
1339 return decodepayloadchunks(self.ui, self._fp)
1339 return decodepayloadchunks(self.ui, self._fp)
1340
1340
1341 def consume(self):
1341 def consume(self):
1342 """Read the part payload until completion.
1342 """Read the part payload until completion.
1343
1343
1344 By consuming the part data, the underlying stream read offset will
1344 By consuming the part data, the underlying stream read offset will
1345 be advanced to the next part (or end of stream).
1345 be advanced to the next part (or end of stream).
1346 """
1346 """
1347 if self.consumed:
1347 if self.consumed:
1348 return
1348 return
1349
1349
1350 chunk = self.read(32768)
1350 chunk = self.read(32768)
1351 while chunk:
1351 while chunk:
1352 self._pos += len(chunk)
1352 self._pos += len(chunk)
1353 chunk = self.read(32768)
1353 chunk = self.read(32768)
1354
1354
1355 def read(self, size=None):
1355 def read(self, size=None):
1356 """read payload data"""
1356 """read payload data"""
1357 if not self._initialized:
1357 if not self._initialized:
1358 self._readheader()
1358 self._readheader()
1359 if size is None:
1359 if size is None:
1360 data = self._payloadstream.read()
1360 data = self._payloadstream.read()
1361 else:
1361 else:
1362 data = self._payloadstream.read(size)
1362 data = self._payloadstream.read(size)
1363 self._pos += len(data)
1363 self._pos += len(data)
1364 if size is None or len(data) < size:
1364 if size is None or len(data) < size:
1365 if not self.consumed and self._pos:
1365 if not self.consumed and self._pos:
1366 self.ui.debug('bundle2-input-part: total payload size %i\n'
1366 self.ui.debug('bundle2-input-part: total payload size %i\n'
1367 % self._pos)
1367 % self._pos)
1368 self.consumed = True
1368 self.consumed = True
1369 return data
1369 return data
1370
1370
1371 class seekableunbundlepart(unbundlepart):
1371 class seekableunbundlepart(unbundlepart):
1372 """A bundle2 part in a bundle that is seekable.
1372 """A bundle2 part in a bundle that is seekable.
1373
1373
1374 Regular ``unbundlepart`` instances can only be read once. This class
1374 Regular ``unbundlepart`` instances can only be read once. This class
1375 extends ``unbundlepart`` to enable bi-directional seeking within the
1375 extends ``unbundlepart`` to enable bi-directional seeking within the
1376 part.
1376 part.
1377
1377
1378 Bundle2 part data consists of framed chunks. Offsets when seeking
1378 Bundle2 part data consists of framed chunks. Offsets when seeking
1379 refer to the decoded data, not the offsets in the underlying bundle2
1379 refer to the decoded data, not the offsets in the underlying bundle2
1380 stream.
1380 stream.
1381
1381
1382 To facilitate quickly seeking within the decoded data, instances of this
1382 To facilitate quickly seeking within the decoded data, instances of this
1383 class maintain a mapping between offsets in the underlying stream and
1383 class maintain a mapping between offsets in the underlying stream and
1384 the decoded payload. This mapping will consume memory in proportion
1384 the decoded payload. This mapping will consume memory in proportion
1385 to the number of chunks within the payload (which almost certainly
1385 to the number of chunks within the payload (which almost certainly
1386 increases in proportion with the size of the part).
1386 increases in proportion with the size of the part).
1387 """
1387 """
1388 def __init__(self, ui, header, fp):
1388 def __init__(self, ui, header, fp):
1389 # (payload, file) offsets for chunk starts.
1389 # (payload, file) offsets for chunk starts.
1390 self._chunkindex = []
1390 self._chunkindex = []
1391
1391
1392 super(seekableunbundlepart, self).__init__(ui, header, fp)
1392 super(seekableunbundlepart, self).__init__(ui, header, fp)
1393
1393
1394 def _payloadchunks(self, chunknum=0):
1394 def _payloadchunks(self, chunknum=0):
1395 '''seek to specified chunk and start yielding data'''
1395 '''seek to specified chunk and start yielding data'''
1396 if len(self._chunkindex) == 0:
1396 if len(self._chunkindex) == 0:
1397 assert chunknum == 0, 'Must start with chunk 0'
1397 assert chunknum == 0, 'Must start with chunk 0'
1398 self._chunkindex.append((0, self._tellfp()))
1398 self._chunkindex.append((0, self._tellfp()))
1399 else:
1399 else:
1400 assert chunknum < len(self._chunkindex), \
1400 assert chunknum < len(self._chunkindex), \
1401 'Unknown chunk %d' % chunknum
1401 'Unknown chunk %d' % chunknum
1402 self._seekfp(self._chunkindex[chunknum][1])
1402 self._seekfp(self._chunkindex[chunknum][1])
1403
1403
1404 pos = self._chunkindex[chunknum][0]
1404 pos = self._chunkindex[chunknum][0]
1405
1405
1406 for chunk in decodepayloadchunks(self.ui, self._fp):
1406 for chunk in decodepayloadchunks(self.ui, self._fp):
1407 chunknum += 1
1407 chunknum += 1
1408 pos += len(chunk)
1408 pos += len(chunk)
1409 if chunknum == len(self._chunkindex):
1409 if chunknum == len(self._chunkindex):
1410 self._chunkindex.append((pos, self._tellfp()))
1410 self._chunkindex.append((pos, self._tellfp()))
1411
1411
1412 yield chunk
1412 yield chunk
1413
1413
1414 def _findchunk(self, pos):
1414 def _findchunk(self, pos):
1415 '''for a given payload position, return a chunk number and offset'''
1415 '''for a given payload position, return a chunk number and offset'''
1416 for chunk, (ppos, fpos) in enumerate(self._chunkindex):
1416 for chunk, (ppos, fpos) in enumerate(self._chunkindex):
1417 if ppos == pos:
1417 if ppos == pos:
1418 return chunk, 0
1418 return chunk, 0
1419 elif ppos > pos:
1419 elif ppos > pos:
1420 return chunk - 1, pos - self._chunkindex[chunk - 1][0]
1420 return chunk - 1, pos - self._chunkindex[chunk - 1][0]
1421 raise ValueError('Unknown chunk')
1421 raise ValueError('Unknown chunk')
1422
1422
1423 def tell(self):
1423 def tell(self):
1424 return self._pos
1424 return self._pos
1425
1425
1426 def seek(self, offset, whence=os.SEEK_SET):
1426 def seek(self, offset, whence=os.SEEK_SET):
1427 if whence == os.SEEK_SET:
1427 if whence == os.SEEK_SET:
1428 newpos = offset
1428 newpos = offset
1429 elif whence == os.SEEK_CUR:
1429 elif whence == os.SEEK_CUR:
1430 newpos = self._pos + offset
1430 newpos = self._pos + offset
1431 elif whence == os.SEEK_END:
1431 elif whence == os.SEEK_END:
1432 if not self.consumed:
1432 if not self.consumed:
1433 # Can't use self.consume() here because it advances self._pos.
1433 # Can't use self.consume() here because it advances self._pos.
1434 chunk = self.read(32768)
1434 chunk = self.read(32768)
1435 while chunk:
1435 while chunk:
1436 chunk = self.read(32768)
1436 chunk = self.read(32768)
1437 newpos = self._chunkindex[-1][0] - offset
1437 newpos = self._chunkindex[-1][0] - offset
1438 else:
1438 else:
1439 raise ValueError('Unknown whence value: %r' % (whence,))
1439 raise ValueError('Unknown whence value: %r' % (whence,))
1440
1440
1441 if newpos > self._chunkindex[-1][0] and not self.consumed:
1441 if newpos > self._chunkindex[-1][0] and not self.consumed:
1442 # Can't use self.consume() here because it advances self._pos.
1442 # Can't use self.consume() here because it advances self._pos.
1443 chunk = self.read(32768)
1443 chunk = self.read(32768)
1444 while chunk:
1444 while chunk:
1445 chunk = self.read(32668)
1445 chunk = self.read(32668)
1446
1446
1447 if not 0 <= newpos <= self._chunkindex[-1][0]:
1447 if not 0 <= newpos <= self._chunkindex[-1][0]:
1448 raise ValueError('Offset out of range')
1448 raise ValueError('Offset out of range')
1449
1449
1450 if self._pos != newpos:
1450 if self._pos != newpos:
1451 chunk, internaloffset = self._findchunk(newpos)
1451 chunk, internaloffset = self._findchunk(newpos)
1452 self._payloadstream = util.chunkbuffer(self._payloadchunks(chunk))
1452 self._payloadstream = util.chunkbuffer(self._payloadchunks(chunk))
1453 adjust = self.read(internaloffset)
1453 adjust = self.read(internaloffset)
1454 if len(adjust) != internaloffset:
1454 if len(adjust) != internaloffset:
1455 raise error.Abort(_('Seek failed\n'))
1455 raise error.Abort(_('Seek failed\n'))
1456 self._pos = newpos
1456 self._pos = newpos
1457
1457
1458 def _seekfp(self, offset, whence=0):
1458 def _seekfp(self, offset, whence=0):
1459 """move the underlying file pointer
1459 """move the underlying file pointer
1460
1460
1461 This method is meant for internal usage by the bundle2 protocol only.
1461 This method is meant for internal usage by the bundle2 protocol only.
1462 They directly manipulate the low level stream including bundle2 level
1462 They directly manipulate the low level stream including bundle2 level
1463 instruction.
1463 instruction.
1464
1464
1465 Do not use it to implement higher-level logic or methods."""
1465 Do not use it to implement higher-level logic or methods."""
1466 if self._seekable:
1466 if self._seekable:
1467 return self._fp.seek(offset, whence)
1467 return self._fp.seek(offset, whence)
1468 else:
1468 else:
1469 raise NotImplementedError(_('File pointer is not seekable'))
1469 raise NotImplementedError(_('File pointer is not seekable'))
1470
1470
1471 def _tellfp(self):
1471 def _tellfp(self):
1472 """return the file offset, or None if file is not seekable
1472 """return the file offset, or None if file is not seekable
1473
1473
1474 This method is meant for internal usage by the bundle2 protocol only.
1474 This method is meant for internal usage by the bundle2 protocol only.
1475 They directly manipulate the low level stream including bundle2 level
1475 They directly manipulate the low level stream including bundle2 level
1476 instruction.
1476 instruction.
1477
1477
1478 Do not use it to implement higher-level logic or methods."""
1478 Do not use it to implement higher-level logic or methods."""
1479 if self._seekable:
1479 if self._seekable:
1480 try:
1480 try:
1481 return self._fp.tell()
1481 return self._fp.tell()
1482 except IOError as e:
1482 except IOError as e:
1483 if e.errno == errno.ESPIPE:
1483 if e.errno == errno.ESPIPE:
1484 self._seekable = False
1484 self._seekable = False
1485 else:
1485 else:
1486 raise
1486 raise
1487 return None
1487 return None
1488
1488
1489 # These are only the static capabilities.
1489 # These are only the static capabilities.
1490 # Check the 'getrepocaps' function for the rest.
1490 # Check the 'getrepocaps' function for the rest.
1491 capabilities = {'HG20': (),
1491 capabilities = {'HG20': (),
1492 'bookmarks': (),
1492 'bookmarks': (),
1493 'error': ('abort', 'unsupportedcontent', 'pushraced',
1493 'error': ('abort', 'unsupportedcontent', 'pushraced',
1494 'pushkey'),
1494 'pushkey'),
1495 'listkeys': (),
1495 'listkeys': (),
1496 'pushkey': (),
1496 'pushkey': (),
1497 'digests': tuple(sorted(util.DIGESTS.keys())),
1497 'digests': tuple(sorted(util.DIGESTS.keys())),
1498 'remote-changegroup': ('http', 'https'),
1498 'remote-changegroup': ('http', 'https'),
1499 'hgtagsfnodes': (),
1499 'hgtagsfnodes': (),
1500 'rev-branch-cache': (),
1500 'rev-branch-cache': (),
1501 'phases': ('heads',),
1501 'phases': ('heads',),
1502 'stream': ('v2',),
1502 'stream': ('v2',),
1503 }
1503 }
1504
1504
1505 def getrepocaps(repo, allowpushback=False, role=None):
1505 def getrepocaps(repo, allowpushback=False, role=None):
1506 """return the bundle2 capabilities for a given repo
1506 """return the bundle2 capabilities for a given repo
1507
1507
1508 Exists to allow extensions (like evolution) to mutate the capabilities.
1508 Exists to allow extensions (like evolution) to mutate the capabilities.
1509
1509
1510 The returned value is used for servers advertising their capabilities as
1510 The returned value is used for servers advertising their capabilities as
1511 well as clients advertising their capabilities to servers as part of
1511 well as clients advertising their capabilities to servers as part of
1512 bundle2 requests. The ``role`` argument specifies which is which.
1512 bundle2 requests. The ``role`` argument specifies which is which.
1513 """
1513 """
1514 if role not in ('client', 'server'):
1514 if role not in ('client', 'server'):
1515 raise error.ProgrammingError('role argument must be client or server')
1515 raise error.ProgrammingError('role argument must be client or server')
1516
1516
1517 caps = capabilities.copy()
1517 caps = capabilities.copy()
1518 caps['changegroup'] = tuple(sorted(
1518 caps['changegroup'] = tuple(sorted(
1519 changegroup.supportedincomingversions(repo)))
1519 changegroup.supportedincomingversions(repo)))
1520 if obsolete.isenabled(repo, obsolete.exchangeopt):
1520 if obsolete.isenabled(repo, obsolete.exchangeopt):
1521 supportedformat = tuple('V%i' % v for v in obsolete.formats)
1521 supportedformat = tuple('V%i' % v for v in obsolete.formats)
1522 caps['obsmarkers'] = supportedformat
1522 caps['obsmarkers'] = supportedformat
1523 if allowpushback:
1523 if allowpushback:
1524 caps['pushback'] = ()
1524 caps['pushback'] = ()
1525 cpmode = repo.ui.config('server', 'concurrent-push-mode')
1525 cpmode = repo.ui.config('server', 'concurrent-push-mode')
1526 if cpmode == 'check-related':
1526 if cpmode == 'check-related':
1527 caps['checkheads'] = ('related',)
1527 caps['checkheads'] = ('related',)
1528 if 'phases' in repo.ui.configlist('devel', 'legacy.exchange'):
1528 if 'phases' in repo.ui.configlist('devel', 'legacy.exchange'):
1529 caps.pop('phases')
1529 caps.pop('phases')
1530
1530
1531 # Don't advertise stream clone support in server mode if not configured.
1531 # Don't advertise stream clone support in server mode if not configured.
1532 if role == 'server':
1532 if role == 'server':
1533 streamsupported = repo.ui.configbool('server', 'uncompressed',
1533 streamsupported = repo.ui.configbool('server', 'uncompressed',
1534 untrusted=True)
1534 untrusted=True)
1535 featuresupported = repo.ui.configbool('experimental', 'bundle2.stream')
1535 featuresupported = repo.ui.configbool('experimental', 'bundle2.stream')
1536
1536
1537 if not streamsupported or not featuresupported:
1537 if not streamsupported or not featuresupported:
1538 caps.pop('stream')
1538 caps.pop('stream')
1539 # Else always advertise support on client, because payload support
1539 # Else always advertise support on client, because payload support
1540 # should always be advertised.
1540 # should always be advertised.
1541
1541
1542 return caps
1542 return caps
1543
1543
1544 def bundle2caps(remote):
1544 def bundle2caps(remote):
1545 """return the bundle capabilities of a peer as dict"""
1545 """return the bundle capabilities of a peer as dict"""
1546 raw = remote.capable('bundle2')
1546 raw = remote.capable('bundle2')
1547 if not raw and raw != '':
1547 if not raw and raw != '':
1548 return {}
1548 return {}
1549 capsblob = urlreq.unquote(remote.capable('bundle2'))
1549 capsblob = urlreq.unquote(remote.capable('bundle2'))
1550 return decodecaps(capsblob)
1550 return decodecaps(capsblob)
1551
1551
1552 def obsmarkersversion(caps):
1552 def obsmarkersversion(caps):
1553 """extract the list of supported obsmarkers versions from a bundle2caps dict
1553 """extract the list of supported obsmarkers versions from a bundle2caps dict
1554 """
1554 """
1555 obscaps = caps.get('obsmarkers', ())
1555 obscaps = caps.get('obsmarkers', ())
1556 return [int(c[1:]) for c in obscaps if c.startswith('V')]
1556 return [int(c[1:]) for c in obscaps if c.startswith('V')]
1557
1557
1558 def writenewbundle(ui, repo, source, filename, bundletype, outgoing, opts,
1558 def writenewbundle(ui, repo, source, filename, bundletype, outgoing, opts,
1559 vfs=None, compression=None, compopts=None):
1559 vfs=None, compression=None, compopts=None):
1560 if bundletype.startswith('HG10'):
1560 if bundletype.startswith('HG10'):
1561 cg = changegroup.makechangegroup(repo, outgoing, '01', source)
1561 cg = changegroup.makechangegroup(repo, outgoing, '01', source)
1562 return writebundle(ui, cg, filename, bundletype, vfs=vfs,
1562 return writebundle(ui, cg, filename, bundletype, vfs=vfs,
1563 compression=compression, compopts=compopts)
1563 compression=compression, compopts=compopts)
1564 elif not bundletype.startswith('HG20'):
1564 elif not bundletype.startswith('HG20'):
1565 raise error.ProgrammingError('unknown bundle type: %s' % bundletype)
1565 raise error.ProgrammingError('unknown bundle type: %s' % bundletype)
1566
1566
1567 caps = {}
1567 caps = {}
1568 if 'obsolescence' in opts:
1568 if 'obsolescence' in opts:
1569 caps['obsmarkers'] = ('V1',)
1569 caps['obsmarkers'] = ('V1',)
1570 bundle = bundle20(ui, caps)
1570 bundle = bundle20(ui, caps)
1571 bundle.setcompression(compression, compopts)
1571 bundle.setcompression(compression, compopts)
1572 _addpartsfromopts(ui, repo, bundle, source, outgoing, opts)
1572 _addpartsfromopts(ui, repo, bundle, source, outgoing, opts)
1573 chunkiter = bundle.getchunks()
1573 chunkiter = bundle.getchunks()
1574
1574
1575 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs)
1575 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs)
1576
1576
1577 def _addpartsfromopts(ui, repo, bundler, source, outgoing, opts):
1577 def _addpartsfromopts(ui, repo, bundler, source, outgoing, opts):
1578 # We should eventually reconcile this logic with the one behind
1578 # We should eventually reconcile this logic with the one behind
1579 # 'exchange.getbundle2partsgenerator'.
1579 # 'exchange.getbundle2partsgenerator'.
1580 #
1580 #
1581 # The type of input from 'getbundle' and 'writenewbundle' are a bit
1581 # The type of input from 'getbundle' and 'writenewbundle' are a bit
1582 # different right now. So we keep them separated for now for the sake of
1582 # different right now. So we keep them separated for now for the sake of
1583 # simplicity.
1583 # simplicity.
1584
1584
1585 # we might not always want a changegroup in such bundle, for example in
1585 # we might not always want a changegroup in such bundle, for example in
1586 # stream bundles
1586 # stream bundles
1587 if opts.get('changegroup', True):
1587 if opts.get('changegroup', True):
1588 cgversion = opts.get('cg.version')
1588 cgversion = opts.get('cg.version')
1589 if cgversion is None:
1589 if cgversion is None:
1590 cgversion = changegroup.safeversion(repo)
1590 cgversion = changegroup.safeversion(repo)
1591 cg = changegroup.makechangegroup(repo, outgoing, cgversion, source)
1591 cg = changegroup.makechangegroup(repo, outgoing, cgversion, source)
1592 part = bundler.newpart('changegroup', data=cg.getchunks())
1592 part = bundler.newpart('changegroup', data=cg.getchunks())
1593 part.addparam('version', cg.version)
1593 part.addparam('version', cg.version)
1594 if 'clcount' in cg.extras:
1594 if 'clcount' in cg.extras:
1595 part.addparam('nbchanges', '%d' % cg.extras['clcount'],
1595 part.addparam('nbchanges', '%d' % cg.extras['clcount'],
1596 mandatory=False)
1596 mandatory=False)
1597 if opts.get('phases') and repo.revs('%ln and secret()',
1597 if opts.get('phases') and repo.revs('%ln and secret()',
1598 outgoing.missingheads):
1598 outgoing.missingheads):
1599 part.addparam('targetphase', '%d' % phases.secret, mandatory=False)
1599 part.addparam('targetphase', '%d' % phases.secret, mandatory=False)
1600
1600
1601 if opts.get('streamv2', False):
1601 if opts.get('streamv2', False):
1602 addpartbundlestream2(bundler, repo, stream=True)
1602 addpartbundlestream2(bundler, repo, stream=True)
1603
1603
1604 if opts.get('tagsfnodescache', True):
1604 if opts.get('tagsfnodescache', True):
1605 addparttagsfnodescache(repo, bundler, outgoing)
1605 addparttagsfnodescache(repo, bundler, outgoing)
1606
1606
1607 if opts.get('revbranchcache', True):
1607 if opts.get('revbranchcache', True):
1608 addpartrevbranchcache(repo, bundler, outgoing)
1608 addpartrevbranchcache(repo, bundler, outgoing)
1609
1609
1610 if opts.get('obsolescence', False):
1610 if opts.get('obsolescence', False):
1611 obsmarkers = repo.obsstore.relevantmarkers(outgoing.missing)
1611 obsmarkers = repo.obsstore.relevantmarkers(outgoing.missing)
1612 buildobsmarkerspart(bundler, obsmarkers)
1612 buildobsmarkerspart(bundler, obsmarkers)
1613
1613
1614 if opts.get('phases', False):
1614 if opts.get('phases', False):
1615 headsbyphase = phases.subsetphaseheads(repo, outgoing.missing)
1615 headsbyphase = phases.subsetphaseheads(repo, outgoing.missing)
1616 phasedata = phases.binaryencode(headsbyphase)
1616 phasedata = phases.binaryencode(headsbyphase)
1617 bundler.newpart('phase-heads', data=phasedata)
1617 bundler.newpart('phase-heads', data=phasedata)
1618
1618
1619 def addparttagsfnodescache(repo, bundler, outgoing):
1619 def addparttagsfnodescache(repo, bundler, outgoing):
1620 # we include the tags fnode cache for the bundle changeset
1620 # we include the tags fnode cache for the bundle changeset
1621 # (as an optional parts)
1621 # (as an optional parts)
1622 cache = tags.hgtagsfnodescache(repo.unfiltered())
1622 cache = tags.hgtagsfnodescache(repo.unfiltered())
1623 chunks = []
1623 chunks = []
1624
1624
1625 # .hgtags fnodes are only relevant for head changesets. While we could
1625 # .hgtags fnodes are only relevant for head changesets. While we could
1626 # transfer values for all known nodes, there will likely be little to
1626 # transfer values for all known nodes, there will likely be little to
1627 # no benefit.
1627 # no benefit.
1628 #
1628 #
1629 # We don't bother using a generator to produce output data because
1629 # We don't bother using a generator to produce output data because
1630 # a) we only have 40 bytes per head and even esoteric numbers of heads
1630 # a) we only have 40 bytes per head and even esoteric numbers of heads
1631 # consume little memory (1M heads is 40MB) b) we don't want to send the
1631 # consume little memory (1M heads is 40MB) b) we don't want to send the
1632 # part if we don't have entries and knowing if we have entries requires
1632 # part if we don't have entries and knowing if we have entries requires
1633 # cache lookups.
1633 # cache lookups.
1634 for node in outgoing.missingheads:
1634 for node in outgoing.missingheads:
1635 # Don't compute missing, as this may slow down serving.
1635 # Don't compute missing, as this may slow down serving.
1636 fnode = cache.getfnode(node, computemissing=False)
1636 fnode = cache.getfnode(node, computemissing=False)
1637 if fnode is not None:
1637 if fnode is not None:
1638 chunks.extend([node, fnode])
1638 chunks.extend([node, fnode])
1639
1639
1640 if chunks:
1640 if chunks:
1641 bundler.newpart('hgtagsfnodes', data=''.join(chunks))
1641 bundler.newpart('hgtagsfnodes', data=''.join(chunks))
1642
1642
1643 def addpartrevbranchcache(repo, bundler, outgoing):
1643 def addpartrevbranchcache(repo, bundler, outgoing):
1644 # we include the rev branch cache for the bundle changeset
1644 # we include the rev branch cache for the bundle changeset
1645 # (as an optional parts)
1645 # (as an optional parts)
1646 cache = repo.revbranchcache()
1646 cache = repo.revbranchcache()
1647 cl = repo.unfiltered().changelog
1647 cl = repo.unfiltered().changelog
1648 branchesdata = collections.defaultdict(lambda: (set(), set()))
1648 branchesdata = collections.defaultdict(lambda: (set(), set()))
1649 for node in outgoing.missing:
1649 for node in outgoing.missing:
1650 branch, close = cache.branchinfo(cl.rev(node))
1650 branch, close = cache.branchinfo(cl.rev(node))
1651 branchesdata[branch][close].add(node)
1651 branchesdata[branch][close].add(node)
1652
1652
1653 def generate():
1653 def generate():
1654 for branch, (nodes, closed) in sorted(branchesdata.items()):
1654 for branch, (nodes, closed) in sorted(branchesdata.items()):
1655 utf8branch = encoding.fromlocal(branch)
1655 utf8branch = encoding.fromlocal(branch)
1656 yield rbcstruct.pack(len(utf8branch), len(nodes), len(closed))
1656 yield rbcstruct.pack(len(utf8branch), len(nodes), len(closed))
1657 yield utf8branch
1657 yield utf8branch
1658 for n in sorted(nodes):
1658 for n in sorted(nodes):
1659 yield n
1659 yield n
1660 for n in sorted(closed):
1660 for n in sorted(closed):
1661 yield n
1661 yield n
1662
1662
1663 bundler.newpart('cache:rev-branch-cache', data=generate(),
1663 bundler.newpart('cache:rev-branch-cache', data=generate(),
1664 mandatory=False)
1664 mandatory=False)
1665
1665
1666 def _formatrequirementsspec(requirements):
1666 def _formatrequirementsspec(requirements):
1667 return urlreq.quote(','.join(sorted(requirements)))
1667 return urlreq.quote(','.join(sorted(requirements)))
1668
1668
1669 def _formatrequirementsparams(requirements):
1669 def _formatrequirementsparams(requirements):
1670 requirements = _formatrequirementsspec(requirements)
1670 requirements = _formatrequirementsspec(requirements)
1671 params = "%s%s" % (urlreq.quote("requirements="), requirements)
1671 params = "%s%s" % (urlreq.quote("requirements="), requirements)
1672 return params
1672 return params
1673
1673
1674 def addpartbundlestream2(bundler, repo, **kwargs):
1674 def addpartbundlestream2(bundler, repo, **kwargs):
1675 if not kwargs.get('stream', False):
1675 if not kwargs.get('stream', False):
1676 return
1676 return
1677
1677
1678 if not streamclone.allowservergeneration(repo):
1678 if not streamclone.allowservergeneration(repo):
1679 raise error.Abort(_('stream data requested but server does not allow '
1679 raise error.Abort(_('stream data requested but server does not allow '
1680 'this feature'),
1680 'this feature'),
1681 hint=_('well-behaved clients should not be '
1681 hint=_('well-behaved clients should not be '
1682 'requesting stream data from servers not '
1682 'requesting stream data from servers not '
1683 'advertising it; the client may be buggy'))
1683 'advertising it; the client may be buggy'))
1684
1684
1685 # Stream clones don't compress well. And compression undermines a
1685 # Stream clones don't compress well. And compression undermines a
1686 # goal of stream clones, which is to be fast. Communicate the desire
1686 # goal of stream clones, which is to be fast. Communicate the desire
1687 # to avoid compression to consumers of the bundle.
1687 # to avoid compression to consumers of the bundle.
1688 bundler.prefercompressed = False
1688 bundler.prefercompressed = False
1689
1689
1690 filecount, bytecount, it = streamclone.generatev2(repo)
1690 filecount, bytecount, it = streamclone.generatev2(repo)
1691 requirements = _formatrequirementsspec(repo.requirements)
1691 requirements = _formatrequirementsspec(repo.requirements)
1692 part = bundler.newpart('stream2', data=it)
1692 part = bundler.newpart('stream2', data=it)
1693 part.addparam('bytecount', '%d' % bytecount, mandatory=True)
1693 part.addparam('bytecount', '%d' % bytecount, mandatory=True)
1694 part.addparam('filecount', '%d' % filecount, mandatory=True)
1694 part.addparam('filecount', '%d' % filecount, mandatory=True)
1695 part.addparam('requirements', requirements, mandatory=True)
1695 part.addparam('requirements', requirements, mandatory=True)
1696
1696
1697 def buildobsmarkerspart(bundler, markers):
1697 def buildobsmarkerspart(bundler, markers):
1698 """add an obsmarker part to the bundler with <markers>
1698 """add an obsmarker part to the bundler with <markers>
1699
1699
1700 No part is created if markers is empty.
1700 No part is created if markers is empty.
1701 Raises ValueError if the bundler doesn't support any known obsmarker format.
1701 Raises ValueError if the bundler doesn't support any known obsmarker format.
1702 """
1702 """
1703 if not markers:
1703 if not markers:
1704 return None
1704 return None
1705
1705
1706 remoteversions = obsmarkersversion(bundler.capabilities)
1706 remoteversions = obsmarkersversion(bundler.capabilities)
1707 version = obsolete.commonversion(remoteversions)
1707 version = obsolete.commonversion(remoteversions)
1708 if version is None:
1708 if version is None:
1709 raise ValueError('bundler does not support common obsmarker format')
1709 raise ValueError('bundler does not support common obsmarker format')
1710 stream = obsolete.encodemarkers(markers, True, version=version)
1710 stream = obsolete.encodemarkers(markers, True, version=version)
1711 return bundler.newpart('obsmarkers', data=stream)
1711 return bundler.newpart('obsmarkers', data=stream)
1712
1712
1713 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None,
1713 def writebundle(ui, cg, filename, bundletype, vfs=None, compression=None,
1714 compopts=None):
1714 compopts=None):
1715 """Write a bundle file and return its filename.
1715 """Write a bundle file and return its filename.
1716
1716
1717 Existing files will not be overwritten.
1717 Existing files will not be overwritten.
1718 If no filename is specified, a temporary file is created.
1718 If no filename is specified, a temporary file is created.
1719 bz2 compression can be turned off.
1719 bz2 compression can be turned off.
1720 The bundle file will be deleted in case of errors.
1720 The bundle file will be deleted in case of errors.
1721 """
1721 """
1722
1722
1723 if bundletype == "HG20":
1723 if bundletype == "HG20":
1724 bundle = bundle20(ui)
1724 bundle = bundle20(ui)
1725 bundle.setcompression(compression, compopts)
1725 bundle.setcompression(compression, compopts)
1726 part = bundle.newpart('changegroup', data=cg.getchunks())
1726 part = bundle.newpart('changegroup', data=cg.getchunks())
1727 part.addparam('version', cg.version)
1727 part.addparam('version', cg.version)
1728 if 'clcount' in cg.extras:
1728 if 'clcount' in cg.extras:
1729 part.addparam('nbchanges', '%d' % cg.extras['clcount'],
1729 part.addparam('nbchanges', '%d' % cg.extras['clcount'],
1730 mandatory=False)
1730 mandatory=False)
1731 chunkiter = bundle.getchunks()
1731 chunkiter = bundle.getchunks()
1732 else:
1732 else:
1733 # compression argument is only for the bundle2 case
1733 # compression argument is only for the bundle2 case
1734 assert compression is None
1734 assert compression is None
1735 if cg.version != '01':
1735 if cg.version != '01':
1736 raise error.Abort(_('old bundle types only supports v1 '
1736 raise error.Abort(_('old bundle types only supports v1 '
1737 'changegroups'))
1737 'changegroups'))
1738 header, comp = bundletypes[bundletype]
1738 header, comp = bundletypes[bundletype]
1739 if comp not in util.compengines.supportedbundletypes:
1739 if comp not in util.compengines.supportedbundletypes:
1740 raise error.Abort(_('unknown stream compression type: %s')
1740 raise error.Abort(_('unknown stream compression type: %s')
1741 % comp)
1741 % comp)
1742 compengine = util.compengines.forbundletype(comp)
1742 compengine = util.compengines.forbundletype(comp)
1743 def chunkiter():
1743 def chunkiter():
1744 yield header
1744 yield header
1745 for chunk in compengine.compressstream(cg.getchunks(), compopts):
1745 for chunk in compengine.compressstream(cg.getchunks(), compopts):
1746 yield chunk
1746 yield chunk
1747 chunkiter = chunkiter()
1747 chunkiter = chunkiter()
1748
1748
1749 # parse the changegroup data, otherwise we will block
1749 # parse the changegroup data, otherwise we will block
1750 # in case of sshrepo because we don't know the end of the stream
1750 # in case of sshrepo because we don't know the end of the stream
1751 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs)
1751 return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs)
1752
1752
1753 def combinechangegroupresults(op):
1753 def combinechangegroupresults(op):
1754 """logic to combine 0 or more addchangegroup results into one"""
1754 """logic to combine 0 or more addchangegroup results into one"""
1755 results = [r.get('return', 0)
1755 results = [r.get('return', 0)
1756 for r in op.records['changegroup']]
1756 for r in op.records['changegroup']]
1757 changedheads = 0
1757 changedheads = 0
1758 result = 1
1758 result = 1
1759 for ret in results:
1759 for ret in results:
1760 # If any changegroup result is 0, return 0
1760 # If any changegroup result is 0, return 0
1761 if ret == 0:
1761 if ret == 0:
1762 result = 0
1762 result = 0
1763 break
1763 break
1764 if ret < -1:
1764 if ret < -1:
1765 changedheads += ret + 1
1765 changedheads += ret + 1
1766 elif ret > 1:
1766 elif ret > 1:
1767 changedheads += ret - 1
1767 changedheads += ret - 1
1768 if changedheads > 0:
1768 if changedheads > 0:
1769 result = 1 + changedheads
1769 result = 1 + changedheads
1770 elif changedheads < 0:
1770 elif changedheads < 0:
1771 result = -1 + changedheads
1771 result = -1 + changedheads
1772 return result
1772 return result
1773
1773
1774 @parthandler('changegroup', ('version', 'nbchanges', 'treemanifest',
1774 @parthandler('changegroup', ('version', 'nbchanges', 'treemanifest',
1775 'targetphase'))
1775 'targetphase'))
1776 def handlechangegroup(op, inpart):
1776 def handlechangegroup(op, inpart):
1777 """apply a changegroup part on the repo
1777 """apply a changegroup part on the repo
1778
1778
1779 This is a very early implementation that will massive rework before being
1779 This is a very early implementation that will massive rework before being
1780 inflicted to any end-user.
1780 inflicted to any end-user.
1781 """
1781 """
1782 tr = op.gettransaction()
1782 tr = op.gettransaction()
1783 unpackerversion = inpart.params.get('version', '01')
1783 unpackerversion = inpart.params.get('version', '01')
1784 # We should raise an appropriate exception here
1784 # We should raise an appropriate exception here
1785 cg = changegroup.getunbundler(unpackerversion, inpart, None)
1785 cg = changegroup.getunbundler(unpackerversion, inpart, None)
1786 # the source and url passed here are overwritten by the one contained in
1786 # the source and url passed here are overwritten by the one contained in
1787 # the transaction.hookargs argument. So 'bundle2' is a placeholder
1787 # the transaction.hookargs argument. So 'bundle2' is a placeholder
1788 nbchangesets = None
1788 nbchangesets = None
1789 if 'nbchanges' in inpart.params:
1789 if 'nbchanges' in inpart.params:
1790 nbchangesets = int(inpart.params.get('nbchanges'))
1790 nbchangesets = int(inpart.params.get('nbchanges'))
1791 if ('treemanifest' in inpart.params and
1791 if ('treemanifest' in inpart.params and
1792 'treemanifest' not in op.repo.requirements):
1792 'treemanifest' not in op.repo.requirements):
1793 if len(op.repo.changelog) != 0:
1793 if len(op.repo.changelog) != 0:
1794 raise error.Abort(_(
1794 raise error.Abort(_(
1795 "bundle contains tree manifests, but local repo is "
1795 "bundle contains tree manifests, but local repo is "
1796 "non-empty and does not use tree manifests"))
1796 "non-empty and does not use tree manifests"))
1797 op.repo.requirements.add('treemanifest')
1797 op.repo.requirements.add('treemanifest')
1798 op.repo._applyopenerreqs()
1798 op.repo._applyopenerreqs()
1799 op.repo._writerequirements()
1799 op.repo._writerequirements()
1800 extrakwargs = {}
1800 extrakwargs = {}
1801 targetphase = inpart.params.get('targetphase')
1801 targetphase = inpart.params.get('targetphase')
1802 if targetphase is not None:
1802 if targetphase is not None:
1803 extrakwargs[r'targetphase'] = int(targetphase)
1803 extrakwargs[r'targetphase'] = int(targetphase)
1804 ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2',
1804 ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2',
1805 expectedtotal=nbchangesets, **extrakwargs)
1805 expectedtotal=nbchangesets, **extrakwargs)
1806 if op.reply is not None:
1806 if op.reply is not None:
1807 # This is definitely not the final form of this
1807 # This is definitely not the final form of this
1808 # return. But one need to start somewhere.
1808 # return. But one need to start somewhere.
1809 part = op.reply.newpart('reply:changegroup', mandatory=False)
1809 part = op.reply.newpart('reply:changegroup', mandatory=False)
1810 part.addparam(
1810 part.addparam(
1811 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
1811 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
1812 part.addparam('return', '%i' % ret, mandatory=False)
1812 part.addparam('return', '%i' % ret, mandatory=False)
1813 assert not inpart.read()
1813 assert not inpart.read()
1814
1814
1815 _remotechangegroupparams = tuple(['url', 'size', 'digests'] +
1815 _remotechangegroupparams = tuple(['url', 'size', 'digests'] +
1816 ['digest:%s' % k for k in util.DIGESTS.keys()])
1816 ['digest:%s' % k for k in util.DIGESTS.keys()])
1817 @parthandler('remote-changegroup', _remotechangegroupparams)
1817 @parthandler('remote-changegroup', _remotechangegroupparams)
1818 def handleremotechangegroup(op, inpart):
1818 def handleremotechangegroup(op, inpart):
1819 """apply a bundle10 on the repo, given an url and validation information
1819 """apply a bundle10 on the repo, given an url and validation information
1820
1820
1821 All the information about the remote bundle to import are given as
1821 All the information about the remote bundle to import are given as
1822 parameters. The parameters include:
1822 parameters. The parameters include:
1823 - url: the url to the bundle10.
1823 - url: the url to the bundle10.
1824 - size: the bundle10 file size. It is used to validate what was
1824 - size: the bundle10 file size. It is used to validate what was
1825 retrieved by the client matches the server knowledge about the bundle.
1825 retrieved by the client matches the server knowledge about the bundle.
1826 - digests: a space separated list of the digest types provided as
1826 - digests: a space separated list of the digest types provided as
1827 parameters.
1827 parameters.
1828 - digest:<digest-type>: the hexadecimal representation of the digest with
1828 - digest:<digest-type>: the hexadecimal representation of the digest with
1829 that name. Like the size, it is used to validate what was retrieved by
1829 that name. Like the size, it is used to validate what was retrieved by
1830 the client matches what the server knows about the bundle.
1830 the client matches what the server knows about the bundle.
1831
1831
1832 When multiple digest types are given, all of them are checked.
1832 When multiple digest types are given, all of them are checked.
1833 """
1833 """
1834 try:
1834 try:
1835 raw_url = inpart.params['url']
1835 raw_url = inpart.params['url']
1836 except KeyError:
1836 except KeyError:
1837 raise error.Abort(_('remote-changegroup: missing "%s" param') % 'url')
1837 raise error.Abort(_('remote-changegroup: missing "%s" param') % 'url')
1838 parsed_url = util.url(raw_url)
1838 parsed_url = util.url(raw_url)
1839 if parsed_url.scheme not in capabilities['remote-changegroup']:
1839 if parsed_url.scheme not in capabilities['remote-changegroup']:
1840 raise error.Abort(_('remote-changegroup does not support %s urls') %
1840 raise error.Abort(_('remote-changegroup does not support %s urls') %
1841 parsed_url.scheme)
1841 parsed_url.scheme)
1842
1842
1843 try:
1843 try:
1844 size = int(inpart.params['size'])
1844 size = int(inpart.params['size'])
1845 except ValueError:
1845 except ValueError:
1846 raise error.Abort(_('remote-changegroup: invalid value for param "%s"')
1846 raise error.Abort(_('remote-changegroup: invalid value for param "%s"')
1847 % 'size')
1847 % 'size')
1848 except KeyError:
1848 except KeyError:
1849 raise error.Abort(_('remote-changegroup: missing "%s" param') % 'size')
1849 raise error.Abort(_('remote-changegroup: missing "%s" param') % 'size')
1850
1850
1851 digests = {}
1851 digests = {}
1852 for typ in inpart.params.get('digests', '').split():
1852 for typ in inpart.params.get('digests', '').split():
1853 param = 'digest:%s' % typ
1853 param = 'digest:%s' % typ
1854 try:
1854 try:
1855 value = inpart.params[param]
1855 value = inpart.params[param]
1856 except KeyError:
1856 except KeyError:
1857 raise error.Abort(_('remote-changegroup: missing "%s" param') %
1857 raise error.Abort(_('remote-changegroup: missing "%s" param') %
1858 param)
1858 param)
1859 digests[typ] = value
1859 digests[typ] = value
1860
1860
1861 real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests)
1861 real_part = util.digestchecker(url.open(op.ui, raw_url), size, digests)
1862
1862
1863 tr = op.gettransaction()
1863 tr = op.gettransaction()
1864 from . import exchange
1864 from . import exchange
1865 cg = exchange.readbundle(op.repo.ui, real_part, raw_url)
1865 cg = exchange.readbundle(op.repo.ui, real_part, raw_url)
1866 if not isinstance(cg, changegroup.cg1unpacker):
1866 if not isinstance(cg, changegroup.cg1unpacker):
1867 raise error.Abort(_('%s: not a bundle version 1.0') %
1867 raise error.Abort(_('%s: not a bundle version 1.0') %
1868 util.hidepassword(raw_url))
1868 util.hidepassword(raw_url))
1869 ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2')
1869 ret = _processchangegroup(op, cg, tr, 'bundle2', 'bundle2')
1870 if op.reply is not None:
1870 if op.reply is not None:
1871 # This is definitely not the final form of this
1871 # This is definitely not the final form of this
1872 # return. But one need to start somewhere.
1872 # return. But one need to start somewhere.
1873 part = op.reply.newpart('reply:changegroup')
1873 part = op.reply.newpart('reply:changegroup')
1874 part.addparam(
1874 part.addparam(
1875 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
1875 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
1876 part.addparam('return', '%i' % ret, mandatory=False)
1876 part.addparam('return', '%i' % ret, mandatory=False)
1877 try:
1877 try:
1878 real_part.validate()
1878 real_part.validate()
1879 except error.Abort as e:
1879 except error.Abort as e:
1880 raise error.Abort(_('bundle at %s is corrupted:\n%s') %
1880 raise error.Abort(_('bundle at %s is corrupted:\n%s') %
1881 (util.hidepassword(raw_url), str(e)))
1881 (util.hidepassword(raw_url), bytes(e)))
1882 assert not inpart.read()
1882 assert not inpart.read()
1883
1883
1884 @parthandler('reply:changegroup', ('return', 'in-reply-to'))
1884 @parthandler('reply:changegroup', ('return', 'in-reply-to'))
1885 def handlereplychangegroup(op, inpart):
1885 def handlereplychangegroup(op, inpart):
1886 ret = int(inpart.params['return'])
1886 ret = int(inpart.params['return'])
1887 replyto = int(inpart.params['in-reply-to'])
1887 replyto = int(inpart.params['in-reply-to'])
1888 op.records.add('changegroup', {'return': ret}, replyto)
1888 op.records.add('changegroup', {'return': ret}, replyto)
1889
1889
1890 @parthandler('check:bookmarks')
1890 @parthandler('check:bookmarks')
1891 def handlecheckbookmarks(op, inpart):
1891 def handlecheckbookmarks(op, inpart):
1892 """check location of bookmarks
1892 """check location of bookmarks
1893
1893
1894 This part is to be used to detect push race regarding bookmark, it
1894 This part is to be used to detect push race regarding bookmark, it
1895 contains binary encoded (bookmark, node) tuple. If the local state does
1895 contains binary encoded (bookmark, node) tuple. If the local state does
1896 not marks the one in the part, a PushRaced exception is raised
1896 not marks the one in the part, a PushRaced exception is raised
1897 """
1897 """
1898 bookdata = bookmarks.binarydecode(inpart)
1898 bookdata = bookmarks.binarydecode(inpart)
1899
1899
1900 msgstandard = ('repository changed while pushing - please try again '
1900 msgstandard = ('repository changed while pushing - please try again '
1901 '(bookmark "%s" move from %s to %s)')
1901 '(bookmark "%s" move from %s to %s)')
1902 msgmissing = ('repository changed while pushing - please try again '
1902 msgmissing = ('repository changed while pushing - please try again '
1903 '(bookmark "%s" is missing, expected %s)')
1903 '(bookmark "%s" is missing, expected %s)')
1904 msgexist = ('repository changed while pushing - please try again '
1904 msgexist = ('repository changed while pushing - please try again '
1905 '(bookmark "%s" set on %s, expected missing)')
1905 '(bookmark "%s" set on %s, expected missing)')
1906 for book, node in bookdata:
1906 for book, node in bookdata:
1907 currentnode = op.repo._bookmarks.get(book)
1907 currentnode = op.repo._bookmarks.get(book)
1908 if currentnode != node:
1908 if currentnode != node:
1909 if node is None:
1909 if node is None:
1910 finalmsg = msgexist % (book, nodemod.short(currentnode))
1910 finalmsg = msgexist % (book, nodemod.short(currentnode))
1911 elif currentnode is None:
1911 elif currentnode is None:
1912 finalmsg = msgmissing % (book, nodemod.short(node))
1912 finalmsg = msgmissing % (book, nodemod.short(node))
1913 else:
1913 else:
1914 finalmsg = msgstandard % (book, nodemod.short(node),
1914 finalmsg = msgstandard % (book, nodemod.short(node),
1915 nodemod.short(currentnode))
1915 nodemod.short(currentnode))
1916 raise error.PushRaced(finalmsg)
1916 raise error.PushRaced(finalmsg)
1917
1917
1918 @parthandler('check:heads')
1918 @parthandler('check:heads')
1919 def handlecheckheads(op, inpart):
1919 def handlecheckheads(op, inpart):
1920 """check that head of the repo did not change
1920 """check that head of the repo did not change
1921
1921
1922 This is used to detect a push race when using unbundle.
1922 This is used to detect a push race when using unbundle.
1923 This replaces the "heads" argument of unbundle."""
1923 This replaces the "heads" argument of unbundle."""
1924 h = inpart.read(20)
1924 h = inpart.read(20)
1925 heads = []
1925 heads = []
1926 while len(h) == 20:
1926 while len(h) == 20:
1927 heads.append(h)
1927 heads.append(h)
1928 h = inpart.read(20)
1928 h = inpart.read(20)
1929 assert not h
1929 assert not h
1930 # Trigger a transaction so that we are guaranteed to have the lock now.
1930 # Trigger a transaction so that we are guaranteed to have the lock now.
1931 if op.ui.configbool('experimental', 'bundle2lazylocking'):
1931 if op.ui.configbool('experimental', 'bundle2lazylocking'):
1932 op.gettransaction()
1932 op.gettransaction()
1933 if sorted(heads) != sorted(op.repo.heads()):
1933 if sorted(heads) != sorted(op.repo.heads()):
1934 raise error.PushRaced('repository changed while pushing - '
1934 raise error.PushRaced('repository changed while pushing - '
1935 'please try again')
1935 'please try again')
1936
1936
1937 @parthandler('check:updated-heads')
1937 @parthandler('check:updated-heads')
1938 def handlecheckupdatedheads(op, inpart):
1938 def handlecheckupdatedheads(op, inpart):
1939 """check for race on the heads touched by a push
1939 """check for race on the heads touched by a push
1940
1940
1941 This is similar to 'check:heads' but focus on the heads actually updated
1941 This is similar to 'check:heads' but focus on the heads actually updated
1942 during the push. If other activities happen on unrelated heads, it is
1942 during the push. If other activities happen on unrelated heads, it is
1943 ignored.
1943 ignored.
1944
1944
1945 This allow server with high traffic to avoid push contention as long as
1945 This allow server with high traffic to avoid push contention as long as
1946 unrelated parts of the graph are involved."""
1946 unrelated parts of the graph are involved."""
1947 h = inpart.read(20)
1947 h = inpart.read(20)
1948 heads = []
1948 heads = []
1949 while len(h) == 20:
1949 while len(h) == 20:
1950 heads.append(h)
1950 heads.append(h)
1951 h = inpart.read(20)
1951 h = inpart.read(20)
1952 assert not h
1952 assert not h
1953 # trigger a transaction so that we are guaranteed to have the lock now.
1953 # trigger a transaction so that we are guaranteed to have the lock now.
1954 if op.ui.configbool('experimental', 'bundle2lazylocking'):
1954 if op.ui.configbool('experimental', 'bundle2lazylocking'):
1955 op.gettransaction()
1955 op.gettransaction()
1956
1956
1957 currentheads = set()
1957 currentheads = set()
1958 for ls in op.repo.branchmap().itervalues():
1958 for ls in op.repo.branchmap().itervalues():
1959 currentheads.update(ls)
1959 currentheads.update(ls)
1960
1960
1961 for h in heads:
1961 for h in heads:
1962 if h not in currentheads:
1962 if h not in currentheads:
1963 raise error.PushRaced('repository changed while pushing - '
1963 raise error.PushRaced('repository changed while pushing - '
1964 'please try again')
1964 'please try again')
1965
1965
1966 @parthandler('check:phases')
1966 @parthandler('check:phases')
1967 def handlecheckphases(op, inpart):
1967 def handlecheckphases(op, inpart):
1968 """check that phase boundaries of the repository did not change
1968 """check that phase boundaries of the repository did not change
1969
1969
1970 This is used to detect a push race.
1970 This is used to detect a push race.
1971 """
1971 """
1972 phasetonodes = phases.binarydecode(inpart)
1972 phasetonodes = phases.binarydecode(inpart)
1973 unfi = op.repo.unfiltered()
1973 unfi = op.repo.unfiltered()
1974 cl = unfi.changelog
1974 cl = unfi.changelog
1975 phasecache = unfi._phasecache
1975 phasecache = unfi._phasecache
1976 msg = ('repository changed while pushing - please try again '
1976 msg = ('repository changed while pushing - please try again '
1977 '(%s is %s expected %s)')
1977 '(%s is %s expected %s)')
1978 for expectedphase, nodes in enumerate(phasetonodes):
1978 for expectedphase, nodes in enumerate(phasetonodes):
1979 for n in nodes:
1979 for n in nodes:
1980 actualphase = phasecache.phase(unfi, cl.rev(n))
1980 actualphase = phasecache.phase(unfi, cl.rev(n))
1981 if actualphase != expectedphase:
1981 if actualphase != expectedphase:
1982 finalmsg = msg % (nodemod.short(n),
1982 finalmsg = msg % (nodemod.short(n),
1983 phases.phasenames[actualphase],
1983 phases.phasenames[actualphase],
1984 phases.phasenames[expectedphase])
1984 phases.phasenames[expectedphase])
1985 raise error.PushRaced(finalmsg)
1985 raise error.PushRaced(finalmsg)
1986
1986
1987 @parthandler('output')
1987 @parthandler('output')
1988 def handleoutput(op, inpart):
1988 def handleoutput(op, inpart):
1989 """forward output captured on the server to the client"""
1989 """forward output captured on the server to the client"""
1990 for line in inpart.read().splitlines():
1990 for line in inpart.read().splitlines():
1991 op.ui.status(_('remote: %s\n') % line)
1991 op.ui.status(_('remote: %s\n') % line)
1992
1992
1993 @parthandler('replycaps')
1993 @parthandler('replycaps')
1994 def handlereplycaps(op, inpart):
1994 def handlereplycaps(op, inpart):
1995 """Notify that a reply bundle should be created
1995 """Notify that a reply bundle should be created
1996
1996
1997 The payload contains the capabilities information for the reply"""
1997 The payload contains the capabilities information for the reply"""
1998 caps = decodecaps(inpart.read())
1998 caps = decodecaps(inpart.read())
1999 if op.reply is None:
1999 if op.reply is None:
2000 op.reply = bundle20(op.ui, caps)
2000 op.reply = bundle20(op.ui, caps)
2001
2001
2002 class AbortFromPart(error.Abort):
2002 class AbortFromPart(error.Abort):
2003 """Sub-class of Abort that denotes an error from a bundle2 part."""
2003 """Sub-class of Abort that denotes an error from a bundle2 part."""
2004
2004
2005 @parthandler('error:abort', ('message', 'hint'))
2005 @parthandler('error:abort', ('message', 'hint'))
2006 def handleerrorabort(op, inpart):
2006 def handleerrorabort(op, inpart):
2007 """Used to transmit abort error over the wire"""
2007 """Used to transmit abort error over the wire"""
2008 raise AbortFromPart(inpart.params['message'],
2008 raise AbortFromPart(inpart.params['message'],
2009 hint=inpart.params.get('hint'))
2009 hint=inpart.params.get('hint'))
2010
2010
2011 @parthandler('error:pushkey', ('namespace', 'key', 'new', 'old', 'ret',
2011 @parthandler('error:pushkey', ('namespace', 'key', 'new', 'old', 'ret',
2012 'in-reply-to'))
2012 'in-reply-to'))
2013 def handleerrorpushkey(op, inpart):
2013 def handleerrorpushkey(op, inpart):
2014 """Used to transmit failure of a mandatory pushkey over the wire"""
2014 """Used to transmit failure of a mandatory pushkey over the wire"""
2015 kwargs = {}
2015 kwargs = {}
2016 for name in ('namespace', 'key', 'new', 'old', 'ret'):
2016 for name in ('namespace', 'key', 'new', 'old', 'ret'):
2017 value = inpart.params.get(name)
2017 value = inpart.params.get(name)
2018 if value is not None:
2018 if value is not None:
2019 kwargs[name] = value
2019 kwargs[name] = value
2020 raise error.PushkeyFailed(inpart.params['in-reply-to'],
2020 raise error.PushkeyFailed(inpart.params['in-reply-to'],
2021 **pycompat.strkwargs(kwargs))
2021 **pycompat.strkwargs(kwargs))
2022
2022
2023 @parthandler('error:unsupportedcontent', ('parttype', 'params'))
2023 @parthandler('error:unsupportedcontent', ('parttype', 'params'))
2024 def handleerrorunsupportedcontent(op, inpart):
2024 def handleerrorunsupportedcontent(op, inpart):
2025 """Used to transmit unknown content error over the wire"""
2025 """Used to transmit unknown content error over the wire"""
2026 kwargs = {}
2026 kwargs = {}
2027 parttype = inpart.params.get('parttype')
2027 parttype = inpart.params.get('parttype')
2028 if parttype is not None:
2028 if parttype is not None:
2029 kwargs['parttype'] = parttype
2029 kwargs['parttype'] = parttype
2030 params = inpart.params.get('params')
2030 params = inpart.params.get('params')
2031 if params is not None:
2031 if params is not None:
2032 kwargs['params'] = params.split('\0')
2032 kwargs['params'] = params.split('\0')
2033
2033
2034 raise error.BundleUnknownFeatureError(**pycompat.strkwargs(kwargs))
2034 raise error.BundleUnknownFeatureError(**pycompat.strkwargs(kwargs))
2035
2035
2036 @parthandler('error:pushraced', ('message',))
2036 @parthandler('error:pushraced', ('message',))
2037 def handleerrorpushraced(op, inpart):
2037 def handleerrorpushraced(op, inpart):
2038 """Used to transmit push race error over the wire"""
2038 """Used to transmit push race error over the wire"""
2039 raise error.ResponseError(_('push failed:'), inpart.params['message'])
2039 raise error.ResponseError(_('push failed:'), inpart.params['message'])
2040
2040
2041 @parthandler('listkeys', ('namespace',))
2041 @parthandler('listkeys', ('namespace',))
2042 def handlelistkeys(op, inpart):
2042 def handlelistkeys(op, inpart):
2043 """retrieve pushkey namespace content stored in a bundle2"""
2043 """retrieve pushkey namespace content stored in a bundle2"""
2044 namespace = inpart.params['namespace']
2044 namespace = inpart.params['namespace']
2045 r = pushkey.decodekeys(inpart.read())
2045 r = pushkey.decodekeys(inpart.read())
2046 op.records.add('listkeys', (namespace, r))
2046 op.records.add('listkeys', (namespace, r))
2047
2047
2048 @parthandler('pushkey', ('namespace', 'key', 'old', 'new'))
2048 @parthandler('pushkey', ('namespace', 'key', 'old', 'new'))
2049 def handlepushkey(op, inpart):
2049 def handlepushkey(op, inpart):
2050 """process a pushkey request"""
2050 """process a pushkey request"""
2051 dec = pushkey.decode
2051 dec = pushkey.decode
2052 namespace = dec(inpart.params['namespace'])
2052 namespace = dec(inpart.params['namespace'])
2053 key = dec(inpart.params['key'])
2053 key = dec(inpart.params['key'])
2054 old = dec(inpart.params['old'])
2054 old = dec(inpart.params['old'])
2055 new = dec(inpart.params['new'])
2055 new = dec(inpart.params['new'])
2056 # Grab the transaction to ensure that we have the lock before performing the
2056 # Grab the transaction to ensure that we have the lock before performing the
2057 # pushkey.
2057 # pushkey.
2058 if op.ui.configbool('experimental', 'bundle2lazylocking'):
2058 if op.ui.configbool('experimental', 'bundle2lazylocking'):
2059 op.gettransaction()
2059 op.gettransaction()
2060 ret = op.repo.pushkey(namespace, key, old, new)
2060 ret = op.repo.pushkey(namespace, key, old, new)
2061 record = {'namespace': namespace,
2061 record = {'namespace': namespace,
2062 'key': key,
2062 'key': key,
2063 'old': old,
2063 'old': old,
2064 'new': new}
2064 'new': new}
2065 op.records.add('pushkey', record)
2065 op.records.add('pushkey', record)
2066 if op.reply is not None:
2066 if op.reply is not None:
2067 rpart = op.reply.newpart('reply:pushkey')
2067 rpart = op.reply.newpart('reply:pushkey')
2068 rpart.addparam(
2068 rpart.addparam(
2069 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
2069 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
2070 rpart.addparam('return', '%i' % ret, mandatory=False)
2070 rpart.addparam('return', '%i' % ret, mandatory=False)
2071 if inpart.mandatory and not ret:
2071 if inpart.mandatory and not ret:
2072 kwargs = {}
2072 kwargs = {}
2073 for key in ('namespace', 'key', 'new', 'old', 'ret'):
2073 for key in ('namespace', 'key', 'new', 'old', 'ret'):
2074 if key in inpart.params:
2074 if key in inpart.params:
2075 kwargs[key] = inpart.params[key]
2075 kwargs[key] = inpart.params[key]
2076 raise error.PushkeyFailed(partid='%d' % inpart.id,
2076 raise error.PushkeyFailed(partid='%d' % inpart.id,
2077 **pycompat.strkwargs(kwargs))
2077 **pycompat.strkwargs(kwargs))
2078
2078
2079 @parthandler('bookmarks')
2079 @parthandler('bookmarks')
2080 def handlebookmark(op, inpart):
2080 def handlebookmark(op, inpart):
2081 """transmit bookmark information
2081 """transmit bookmark information
2082
2082
2083 The part contains binary encoded bookmark information.
2083 The part contains binary encoded bookmark information.
2084
2084
2085 The exact behavior of this part can be controlled by the 'bookmarks' mode
2085 The exact behavior of this part can be controlled by the 'bookmarks' mode
2086 on the bundle operation.
2086 on the bundle operation.
2087
2087
2088 When mode is 'apply' (the default) the bookmark information is applied as
2088 When mode is 'apply' (the default) the bookmark information is applied as
2089 is to the unbundling repository. Make sure a 'check:bookmarks' part is
2089 is to the unbundling repository. Make sure a 'check:bookmarks' part is
2090 issued earlier to check for push races in such update. This behavior is
2090 issued earlier to check for push races in such update. This behavior is
2091 suitable for pushing.
2091 suitable for pushing.
2092
2092
2093 When mode is 'records', the information is recorded into the 'bookmarks'
2093 When mode is 'records', the information is recorded into the 'bookmarks'
2094 records of the bundle operation. This behavior is suitable for pulling.
2094 records of the bundle operation. This behavior is suitable for pulling.
2095 """
2095 """
2096 changes = bookmarks.binarydecode(inpart)
2096 changes = bookmarks.binarydecode(inpart)
2097
2097
2098 pushkeycompat = op.repo.ui.configbool('server', 'bookmarks-pushkey-compat')
2098 pushkeycompat = op.repo.ui.configbool('server', 'bookmarks-pushkey-compat')
2099 bookmarksmode = op.modes.get('bookmarks', 'apply')
2099 bookmarksmode = op.modes.get('bookmarks', 'apply')
2100
2100
2101 if bookmarksmode == 'apply':
2101 if bookmarksmode == 'apply':
2102 tr = op.gettransaction()
2102 tr = op.gettransaction()
2103 bookstore = op.repo._bookmarks
2103 bookstore = op.repo._bookmarks
2104 if pushkeycompat:
2104 if pushkeycompat:
2105 allhooks = []
2105 allhooks = []
2106 for book, node in changes:
2106 for book, node in changes:
2107 hookargs = tr.hookargs.copy()
2107 hookargs = tr.hookargs.copy()
2108 hookargs['pushkeycompat'] = '1'
2108 hookargs['pushkeycompat'] = '1'
2109 hookargs['namespace'] = 'bookmarks'
2109 hookargs['namespace'] = 'bookmarks'
2110 hookargs['key'] = book
2110 hookargs['key'] = book
2111 hookargs['old'] = nodemod.hex(bookstore.get(book, ''))
2111 hookargs['old'] = nodemod.hex(bookstore.get(book, ''))
2112 hookargs['new'] = nodemod.hex(node if node is not None else '')
2112 hookargs['new'] = nodemod.hex(node if node is not None else '')
2113 allhooks.append(hookargs)
2113 allhooks.append(hookargs)
2114
2114
2115 for hookargs in allhooks:
2115 for hookargs in allhooks:
2116 op.repo.hook('prepushkey', throw=True,
2116 op.repo.hook('prepushkey', throw=True,
2117 **pycompat.strkwargs(hookargs))
2117 **pycompat.strkwargs(hookargs))
2118
2118
2119 bookstore.applychanges(op.repo, op.gettransaction(), changes)
2119 bookstore.applychanges(op.repo, op.gettransaction(), changes)
2120
2120
2121 if pushkeycompat:
2121 if pushkeycompat:
2122 def runhook():
2122 def runhook():
2123 for hookargs in allhooks:
2123 for hookargs in allhooks:
2124 op.repo.hook('pushkey', **pycompat.strkwargs(hookargs))
2124 op.repo.hook('pushkey', **pycompat.strkwargs(hookargs))
2125 op.repo._afterlock(runhook)
2125 op.repo._afterlock(runhook)
2126
2126
2127 elif bookmarksmode == 'records':
2127 elif bookmarksmode == 'records':
2128 for book, node in changes:
2128 for book, node in changes:
2129 record = {'bookmark': book, 'node': node}
2129 record = {'bookmark': book, 'node': node}
2130 op.records.add('bookmarks', record)
2130 op.records.add('bookmarks', record)
2131 else:
2131 else:
2132 raise error.ProgrammingError('unkown bookmark mode: %s' % bookmarksmode)
2132 raise error.ProgrammingError('unkown bookmark mode: %s' % bookmarksmode)
2133
2133
2134 @parthandler('phase-heads')
2134 @parthandler('phase-heads')
2135 def handlephases(op, inpart):
2135 def handlephases(op, inpart):
2136 """apply phases from bundle part to repo"""
2136 """apply phases from bundle part to repo"""
2137 headsbyphase = phases.binarydecode(inpart)
2137 headsbyphase = phases.binarydecode(inpart)
2138 phases.updatephases(op.repo.unfiltered(), op.gettransaction, headsbyphase)
2138 phases.updatephases(op.repo.unfiltered(), op.gettransaction, headsbyphase)
2139
2139
2140 @parthandler('reply:pushkey', ('return', 'in-reply-to'))
2140 @parthandler('reply:pushkey', ('return', 'in-reply-to'))
2141 def handlepushkeyreply(op, inpart):
2141 def handlepushkeyreply(op, inpart):
2142 """retrieve the result of a pushkey request"""
2142 """retrieve the result of a pushkey request"""
2143 ret = int(inpart.params['return'])
2143 ret = int(inpart.params['return'])
2144 partid = int(inpart.params['in-reply-to'])
2144 partid = int(inpart.params['in-reply-to'])
2145 op.records.add('pushkey', {'return': ret}, partid)
2145 op.records.add('pushkey', {'return': ret}, partid)
2146
2146
2147 @parthandler('obsmarkers')
2147 @parthandler('obsmarkers')
2148 def handleobsmarker(op, inpart):
2148 def handleobsmarker(op, inpart):
2149 """add a stream of obsmarkers to the repo"""
2149 """add a stream of obsmarkers to the repo"""
2150 tr = op.gettransaction()
2150 tr = op.gettransaction()
2151 markerdata = inpart.read()
2151 markerdata = inpart.read()
2152 if op.ui.config('experimental', 'obsmarkers-exchange-debug'):
2152 if op.ui.config('experimental', 'obsmarkers-exchange-debug'):
2153 op.ui.write(('obsmarker-exchange: %i bytes received\n')
2153 op.ui.write(('obsmarker-exchange: %i bytes received\n')
2154 % len(markerdata))
2154 % len(markerdata))
2155 # The mergemarkers call will crash if marker creation is not enabled.
2155 # The mergemarkers call will crash if marker creation is not enabled.
2156 # we want to avoid this if the part is advisory.
2156 # we want to avoid this if the part is advisory.
2157 if not inpart.mandatory and op.repo.obsstore.readonly:
2157 if not inpart.mandatory and op.repo.obsstore.readonly:
2158 op.repo.ui.debug('ignoring obsolescence markers, feature not enabled\n')
2158 op.repo.ui.debug('ignoring obsolescence markers, feature not enabled\n')
2159 return
2159 return
2160 new = op.repo.obsstore.mergemarkers(tr, markerdata)
2160 new = op.repo.obsstore.mergemarkers(tr, markerdata)
2161 op.repo.invalidatevolatilesets()
2161 op.repo.invalidatevolatilesets()
2162 if new:
2162 if new:
2163 op.repo.ui.status(_('%i new obsolescence markers\n') % new)
2163 op.repo.ui.status(_('%i new obsolescence markers\n') % new)
2164 op.records.add('obsmarkers', {'new': new})
2164 op.records.add('obsmarkers', {'new': new})
2165 if op.reply is not None:
2165 if op.reply is not None:
2166 rpart = op.reply.newpart('reply:obsmarkers')
2166 rpart = op.reply.newpart('reply:obsmarkers')
2167 rpart.addparam(
2167 rpart.addparam(
2168 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
2168 'in-reply-to', pycompat.bytestr(inpart.id), mandatory=False)
2169 rpart.addparam('new', '%i' % new, mandatory=False)
2169 rpart.addparam('new', '%i' % new, mandatory=False)
2170
2170
2171
2171
2172 @parthandler('reply:obsmarkers', ('new', 'in-reply-to'))
2172 @parthandler('reply:obsmarkers', ('new', 'in-reply-to'))
2173 def handleobsmarkerreply(op, inpart):
2173 def handleobsmarkerreply(op, inpart):
2174 """retrieve the result of a pushkey request"""
2174 """retrieve the result of a pushkey request"""
2175 ret = int(inpart.params['new'])
2175 ret = int(inpart.params['new'])
2176 partid = int(inpart.params['in-reply-to'])
2176 partid = int(inpart.params['in-reply-to'])
2177 op.records.add('obsmarkers', {'new': ret}, partid)
2177 op.records.add('obsmarkers', {'new': ret}, partid)
2178
2178
2179 @parthandler('hgtagsfnodes')
2179 @parthandler('hgtagsfnodes')
2180 def handlehgtagsfnodes(op, inpart):
2180 def handlehgtagsfnodes(op, inpart):
2181 """Applies .hgtags fnodes cache entries to the local repo.
2181 """Applies .hgtags fnodes cache entries to the local repo.
2182
2182
2183 Payload is pairs of 20 byte changeset nodes and filenodes.
2183 Payload is pairs of 20 byte changeset nodes and filenodes.
2184 """
2184 """
2185 # Grab the transaction so we ensure that we have the lock at this point.
2185 # Grab the transaction so we ensure that we have the lock at this point.
2186 if op.ui.configbool('experimental', 'bundle2lazylocking'):
2186 if op.ui.configbool('experimental', 'bundle2lazylocking'):
2187 op.gettransaction()
2187 op.gettransaction()
2188 cache = tags.hgtagsfnodescache(op.repo.unfiltered())
2188 cache = tags.hgtagsfnodescache(op.repo.unfiltered())
2189
2189
2190 count = 0
2190 count = 0
2191 while True:
2191 while True:
2192 node = inpart.read(20)
2192 node = inpart.read(20)
2193 fnode = inpart.read(20)
2193 fnode = inpart.read(20)
2194 if len(node) < 20 or len(fnode) < 20:
2194 if len(node) < 20 or len(fnode) < 20:
2195 op.ui.debug('ignoring incomplete received .hgtags fnodes data\n')
2195 op.ui.debug('ignoring incomplete received .hgtags fnodes data\n')
2196 break
2196 break
2197 cache.setfnode(node, fnode)
2197 cache.setfnode(node, fnode)
2198 count += 1
2198 count += 1
2199
2199
2200 cache.write()
2200 cache.write()
2201 op.ui.debug('applied %i hgtags fnodes cache entries\n' % count)
2201 op.ui.debug('applied %i hgtags fnodes cache entries\n' % count)
2202
2202
2203 rbcstruct = struct.Struct('>III')
2203 rbcstruct = struct.Struct('>III')
2204
2204
2205 @parthandler('cache:rev-branch-cache')
2205 @parthandler('cache:rev-branch-cache')
2206 def handlerbc(op, inpart):
2206 def handlerbc(op, inpart):
2207 """receive a rev-branch-cache payload and update the local cache
2207 """receive a rev-branch-cache payload and update the local cache
2208
2208
2209 The payload is a series of data related to each branch
2209 The payload is a series of data related to each branch
2210
2210
2211 1) branch name length
2211 1) branch name length
2212 2) number of open heads
2212 2) number of open heads
2213 3) number of closed heads
2213 3) number of closed heads
2214 4) open heads nodes
2214 4) open heads nodes
2215 5) closed heads nodes
2215 5) closed heads nodes
2216 """
2216 """
2217 total = 0
2217 total = 0
2218 rawheader = inpart.read(rbcstruct.size)
2218 rawheader = inpart.read(rbcstruct.size)
2219 cache = op.repo.revbranchcache()
2219 cache = op.repo.revbranchcache()
2220 cl = op.repo.unfiltered().changelog
2220 cl = op.repo.unfiltered().changelog
2221 while rawheader:
2221 while rawheader:
2222 header = rbcstruct.unpack(rawheader)
2222 header = rbcstruct.unpack(rawheader)
2223 total += header[1] + header[2]
2223 total += header[1] + header[2]
2224 utf8branch = inpart.read(header[0])
2224 utf8branch = inpart.read(header[0])
2225 branch = encoding.tolocal(utf8branch)
2225 branch = encoding.tolocal(utf8branch)
2226 for x in xrange(header[1]):
2226 for x in xrange(header[1]):
2227 node = inpart.read(20)
2227 node = inpart.read(20)
2228 rev = cl.rev(node)
2228 rev = cl.rev(node)
2229 cache.setdata(branch, rev, node, False)
2229 cache.setdata(branch, rev, node, False)
2230 for x in xrange(header[2]):
2230 for x in xrange(header[2]):
2231 node = inpart.read(20)
2231 node = inpart.read(20)
2232 rev = cl.rev(node)
2232 rev = cl.rev(node)
2233 cache.setdata(branch, rev, node, True)
2233 cache.setdata(branch, rev, node, True)
2234 rawheader = inpart.read(rbcstruct.size)
2234 rawheader = inpart.read(rbcstruct.size)
2235 cache.write()
2235 cache.write()
2236
2236
2237 @parthandler('pushvars')
2237 @parthandler('pushvars')
2238 def bundle2getvars(op, part):
2238 def bundle2getvars(op, part):
2239 '''unbundle a bundle2 containing shellvars on the server'''
2239 '''unbundle a bundle2 containing shellvars on the server'''
2240 # An option to disable unbundling on server-side for security reasons
2240 # An option to disable unbundling on server-side for security reasons
2241 if op.ui.configbool('push', 'pushvars.server'):
2241 if op.ui.configbool('push', 'pushvars.server'):
2242 hookargs = {}
2242 hookargs = {}
2243 for key, value in part.advisoryparams:
2243 for key, value in part.advisoryparams:
2244 key = key.upper()
2244 key = key.upper()
2245 # We want pushed variables to have USERVAR_ prepended so we know
2245 # We want pushed variables to have USERVAR_ prepended so we know
2246 # they came from the --pushvar flag.
2246 # they came from the --pushvar flag.
2247 key = "USERVAR_" + key
2247 key = "USERVAR_" + key
2248 hookargs[key] = value
2248 hookargs[key] = value
2249 op.addhookargs(hookargs)
2249 op.addhookargs(hookargs)
2250
2250
2251 @parthandler('stream2', ('requirements', 'filecount', 'bytecount'))
2251 @parthandler('stream2', ('requirements', 'filecount', 'bytecount'))
2252 def handlestreamv2bundle(op, part):
2252 def handlestreamv2bundle(op, part):
2253
2253
2254 requirements = urlreq.unquote(part.params['requirements']).split(',')
2254 requirements = urlreq.unquote(part.params['requirements']).split(',')
2255 filecount = int(part.params['filecount'])
2255 filecount = int(part.params['filecount'])
2256 bytecount = int(part.params['bytecount'])
2256 bytecount = int(part.params['bytecount'])
2257
2257
2258 repo = op.repo
2258 repo = op.repo
2259 if len(repo):
2259 if len(repo):
2260 msg = _('cannot apply stream clone to non empty repository')
2260 msg = _('cannot apply stream clone to non empty repository')
2261 raise error.Abort(msg)
2261 raise error.Abort(msg)
2262
2262
2263 repo.ui.debug('applying stream bundle\n')
2263 repo.ui.debug('applying stream bundle\n')
2264 streamclone.applybundlev2(repo, part, filecount, bytecount,
2264 streamclone.applybundlev2(repo, part, filecount, bytecount,
2265 requirements)
2265 requirements)
General Comments 0
You need to be logged in to leave comments. Login now