##// END OF EJS Templates
bundle2: add ability to write to a file to the test...
Pierre-Yves David -
r20841:cff562fe default
parent child Browse files
Show More
@@ -1,170 +1,186 b''
1 1
2 2 Create an extension to test bundle2 API
3 3
4 4 $ cat > bundle2.py << EOF
5 5 > """A small extension to test bundle2 implementation
6 6 >
7 7 > Current bundle2 implementation is far too limited to be used in any core
8 8 > code. We still need to be able to test it while it grow up.
9 9 > """
10 10 >
11 11 > import sys
12 12 > from mercurial import cmdutil
13 13 > from mercurial import util
14 14 > from mercurial import bundle2
15 15 > cmdtable = {}
16 16 > command = cmdutil.command(cmdtable)
17 17 >
18 18 > @command('bundle2',
19 19 > [('', 'param', [], 'stream level parameter'),],
20 > '')
21 > def cmdbundle2(ui, repo, **opts):
20 > '[OUTPUTFILE]')
21 > def cmdbundle2(ui, repo, path=None, **opts):
22 22 > """write a bundle2 container on standard ouput"""
23 23 > bundler = bundle2.bundle20()
24 24 > for p in opts['param']:
25 25 > p = p.split('=', 1)
26 26 > try:
27 27 > bundler.addparam(*p)
28 28 > except ValueError, exc:
29 29 > raise util.Abort('%s' % exc)
30 30 >
31 > if path is None:
32 > file = sys.stdout
33 > else:
34 > file = open(path, 'w')
35 >
31 36 > for chunk in bundler.getchunks():
32 > ui.write(chunk)
37 > file.write(chunk)
33 38 >
34 39 > @command('unbundle2', [], '')
35 40 > def cmdunbundle2(ui, repo):
36 41 > """read a bundle2 container from standard input"""
37 42 > unbundler = bundle2.unbundle20(sys.stdin)
38 43 > ui.write('options count: %i\n' % len(unbundler.params))
39 44 > for key in sorted(unbundler.params):
40 45 > ui.write('- %s\n' % key)
41 46 > value = unbundler.params[key]
42 47 > if value is not None:
43 48 > ui.write(' %s\n' % value)
44 49 > parts = list(unbundler)
45 50 > ui.write('parts count: %i\n' % len(parts))
46 51 > EOF
47 52 $ cat >> $HGRCPATH << EOF
48 53 > [extensions]
49 54 > bundle2=$TESTTMP/bundle2.py
50 55 > EOF
51 56
52 57 The extension requires a repo (currently unused)
53 58
54 59 $ hg init main
55 60 $ cd main
56 61 $ touch a
57 62 $ hg add a
58 63 $ hg commit -m 'a'
59 64
60 65
61 66 Empty bundle
62 67 =================
63 68
64 69 - no option
65 70 - no parts
66 71
67 72 Test bundling
68 73
69 74 $ hg bundle2
70 75 HG20\x00\x00\x00\x00 (no-eol) (esc)
71 76
72 77 Test unbundling
73 78
74 79 $ hg bundle2 | hg unbundle2
75 80 options count: 0
76 81 parts count: 0
77 82
78 83 Test old style bundle are detected and refused
79 84
80 85 $ hg bundle --all ../bundle.hg
81 86 1 changesets found
82 87 $ hg unbundle2 < ../bundle.hg
83 88 abort: unknown bundle version 10
84 89 [255]
85 90
86 91 Test parameters
87 92 =================
88 93
89 94 - some options
90 95 - no parts
91 96
92 97 advisory parameters, no value
93 98 -------------------------------
94 99
95 100 Simplest possible parameters form
96 101
97 102 Test generation simple option
98 103
99 104 $ hg bundle2 --param 'caution'
100 105 HG20\x00\x07caution\x00\x00 (no-eol) (esc)
101 106
102 107 Test unbundling
103 108
104 109 $ hg bundle2 --param 'caution' | hg unbundle2
105 110 options count: 1
106 111 - caution
107 112 parts count: 0
108 113
109 114 Test generation multiple option
110 115
111 116 $ hg bundle2 --param 'caution' --param 'meal'
112 117 HG20\x00\x0ccaution meal\x00\x00 (no-eol) (esc)
113 118
114 119 Test unbundling
115 120
116 121 $ hg bundle2 --param 'caution' --param 'meal' | hg unbundle2
117 122 options count: 2
118 123 - caution
119 124 - meal
120 125 parts count: 0
121 126
122 127 advisory parameters, with value
123 128 -------------------------------
124 129
125 130 Test generation
126 131
127 132 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants'
128 133 HG20\x00\x1ccaution meal=vegan elephants\x00\x00 (no-eol) (esc)
129 134
130 135 Test unbundling
131 136
132 137 $ hg bundle2 --param 'caution' --param 'meal=vegan' --param 'elephants' | hg unbundle2
133 138 options count: 3
134 139 - caution
135 140 - elephants
136 141 - meal
137 142 vegan
138 143 parts count: 0
139 144
140 145 parameter with special char in value
141 146 ---------------------------------------------------
142 147
143 148 Test generation
144 149
145 150 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple
146 151 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
147 152
148 153 Test unbundling
149 154
150 155 $ hg bundle2 --param 'e|! 7/=babar%#==tutu' --param simple | hg unbundle2
151 156 options count: 2
152 157 - e|! 7/
153 158 babar%#==tutu
154 159 - simple
155 160 parts count: 0
156 161
162 Test debug output
163 ---------------------------------------------------
164 (no debug output yet)
165
166 $ hg bundle2 --debug --param 'e|! 7/=babar%#==tutu' --param simple ../out.hg2
167
168 file content is ok
169
170 $ cat ../out.hg2
171 HG20\x00)e%7C%21%207/=babar%25%23%3D%3Dtutu simple\x00\x00 (no-eol) (esc)
172
157 173 Test buggy input
158 174 ---------------------------------------------------
159 175
160 176 empty parameter name
161 177
162 178 $ hg bundle2 --param '' --quiet
163 179 abort: empty parameter name
164 180 [255]
165 181
166 182 bad parameter name
167 183
168 184 $ hg bundle2 --param 42babar
169 185 abort: non letter first character: '42babar'
170 186 [255]
General Comments 0
You need to be logged in to leave comments. Login now