Bug 1392012 - ./clang-format with git should exclude files from .clang-format-ignore r=sylvestre
authorXavier ALT <dex@phoenix-ind.net>
Thu, 24 Aug 2017 23:41:44 +0200
changeset 377192 371686fcf5e0
parent 377191 fdade67e7e78
child 377193 e398f356a932
push id49781
push usersledru@mozilla.com
push dateMon, 28 Aug 2017 07:53:18 +0000
treeherderautoland@371686fcf5e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssylvestre
bugs1392012
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1392012 - ./clang-format with git should exclude files from .clang-format-ignore r=sylvestre MozReview-Commit-ID: KsgPnN9aDTC
tools/mach_commands.py
--- a/tools/mach_commands.py
+++ b/tools/mach_commands.py
@@ -266,16 +266,30 @@ class FormatProvider(MachCommandBase):
             args = ["hg", "diff", "-U0", "-r" ".^"]
             for dot_extension in self._format_include_extensions:
                 args += ['--include', 'glob:**{0}'.format(dot_extension)]
             args += ['--exclude', 'listfile:{0}'.format(self._format_ignore_file)]
         else:
             args = ["git", "diff", "--no-color", "-U0", "HEAD", "--"]
             for dot_extension in self._format_include_extensions:
                 args += ['*{0}'.format(dot_extension)]
+            # git-diff doesn't support an 'exclude-from-files' param, but
+            # allow to add individual exclude pattern since v1.9, see
+            # https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec
+            with open(self._format_ignore_file, 'rb') as exclude_pattern_file:
+                for pattern in exclude_pattern_file.readlines():
+                    pattern = pattern.rstrip()
+                    pattern = pattern.replace('.*', '**')
+                    if not pattern or pattern.startswith('#'):
+                        continue  # empty or comment
+                    magics = ['exclude']
+                    if pattern.startswith('^'):
+                        magics += ['top']
+                        pattern = pattern[1:]
+                    args += [':({0}){1}'.format(','.join(magics), pattern)]
         return args
 
     def run_clang_format_diff(self, clang_format_diff, show):
         # Run clang-format on the diff
         # Note that this will potentially miss a lot things
         from subprocess import Popen, PIPE
 
         diff_process = Popen(self._get_clang_format_diff_command(), stdout=PIPE)