forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit440fcc5
committed
Fix psql \s to work with recent libedit, and add pager support.
psql's \s (print command history) doesn't work at all with recent libeditversions when printing to the terminal, because libedit tries to do anfchmod() on the target file which will fail if the target is /dev/tty.(We'd already noted this in the context of the target being /dev/null.)Even before that, it didn't work pleasantly, because libedit likes toencode the command history file (to ensure successful reloading), whichrenders it nigh unreadable, not to mention significantly different-lookingdepending on exactly which libedit version you have. So let's forget usingwrite_history() for this purpose, and instead print the data ourselves,using logic similar to that used to iterate over the history for newlineencoding/decoding purposes.While we're at it, insert the ability to use the pager when \s is printingto the terminal. This has been an acknowledged shortcoming of \s for manyyears, so while you could argue it's not exactly a back-patchable bug fixit still seems like a good improvement. Anyone who's seriously annoyedat this can use "\s /dev/tty" or local equivalent to get the old behavior.Experimentation with this showed that the history iteration logic wasactually rather broken when used with libedit. It turns out that withlibedit you have to use previous_history() not next_history() to advanceto more recent history entries. The easiest and most robust fix for thisseems to be to make a run-time test to verify which function to call.We had not noticed this because libedit doesn't really need the newlineencoding logic: its own encoding ensures that command entries containingnewlines are reloaded correctly (unlike libreadline). So the effectivebehavior with recent libedits was that only the oldest history entry gotnewline-encoded or newline-decoded. However, because of yet other bugs inhistory_set_pos(), some old versions of libedit allowed the existing looplogic to reach entries besides the oldest, which means there may be libedit~/.psql_history files out there containing encoded newlines in more thanjust the oldest entry. To ensure we can reload such files, it seemsappropriate to back-patch this fix, even though that will result in someincompatibility with older psql versions (ie, multiline history entrieswritten by a psql with this fix will look corrupted to a psql without it,if its libedit is reasonably up to date).Stepan Rutz and Tom Lane1 parent61d7c6d commit440fcc5
File tree
4 files changed
+144
-52
lines changed- doc/src/sgml/ref
- src/bin/psql
4 files changed
+144
-52
lines changedLines changed: 9 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
261 | 261 |
| |
262 | 262 |
| |
263 | 263 |
| |
264 |
| - | |
| 264 | + | |
| 265 | + | |
265 | 266 |
| |
266 | 267 |
| |
267 | 268 |
| |
| |||
2173 | 2174 |
| |
2174 | 2175 |
| |
2175 | 2176 |
| |
2176 |
| - | |
2177 |
| - | |
2178 |
| - | |
2179 |
| - | |
2180 |
| - | |
2181 |
| - | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
| 2180 | + | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
2182 | 2184 |
| |
2183 | 2185 |
| |
2184 | 2186 |
| |
|
Lines changed: 1 addition & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1046 | 1046 |
| |
1047 | 1047 |
| |
1048 | 1048 |
| |
1049 |
| - | |
1050 |
| - | |
1051 |
| - | |
1052 |
| - | |
1053 |
| - | |
1054 |
| - | |
1055 |
| - | |
1056 |
| - | |
1057 |
| - | |
1058 |
| - | |
1059 |
| - | |
1060 | 1049 |
| |
1061 |
| - | |
1062 |
| - | |
| 1050 | + | |
1063 | 1051 |
| |
1064 | 1052 |
| |
1065 | 1053 |
| |
|
Lines changed: 132 additions & 31 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| 14 | + | |
14 | 15 |
| |
15 | 16 |
| |
16 | 17 |
| |
| |||
227 | 228 |
| |
228 | 229 |
| |
229 | 230 |
| |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
230 | 280 |
| |
231 | 281 |
| |
232 | 282 |
| |
233 | 283 |
| |
234 | 284 |
| |
235 | 285 |
| |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 |
| - | |
240 |
| - | |
| 286 | + | |
241 | 287 |
| |
| 288 | + | |
| 289 | + | |
242 | 290 |
| |
243 | 291 |
| |
| 292 | + | |
244 | 293 |
| |
245 | 294 |
| |
| 295 | + | |
246 | 296 |
| |
| 297 | + | |
247 | 298 |
| |
248 | 299 |
| |
249 | 300 |
| |
| |||
252 | 303 |
| |
253 | 304 |
| |
254 | 305 |
| |
255 |
| - | |
256 |
| - | |
257 |
| - | |
258 |
| - | |
259 |
| - | |
| 306 | + | |
260 | 307 |
| |
| 308 | + | |
| 309 | + | |
261 | 310 |
| |
262 | 311 |
| |
| 312 | + | |
263 | 313 |
| |
264 | 314 |
| |
| 315 | + | |
265 | 316 |
| |
| 317 | + | |
266 | 318 |
| |
267 | 319 |
| |
268 | 320 |
| |
| |||
322 | 374 |
| |
323 | 375 |
| |
324 | 376 |
| |
325 |
| - | |
326 |
| - | |
| 377 | + | |
327 | 378 |
| |
328 | 379 |
| |
329 | 380 |
| |
330 | 381 |
| |
331 | 382 |
| |
332 |
| - | |
333 |
| - | |
334 |
| - | |
335 |
| - | |
336 |
| - | |
337 |
| - | |
338 | 383 |
| |
339 |
| - | |
340 |
| - | |
| 384 | + | |
| 385 | + | |
341 | 386 |
| |
342 | 387 |
| |
343 | 388 |
| |
| |||
347 | 392 |
| |
348 | 393 |
| |
349 | 394 |
| |
350 |
| - | |
351 |
| - | |
| 395 | + | |
352 | 396 |
| |
353 |
| - | |
354 |
| - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
355 | 404 |
| |
356 | 405 |
| |
357 | 406 |
| |
| |||
365 | 414 |
| |
366 | 415 |
| |
367 | 416 |
| |
368 |
| - | |
369 | 417 |
| |
370 | 418 |
| |
371 | 419 |
| |
| |||
390 | 438 |
| |
391 | 439 |
| |
392 | 440 |
| |
393 |
| - | |
394 |
| - | |
| 441 | + | |
395 | 442 |
| |
396 | 443 |
| |
397 | 444 |
| |
| |||
402 | 449 |
| |
403 | 450 |
| |
404 | 451 |
| |
| 452 | + | |
405 | 453 |
| |
406 | 454 |
| |
407 | 455 |
| |
408 | 456 |
| |
409 |
| - | |
410 |
| - | |
411 |
| - | |
412 | 457 |
| |
413 | 458 |
| |
414 | 459 |
| |
415 | 460 |
| |
416 | 461 |
| |
417 | 462 |
| |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
418 | 519 |
| |
419 | 520 |
| |
420 | 521 |
| |
| |||
428 | 529 |
| |
429 | 530 |
| |
430 | 531 |
| |
431 |
| - | |
| 532 | + | |
432 | 533 |
| |
433 | 534 |
| |
434 | 535 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
42 | 42 |
| |
43 | 43 |
| |
44 | 44 |
| |
45 |
| - | |
| 45 | + | |
| 46 | + | |
46 | 47 |
| |
47 | 48 |
| |
48 | 49 |
| |
|
0 commit comments
Comments
(0)