Re: pg_get_viewdefs() indentation considered harmful

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: pg_get_viewdefs() indentation considered harmful
Дата
Msg-id CAM-w4HN8d_HY1rGQ_j5fa58+AO-MF0aFPbNZdPYGzPnhvv8YXg@mail.gmail.com
обсуждение исходный текст
Ответ на pg_get_viewdefs() indentation considered harmful  (Greg Stark <stark@mit.edu>)
Список 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);

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Hello World
Дата:
Сообщение: libpq: How to get the error code after a failed PGconn connection
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pg_get_viewdefs() indentation considered harmful