Commit 7d4c99b4 authored by Bruce Momjian's avatar Bruce Momjian

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.
parent f6e8730d
......@@ -41,7 +41,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* 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;
/*
* Honor the write-WAL-before-data rule, if appropriate, so that we do
* not write out data before associated WAL records. This is the same
* action performed during FlushBuffer() in the main buffer manager.
* Honor the write-WAL-before-data rule, if appropriate, so that we do not
* write out data before associated WAL records. This is the same action
* performed during FlushBuffer() in the main buffer manager.
*/
if (shared->group_lsn != NULL)
{
/*
* We must determine the largest async-commit LSN for the page.
* This is a bit tedious, but since this entire function is a slow
* path anyway, it seems better to do this here than to maintain
* a per-page LSN variable (which'd need an extra comparison in the
* We must determine the largest async-commit LSN for the page. This
* is a bit tedious, but since this entire function is a slow path
* anyway, it seems better to do this here than to maintain a per-page
* LSN variable (which'd need an extra comparison in the
* transaction-commit path).
*/
XLogRecPtr max_lsn;
int lsnindex, lsnoff;
int lsnindex,
lsnoff;
lsnindex = slotno * shared->lsn_groups_per_page;
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
* XLogFlush were to fail, we must PANIC. This isn't much of
* a restriction because XLogFlush is just about all critical
* XLogFlush were to fail, we must PANIC. This isn't much of a
* restriction because XLogFlush is just about all critical
* section anyway, but let's make sure.
*/
START_CRIT_SECTION();
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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
* that references one of the built-in RI_FKey trigger functions, assume
* it is from a dump of a pre-7.3 foreign key constraint, and take steps
* to convert this legacy representation into a regular foreign key
* If the command is a user-entered CREATE CONSTRAINT TRIGGER command that
* references one of the built-in RI_FKey trigger functions, assume it is
* from a dump of a pre-7.3 foreign key constraint, and take steps to
* convert this legacy representation into a regular foreign key
* constraint. Ugly, but necessary for loading old dump files.
*/
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
* constraint. We can skip depending on the relations, as there'll
* be an indirect dependency via the constraint.
* constraint. We can skip depending on the relations, as there'll be
* an indirect dependency via the constraint.
*/
referenced.classId = ConstraintRelationId;
referenced.objectId = constraintOid;
......@@ -475,7 +475,8 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid)
* We match triggers together by comparing the trigger arguments (which
* 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 */
Oid funcoids[3]; /* OIDs of trigger functions */
/* The three function OIDs are stored in the order update, delete, child */
......@@ -486,7 +487,7 @@ ConvertTriggerToFK(CreateTrigStmt *stmt, Oid funcoid)
{
static List *info_list = NIL;
static const char * const funcdescr[3] = {
static const char *const funcdescr[3] = {
gettext_noop("Found referenced table's UPDATE trigger."),
gettext_noop("Found referenced table's DELETE trigger."),
gettext_noop("Found referencing table's trigger.")
......@@ -2905,8 +2906,8 @@ AfterTriggerFireDeferred(void)
ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
/*
* Run all the remaining triggers. Loop until they are all gone, in
* case some trigger queues more for us to do.
* Run all the remaining triggers. Loop until they are all gone, in case
* some trigger queues more for us to do.
*/
while (afterTriggerMarkEvents(events, NULL, false))
{
......@@ -2940,13 +2941,13 @@ AfterTriggerEndXact(bool isCommit)
*
* Since all the info is in TopTransactionContext or children thereof, we
* 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
* it as soon as possible --- especially if we are aborting because we
* ran out of memory for the list!
* pending-events list could be large, and so it's useful to discard it as
* soon as possible --- especially if we are aborting because we ran out
* of memory for the list!
*
* (Note: any event_cxts of child subtransactions could also be
* deleted here, but we have no convenient way to find them, so we
* leave it to TopTransactionContext reset to clean them up.)
* (Note: any event_cxts of child subtransactions could also be deleted
* here, but we have no convenient way to find them, so we leave it to
* TopTransactionContext reset to clean them up.)
*/
if (afterTriggers && afterTriggers->event_cxt)
MemoryContextDelete(afterTriggers->event_cxt);
......@@ -2973,9 +2974,8 @@ AfterTriggerBeginSubXact(void)
/*
* Allocate more space in the stacks if needed. (Note: because the
* minimum nest level of a subtransaction is 2, we waste the first
* couple entries of each array; not worth the notational effort to
* avoid it.)
* minimum nest level of a subtransaction is 2, we waste the first couple
* entries of each array; not worth the notational effort to avoid it.)
*/
while (my_level >= afterTriggers->maxtransdepth)
{
......@@ -3071,16 +3071,17 @@ AfterTriggerEndSubXact(bool isCommit)
afterTriggers->state_stack[my_level] = NULL;
Assert(afterTriggers->query_depth ==
afterTriggers->depth_stack[my_level]);
/*
* It's entirely possible that the subxact created an event_cxt but
* there is not anything left in it (because all the triggers were
* fired at end-of-statement). If so, we should release the context
* to prevent memory leakage in a long sequence of subtransactions.
* We can detect whether there's anything of use in the context by
* seeing if anything was added to the global events list since
* subxact start. (This test doesn't catch every case where the
* context is deletable; for instance maybe the only additions were
* from a sub-sub-xact. But it handles the common case.)
* to prevent memory leakage in a long sequence of subtransactions. We
* can detect whether there's anything of use in the context by seeing
* if anything was added to the global events list since subxact
* start. (This test doesn't catch every case where the context is
* deletable; for instance maybe the only additions were from a
* sub-sub-xact. But it handles the common case.)
*/
if (afterTriggers->cxt_stack[my_level] &&
afterTriggers->events.tail == afterTriggers->events_stack[my_level].tail)
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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];
/*
* Suppress ON INSERT/UPDATE/DELETE rules that are disabled
* or configured to not fire during the current sessions
* replication role. ON SELECT rules will always be applied
* in order to keep views working even in LOCAL or REPLICA
* role.
* Suppress ON INSERT/UPDATE/DELETE rules that are disabled or
* configured to not fire during the current sessions replication
* role. ON SELECT rules will always be applied in order to keep views
* working even in LOCAL or REPLICA role.
*/
if (oneLock->event != CMD_SELECT)
{
......
......@@ -7,7 +7,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
......@@ -254,7 +254,7 @@ tsvector_setweight(PG_FUNCTION_ARGS)
}
static int
compareEntry(char *ptra, WordEntry * a, char *ptrb, WordEntry * b)
compareEntry(char *ptra, WordEntry *a, char *ptrb, WordEntry *b)
{
if (a->len == b->len)
{
......@@ -271,8 +271,8 @@ compareEntry(char *ptra, WordEntry * a, char *ptrb, WordEntry * b)
* Return the number added (might be less than expected due to overflow)
*/
static int4
add_pos(TSVector src, WordEntry * srcptr,
TSVector dest, WordEntry * destptr,
add_pos(TSVector src, WordEntry *srcptr,
TSVector dest, WordEntry *destptr,
int4 maxpos)
{
uint16 *clen = &_POSVECPTR(dest, destptr)->npos;
......@@ -482,8 +482,8 @@ tsvector_concat(PG_FUNCTION_ARGS)
}
/*
* Instead of checking each offset individually, we check for overflow
* of pos fields once at the end.
* Instead of checking each offset individually, we check for overflow of
* pos fields once at the end.
*/
if (dataoff > MAXSTRPOS)
ereport(ERROR,
......@@ -504,7 +504,7 @@ tsvector_concat(PG_FUNCTION_ARGS)
* compare 2 string values
*/
static int4
ValCompare(CHKVAL * chkval, WordEntry * ptr, QueryOperand * item)
ValCompare(CHKVAL *chkval, WordEntry *ptr, QueryOperand *item)
{
if (ptr->len == item->length)
return strncmp(
......@@ -544,7 +544,7 @@ checkclass_str(CHKVAL *chkval, WordEntry *val, QueryOperand *item)
* is there value 'val' in array or not ?
*/
static bool
checkcondition_str(void *checkval, QueryOperand * val)
checkcondition_str(void *checkval, QueryOperand *val)
{
CHKVAL *chkval = (CHKVAL *) checkval;
WordEntry *StopLow = chkval->arrb;
......@@ -580,8 +580,8 @@ checkcondition_str(void *checkval, QueryOperand * val)
*
*/
bool
TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
bool (*chkcond) (void *checkval, QueryOperand * val))
TS_execute(QueryItem *curitem, void *checkval, bool calcnot,
bool (*chkcond) (void *checkval, QueryOperand *val))
{
/* since this function recurses, it could be driven to stack overflow */
check_stack_depth();
......@@ -589,7 +589,7 @@ TS_execute(QueryItem * curitem, void *checkval, bool calcnot,
if (curitem->type == QI_VAL)
return chkcond(checkval, (QueryOperand *) curitem);
switch(curitem->operator.oper)
switch (curitem->operator.oper)
{
case OP_NOT:
if (calcnot)
......@@ -710,7 +710,7 @@ ts_match_tq(PG_FUNCTION_ARGS)
* that have a weight equal to one of the weights in 'weight' bitmask.
*/
static int
check_weight(TSVector txt, WordEntry * wptr, int8 weight)
check_weight(TSVector txt, WordEntry *wptr, int8 weight)
{
int len = POSDATALEN(txt, wptr);
int num = 0;
......@@ -726,7 +726,7 @@ check_weight(TSVector txt, WordEntry * wptr, int8 weight)
}
static WordEntry **
SEI_realloc(WordEntry ** in, uint32 *len)
SEI_realloc(WordEntry **in, uint32 *len)
{
if (*len == 0 || in == NULL)
{
......@@ -742,7 +742,7 @@ SEI_realloc(WordEntry ** in, uint32 *len)
}
static int
compareStatWord(StatEntry * a, WordEntry * b, tsstat * stat, TSVector txt)
compareStatWord(StatEntry *a, WordEntry *b, tsstat *stat, TSVector txt)
{
if (a->len == b->len)
return strncmp(
......@@ -754,7 +754,7 @@ compareStatWord(StatEntry * a, WordEntry * b, tsstat * stat, TSVector txt)
}
static tsstat *
formstat(tsstat * stat, TSVector txt, WordEntry ** entry, uint32 len)
formstat(tsstat *stat, TSVector txt, WordEntry **entry, uint32 len)
{
tsstat *newstat;
uint32 totallen,
......@@ -870,7 +870,7 @@ formstat(tsstat * stat, TSVector txt, WordEntry ** entry, uint32 len)
*/
static tsstat *
ts_accum(tsstat * stat, Datum data)
ts_accum(tsstat *stat, Datum data)
{
tsstat *newstat;
TSVector txt = DatumGetTSVector(data);
......@@ -1012,7 +1012,7 @@ ts_accum(tsstat * stat, Datum data)
static void
ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
tsstat * stat)
tsstat *stat)
{
TupleDesc tupdesc;
MemoryContext oldcontext;
......@@ -1232,11 +1232,11 @@ static bool
istexttype(Oid typid)
{
/* varchar(n) and char(n) are binary-compatible with text */
if (typid==TEXTOID || typid==VARCHAROID || typid==BPCHAROID)
if (typid == TEXTOID || typid == VARCHAROID || typid == BPCHAROID)
return true;
/* Allow domains over these types, too */
typid = getBaseType(typid);
if (typid==TEXTOID || typid==VARCHAROID || typid==BPCHAROID)
if (typid == TEXTOID || typid == VARCHAROID || typid == BPCHAROID)
return true;
return false;
}
......
......@@ -6,7 +6,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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,10 +274,13 @@ compare2(const void *p1, const void *p2)
static int
compare3(const void *p1, const void *p2)
{
uint32 s1, s2, d1, d2;
uint32 s1,
s2,
d1,
d2;
s1 = *(uint32 *)p1;
s2 = *((uint32 *)p1 + 1);
s1 = *(uint32 *) p1;
s2 = *((uint32 *) p1 + 1);
d1 = ((pg_utf_to_local_combined *) p2)->utf1;
d2 = ((pg_utf_to_local_combined *) p2)->utf2;
return (s1 > d1 || (s1 == d1 && s2 > d2)) ? 1 : ((s1 == d1 && s2 == d2) ? 0 : -1);
......@@ -301,7 +304,8 @@ compare4(const void *p1, const void *p2)
/*
* 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)
*iso++ = code >> 24;
......@@ -549,8 +553,8 @@ LocalToUtf(const unsigned char *iso, unsigned char *utf,
if (p == NULL)
{
/*
* not found in the ordinary map. if there's a combined
* character map, try with it
* not found in the ordinary map. if there's a combined character
* map, try with it
*/
if (cmap)
{
......
......@@ -3,7 +3,7 @@
*
* 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?
* It also seems that the mbvalidate function is redundant with existing
......
#!/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:
#
......@@ -33,22 +33,31 @@ fi
for FILE
do
cat "$FILE" |
# convert // comments to /* */
# Convert // comments to /* */
sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' |
# Avoid bug that converts 'x =- 1' to 'x = -1'
sed 's;=- ;-= ;g' |
# mark some comments for special treatment later
# Mark some comments for special treatment later
sed 's;/\* *---;/*---X_X;g' |
# workaround for indent bug with 'else' handling
# trim trailing space after single-line after-'else' comment
# so next test can be done easily
sed 's;\([} ]\)else[ ]*\(/\*.*\*/\)[ ]*$;\1else \2;g' |
# indent multi-line after-'else' comment so BSD indent will move it properly
sed 's;\([} ]\)else[ ]*\(/\*.*[^\*][^/]\)$;\1else\
# 'else' followed by a single-line comment, followed by
# a brace on the next line confuses BSD indent, so we push
# the comment down to the next line, then later pull it
# back up again.
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' |
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.
awk ' BEGIN {line1 = ""; line2 = ""}
{
......@@ -71,7 +80,7 @@ do
print line1;
}' |
# prevent indenting of code in 'extern "C"' blocks
# Prevent indenting of code in 'extern "C"' blocks.
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
{
line2 = $0;
......@@ -106,10 +115,10 @@ do
print line1;
}' |
# protect backslashes in DATA()
# Protect backslashes in DATA().
sed 's;^DATA(.*$;/*&*/;' |
# protect wrapping in CATALOG()
# Protect wrapping in CATALOG().
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
# We get the list of typedef's from /src/tools/find_typedef
......@@ -2130,30 +2139,30 @@ do
fi
cat /tmp/$$a |
# restore DATA/CATALOG lines
# Restore DATA/CATALOG lines.
sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
# remove tabs and retab with four spaces
# Remove tabs and retab with four spaces.
detab -t8 -qc |
entab -t4 -qc |
sed 's;^/\* Open extern \"C\" \*/$;{;' |
sed 's;^/\* Close extern \"C\" \*/$;};' |
sed 's;/\*---X_X;/* ---;g' |
# workaround indent bug for 'static'
# Workaround indent bug for 'static'.
sed 's;^static[ ][ ]*;static ;g' |
# remove too much indenting after closing brace
# Remove too much indenting after closing brace.
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' |
# pull in #endif comments
# Pull in #endif comments.
sed 's;^#endif[ ][ ]*/\*;#endif /*;' |
# work around misindenting of function with no variables defined
# Work around misindenting of function with no variables defined.
awk '
{
if ($0 ~ /^[ ]*int[ ]*pgindent_func_no_var_fix;/)
......@@ -2164,13 +2173,13 @@ do
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;' |
# move trailing * in function return type
# Move trailing * in function return type.
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
# isn't needed for general use.
# awk '
......@@ -2200,7 +2209,7 @@ do
# print line2;
# }' |
# remove blank line between opening brace and block comment
# Remove blank line between opening brace and block comment.
awk '
{
line3 = $0;
......@@ -2229,7 +2238,33 @@ do
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;}
{
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}
{
line2 = $0;
......@@ -2268,7 +2303,7 @@ do
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 = ""}
{
line2 = $0;
......@@ -2326,7 +2361,7 @@ do
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$'
then sed 's/^[ ]*typedef enum/typedef enum/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment