Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """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.
| |
| 6 | |
| 7 import subprocess | |
| 8 import sys | |
| 9 | |
| 10 import clang_format | |
| 11 | |
| 12 | |
| 13 def main(): | |
| 14 if len(sys.argv) < 5: | |
| 15 print('usage: %s <base> <current> <others> <path in the tree>' % | |
| 16 sys.argv[0]) | |
| 17 sys.exit(1) | |
| 18 | |
| 19 base, current, others, file_name_in_tree = sys.argv[1:5] | |
| 20 print '\nRunning clang-format 3-way merge driver on ' + file_name_in_tree | |
| 21 | |
| 22 try: | |
| 23 tool = clang_format.FindClangFormatToolInChromiumTree() | |
| 24 for fpath in base, current, others: | |
| 25 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.
| |
| 26 output = subprocess.check_output( | |
| 27 [tool, '--assume-filename=%s' % file_name_in_tree, '--style=file'], | |
| 28 stdin=input_file) | |
| 29 with open(fpath, 'wb') as output_file: | |
| 30 output_file.write(output) | |
| 31 except clang_format.NotFoundError, e: | |
| 32 print e | |
| 33 print 'Failed to find clang-format. Falling-back on standard 3-way merge' | |
| 34 | |
| 35 return subprocess.call(['git', 'merge-file', '-Lcurrent', '-Lbase', '-Lother', | |
| 36 current, base, others]) | |
| 37 | |
| 38 | |
| 39 if __name__ == '__main__': | |
| 40 sys.exit(main()) | |
| OLD | NEW |