788
Comment:
|
2939
|
Deletions are marked like this. | Additions are marked like this. |
Line 7: | Line 7: |
The repository contains a Mercurial extension that integrates {{{uncrustify}}} into Mercurial nicely. See ../MercurialUncrustifyExtension. | Not all aspects of source layout are handled by {{{uncrustify}}}, so please still pay attention to our [[../Whitespace]] rules and other [[../CodingConventions]]. |
Line 9: | Line 9: |
Not all aspects of source layout are handled by {{{uncrustify}}}, so please still pay attention to our [[../Whitespace]] rules. | == Mercurial "uncrustify" extension == The repository contains a Mercurial extension (in file {{{misc/uncrustify.py}}}) that provides the new command {{{ hg uncrustify }}} to automatically run {{{uncrustify}}} with the correct settings on your working directory. === Using the extension === Examples: {{{ hg uncrustify hg uncrustify . hg uncrustify --diff bar/baz.cc foo hg uncrustify --modify foo hg uncrustify --modify --no-backup foo }}} In order, these do the following: * List all files in the repository that need to be uncrustified (i.e. which violate the formatting conventions). * List all files in the repository below the current working directory that need to be uncrustified. * Show the diff that would need to be applied to uncrustify source file {{{bar/baz.cc}}} as well as all source files below directory {{{foo}}}. * Uncrustify all source files below directory {{{foo}}}. Backup files with extension {{{.crusty}}} are generated for all modified files, containing the original (not yet uncrustified) source. * Like the previous command, but without creating backups. For more details, run {{{ hg help uncrustify }}} === Setting up the extension === /!\ Warning: Mercurial extensions can execute arbitrary code on your machine. If you don't trust everyone with write access to whatever repository you grabbed {{{uncrustify.py}}} from, don't use it. First of all, you will need {{{uncrustify}}} itself. On Ubuntu, install it with {{{ sudo apt-get install uncrustify }}} To set up the actual extension, add the following lines to your {{{hgrc}}}: {{{ [extensions] uncrustify = FULL_PATH_TO/uncrustify.py [alias] uncrustify = uncrustify -X re:^src/bugs -X re:^src/VAL }}} where {{{FULL_PATH_TO/uncrustify.py}}} is the full path to the {{{uncrustify.py}}} file (absolute, but may use {{{~}}} expansion). Alternatively, install {{{uncrustify.py}}} in some directory on your {{{PYTHONPATH}}} and write {{{ [extensions] uncrustify = }}} in your {{{hgrc}}} instead of providing the full path to the source file. The {{{alias}}} section above is optional. It makes {{{hg uncrustify}}} ignore the {{{src/bugs}}} and {{{src/VAL}}} directories which do not need to be uncrustified. |
Back to developer page.
Using uncrustify to fix code layout
We use uncrustify with a Fast Downward configuration file (.uncrustify.cfg in the repository root) to enforce some of our formatting conventions. If a source file is properly formatted, applying uncrustify should be an idempotent operation (i.e., result in an identical file). This is important so that we can verify our style rules automatically, at least for those rules which uncrustify can handle.
Not all aspects of source layout are handled by uncrustify, so please still pay attention to our ../Whitespace rules and other ../CodingConventions.
Mercurial "uncrustify" extension
The repository contains a Mercurial extension (in file misc/uncrustify.py) that provides the new command
hg uncrustify
to automatically run uncrustify with the correct settings on your working directory.
Using the extension
Examples:
hg uncrustify hg uncrustify . hg uncrustify --diff bar/baz.cc foo hg uncrustify --modify foo hg uncrustify --modify --no-backup foo
In order, these do the following:
- List all files in the repository that need to be uncrustified (i.e. which violate the formatting conventions).
- List all files in the repository below the current working directory that need to be uncrustified.
Show the diff that would need to be applied to uncrustify source file bar/baz.cc as well as all source files below directory foo.
Uncrustify all source files below directory foo. Backup files with extension .crusty are generated for all modified files, containing the original (not yet uncrustified) source.
- Like the previous command, but without creating backups.
For more details, run
hg help uncrustify
Setting up the extension
Warning: Mercurial extensions can execute arbitrary code on your machine. If you don't trust everyone with write access to whatever repository you grabbed uncrustify.py from, don't use it.
First of all, you will need uncrustify itself. On Ubuntu, install it with
sudo apt-get install uncrustify
To set up the actual extension, add the following lines to your hgrc:
[extensions] uncrustify = FULL_PATH_TO/uncrustify.py [alias] uncrustify = uncrustify -X re:^src/bugs -X re:^src/VAL
where FULL_PATH_TO/uncrustify.py is the full path to the uncrustify.py file (absolute, but may use ~ expansion). Alternatively, install uncrustify.py in some directory on your PYTHONPATH and write
[extensions] uncrustify =
in your hgrc instead of providing the full path to the source file.
The alias section above is optional. It makes hg uncrustify ignore the src/bugs and src/VAL directories which do not need to be uncrustified.