Chromium Code Reviews| Index: clang_format_merge_driver.py |
| diff --git a/clang_format_merge_driver.py b/clang_format_merge_driver.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..aee7f7d78183e438d5e42039b5e992b3637045b8 |
| --- /dev/null |
| +++ b/clang_format_merge_driver.py |
| @@ -0,0 +1,40 @@ |
| +#!/usr/bin/env python |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +"""Clang-format 3-way merge driver.""" |
|
Nico
2016/09/20 21:54:26
maybe add some more here (what does this do, how d
dcheng
2016/09/20 22:11:19
Done.
|
| + |
| +import subprocess |
| +import sys |
| + |
| +import clang_format |
| + |
| + |
| +def main(): |
| + if len(sys.argv) < 5: |
| + print('usage: %s <base> <current> <others> <path in the tree>' % |
| + sys.argv[0]) |
| + sys.exit(1) |
| + |
| + base, current, others, file_name_in_tree = sys.argv[1:5] |
| + print '\nRunning clang-format 3-way merge driver on ' + file_name_in_tree |
| + |
| + try: |
| + tool = clang_format.FindClangFormatToolInChromiumTree() |
| + for fpath in base, current, others: |
| + with open(fpath, 'rb') as input_file: |
|
dcheng
2016/09/20 21:41:06
Merge always appear to occur relative to the repo
Nico
2016/09/20 21:54:26
add a comment summarizing this
dcheng
2016/09/20 22:11:19
Done.
|
| + output = subprocess.check_output( |
| + [tool, '--assume-filename=%s' % file_name_in_tree, '--style=file'], |
| + stdin=input_file) |
| + with open(fpath, 'wb') as output_file: |
| + output_file.write(output) |
| + except clang_format.NotFoundError, e: |
| + print e |
| + print 'Failed to find clang-format. Falling-back on standard 3-way merge' |
| + |
| + return subprocess.call(['git', 'merge-file', '-Lcurrent', '-Lbase', '-Lother', |
| + current, base, others]) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |