From: | Greg Stark <stark(at)mit(dot)edu> |
---|---|
To: | Bruce Momjian <bruce(at)momjian(dot)us> |
Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: pg_get_viewdefs() indentation considered harmful |
Date: | 2014-04-29 18:25:23 |
Message-ID: | CAM-w4HN8d_HY1rGQ_j5fa58+AO-MF0aFPbNZdPYGzPnhvv8YXg@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
I propose the attached patch. It wraps at 40 and also divides the
indent level by half the std indent level. I tried a few different
combinations and this is the one that produced the output I liked
best. I attached the output for the pg_seclabels view (the only one
the regression tests noticed changed) and a simple view consisting of
many nested unions.
$ git diff | filterdiff --format=context | tee /tmp/wrap-psql-indent-level.patch
*** a/src/backend/utils/adt/ruleutils.c
--- b/src/backend/utils/adt/ruleutils.c
***************
*** 6398,6405 **** appendContextKeyword(deparse_context *context,
const char *str,
removeStringInfoSpaces(buf);
/* ... then add a newline and some spaces */
appendStringInfoChar(buf, '\n');
! appendStringInfoSpaces(buf,
! Max(context->indentLevel, 0) + indentPlus);
appendStringInfoString(buf, str);
--- 6398,6419 ----
removeStringInfoSpaces(buf);
/* ... then add a newline and some spaces */
appendStringInfoChar(buf, '\n');
!
! if (context->indentLevel <= 40)
! appendStringInfoSpaces(buf,
! Max(context->indentLevel, 0) + indentPlus);
!
! else
! {
! /* If we're indented > 40 characters try to conserve horizontal
! * space. Specifically it's important that the indentation not
! * grow unboundedly or else the size of some queries is
! * O(n^2). Wrapping modulo 40 guarantees at most a linear blowup
! * in size. */
! unsigned wrapped_indent = context->indentLevel + indentPlus;
! wrapped_indent = (wrapped_indent / (PRETTYINDENT_STD/2)) % 40;
! appendStringInfoSpaces(buf, wrapped_indent);
! }
appendStringInfoString(buf, str);
Attachment | Content-Type | Size |
---|---|---|
test_view | application/octet-stream | 70.1 KB |
wrap-psql-indent-level.patch | text/x-patch | 1.2 KB |
pg_seclabels | application/octet-stream | 21.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-04-29 18:46:11 | Re: pg_get_viewdefs() indentation considered harmful |
Previous Message | Hello World | 2014-04-29 18:19:03 | libpq: How to get the error code after a failed PGconn connection |