| 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 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 | 2241 |
| 2242 | 2242 |
| 2243 def CMDformat(parser, args): | 2243 def CMDformat(parser, args): |
| 2244 """Runs clang-format on the diff.""" | 2244 """Runs clang-format on the diff.""" |
| 2245 CLANG_EXTS = ['.cc', '.cpp', '.h'] | 2245 CLANG_EXTS = ['.cc', '.cpp', '.h'] |
| 2246 parser.add_option('--full', action='store_true', default=False) | 2246 parser.add_option('--full', action='store_true', default=False) |
| 2247 opts, args = parser.parse_args(args) | 2247 opts, args = parser.parse_args(args) |
| 2248 if args: | 2248 if args: |
| 2249 parser.error('Unrecognized args: %s' % ' '.join(args)) | 2249 parser.error('Unrecognized args: %s' % ' '.join(args)) |
| 2250 | 2250 |
| 2251 # git diff generates paths against the root of the repository. Change |
| 2252 # to that directory so clang-format can find files even within subdirs. |
| 2253 rel_base_path = RunGit(['rev-parse', '--show-cdup']).strip() |
| 2254 if rel_base_path: |
| 2255 os.chdir(rel_base_path) |
| 2256 |
| 2251 # Generate diff for the current branch's changes. | 2257 # Generate diff for the current branch's changes. |
| 2252 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] | 2258 diff_cmd = ['diff', '--no-ext-diff', '--no-prefix'] |
| 2253 if opts.full: | 2259 if opts.full: |
| 2254 # Only list the names of modified files. | 2260 # Only list the names of modified files. |
| 2255 diff_cmd.append('--name-only') | 2261 diff_cmd.append('--name-only') |
| 2256 else: | 2262 else: |
| 2257 # Only generate context-less patches. | 2263 # Only generate context-less patches. |
| 2258 diff_cmd.append('-U0') | 2264 diff_cmd.append('-U0') |
| 2259 | 2265 |
| 2260 # Grab the merge-base commit, i.e. the upstream commit of the current | 2266 # Grab the merge-base commit, i.e. the upstream commit of the current |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2353 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2348 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2354 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2349 | 2355 |
| 2350 | 2356 |
| 2351 if __name__ == '__main__': | 2357 if __name__ == '__main__': |
| 2352 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2358 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2353 # unit testing. | 2359 # unit testing. |
| 2354 fix_encoding.fix_encoding() | 2360 fix_encoding.fix_encoding() |
| 2355 colorama.init() | 2361 colorama.init() |
| 2356 sys.exit(main(sys.argv[1:])) | 2362 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |