Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 import json | 10 import json |
| (...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1916 _, args = parser.parse_args(args) | 1916 _, args = parser.parse_args(args) |
| 1917 if args: | 1917 if args: |
| 1918 parser.error('Unrecognized args: %s' % ' '.join(args)) | 1918 parser.error('Unrecognized args: %s' % ' '.join(args)) |
| 1919 cl = Changelist() | 1919 cl = Changelist() |
| 1920 # Ensure there actually is an issue to close. | 1920 # Ensure there actually is an issue to close. |
| 1921 cl.GetDescription() | 1921 cl.GetDescription() |
| 1922 cl.CloseIssue() | 1922 cl.CloseIssue() |
| 1923 return 0 | 1923 return 0 |
| 1924 | 1924 |
| 1925 | 1925 |
| 1926 def CMDformat(parser, args): | |
| 1927 """run clang-format on the diff""" | |
| 1928 CLANG_EXTS = ['.cc', '.cpp', '.h'] | |
| 1929 parser.add_option('--full', action='store_true', default=False) | |
| 1930 opts, args = parser.parse_args(args) | |
| 1931 if args: | |
| 1932 parser.error('Unrecognized args: %s' % ' '.join(args)) | |
| 1933 | |
| 1934 if opts.full: | |
| 1935 cmd = ['diff', '--name-only', '--'] + ['.*' + ext for ext in CLANG_EXTS] | |
| 1936 files = RunGit(cmd).split() | |
| 1937 if not files: | |
| 1938 print "Nothing to format." | |
| 1939 return 0 | |
| 1940 cmd = ['clang-format', '-i'] + files | |
| 1941 RunCommand(cmd) | |
|
M-A Ruel
2013/05/03 01:55:56
RunCommand(['clang-format', '-i'] + files)
agable
2013/05/06 17:41:31
Done.
| |
| 1942 else: | |
| 1943 cfd_path = os.path.join('/usr', 'lib', 'clang-format', | |
|
M-A Ruel
2013/05/03 01:55:56
It looks like it fits one line.
agable
2013/05/06 17:41:31
Nope, it's 82 chars.
| |
| 1944 'clang-format-diff.py') | |
| 1945 if not os.path.exists(cfd_path): | |
| 1946 print >> sys.stderr, 'Could not find clang-format-diff at %s.' % cfd_path | |
| 1947 return 2 | |
| 1948 cmd = ['diff', '-U0', '@{u}', '--'] + ['.*' + ext for ext in CLANG_EXTS] | |
| 1949 diff = RunGit(cmd) | |
| 1950 cmd = [sys.executable, '/usr/lib/clang-format/clang-format-diff.py', | |
| 1951 '-style', 'Chromium'] | |
| 1952 RunCommand(cmd, stdin=diff) | |
| 1953 | |
| 1954 return 0 | |
| 1955 | |
| 1956 | |
| 1926 def Command(name): | 1957 def Command(name): |
| 1927 return getattr(sys.modules[__name__], 'CMD' + name, None) | 1958 return getattr(sys.modules[__name__], 'CMD' + name, None) |
| 1928 | 1959 |
| 1929 | 1960 |
| 1930 def CMDhelp(parser, args): | 1961 def CMDhelp(parser, args): |
| 1931 """print list of commands or help for a specific command""" | 1962 """print list of commands or help for a specific command""" |
| 1932 _, args = parser.parse_args(args) | 1963 _, args = parser.parse_args(args) |
| 1933 if len(args) == 1: | 1964 if len(args) == 1: |
| 1934 return main(args + ['--help']) | 1965 return main(args + ['--help']) |
| 1935 parser.print_help() | 1966 parser.print_help() |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1997 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2028 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 1998 | 2029 |
| 1999 # Not a known command. Default to help. | 2030 # Not a known command. Default to help. |
| 2000 GenUsage(parser, 'help') | 2031 GenUsage(parser, 'help') |
| 2001 return CMDhelp(parser, argv) | 2032 return CMDhelp(parser, argv) |
| 2002 | 2033 |
| 2003 | 2034 |
| 2004 if __name__ == '__main__': | 2035 if __name__ == '__main__': |
| 2005 fix_encoding.fix_encoding() | 2036 fix_encoding.fix_encoding() |
| 2006 sys.exit(main(sys.argv[1:])) | 2037 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |