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

Side by Side Diff: git_cl.py

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

Powered by Google App Engine
This is Rietveld 408576698