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