]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Enhance make_ctags and make_etags.
authorTatsuo Ishii <ishii@postgresql.org>
Wed, 19 Oct 2022 03:59:29 +0000 (12:59 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 9 Apr 2026 22:55:16 +0000 (07:55 +0900)
make_ctags did not include field members of structs since the commit
964d01ae90c314eb31132c2e7712d5d9fc237331.

For example, in the following field of RestrictInfo:

   Selectivity norm_selec pg_node_attr(equal_ignore);

pg_node_attr was mistakenly interpreted to be the name of the field.
To fix this, add -I option to ctags command if the command is
Exuberant ctags or Universal ctags (for plain old ctags, struct
members are not included in the tags file anyway).

Also add "-e" and "-n" options to make_ctags. The -e option invokes
ctags command with -e option, which produces TAGS file for emacs. This
allows to eliminate duplicate codes in make_etags so that make_etags
just exec make_ctags with -e option.

The -n option allows not to produce symbolic links in each
sub directory (the default is producing symbolic links).

This includes the follow-up fixes: 87f21d2c6890 and ae66716bf3ef.  This
change is applied to v15 and v14, v16 and nwer versions already
including these improvements.  One reason why I am doing this backpatch
is that this can be really useful for backpatching purposes, especially
the -n option that limits the number of TAGS/tags files created in the
tree.

Author: Yugo Nagata
Reviewers: Alvaro Herrera, Tatsuo Ishii
Discussion: https://postgr.es/m/flat/20221007154442.76233afc7c5b255c4de6528a%40sraoss.co.jp
Discussion: https://postgr.es/m/adcKr7fob5ZvjhlH@paquier.xyz
Backpatch-through: 14

src/tools/make_ctags

index 9e952ce916f234d923f62aff3787bcf16430b917..ad027c71e3ddeff2e28f0d51f6feca12e8e64c91 100755 (executable)
@@ -1,16 +1,54 @@
 #!/bin/sh
 
-# src/tools/make_ctags
+# src/tools/make_ctags [-e] [-n]
+# If -e is specified, generate tags files for emacs.
+# If -n is specified, don't create symbolic links of tags file.
+usage="Usage:  $0 [-e][-n]"
+if [ $# -gt 2 ]
+then   echo $usage
+       exit 1
+fi
 
-command -v ctags >/dev/null || \
-       { echo "'ctags' program not found" 1>&2; exit 1; }
+EMACS_MODE=
+NO_SYMLINK=
+IS_EXUBERANT=
+PROG="ctags"
+TAGS_OPT="-a -f"
+TAGS_FILE="tags"
+FLAGS=
+IGNORE_IDENTIFIES=
 
-trap "rm -f /tmp/$$" 0 1 2 3 15
-rm -f ./tags
+while [ $# -gt 0 ]
+do
+       if [ $1 = "-e" ]
+       then    EMACS_MODE="Y"
+       elif [ $1 = "-n" ]
+       then    NO_SYMLINK="Y"
+       else
+               echo $usage
+               exit 1
+       fi
+       shift
+done
+
+if [ ! "$EMACS_MODE" ]
+then   (command -v ctags >/dev/null) || \
+       { echo "'ctags' program not found" 1>&2; exit 1; }
+fi
 
-IS_EXUBERANT=""
 ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
+if [ "$EMACS_MODE" ]
+then   TAGS_FILE="TAGS"
+       if [ "$IS_EXUBERANT" ]
+       then PROG="ctags -e"
+       else    (command -v etags >/dev/null) || \
+               { echo "neither 'etags' nor exuberant 'ctags' program not found" 1>&2; exit 1; }
+               PROG="etags"
+               TAGS_OPT="-a -o"
+       fi
+fi
+
 # List of kinds supported by Exuberant Ctags 5.8
 # generated by ctags --list-kinds
 # --c-kinds was called --c-types before 2003
@@ -31,12 +69,23 @@ ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
 if [ "$IS_EXUBERANT" ]
 then   FLAGS="--c-kinds=+dfmstuv"
-else   FLAGS="-dt"
+elif [ ! "$EMACS_MODE" ]
+then   FLAGS="-dt"
+fi
+
+# Use -I option to ignore a macro
+if [ "$IS_EXUBERANT" ]
+then   IGNORE_IDENTIFIES="-I pg_node_attr+"
 fi
 
+trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15
+rm -f ./$TAGS_FILE
+
 # this is outputting the tags into the file 'tags', and appending
-find `pwd`/ -type f -name '*.[chyl]' -print |
-       xargs ctags -a -f tags "$FLAGS"
+find `pwd`/ \( -name tmp_install -prune -o -name tmp_check -prune \) \
+       -o \( -name "*.[chly]" -o -iname "*makefile*" -o -name "*.mk" -o -name "*.in" \
+       -o -name "*.sql" -o -name "*.p[lm]" \) -type f -print |
+       xargs $PROG $TAGS_OPT $TAGS_FILE $FLAGS $IGNORE_IDENTIFIES
 
 # Sorting non-Exuberant ctags file allows for fast searching of the tags file.
 # Since etags file has a header that we cannot sort in with the other entries
@@ -44,10 +93,13 @@ find `pwd`/ -type f -name '*.[chyl]' -print |
 if [ ! "$IS_EXUBERANT" -a ! "$EMACS_MODE" ]
 then   LC_ALL=C
        export LC_ALL
-       sort tags >/tmp/$$ && mv /tmp/$$ tags
+       sort $TAGS_FILE >/tmp/$$ && mv /tmp/$$ $TAGS_FILE
 fi
 
-find . \( -name 'CVS' -prune \) -o \( -name .git -prune \) -o -type d -print |
-while read DIR
-do     [ "$DIR" != "." ] && ln -f -s `echo "$DIR" | sed 's;/[^/]*;/..;g'`/tags "$DIR"/tags
-done
+# create symbolic links
+if [ ! "$NO_SYMLINK" ]
+then    find . \( -name 'CVS' -prune \) -o \( -name .git -prune \) -o -type d -print |
+       while read DIR
+       do      [ "$DIR" != "." ] && ln -f -s `echo "$DIR" | sed 's;/[^/]*;/..;g'`/$TAGS_FILE "$DIR"/$TAGS_FILE
+       done
+fi