Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from recipe_engine import recipe_api | 5 from recipe_engine import recipe_api |
| 6 | 6 |
| 7 import string | |
| 8 | |
| 9 def clean_message(msg): | |
| 10 """Cleans a commit message to be able to be printed on the command line.""" | |
| 11 i = 0 | |
| 12 for i in range(len(msg)): | |
|
tandrii(chromium)
2016/06/22 14:41:15
1. Pythonic way:
for i, c in enumerate(msg):
martiniss
2016/06/22 22:47:33
Great, thanks.
| |
| 13 if not msg[i] in string.printable: | |
| 14 break | |
| 15 if i < len(msg) - 1: | |
| 16 msg = msg[:i] | |
| 17 | |
| 18 return msg | |
| 19 | |
| 7 class GitClApi(recipe_api.RecipeApi): | 20 class GitClApi(recipe_api.RecipeApi): |
| 8 def __call__(self, subcmd, args, name=None, **kwargs): | 21 def __call__(self, subcmd, args, name=None, **kwargs): |
| 9 if not name: | 22 if not name: |
| 10 name = 'git_cl ' + subcmd | 23 name = 'git_cl ' + subcmd |
| 11 | 24 |
| 12 if kwargs.get('suffix'): | 25 if kwargs.get('suffix'): |
| 13 name = name + ' (%s)' % kwargs.pop('suffix') | 26 name = name + ' (%s)' % kwargs.pop('suffix') |
| 14 | 27 |
| 15 if 'cwd' not in kwargs: | 28 if 'cwd' not in kwargs: |
| 16 kwargs['cwd'] = (self.c and self.c.repo_location) or None | 29 kwargs['cwd'] = (self.c and self.c.repo_location) or None |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 32 args = ['-n', '-'] | 45 args = ['-n', '-'] |
| 33 if patch or codereview: | 46 if patch or codereview: |
| 34 assert patch and codereview, "Both patch and codereview must be provided" | 47 assert patch and codereview, "Both patch and codereview must be provided" |
| 35 args.append(patch) | 48 args.append(patch) |
| 36 args.append('--%s' % codereview) | 49 args.append('--%s' % codereview) |
| 37 | 50 |
| 38 return self( | 51 return self( |
| 39 'description', args, stdout=self.m.raw_io.output(), | 52 'description', args, stdout=self.m.raw_io.output(), |
| 40 stdin=self.m.raw_io.input(data=description), | 53 stdin=self.m.raw_io.input(data=description), |
| 41 name='git_cl set description', **kwargs) | 54 name='git_cl set description', **kwargs) |
| 55 | |
| 56 def upload(self, message, upload_args=None, **kwargs): | |
| 57 upload_args = upload_args or [] | |
| 58 # message can have unicode, which we can't pass on the command line, so | |
|
tandrii(chromium)
2016/06/22 14:41:15
why not pass it in a temp file, or stdin? Patching
martiniss
2016/06/22 22:47:33
I do that below, in the call to set description.
tandrii(chromium)
2016/06/23 11:23:50
oh, well, then why do you even need to clean the m
martiniss
2016/06/23 18:35:41
It sends out an email immediately, which has the s
martiniss
2016/06/23 18:44:15
Look at https://codereview.chromium.org/2098603002
| |
| 59 # upload it separately. Get a one line message for the subject for now. | |
| 60 one_line_message = clean_message(message.split('\n')[0]) + "..." | |
|
tandrii(chromium)
2016/06/22 14:41:15
message.splitlines()[0]
martiniss
2016/06/22 22:47:34
Done.
| |
| 61 | |
| 62 upload_args.extend(['-m', one_line_message]) | |
|
tandrii(chromium)
2016/06/23 11:23:50
s/one_line_message/"whatever"
| |
| 63 | |
| 64 result = self('upload', upload_args, **kwargs) | |
| 65 | |
| 66 # Really set the description | |
| 67 self.set_description(message) | |
| 68 return result | |
| 69 | |
| 70 def issue(self, **kwargs): | |
| 71 return self('issue', [], stdout=self.m.raw_io.output(), **kwargs) | |
| 72 | |
| OLD | NEW |