Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 452794451766fb9fd8691207e8e0ee8fd80d36bc..45f7dcd8c07cf3a2295b951baec6c6ad71464875 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -80,15 +80,20 @@ def RunGit(args, **kwargs): |
| return RunCommand(['git'] + args, **kwargs) |
| -def RunGitWithCode(args): |
| +def RunGitWithCode(args, suppress_stderr=False): |
| """Returns return code and stdout.""" |
| try: |
| env = os.environ.copy() |
| # 'cat' is a magical git string that disables pagers on all platforms. |
| env['GIT_PAGER'] = 'cat' |
| + if suppress_stderr: |
| + stderr = open("/dev/null", "w") |
|
ncarter (slow)
2014/01/17 07:07:08
"/dev/null" -> os.devnull
This is very much TIL t
enne (OOO)
2014/01/17 19:24:42
Thanks! Done.
|
| + else: |
|
ncarter (slow)
2014/01/17 07:07:08
pylint usually will yell at you to use single-quot
enne (OOO)
2014/01/17 19:24:42
Oops, done. C++ has infected by brain. :(
|
| + stderr = sys.stderr |
| out, code = subprocess2.communicate(['git'] + args, |
| env=env, |
| - stdout=subprocess2.PIPE) |
| + stdout=subprocess2.PIPE, |
| + stderr=stderr) |
| return code, out[0] |
| except ValueError: |
| # When the subprocess fails, it returns None. That triggers a ValueError |
| @@ -2301,7 +2306,10 @@ def CMDowners(parser, args): |
| def CMDformat(parser, args): |
| """Runs clang-format on the diff.""" |
| CLANG_EXTS = ['.cc', '.cpp', '.h'] |
| - parser.add_option('--full', action='store_true', default=False) |
| + parser.add_option('--full', action='store_true', |
| + help='Reformat the full content of all touched files') |
| + parser.add_option('--dry-run', action='store_true', |
| + help='Don\'t modify any file on disk.') |
| opts, args = parser.parse_args(args) |
| if args: |
| parser.error('Unrecognized args: %s' % ' '.join(args)) |
| @@ -2358,8 +2366,10 @@ def CMDformat(parser, args): |
| if not files: |
| print "Nothing to format." |
| return 0 |
| - RunCommand([clang_format_tool, '-i', '-style', 'Chromium'] + files, |
| - cwd=top_dir) |
| + cmd = [clang_format_tool, '-style', 'Chromium'] |
| + if not opts.dry_run: |
| + cmd.append('-i') |
| + stdout = RunCommand(cmd + files, cwd=top_dir) |
| else: |
| env = os.environ.copy() |
| env['PATH'] = os.path.dirname(clang_format_tool) |
| @@ -2370,9 +2380,13 @@ def CMDformat(parser, args): |
| except clang_format.NotFoundError, e: |
| DieWithError(e) |
| - cmd = [sys.executable, script, '-p0', '-style', 'Chromium', '-i'] |
| + cmd = [sys.executable, script, '-p0', '-style', 'Chromium'] |
| + if not opts.dry_run: |
| + cmd.append('-i') |
| - RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) |
| + stdout = RunCommand(cmd, stdin=diff_output, cwd=top_dir, env=env) |
| + if opts.dry_run and len(stdout) > 0: |
| + return 2 |
| return 0 |