Skip to content

Commit fa074a6

Browse files
author
MarcoFalke
committed
[contrib] Prepare clang-format-diff for usage
1 parent fa4f4b6 commit fa074a6

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

contrib/devtools/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ clang-format.py
77

88
A script to format cpp source code according to [.clang-format](../../src/.clang-format). This should only be applied to new files or files which are currently not actively developed on. Also, git subtrees are not subject to formatting.
99

10+
clang-format-diff.py
11+
===================
12+
13+
A script to format unified git diffs according to [.clang-format](../../src/.clang-format).
14+
15+
For instance, to format the last commit with 0 lines of context,
16+
the script should be called from the git root folder as follows.
17+
18+
```
19+
git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v
20+
```
21+
1022
fix-copyright-headers.py
1123
========================
1224

contrib/devtools/clang-format-diff.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,52 @@
55
# The LLVM Compiler Infrastructure
66
#
77
# This file is distributed under the University of Illinois Open Source
8-
# License. See LICENSE.TXT for details.
8+
# License.
9+
#
10+
# ============================================================
11+
#
12+
# University of Illinois/NCSA
13+
# Open Source License
14+
#
15+
# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign.
16+
# All rights reserved.
17+
#
18+
# Developed by:
19+
#
20+
# LLVM Team
21+
#
22+
# University of Illinois at Urbana-Champaign
23+
#
24+
# http://llvm.org
25+
#
26+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
27+
# this software and associated documentation files (the "Software"), to deal with
28+
# the Software without restriction, including without limitation the rights to
29+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
30+
# of the Software, and to permit persons to whom the Software is furnished to do
31+
# so, subject to the following conditions:
32+
#
33+
# * Redistributions of source code must retain the above copyright notice,
34+
# this list of conditions and the following disclaimers.
35+
#
36+
# * Redistributions in binary form must reproduce the above copyright notice,
37+
# this list of conditions and the following disclaimers in the
38+
# documentation and/or other materials provided with the distribution.
39+
#
40+
# * Neither the names of the LLVM Team, University of Illinois at
41+
# Urbana-Champaign, nor the names of its contributors may be used to
42+
# endorse or promote products derived from this Software without specific
43+
# prior written permission.
44+
#
45+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
46+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
47+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
48+
# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
49+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
50+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
51+
# SOFTWARE.
52+
#
53+
# ============================================================
954
#
1055
#===------------------------------------------------------------------------===#
1156

@@ -56,10 +101,6 @@ def main():
56101
help='let clang-format sort include blocks')
57102
parser.add_argument('-v', '--verbose', action='store_true',
58103
help='be more verbose, ineffective without -i')
59-
parser.add_argument(
60-
'-style',
61-
help=
62-
'formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)')
63104
args = parser.parse_args()
64105

65106
# Extract changed lines for each file.
@@ -101,8 +142,7 @@ def main():
101142
if args.sort_includes:
102143
command.append('-sort-includes')
103144
command.extend(lines)
104-
if args.style:
105-
command.extend(['-style', args.style])
145+
command.extend(['-style=file', '-fallback-style=none'])
106146
p = subprocess.Popen(command, stdout=subprocess.PIPE,
107147
stderr=None, stdin=subprocess.PIPE)
108148
stdout, stderr = p.communicate()

0 commit comments

Comments
 (0)