From fa074a6fd098153c75ba0e76b7dd94eab82ae599 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 6 Jan 2016 16:11:31 +0100 Subject: [PATCH] [contrib] Prepare clang-format-diff for usage --- contrib/devtools/README.md | 12 ++++++ contrib/devtools/clang-format-diff.py | 54 +++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 240ab6d9e..978f26b08 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -7,6 +7,18 @@ clang-format.py 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. +clang-format-diff.py +=================== + +A script to format unified git diffs according to [.clang-format](../../src/.clang-format). + +For instance, to format the last commit with 0 lines of context, +the script should be called from the git root folder as follows. + +``` +git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v +``` + fix-copyright-headers.py ======================== diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py index 9e02bb093..13d2573b9 100755 --- a/contrib/devtools/clang-format-diff.py +++ b/contrib/devtools/clang-format-diff.py @@ -5,7 +5,52 @@ # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. +# License. +# +# ============================================================ +# +# University of Illinois/NCSA +# Open Source License +# +# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign. +# All rights reserved. +# +# Developed by: +# +# LLVM Team +# +# University of Illinois at Urbana-Champaign +# +# http://llvm.org +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal with +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimers. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimers in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of the LLVM Team, University of Illinois at +# Urbana-Champaign, nor the names of its contributors may be used to +# endorse or promote products derived from this Software without specific +# prior written permission. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +# SOFTWARE. +# +# ============================================================ # #===------------------------------------------------------------------------===# @@ -56,10 +101,6 @@ def main(): help='let clang-format sort include blocks') parser.add_argument('-v', '--verbose', action='store_true', help='be more verbose, ineffective without -i') - parser.add_argument( - '-style', - help= - 'formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') args = parser.parse_args() # Extract changed lines for each file. @@ -101,8 +142,7 @@ def main(): if args.sort_includes: command.append('-sort-includes') command.extend(lines) - if args.style: - command.extend(['-style', args.style]) + command.extend(['-style=file', '-fallback-style=none']) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, stdin=subprocess.PIPE) stdout, stderr = p.communicate()