1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-05 07:41:25 +03:00

Fix pgindent to properly handle 'else' and single-line comments on the

same line;  previous fix was only partial.  Re-run pgindent on files
that need it.
This commit is contained in:
Bruce Momjian
2007-11-15 23:23:44 +00:00
parent f6e8730d11
commit 7d4c99b414
7 changed files with 209 additions and 169 deletions

View File

@@ -41,7 +41,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.41 2007/08/01 22:45:07 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/slru.c,v 1.42 2007/11/15 23:23:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -669,21 +669,22 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
int fd = -1; int fd = -1;
/* /*
* Honor the write-WAL-before-data rule, if appropriate, so that we do * Honor the write-WAL-before-data rule, if appropriate, so that we do not
* not write out data before associated WAL records. This is the same * write out data before associated WAL records. This is the same action
* action performed during FlushBuffer() in the main buffer manager. * performed during FlushBuffer() in the main buffer manager.
*/ */
if (shared->group_lsn != NULL) if (shared->group_lsn != NULL)
{ {
/* /*
* We must determine the largest async-commit LSN for the page. * We must determine the largest async-commit LSN for the page. This
* This is a bit tedious, but since this entire function is a slow * is a bit tedious, but since this entire function is a slow path
* path anyway, it seems better to do this here than to maintain * anyway, it seems better to do this here than to maintain a per-page
* a per-page LSN variable (which'd need an extra comparison in the * LSN variable (which'd need an extra comparison in the
* transaction-commit path). * transaction-commit path).
*/ */
XLogRecPtr max_lsn; XLogRecPtr max_lsn;
int lsnindex, lsnoff; int lsnindex,
lsnoff;
lsnindex = slotno * shared->lsn_groups_per_page; lsnindex = slotno * shared->lsn_groups_per_page;
max_lsn = shared->group_lsn[lsnindex++]; max_lsn = shared->group_lsn[lsnindex++];
@@ -699,8 +700,8 @@ SlruPhysicalWritePage(SlruCtl ctl, int pageno, int slotno, SlruFlush fdata)
{ {
/* /*
* As noted above, elog(ERROR) is not acceptable here, so if * As noted above, elog(ERROR) is not acceptable here, so if
* XLogFlush were to fail, we must PANIC. This isn't much of * XLogFlush were to fail, we must PANIC. This isn't much of a
* a restriction because XLogFlush is just about all critical * restriction because XLogFlush is just about all critical
* section anyway, but let's make sure. * section anyway, but let's make sure.
*/ */
START_CRIT_SECTION(); START_CRIT_SECTION();

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.222 2007/11/05 19:00:25 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.223 2007/11/15 23:23:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -211,10 +211,10 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid)
} }
/* /*
* If the command is a user-entered CREATE CONSTRAINT TRIGGER command * If the command is a user-entered CREATE CONSTRAINT TRIGGER command that
* that references one of the built-in RI_FKey trigger functions, assume * references one of the built-in RI_FKey trigger functions, assume it is
* it is from a dump of a pre-7.3 foreign key constraint, and take steps * from a dump of a pre-7.3 foreign key constraint, and take steps to
* to convert this legacy representation into a regular foreign key * convert this legacy representation into a regular foreign key
* constraint. Ugly, but necessary for loading old dump files. * constraint. Ugly, but necessary for loading old dump files.
*/ */
if (stmt->isconstraint && !OidIsValid(constraintOid) && if (stmt->isconstraint && !OidIsValid(constraintOid) &&
@@ -421,8 +421,8 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid)
{ {
/* /*
* It's for a constraint, so make it an internal dependency of the * It's for a constraint, so make it an internal dependency of the
* constraint. We can skip depending on the relations, as there'll * constraint. We can skip depending on the relations, as there'll be
* be an indirect dependency via the constraint. * an indirect dependency via the constraint.
*/ */
referenced.classId = ConstraintRelationId; referenced.classId = ConstraintRelationId;
referenced.objectId = constraintOid; referenced.objectId = constraintOid;
@@ -475,7 +475,8 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid)
* We match triggers together by comparing the trigger arguments (which * We match triggers together by comparing the trigger arguments (which
* include constraint name, table and column names, so should be good enough). * include constraint name, table and column names, so should be good enough).
*/ */
typedef struct { typedef struct
{
List *args; /* list of (T_String) Values or NIL */ List *args; /* list of (T_String) Values or NIL */
Oid funcoids[3]; /* OIDs of trigger functions */ Oid funcoids[3]; /* OIDs of trigger functions */
/* The three function OIDs are stored in the order update, delete, child */ /* The three function OIDs are stored in the order update, delete, child */
@@ -2905,8 +2906,8 @@ AfterTriggerFireDeferred(void)
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot()); ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
/* /*
* Run all the remaining triggers. Loop until they are all gone, in * Run all the remaining triggers. Loop until they are all gone, in case
* case some trigger queues more for us to do. * some trigger queues more for us to do.
*/ */
while (afterTriggerMarkEvents(events, NULL, false)) while (afterTriggerMarkEvents(events, NULL, false))
{ {
@@ -2940,13 +2941,13 @@ AfterTriggerEndXact(bool isCommit)
* *
* Since all the info is in TopTransactionContext or children thereof, we * Since all the info is in TopTransactionContext or children thereof, we
* don't really need to do anything to reclaim memory. However, the * don't really need to do anything to reclaim memory. However, the
* pending-events list could be large, and so it's useful to discard * pending-events list could be large, and so it's useful to discard it as
* it as soon as possible --- especially if we are aborting because we * soon as possible --- especially if we are aborting because we ran out
* ran out of memory for the list! * of memory for the list!
* *
* (Note: any event_cxts of child subtransactions could also be * (Note: any event_cxts of child subtransactions could also be deleted
* deleted here, but we have no convenient way to find them, so we * here, but we have no convenient way to find them, so we leave it to
* leave it to TopTransactionContext reset to clean them up.) * TopTransactionContext reset to clean them up.)
*/ */
if (afterTriggers && afterTriggers->event_cxt) if (afterTriggers && afterTriggers->event_cxt)
MemoryContextDelete(afterTriggers->event_cxt); MemoryContextDelete(afterTriggers->event_cxt);
@@ -2973,9 +2974,8 @@ AfterTriggerBeginSubXact(void)
/* /*
* Allocate more space in the stacks if needed. (Note: because the * Allocate more space in the stacks if needed. (Note: because the
* minimum nest level of a subtransaction is 2, we waste the first * minimum nest level of a subtransaction is 2, we waste the first couple
* couple entries of each array; not worth the notational effort to * entries of each array; not worth the notational effort to avoid it.)
* avoid it.)
*/ */
while (my_level >= afterTriggers->maxtransdepth) while (my_level >= afterTriggers->maxtransdepth)
{ {
@@ -3071,16 +3071,17 @@ AfterTriggerEndSubXact(bool isCommit)
afterTriggers->state_stack[my_level] = NULL; afterTriggers->state_stack[my_level] = NULL;
Assert(afterTriggers->query_depth == Assert(afterTriggers->query_depth ==
afterTriggers->depth_stack[my_level]); afterTriggers->depth_stack[my_level]);
/* /*
* It's entirely possible that the subxact created an event_cxt but * It's entirely possible that the subxact created an event_cxt but
* there is not anything left in it (because all the triggers were * there is not anything left in it (because all the triggers were
* fired at end-of-statement). If so, we should release the context * fired at end-of-statement). If so, we should release the context
* to prevent memory leakage in a long sequence of subtransactions. * to prevent memory leakage in a long sequence of subtransactions. We
* We can detect whether there's anything of use in the context by * can detect whether there's anything of use in the context by seeing
* seeing if anything was added to the global events list since * if anything was added to the global events list since subxact
* subxact start. (This test doesn't catch every case where the * start. (This test doesn't catch every case where the context is
* context is deletable; for instance maybe the only additions were * deletable; for instance maybe the only additions were from a
* from a sub-sub-xact. But it handles the common case.) * sub-sub-xact. But it handles the common case.)
*/ */
if (afterTriggers->cxt_stack[my_level] && if (afterTriggers->cxt_stack[my_level] &&
afterTriggers->events.tail == afterTriggers->events_stack[my_level].tail) afterTriggers->events.tail == afterTriggers->events_stack[my_level].tail)

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.174 2007/09/06 17:31:58 tgl Exp $ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.175 2007/11/15 23:23:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -1038,11 +1038,10 @@ matchLocks(CmdType event,
RewriteRule *oneLock = rulelocks->rules[i]; RewriteRule *oneLock = rulelocks->rules[i];
/* /*
* Suppress ON INSERT/UPDATE/DELETE rules that are disabled * Suppress ON INSERT/UPDATE/DELETE rules that are disabled or
* or configured to not fire during the current sessions * configured to not fire during the current sessions replication
* replication role. ON SELECT rules will always be applied * role. ON SELECT rules will always be applied in order to keep views
* in order to keep views working even in LOCAL or REPLICA * working even in LOCAL or REPLICA role.
* role.
*/ */
if (oneLock->event != CMD_SELECT) if (oneLock->event != CMD_SELECT)
{ {

View File

@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.7 2007/10/24 03:30:03 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.8 2007/11/15 23:23:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -482,8 +482,8 @@ tsvector_concat(PG_FUNCTION_ARGS)
} }
/* /*
* Instead of checking each offset individually, we check for overflow * Instead of checking each offset individually, we check for overflow of
* of pos fields once at the end. * pos fields once at the end.
*/ */
if (dataoff > MAXSTRPOS) if (dataoff > MAXSTRPOS)
ereport(ERROR, ereport(ERROR,

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.63 2007/03/25 11:56:02 ishii Exp $ * $PostgreSQL: pgsql/src/backend/utils/mb/conv.c,v 1.64 2007/11/15 23:23:44 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@@ -274,7 +274,10 @@ compare2(const void *p1, const void *p2)
static int static int
compare3(const void *p1, const void *p2) compare3(const void *p1, const void *p2)
{ {
uint32 s1, s2, d1, d2; uint32 s1,
s2,
d1,
d2;
s1 = *(uint32 *) p1; s1 = *(uint32 *) p1;
s2 = *((uint32 *) p1 + 1); s2 = *((uint32 *) p1 + 1);
@@ -301,7 +304,8 @@ compare4(const void *p1, const void *p2)
/* /*
* convert 32bit wide character to mutibye stream pointed to by iso * convert 32bit wide character to mutibye stream pointed to by iso
*/ */
static unsigned char *set_iso_code(unsigned char *iso, uint32 code) static unsigned char *
set_iso_code(unsigned char *iso, uint32 code)
{ {
if (code & 0xff000000) if (code & 0xff000000)
*iso++ = code >> 24; *iso++ = code >> 24;
@@ -549,8 +553,8 @@ LocalToUtf(const unsigned char *iso, unsigned char *utf,
if (p == NULL) if (p == NULL)
{ {
/* /*
* not found in the ordinary map. if there's a combined * not found in the ordinary map. if there's a combined character
* character map, try with it * map, try with it
*/ */
if (cmap) if (cmap)
{ {

View File

@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2007, PostgreSQL Global Development Group * Copyright (c) 2000-2007, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.26 2007/10/13 20:18:41 tgl Exp $ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.27 2007/11/15 23:23:44 momjian Exp $
* *
* XXX this file does not really belong in psql/. Perhaps move to libpq? * XXX this file does not really belong in psql/. Perhaps move to libpq?
* It also seems that the mbvalidate function is redundant with existing * It also seems that the mbvalidate function is redundant with existing

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.93 2007/11/15 22:12:09 momjian Exp $ # $PostgreSQL: pgsql/src/tools/pgindent/pgindent,v 1.94 2007/11/15 23:23:44 momjian Exp $
# Known bugs: # Known bugs:
# #
@@ -33,22 +33,31 @@ fi
for FILE for FILE
do do
cat "$FILE" | cat "$FILE" |
# convert // comments to /* */
# Convert // comments to /* */
sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' | sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' |
# Avoid bug that converts 'x =- 1' to 'x = -1' # Avoid bug that converts 'x =- 1' to 'x = -1'
sed 's;=- ;-= ;g' | sed 's;=- ;-= ;g' |
# mark some comments for special treatment later
# Mark some comments for special treatment later
sed 's;/\* *---;/*---X_X;g' | sed 's;/\* *---;/*---X_X;g' |
# workaround for indent bug with 'else' handling
# trim trailing space after single-line after-'else' comment # 'else' followed by a single-line comment, followed by
# so next test can be done easily # a brace on the next line confuses BSD indent, so we push
sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' | # the comment down to the next line, then later pull it
# indent multi-line after-'else' comment so BSD indent will move it properly # back up again.
sed 's;\([} ]\)else[ ]*\(/\*.*[^\*][^/]\)$;\1else\ sed 's;\([} ]\)else[ ]*\(/\*\)\(.*\*/\)[ ]*$;\1else\
\2PGINDENT_MOVED\3;g' |
# Indent multi-line after-'else' comment so BSD indent will move it properly.
# We already moved down single-line comments above. Check for '*' to make
# sure we are not in a single-line comment that has other text on the line.
sed 's;\([} ]\)else[ ]*\(/\*[^\*]*\)[ ]*$;\1else\
\2;g' | \2;g' |
detab -t4 -qc | detab -t4 -qc |
# work around bug where function that defines no local variables misindents # Work around bug where function that defines no local variables misindents
# switch() case lines and line after #else. Do not do for struct/enum. # switch() case lines and line after #else. Do not do for struct/enum.
awk ' BEGIN {line1 = ""; line2 = ""} awk ' BEGIN {line1 = ""; line2 = ""}
{ {
@@ -71,7 +80,7 @@ do
print line1; print line1;
}' | }' |
# prevent indenting of code in 'extern "C"' blocks # Prevent indenting of code in 'extern "C"' blocks.
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0} awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
{ {
line2 = $0; line2 = $0;
@@ -106,10 +115,10 @@ do
print line1; print line1;
}' | }' |
# protect backslashes in DATA() # Protect backslashes in DATA().
sed 's;^DATA(.*$;/*&*/;' | sed 's;^DATA(.*$;/*&*/;' |
# protect wrapping in CATALOG() # Protect wrapping in CATALOG().
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
# We get the list of typedef's from /src/tools/find_typedef # We get the list of typedef's from /src/tools/find_typedef
@@ -2130,30 +2139,30 @@ do
fi fi
cat /tmp/$$a | cat /tmp/$$a |
# restore DATA/CATALOG lines # Restore DATA/CATALOG lines.
sed 's;^/\*\(DATA(.*\)\*/$;\1;' | sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' | sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
# remove tabs and retab with four spaces # Remove tabs and retab with four spaces.
detab -t8 -qc | detab -t8 -qc |
entab -t4 -qc | entab -t4 -qc |
sed 's;^/\* Open extern \"C\" \*/$;{;' | sed 's;^/\* Open extern \"C\" \*/$;{;' |
sed 's;^/\* Close extern \"C\" \*/$;};' | sed 's;^/\* Close extern \"C\" \*/$;};' |
sed 's;/\*---X_X;/* ---;g' | sed 's;/\*---X_X;/* ---;g' |
# workaround indent bug for 'static' # Workaround indent bug for 'static'.
sed 's;^static[ ][ ]*;static ;g' | sed 's;^static[ ][ ]*;static ;g' |
# remove too much indenting after closing brace # Remove too much indenting after closing brace.
sed 's;^} [ ]*;} ;' | sed 's;^} [ ]*;} ;' |
# indent single-line after-'else' comment by only one tab # Indent single-line after-'else' comment by only one tab.
sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' | sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' |
# pull in #endif comments # Pull in #endif comments.
sed 's;^#endif[ ][ ]*/\*;#endif /*;' | sed 's;^#endif[ ][ ]*/\*;#endif /*;' |
# work around misindenting of function with no variables defined # Work around misindenting of function with no variables defined.
awk ' awk '
{ {
if ($0 ~ /^[ ]*int[ ]*pgindent_func_no_var_fix;/) if ($0 ~ /^[ ]*int[ ]*pgindent_func_no_var_fix;/)
@@ -2164,13 +2173,13 @@ do
else print $0; else print $0;
}' | }' |
# add space after comments that start on tab stops # Add space after comments that start on tab stops.
sed 's;\([^ ]\)\(/\*.*\*/\)$;\1 \2;' | sed 's;\([^ ]\)\(/\*.*\*/\)$;\1 \2;' |
# move trailing * in function return type # Move trailing * in function return type.
sed 's;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' | sed 's;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' |
# remove un-needed braces around single statements # Remove un-needed braces around single statements.
# Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably # Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably
# isn't needed for general use. # isn't needed for general use.
# awk ' # awk '
@@ -2200,7 +2209,7 @@ do
# print line2; # print line2;
# }' | # }' |
# remove blank line between opening brace and block comment # Remove blank line between opening brace and block comment.
awk ' awk '
{ {
line3 = $0; line3 = $0;
@@ -2229,7 +2238,33 @@ do
print line2; print line2;
}' | }' |
# remove trailing blank lines, helps with adding blank before trailing #endif # Pull up single-line comment after 'else' that was pulled down above
awk '
{
if (NR != 1)
{
if ($0 ~ "/\*PGINDENT_MOVED")
{
# remove tag
sub("PGINDENT_MOVED", "", $0);
# remove leading whitespace
sub("^[ ]*", "", $0);
# add comment with single tab prefix
print prev_line" "$0;
# throw away current line
getline;
}
else
print prev_line;
}
prev_line = $0;
}
END {
if (NR >= 1)
print prev_line;
}' |
# Remove trailing blank lines, helps with adding blank before trailing #endif.
awk ' BEGIN {blank_lines = 0;} awk ' BEGIN {blank_lines = 0;}
{ {
line1 = $0; line1 = $0;
@@ -2243,7 +2278,7 @@ do
} }
}' | }' |
# remove blank line before #else, #elif, and #endif # Remove blank line before #else, #elif, and #endif.
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0} awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
{ {
line2 = $0; line2 = $0;
@@ -2268,7 +2303,7 @@ do
print line1; print line1;
}' | }' |
# add blank line before #endif if it is the last line in the file # Add blank line before #endif if it is the last line in the file.
awk ' BEGIN {line1 = ""; line2 = ""} awk ' BEGIN {line1 = ""; line2 = ""}
{ {
line2 = $0; line2 = $0;
@@ -2326,7 +2361,7 @@ do
else print $0; else print $0;
}' | }' |
# fix indenting of typedef caused by __cplusplus in libpq-fe.h # Fix indenting of typedef caused by __cplusplus in libpq-fe.h.
( (
if echo "$FILE" | grep -q 'libpq-fe.h$' if echo "$FILE" | grep -q 'libpq-fe.h$'
then sed 's/^[ ]*typedef enum/typedef enum/' then sed 's/^[ ]*typedef enum/typedef enum/'