Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-RAN
Commits
5ec8a11e
Commit
5ec8a11e
authored
Aug 22, 2022
by
Robert Schmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add readme for clang-format
parent
91f2453a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
doc/clang-format.md
doc/clang-format.md
+66
-0
No files found.
doc/clang-format.md
0 → 100644
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`
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment