author Mozilla Releng Treescript <>
Fri, 08 Mar 2019 16:28:11 +0000
changeset 513432 641653ef68b3b79744327675054a65fca442b874
parent 508086 d7507f185a63f25f2d1cf2a3925ade57498ab3a5
child 523682 a108772f1d772959dbc622999da19900b76ecd95
permissions -rwxr-xr-x
No bug - Tagging 13bfcad39c39edcd4e3fc5b26fd62b25d338235f with DEVEDITION_66_0b14_RELEASE a=release CLOSED TREE DONTBUILD

#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at

import os
import subprocess
import sys

here = os.path.dirname(os.path.realpath(__file__))
topsrcdir = os.path.join(here, os.pardir, os.pardir)

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):
        vcs = get_repository_object(topsrcdir)
    except InvalidRepoPath:

    changedFiles = vcs.get_outgoing_files('AM')
    if not changedFiles:
        # No files have been touched

    arguments = ['clang-format', '-s', '-p'] + changedFiles
    # On windows we need this to call the command in a shell, see Bug 1511594
    if == 'nt':
        clang_format_cmd = ['sh', 'mach'] + arguments
        clang_format_cmd = [os.path.join(topsrcdir, "mach")] + arguments
    if 'commit' in hooktype:
        # don't prevent commits, just display the clang-format results
        return False

    print("warning: '{}' is not a valid clang-format hooktype".format(hooktype))
    return False

def hg(ui, repo, node, **kwargs):
    hooktype = kwargs['hooktype']
    return run_clang_format(hooktype, kwargs.get('pats', []))

def git():
    hooktype = os.path.basename(__file__)
    if hooktype == '':
        hooktype = 'pre-push'
    return run_clang_format(hooktype, [])

if __name__ == '__main__':