From 5c512d6a34e75b31b7f376e7deb4057aac2f2fd6 Mon Sep 17 00:00:00 2001 From: mozga-intel Date: Sat, 25 Sep 2021 12:28:13 +0200 Subject: [PATCH 1/3] Clang-format description on a wiki --- .../src/pages/community/clang_format_guide.md | 58 +++++++++++++++++++ docs/static_site/src/pages/community/index.md | 1 + 2 files changed, 59 insertions(+) create mode 100644 docs/static_site/src/pages/community/clang_format_guide.md diff --git a/docs/static_site/src/pages/community/clang_format_guide.md b/docs/static_site/src/pages/community/clang_format_guide.md new file mode 100644 index 000000000000..02ece669b3ce --- /dev/null +++ b/docs/static_site/src/pages/community/clang_format_guide.md @@ -0,0 +1,58 @@ +--- +layout: page +title: Clang format +subtitle: Clang format in MXNet codebase for reviewers and contributors. +action: Contribute +action_url: /community/index +permalink: /community/code_guide +--- + + + + + + + + + + + + + + + + + +Clang-format Guide and Tips +=================== + +This wiki page describes how to set up clang-format tool as a part of your worklow. Running the command given in the description will fix clang-format problem. + + +- Add `tools/lint/git-clang-format-13 ` to your `$PATH`. Once its added to your `$PATH`, running `git clang-format` will invoke it. +```bash +git clang-format +``` + + +- To reformat chosen file just do: +```bash +# `_FILE_NAME_` is the name of a file to be formatted. +# i - apply edits to files instead of displaying a diff +clang-format -i _FILE_NAME_ +``` + +- To reformat all the lines in the latest git commit, just do: +```bash +git diff -U0 --no-color HEAD^ | clang-format-diff.py -i -p1 + +``` + +- If you want to apply clang-format only to the changed lines in each commit do the following: +```bash +# If it's a child of origin/master, the following command-line could be used: +# If you want to run this command on another brnach, then origin/master needs to be replaced. +export COMMIT_SHA=$(git rev-list --ancestry-path origin/master..HEAD | tail -n 1) + +git filter-branch --tree-filter 'git-clang-format $COMMIT_SHA^' -- $COMMIT_SHA..HEAD +``` \ No newline at end of file diff --git a/docs/static_site/src/pages/community/index.md b/docs/static_site/src/pages/community/index.md index 063d5f66c431..afeee71b666e 100644 --- a/docs/static_site/src/pages/community/index.md +++ b/docs/static_site/src/pages/community/index.md @@ -91,6 +91,7 @@ We value all forms of contributions, including, but not limited to: - [Code Guide and Tips]({% link pages/community/code_guide.md %}) - [Error Handling Guide]({% link pages/community/error_handling.md %}) - [Git Usage Tips]({% link pages/community/git_howto.md %}) +- [Clang format]({% link pages/community/clang_format_guide.md %}) #### RFC Process From afd59e87cbd73c7170b4cd8492b482c4be26d55d Mon Sep 17 00:00:00 2001 From: mozga-intel Date: Fri, 15 Oct 2021 13:54:12 +0200 Subject: [PATCH 2/3] Add clang link to other files --- docs/static_site/src/pages/community/code_guide.md | 2 +- docs/static_site/src/pages/community/index.md | 1 - docs/static_site/src/pages/community/pull_request.md | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/static_site/src/pages/community/code_guide.md b/docs/static_site/src/pages/community/code_guide.md index ea24aef31b43..51768f6bc404 100644 --- a/docs/static_site/src/pages/community/code_guide.md +++ b/docs/static_site/src/pages/community/code_guide.md @@ -33,7 +33,7 @@ contributing and process. C++ Code Styles --------------- -- Use the [Google C/C++ style](https://google.github.io/styleguide/cppguide.html). +- Use the [clang-format]({% link pages/community/clang_format_guide.md %}) tool to reformat your code. - The public facing functions are documented in [doxygen](https://www.doxygen.nl/manual/docblocks.html) format. - Favor concrete type declaration over `auto` as long as it is short. - Favor passing by const reference (e.g. `const Expr&`) over passing diff --git a/docs/static_site/src/pages/community/index.md b/docs/static_site/src/pages/community/index.md index afeee71b666e..063d5f66c431 100644 --- a/docs/static_site/src/pages/community/index.md +++ b/docs/static_site/src/pages/community/index.md @@ -91,7 +91,6 @@ We value all forms of contributions, including, but not limited to: - [Code Guide and Tips]({% link pages/community/code_guide.md %}) - [Error Handling Guide]({% link pages/community/error_handling.md %}) - [Git Usage Tips]({% link pages/community/git_howto.md %}) -- [Clang format]({% link pages/community/clang_format_guide.md %}) #### RFC Process diff --git a/docs/static_site/src/pages/community/pull_request.md b/docs/static_site/src/pages/community/pull_request.md index fea547440fd4..a9a734dd7f5f 100644 --- a/docs/static_site/src/pages/community/pull_request.md +++ b/docs/static_site/src/pages/community/pull_request.md @@ -39,7 +39,7 @@ detailed guidelines. ``` - Make sure code style check pass by typing the following command, and - all the existing test-cases pass. + all the existing test-cases pass. Use the [Clang format]({% link pages/community/clang_format_guide.md %}) tool to reformat your code. ```bash # Reproduce the lint procedure in the CI. From 5797904e8a0a76339760998214ec9581a8e0a3be Mon Sep 17 00:00:00 2001 From: mozga-intel Date: Fri, 15 Oct 2021 13:57:15 +0200 Subject: [PATCH 3/3] Tool word is removed from the sentence --- docs/static_site/src/pages/community/code_guide.md | 2 +- docs/static_site/src/pages/community/pull_request.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/static_site/src/pages/community/code_guide.md b/docs/static_site/src/pages/community/code_guide.md index 51768f6bc404..fd5831e91a18 100644 --- a/docs/static_site/src/pages/community/code_guide.md +++ b/docs/static_site/src/pages/community/code_guide.md @@ -33,7 +33,7 @@ contributing and process. C++ Code Styles --------------- -- Use the [clang-format]({% link pages/community/clang_format_guide.md %}) tool to reformat your code. +- Use the [clang-format]({% link pages/community/clang_format_guide.md %}) to reformat your code. - The public facing functions are documented in [doxygen](https://www.doxygen.nl/manual/docblocks.html) format. - Favor concrete type declaration over `auto` as long as it is short. - Favor passing by const reference (e.g. `const Expr&`) over passing diff --git a/docs/static_site/src/pages/community/pull_request.md b/docs/static_site/src/pages/community/pull_request.md index a9a734dd7f5f..2520d552ffa7 100644 --- a/docs/static_site/src/pages/community/pull_request.md +++ b/docs/static_site/src/pages/community/pull_request.md @@ -39,7 +39,7 @@ detailed guidelines. ``` - Make sure code style check pass by typing the following command, and - all the existing test-cases pass. Use the [Clang format]({% link pages/community/clang_format_guide.md %}) tool to reformat your code. + all the existing test-cases pass. Use the [clang-format]({% link pages/community/clang_format_guide.md %}) to reformat your code. ```bash # Reproduce the lint procedure in the CI.