find + xargs + ctags is somehow missing tags for entire subdirectories

Viewed 107

(I am using RHEL7).

For Vim I create a tags file with find and ctags, running it from the directory which contains my many directories of Python packages source code.

Initially I was doing this:

find . -name \*.py | xargs ctags

but at some point I found that it was missing some entire packages.

Strangely it got fixed when I decided to skip all the test directories with:

find . -name \*.py -not \( -path \*/tests\*/\* \) | xargs ctags

I recently added some more Python packages and now this fix is skipping some directories again.

BTW, this works:

find . -name \*.py > files_for_ctags.txt; ctags -L files_for_ctags.txt

so for now it will be my solution.

But it would be nice to understand why the xargs version sometimes skips and entire directory of tags.

Any suggestions?

1 Answers

find may send too many lines to xargs via the pipe. You can confirm it with find . -name \*.py | wc -l.

In the case, xargs launches ctags process more than twice. The nth launched ctags process may overwrite the tags file generated by (n-1)th launched ctags process. This may be the trick of skipping you observed.

As I wrote in the comment, you can avoid the skipping with find . -name \*.py | ctags -L -.

There is one known issue about "-L -". If find sends a file name starting with "--" to ctags, it can be a trouble; ctags recognizes it as an option. See https://github.com/universal-ctags/ctags/issues/1883 .

Related