Bug 1535829 - Ride along, format the file using black r=sheehan
authorSylvestre Ledru <sledru@mozilla.com>
Tue, 19 Mar 2019 15:25:25 +0000
changeset 465036 82e0ac6d662e14a1868c2fb7ac067b4205c965dc
parent 465035 31f675dd6c707c2e3c488a35ced02c043cd328cb
child 465037 22a25f360f553b9bff4fca2c29432c7771aa5832
push id35730
push userrmaries@mozilla.com
push dateTue, 19 Mar 2019 21:51:47 +0000
treeherdermozilla-central@4f6d8ed9e948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssheehan
bugs1535829
milestone68.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 1535829 - Ride along, format the file using black r=sheehan Differential Revision: https://phabricator.services.mozilla.com/D23789
tools/lint/hooks_clang_format.py
--- a/tools/lint/hooks_clang_format.py
+++ b/tools/lint/hooks_clang_format.py
@@ -5,59 +5,59 @@
 
 import os
 import subprocess
 import sys
 
 here = os.path.dirname(os.path.realpath(__file__))
 topsrcdir = os.path.join(here, os.pardir, os.pardir)
 
-EXTRA_PATHS = (
-    'python/mozversioncontrol',
-)
+EXTRA_PATHS = ("python/mozversioncontrol",)
 sys.path[:0] = [os.path.join(topsrcdir, p) for p in EXTRA_PATHS]
 
 from mozversioncontrol import get_repository_object, InvalidRepoPath
 
 
 def run_clang_format(hooktype, args):
     try:
         vcs = get_repository_object(topsrcdir)
     except InvalidRepoPath:
         return
 
-    changedFiles = vcs.get_outgoing_files('AM')
+    changedFiles = vcs.get_outgoing_files("AM")
     if not changedFiles:
         # No files have been touched
         return
 
-    arguments = ['clang-format', '-s', '-p'] + changedFiles
+    arguments = ["clang-format", "-s", "-p"] + changedFiles
     # On windows we need this to call the command in a shell, see Bug 1511594
-    if os.name == 'nt':
-        clang_format_cmd = ['sh', 'mach'] + arguments
+    if os.name == "nt":
+        clang_format_cmd = ["sh", "mach"] + arguments
     else:
         clang_format_cmd = [os.path.join(topsrcdir, "mach")] + arguments
-    if 'commit' in hooktype:
+    if "commit" in hooktype:
         # don't prevent commits, just display the clang-format results
         subprocess.Popen(clang_format_cmd)
         return False
 
     print("warning: '{}' is not a valid clang-format hooktype".format(hooktype))
     return False
 
 
 def hg(ui, repo, node, **kwargs):
-    print("warning: this hook has been deprecated. Please use the hg extension instead.\n"
-          "please add 'clang-format = ~/.mozbuild/version-control-tools/hgext/clang-format'"
-          " to hgrc\n"
-          "Or run 'mach bootstrap'")
+    print(
+        "warning: this hook has been deprecated. Please use the hg extension instead.\n"
+        "please add 'clang-format = ~/.mozbuild/version-control-tools/hgext/clang-format'"
+        " to hgrc\n"
+        "Or run 'mach bootstrap'"
+    )
     return False
 
 
 def git():
     hooktype = os.path.basename(__file__)
-    if hooktype == 'hooks_clang_format.py':
-        hooktype = 'pre-push'
+    if hooktype == "hooks_clang_format.py":
+        hooktype = "pre-push"
     return run_clang_format(hooktype, [])
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     sys.exit(git())