Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: git_cl.py

Issue 14629012: Adding 'git cl format' command for clang-format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Nits Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 _, args = parser.parse_args(args) 1924 _, args = parser.parse_args(args)
1925 if args: 1925 if args:
1926 parser.error('Unrecognized args: %s' % ' '.join(args)) 1926 parser.error('Unrecognized args: %s' % ' '.join(args))
1927 cl = Changelist() 1927 cl = Changelist()
1928 # Ensure there actually is an issue to close. 1928 # Ensure there actually is an issue to close.
1929 cl.GetDescription() 1929 cl.GetDescription()
1930 cl.CloseIssue() 1930 cl.CloseIssue()
1931 return 0 1931 return 0
1932 1932
1933 1933
1934 def CMDformat(parser, args):
1935 """run clang-format on the diff"""
1936 CLANG_EXTS = ['.cc', '.cpp', '.h']
1937 parser.add_option('--full', action='store_true', default=False)
1938 opts, args = parser.parse_args(args)
1939 if args:
1940 parser.error('Unrecognized args: %s' % ' '.join(args))
1941
1942 if opts.full:
1943 cmd = ['diff', '--name-only', '--'] + ['.*' + ext for ext in CLANG_EXTS]
1944 files = RunGit(cmd).split()
1945 if not files:
1946 print "Nothing to format."
1947 return 0
1948 RunCommand(['clang-format', '-i'] + files)
1949 else:
1950 cfd_path = os.path.join('/usr', 'lib', 'clang-format',
1951 'clang-format-diff.py')
1952 if not os.path.exists(cfd_path):
1953 print >> sys.stderr, 'Could not find clang-format-diff at %s.' % cfd_path
1954 return 2
1955 cmd = ['diff', '-U0', '@{u}', '--'] + ['.*' + ext for ext in CLANG_EXTS]
1956 diff = RunGit(cmd)
1957 cmd = [sys.executable, '/usr/lib/clang-format/clang-format-diff.py',
Jiang 2013/05/06 19:27:31 Why don't you use cfd_path here?
1958 '-style', 'Chromium']
1959 RunCommand(cmd, stdin=diff)
1960
1961 return 0
1962
1963
1934 def Command(name): 1964 def Command(name):
1935 return getattr(sys.modules[__name__], 'CMD' + name, None) 1965 return getattr(sys.modules[__name__], 'CMD' + name, None)
1936 1966
1937 1967
1938 def CMDhelp(parser, args): 1968 def CMDhelp(parser, args):
1939 """print list of commands or help for a specific command""" 1969 """print list of commands or help for a specific command"""
1940 _, args = parser.parse_args(args) 1970 _, args = parser.parse_args(args)
1941 if len(args) == 1: 1971 if len(args) == 1:
1942 return main(args + ['--help']) 1972 return main(args + ['--help'])
1943 parser.print_help() 1973 parser.print_help()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2035 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2006 2036
2007 # Not a known command. Default to help. 2037 # Not a known command. Default to help.
2008 GenUsage(parser, 'help') 2038 GenUsage(parser, 'help')
2009 return CMDhelp(parser, argv) 2039 return CMDhelp(parser, argv)
2010 2040
2011 2041
2012 if __name__ == '__main__': 2042 if __name__ == '__main__':
2013 fix_encoding.fix_encoding() 2043 fix_encoding.fix_encoding()
2014 sys.exit(main(sys.argv[1:])) 2044 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698