Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openairinterface5G
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Patricio Latini
openairinterface5G
Commits
5ec8a11e
Commit
5ec8a11e
authored
2 years ago
by
Robert Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add readme for clang-format
parent
91f2453a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/clang-format.md
+66
-0
66 additions, 0 deletions
doc/clang-format.md
with
66 additions
and
0 deletions
doc/clang-format.md
0 → 100644
+
66
−
0
View file @
5ec8a11e
We use
[
clang-format
](
https://clang.llvm.org/docs/ClangFormat.html
)
to format our code.
# Integration into editors
Integration into various editors (
`vim`
,
`emacs`
,
`VSCode`
,
`CLion`
) is on the
[
clang-format project page
](
https://clang.llvm.org/docs/ClangFormat.html
)
.
There is also an
[
eclipse plugin
](
https://github.com/wangzw/CppStyle
)
.
# Integration into git
## Short version
See below for a more detailed explanation. In short: Add this to
`~/.gitconfig`
:
```
[clangFormat]
binary = clang-format-12
style = file
```
Now stage files for reformatting, then run
`git clang-format`
. It will reformat
only the code that is staged, and you can view reformatted code with
`git
diff`
. To add modified lines to your commit, stage them as well, then commit.
There is also a pre-commit hook that you can install. To install it, copy it
`pre-commit-clang`
to
`.git/hooks/pre-commit`
, and make it executable.
## Long version
In order to integrate
`clang-format`
into
`git`
, follow these steps:
1) Copy
`pre-commit-clang`
to
`.git/hooks/pre-commit`
and make it executable.
2) Install clang-format-12 (needs at least Ubuntu 20, remove anything else)
```
bash
$
sudo
apt-get remove clang-format
*
$
sudo
apt-get
install
clang-format-12
```
3) Configure
`git`
(set correct executable, set mode, provide more convenient alias)
```
bash
$
git config
--global
clangFormat.binary clang-format-12
$
git config
--global
clangFormat.style file
$
git config
--global
alias.clang-format clang-format-12
```
When this is done, you are set up. How to use:
4) When committing new code, add the code to commit into the staging (
`git add
-p`
or
`git add <file>`
) _and stash the rest_ (e.g.,
`git stash -p`
, this is
quite important or reformatting might not work properly, or you don't know
what has been reformatted)
5) Run git clang-format. The staged code will be reformatted. After this, you
still have your changes in the staging area, and the formatted code appears
as additional modification. Thus, your changes can be seen with
```
bash
$
git diff
--staged
```
while the modifications of clang-format with
```
bash
$
git diff
```
So now, you can add all or parts of reformatted code to the staging area
6) Commit. It won't work if code is not properly formatted due to the
pre-commit hook. Force committing with
`git commit --no-verify`
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment