##// END OF EJS Templates
pager: account for flakiness in Windows output...
Raphaël Gomès -
r48608:89f64fd1 stable draft
parent child Browse files
Show More
@@ -1,438 +1,438 b''
1 1 $ cat >> fakepager.py <<EOF
2 2 > import sys
3 3 > printed = False
4 4 > for line in sys.stdin:
5 5 > sys.stdout.write('paged! %r\n' % line)
6 6 > printed = True
7 7 > if not printed:
8 8 > sys.stdout.write('paged empty output!\n')
9 9 > EOF
10 10
11 11 Enable ui.formatted because pager won't fire without it, and set up
12 12 pager and tell it to use our fake pager that lets us see when the
13 13 pager was running.
14 14 $ cat >> $HGRCPATH <<EOF
15 15 > [ui]
16 16 > formatted = yes
17 17 > color = no
18 18 > [pager]
19 19 > pager = "$PYTHON" $TESTTMP/fakepager.py
20 20 > EOF
21 21
22 22 $ hg init repo
23 23 $ cd repo
24 24 $ echo a >> a
25 25 $ hg add a
26 26 $ hg ci -m 'add a'
27 27 $ for x in `"$PYTHON" $TESTDIR/seq.py 1 10`; do
28 28 > echo a $x >> a
29 29 > hg ci -m "modify a $x"
30 30 > done
31 31
32 32 By default diff and log are paged, but id is not:
33 33
34 34 $ hg diff -c 2 --pager=yes
35 35 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
36 36 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
37 37 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
38 38 paged! '@@ -1,2 +1,3 @@\n'
39 39 paged! ' a\n'
40 40 paged! ' a 1\n'
41 41 paged! '+a 2\n'
42 42
43 43 $ hg log --limit 2
44 44 paged! 'changeset: 10:46106edeeb38\n'
45 45 paged! 'tag: tip\n'
46 46 paged! 'user: test\n'
47 47 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
48 48 paged! 'summary: modify a 10\n'
49 49 paged! '\n'
50 50 paged! 'changeset: 9:6dd8ea7dd621\n'
51 51 paged! 'user: test\n'
52 52 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
53 53 paged! 'summary: modify a 9\n'
54 54 paged! '\n'
55 55
56 56 $ hg id
57 57 46106edeeb38 tip
58 58
59 59 We can control the pager from the config
60 60
61 61 $ hg log --limit 1 --config 'ui.paginate=False'
62 62 changeset: 10:46106edeeb38
63 63 tag: tip
64 64 user: test
65 65 date: Thu Jan 01 00:00:00 1970 +0000
66 66 summary: modify a 10
67 67
68 68 $ hg log --limit 1 --config 'ui.paginate=0'
69 69 changeset: 10:46106edeeb38
70 70 tag: tip
71 71 user: test
72 72 date: Thu Jan 01 00:00:00 1970 +0000
73 73 summary: modify a 10
74 74
75 75 $ hg log --limit 1 --config 'ui.paginate=1'
76 76 paged! 'changeset: 10:46106edeeb38\n'
77 77 paged! 'tag: tip\n'
78 78 paged! 'user: test\n'
79 79 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
80 80 paged! 'summary: modify a 10\n'
81 81 paged! '\n'
82 82
83 83 explicit --pager=on should take precedence over other configurations
84 84 (issue5580)
85 85
86 86 $ cat >> $HGRCPATH <<EOF
87 87 > [ui]
88 88 > paginate = false
89 89 > EOF
90 90 $ hg log --limit 1 --pager=on
91 91 paged! 'changeset: 10:46106edeeb38\n'
92 92 paged! 'tag: tip\n'
93 93 paged! 'user: test\n'
94 94 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
95 95 paged! 'summary: modify a 10\n'
96 96 paged! '\n'
97 97
98 98 $ cat >> $HGRCPATH <<EOF
99 99 > [ui]
100 100 > # true is default value of ui.paginate
101 101 > paginate = true
102 102 > EOF
103 103 $ hg log --limit 1 --pager=off
104 104 changeset: 10:46106edeeb38
105 105 tag: tip
106 106 user: test
107 107 date: Thu Jan 01 00:00:00 1970 +0000
108 108 summary: modify a 10
109 109
110 110
111 111 We can enable the pager on id:
112 112
113 113 BROKEN: should be paged
114 114 $ hg --config pager.attend-id=yes id
115 115 46106edeeb38 tip
116 116
117 117 Setting attend-$COMMAND to a false value works, even with pager in
118 118 core:
119 119 $ hg --config pager.attend-diff=no diff -c 2
120 120 diff -r f4be7687d414 -r bce265549556 a
121 121 --- a/a Thu Jan 01 00:00:00 1970 +0000
122 122 +++ b/a Thu Jan 01 00:00:00 1970 +0000
123 123 @@ -1,2 +1,3 @@
124 124 a
125 125 a 1
126 126 +a 2
127 127
128 128 Command aliases should have same behavior as main command
129 129
130 130 $ hg history --limit 2
131 131 paged! 'changeset: 10:46106edeeb38\n'
132 132 paged! 'tag: tip\n'
133 133 paged! 'user: test\n'
134 134 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
135 135 paged! 'summary: modify a 10\n'
136 136 paged! '\n'
137 137 paged! 'changeset: 9:6dd8ea7dd621\n'
138 138 paged! 'user: test\n'
139 139 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
140 140 paged! 'summary: modify a 9\n'
141 141 paged! '\n'
142 142
143 143 Abbreviated command alias should also be paged
144 144
145 145 $ hg hist -l 1
146 146 paged! 'changeset: 10:46106edeeb38\n'
147 147 paged! 'tag: tip\n'
148 148 paged! 'user: test\n'
149 149 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
150 150 paged! 'summary: modify a 10\n'
151 151 paged! '\n'
152 152
153 153 Attend for an abbreviated command does not work
154 154
155 155 $ hg --config pager.attend-ident=true ident
156 156 46106edeeb38 tip
157 157
158 158 $ hg --config extensions.pager= --config pager.attend-ident=true ident
159 159 46106edeeb38 tip
160 160
161 161 Pager should not start if stdout is not a tty.
162 162
163 163 $ hg log -l1 -q --config ui.formatted=False
164 164 10:46106edeeb38
165 165
166 166 Pager should be disabled if pager.pager is empty (otherwise the output would
167 167 be silently lost.)
168 168
169 169 $ hg log -l1 -q --config pager.pager=
170 170 10:46106edeeb38
171 171
172 172 Pager with color enabled allows colors to come through by default,
173 173 even though stdout is no longer a tty.
174 174 $ cat >> $HGRCPATH <<EOF
175 175 > [ui]
176 176 > color = always
177 177 > [color]
178 178 > mode = ansi
179 179 > EOF
180 180 $ hg log --limit 3
181 181 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
182 182 paged! 'tag: tip\n'
183 183 paged! 'user: test\n'
184 184 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
185 185 paged! 'summary: modify a 10\n'
186 186 paged! '\n'
187 187 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
188 188 paged! 'user: test\n'
189 189 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
190 190 paged! 'summary: modify a 9\n'
191 191 paged! '\n'
192 192 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
193 193 paged! 'user: test\n'
194 194 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
195 195 paged! 'summary: modify a 8\n'
196 196 paged! '\n'
197 197
198 198 #if no-chg
199 199 An invalid pager command name is reported sensibly if we don't have to
200 200 use shell=True in the subprocess call:
201 201 $ hg log --limit 3 --config pager.pager=this-command-better-never-exist
202 202 missing pager command 'this-command-better-never-exist', skipping pager
203 203 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
204 204 tag: tip
205 205 user: test
206 206 date: Thu Jan 01 00:00:00 1970 +0000
207 207 summary: modify a 10
208 208
209 209 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
210 210 user: test
211 211 date: Thu Jan 01 00:00:00 1970 +0000
212 212 summary: modify a 9
213 213
214 214 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
215 215 user: test
216 216 date: Thu Jan 01 00:00:00 1970 +0000
217 217 summary: modify a 8
218 218
219 219 #endif
220 220
221 221 A complicated pager command gets worse behavior. Bonus points if you can
222 improve this. Windows apparently does this better?
222 improve this. Windows apparently does this better, but only sometimes?
223 223 #if windows
224 224 $ hg log --limit 3 \
225 225 > --config pager.pager='this-command-better-never-exist --seriously' \
226 226 > 2>/dev/null || true
227 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc)
228 tag: tip
229 user: test
230 date: Thu Jan 01 00:00:00 1970 +0000
231 summary: modify a 10
232
233 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc)
234 user: test
235 date: Thu Jan 01 00:00:00 1970 +0000
236 summary: modify a 9
237
238 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc)
239 user: test
240 date: Thu Jan 01 00:00:00 1970 +0000
241 summary: modify a 8
227 \x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m (esc) (?)
228 tag: tip (?)
229 user: test (?)
230 date: Thu Jan 01 00:00:00 1970 +0000 (?)
231 summary: modify a 10 (?)
232 (?)
233 \x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m (esc) (?)
234 user: test (?)
235 date: Thu Jan 01 00:00:00 1970 +0000 (?)
236 summary: modify a 9 (?)
237 (?)
238 \x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m (esc) (?)
239 user: test (?)
240 date: Thu Jan 01 00:00:00 1970 +0000 (?)
241 summary: modify a 8 (?)
242 242
243 243 #else
244 244 $ hg log --limit 3 \
245 245 > --config pager.pager='this-command-better-never-exist --seriously' \
246 246 > 2>/dev/null || true
247 247 #endif
248 248
249 249 Pager works with shell aliases.
250 250
251 251 $ cat >> $HGRCPATH <<EOF
252 252 > [alias]
253 253 > echoa = !echo a
254 254 > EOF
255 255
256 256 $ hg echoa
257 257 a
258 258 BROKEN: should be paged
259 259 $ hg --config pager.attend-echoa=yes echoa
260 260 a
261 261
262 262 Pager works with hg aliases including environment variables.
263 263
264 264 $ cat >> $HGRCPATH <<'EOF'
265 265 > [alias]
266 266 > printa = log -T "$A\n" -r 0
267 267 > EOF
268 268
269 269 $ A=1 hg --config pager.attend-printa=yes printa
270 270 paged! '1\n'
271 271 $ A=2 hg --config pager.attend-printa=yes printa
272 272 paged! '2\n'
273 273
274 274 Something that's explicitly attended is still not paginated if the
275 275 pager is globally set to off using a flag:
276 276 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
277 277 2
278 278
279 279 Pager should not override the exit code of other commands
280 280
281 281 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
282 282 > from mercurial import commands, registrar
283 283 > cmdtable = {}
284 284 > command = registrar.command(cmdtable)
285 285 > @command(b'fortytwo', [], b'fortytwo', norepo=True)
286 286 > def fortytwo(ui, *opts):
287 287 > ui.write(b'42\n')
288 288 > return 42
289 289 > EOF
290 290
291 291 $ cat >> $HGRCPATH <<'EOF'
292 292 > [extensions]
293 293 > fortytwo = $TESTTMP/fortytwo.py
294 294 > EOF
295 295
296 296 $ hg fortytwo --pager=on
297 297 paged! '42\n'
298 298 [42]
299 299
300 300 A command that asks for paging using ui.pager() directly works:
301 301 $ hg blame a
302 302 paged! ' 0: a\n'
303 303 paged! ' 1: a 1\n'
304 304 paged! ' 2: a 2\n'
305 305 paged! ' 3: a 3\n'
306 306 paged! ' 4: a 4\n'
307 307 paged! ' 5: a 5\n'
308 308 paged! ' 6: a 6\n'
309 309 paged! ' 7: a 7\n'
310 310 paged! ' 8: a 8\n'
311 311 paged! ' 9: a 9\n'
312 312 paged! '10: a 10\n'
313 313 but not with HGPLAIN
314 314 $ HGPLAIN=1 hg blame a
315 315 0: a
316 316 1: a 1
317 317 2: a 2
318 318 3: a 3
319 319 4: a 4
320 320 5: a 5
321 321 6: a 6
322 322 7: a 7
323 323 8: a 8
324 324 9: a 9
325 325 10: a 10
326 326 explicit flags work too:
327 327 $ hg blame --pager=no a
328 328 0: a
329 329 1: a 1
330 330 2: a 2
331 331 3: a 3
332 332 4: a 4
333 333 5: a 5
334 334 6: a 6
335 335 7: a 7
336 336 8: a 8
337 337 9: a 9
338 338 10: a 10
339 339
340 340 A command with --output option:
341 341
342 342 $ hg cat -r0 a
343 343 paged! 'a\n'
344 344 $ hg cat -r0 a --output=-
345 345 paged! 'a\n'
346 346 $ hg cat -r0 a --output=out
347 347
348 348 $ hg export -r0
349 349 paged! '# HG changeset patch\n'
350 350 paged! '# User test\n'
351 351 paged! '# Date 0 0\n'
352 352 paged! '# Thu Jan 01 00:00:00 1970 +0000\n'
353 353 paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
354 354 paged! '# Parent 0000000000000000000000000000000000000000\n'
355 355 paged! 'add a\n'
356 356 paged! '\n'
357 357 paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
358 358 paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
359 359 paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
360 360 paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
361 361 paged! '\x1b[0;32m+a\x1b[0m\n'
362 362 $ hg export -r0 -o -
363 363 paged! '# HG changeset patch\n'
364 364 paged! '# User test\n'
365 365 paged! '# Date 0 0\n'
366 366 paged! '# Thu Jan 01 00:00:00 1970 +0000\n'
367 367 paged! '# Node ID 1f0dee641bb7258c56bd60e93edfa2405381c41e\n'
368 368 paged! '# Parent 0000000000000000000000000000000000000000\n'
369 369 paged! 'add a\n'
370 370 paged! '\n'
371 371 paged! '\x1b[0;1mdiff -r 000000000000 -r 1f0dee641bb7 a\x1b[0m\n'
372 372 paged! '\x1b[0;31;1m--- /dev/null\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
373 373 paged! '\x1b[0;32;1m+++ b/a\tThu Jan 01 00:00:00 1970 +0000\x1b[0m\n'
374 374 paged! '\x1b[0;35m@@ -0,0 +1,1 @@\x1b[0m\n'
375 375 paged! '\x1b[0;32m+a\x1b[0m\n'
376 376 $ hg export -r0 -o out
377 377
378 378 $ rm out
379 379
380 380 Put annotate in the ignore list for pager:
381 381 $ cat >> $HGRCPATH <<EOF
382 382 > [pager]
383 383 > ignore = annotate
384 384 > EOF
385 385 $ hg blame a
386 386 0: a
387 387 1: a 1
388 388 2: a 2
389 389 3: a 3
390 390 4: a 4
391 391 5: a 5
392 392 6: a 6
393 393 7: a 7
394 394 8: a 8
395 395 9: a 9
396 396 10: a 10
397 397
398 398 During pushbuffer, pager should not start:
399 399 $ cat > $TESTTMP/pushbufferpager.py <<EOF
400 400 > def uisetup(ui):
401 401 > ui.pushbuffer()
402 402 > ui.pager(b'mycmd')
403 403 > ui.write(b'content\n')
404 404 > ui.write(ui.popbuffer())
405 405 > EOF
406 406
407 407 $ echo append >> a
408 408 $ hg --config extensions.pushbuffer=$TESTTMP/pushbufferpager.py status --color=off
409 409 content
410 410 paged! 'M a\n'
411 411
412 412 Environment variables like LESS and LV are set automatically:
413 413 $ cat > $TESTTMP/printlesslv.py <<EOF
414 414 > from __future__ import absolute_import
415 415 > import os
416 416 > import sys
417 417 > sys.stdin.read()
418 418 > for name in ['LESS', 'LV']:
419 419 > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-')))
420 420 > sys.stdout.flush()
421 421 > EOF
422 422
423 423 $ cat >> $HGRCPATH <<EOF
424 424 > [alias]
425 425 > noop = log -r 0 -T ''
426 426 > [ui]
427 427 > formatted=1
428 428 > [pager]
429 429 > pager = "$PYTHON" $TESTTMP/printlesslv.py
430 430 > EOF
431 431 $ unset LESS
432 432 $ unset LV
433 433 $ hg noop --pager=on
434 434 LESS=FRX
435 435 LV=-c
436 436 $ LESS=EFGH hg noop --pager=on
437 437 LESS=EFGH
438 438 LV=-c
General Comments 0
You need to be logged in to leave comments. Login now