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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 # Initialized in main() | 45 # Initialized in main() |
46 settings = None | 46 settings = None |
47 | 47 |
48 | 48 |
49 def DieWithError(message): | 49 def DieWithError(message): |
50 print >> sys.stderr, message | 50 print >> sys.stderr, message |
51 sys.exit(1) | 51 sys.exit(1) |
52 | 52 |
53 | 53 |
54 def QuoteCommand(command): | |
55 """Quotes command on Windows so it runs fine even with & and | in the string. | |
56 """ | |
57 if sys.platform == 'win32': | |
58 def fix(arg): | |
59 if ('&' in arg or '|' in arg) and '"' not in arg: | |
60 arg = '"%s"' % arg | |
61 return arg | |
62 command = [fix(arg) for arg in command] | |
63 return command | |
64 | |
65 | |
66 def RunCommand(args, error_ok=False, error_message=None, **kwargs): | 54 def RunCommand(args, error_ok=False, error_message=None, **kwargs): |
67 try: | 55 try: |
68 return subprocess2.check_output(QuoteCommand(args), **kwargs) | 56 return subprocess2.check_output(args, shell=False, **kwargs) |
69 except subprocess2.CalledProcessError, e: | 57 except subprocess2.CalledProcessError, e: |
70 if not error_ok: | 58 if not error_ok: |
71 DieWithError( | 59 DieWithError( |
72 'Command "%s" failed.\n%s' % ( | 60 'Command "%s" failed.\n%s' % ( |
73 ' '.join(args), error_message or e.stdout or '')) | 61 ' '.join(args), error_message or e.stdout or '')) |
74 return e.stdout | 62 return e.stdout |
75 | 63 |
76 | 64 |
77 def RunGit(args, **kwargs): | 65 def RunGit(args, **kwargs): |
78 """Returns stdout.""" | 66 """Returns stdout.""" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 (upstream_branch, self.GetBranch())) | 526 (upstream_branch, self.GetBranch())) |
539 | 527 |
540 issue = ConvertToInteger(self.GetIssue()) | 528 issue = ConvertToInteger(self.GetIssue()) |
541 patchset = ConvertToInteger(self.GetPatchset()) | 529 patchset = ConvertToInteger(self.GetPatchset()) |
542 if issue: | 530 if issue: |
543 description = self.GetDescription() | 531 description = self.GetDescription() |
544 else: | 532 else: |
545 # If the change was never uploaded, use the log messages of all commits | 533 # If the change was never uploaded, use the log messages of all commits |
546 # up to the branch point, as git cl upload will prefill the description | 534 # up to the branch point, as git cl upload will prefill the description |
547 # with these log messages. | 535 # with these log messages. |
548 description = CreateDescriptionFromLog([upstream_branch + '..']) | 536 description = RunCommand(['git', 'log', '--pretty=format:%s%n%n%b', |
| 537 '%s...' % (upstream_branch)]).strip() |
549 | 538 |
550 if not author: | 539 if not author: |
551 author = RunGit(['config', 'user.email']).strip() or None | 540 author = RunGit(['config', 'user.email']).strip() or None |
552 return presubmit_support.GitChange( | 541 return presubmit_support.GitChange( |
553 name, | 542 name, |
554 description, | 543 description, |
555 absroot, | 544 absroot, |
556 files, | 545 files, |
557 issue, | 546 issue, |
558 patchset, | 547 patchset, |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 """Pulls out the commit log to use as a base for the CL description.""" | 872 """Pulls out the commit log to use as a base for the CL description.""" |
884 log_args = [] | 873 log_args = [] |
885 if len(args) == 1 and not args[0].endswith('.'): | 874 if len(args) == 1 and not args[0].endswith('.'): |
886 log_args = [args[0] + '..'] | 875 log_args = [args[0] + '..'] |
887 elif len(args) == 1 and args[0].endswith('...'): | 876 elif len(args) == 1 and args[0].endswith('...'): |
888 log_args = [args[0][:-1]] | 877 log_args = [args[0][:-1]] |
889 elif len(args) == 2: | 878 elif len(args) == 2: |
890 log_args = [args[0] + '..' + args[1]] | 879 log_args = [args[0] + '..' + args[1]] |
891 else: | 880 else: |
892 log_args = args[:] # Hope for the best! | 881 log_args = args[:] # Hope for the best! |
893 return RunGit(['log', '--pretty=format:%s%n%n%b'] + log_args) | 882 return RunGit(['log', '--pretty=format:%s\n\n%b'] + log_args) |
894 | 883 |
895 | 884 |
896 def ConvertToInteger(inputval): | 885 def ConvertToInteger(inputval): |
897 """Convert a string to integer, but returns either an int or None.""" | 886 """Convert a string to integer, but returns either an int or None.""" |
898 try: | 887 try: |
899 return int(inputval) | 888 return int(inputval) |
900 except (TypeError, ValueError): | 889 except (TypeError, ValueError): |
901 return None | 890 return None |
902 | 891 |
903 | 892 |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 1551 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
1563 | 1552 |
1564 # Not a known command. Default to help. | 1553 # Not a known command. Default to help. |
1565 GenUsage(parser, 'help') | 1554 GenUsage(parser, 'help') |
1566 return CMDhelp(parser, argv) | 1555 return CMDhelp(parser, argv) |
1567 | 1556 |
1568 | 1557 |
1569 if __name__ == '__main__': | 1558 if __name__ == '__main__': |
1570 fix_encoding.fix_encoding() | 1559 fix_encoding.fix_encoding() |
1571 sys.exit(main(sys.argv[1:])) | 1560 sys.exit(main(sys.argv[1:])) |
OLD | NEW |