OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 import argparse | 6 import argparse |
7 import sys | 7 import sys |
8 | 8 |
9 import subprocess2 | 9 import subprocess2 |
10 | 10 |
11 import git_common as git | 11 import git_common as git |
12 | 12 |
13 def main(args): | 13 def main(args): |
14 default_args = git.config_list('depot-tools.upstream-diff.default-args') | 14 default_args = git.config_list('depot-tools.upstream-diff.default-args') |
15 args = default_args + args | 15 args = default_args + args |
16 | 16 |
17 parser = argparse.ArgumentParser() | 17 parser = argparse.ArgumentParser() |
18 parser.add_argument('--wordwise', action='store_true', default=False, | 18 parser.add_argument('--wordwise', action='store_true', default=False, |
19 help=( | 19 help=( |
20 'Print a colorized wordwise diff ' | 20 'Print a colorized wordwise diff ' |
21 'instead of line-wise diff')) | 21 'instead of line-wise diff')) |
22 parser.add_argument('--HEAD', action='store_true', default=False, | |
23 help=('Diff against HEAD instead of the working copy.' | |
agable
2014/05/07 00:57:48
No space between this period and 'Much...'
iannucci
2014/05/07 01:02:23
Good catch. Done.
| |
24 'Much faster for large repos.')) | |
22 opts, extra_args = parser.parse_known_args(args) | 25 opts, extra_args = parser.parse_known_args(args) |
23 | 26 |
24 cur = git.current_branch() | 27 cur = git.current_branch() |
25 if not cur or cur == 'HEAD': | 28 if not cur or cur == 'HEAD': |
26 print 'fatal: Cannot perform git-upstream-diff while not on a branch' | 29 print 'fatal: Cannot perform git-upstream-diff while not on a branch' |
27 return 1 | 30 return 1 |
28 | 31 |
29 par = git.upstream(cur) | 32 par = git.upstream(cur) |
30 if not par: | 33 if not par: |
31 print 'fatal: No upstream configured for branch \'%s\'' % cur | 34 print 'fatal: No upstream configured for branch \'%s\'' % cur |
32 return 1 | 35 return 1 |
33 | 36 |
34 cmd = [git.GIT_EXE, 'diff', '--patience', '-C', '-C'] | 37 cmd = [git.GIT_EXE, 'diff', '--patience', '-C', '-C'] |
35 if opts.wordwise: | 38 if opts.wordwise: |
36 cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])'] | 39 cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])'] |
37 cmd += [git.get_or_create_merge_base(cur, par)] | 40 if opts.HEAD: |
41 cmd += ['%s..%s' % (git.get_or_create_merge_base(cur, par), cur)] | |
42 else: | |
43 cmd += [git.get_or_create_merge_base(cur, par)] | |
38 | 44 |
39 cmd += extra_args | 45 cmd += extra_args |
40 | 46 |
41 subprocess2.check_call(cmd) | 47 subprocess2.check_call(cmd) |
42 | 48 |
43 | 49 |
44 if __name__ == '__main__': | 50 if __name__ == '__main__': |
45 sys.exit(main(sys.argv[1:])) | 51 sys.exit(main(sys.argv[1:])) |
OLD | NEW |