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 re | 7 import re |
8 import sys | 8 import sys |
9 | 9 |
10 from collections import defaultdict | 10 from collections import defaultdict |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 assert 0 == len(get_footer_change_id(message)) | 76 assert 0 == len(get_footer_change_id(message)) |
77 change_id_line = 'Change-Id: %s' % change_id | 77 change_id_line = 'Change-Id: %s' % change_id |
78 # This code does the same as parse_footers, but keeps track of line | 78 # This code does the same as parse_footers, but keeps track of line |
79 # numbers so that ChangeId is inserted in the right place. | 79 # numbers so that ChangeId is inserted in the right place. |
80 lines = message.splitlines() | 80 lines = message.splitlines() |
81 footer_lines = [] | 81 footer_lines = [] |
82 for line in reversed(lines): | 82 for line in reversed(lines): |
83 if line == '' or line.isspace(): | 83 if line == '' or line.isspace(): |
84 break | 84 break |
85 footer_lines.append(line) | 85 footer_lines.append(line) |
| 86 else: |
| 87 # The whole description was consisting of footers, |
| 88 # which means those aren't footers. |
| 89 footer_lines = [] |
86 # footers order is from end to start of the message. | 90 # footers order is from end to start of the message. |
87 footers = map(parse_footer, footer_lines) | 91 footers = map(parse_footer, footer_lines) |
88 if not all(footers): | 92 if not footers or not all(footers): |
89 lines.append('') | 93 lines.append('') |
90 lines.append(change_id_line) | 94 lines.append(change_id_line) |
91 else: | 95 else: |
92 after = set(map(normalize_name, ['Bug', 'Issue', 'Test', 'Feature'])) | 96 after = set(map(normalize_name, ['Bug', 'Issue', 'Test', 'Feature'])) |
93 for i, (key, _) in enumerate(footers): | 97 for i, (key, _) in enumerate(footers): |
94 if normalize_name(key) in after: | 98 if normalize_name(key) in after: |
95 insert_at = len(lines) - i | 99 insert_at = len(lines) - i |
96 break | 100 break |
97 else: | 101 else: |
98 insert_at = len(lines) - len(footers) | 102 insert_at = len(lines) - len(footers) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 print '%s: %s' % (k, v) | 197 print '%s: %s' % (k, v) |
194 return 0 | 198 return 0 |
195 | 199 |
196 | 200 |
197 if __name__ == '__main__': | 201 if __name__ == '__main__': |
198 try: | 202 try: |
199 sys.exit(main(sys.argv[1:])) | 203 sys.exit(main(sys.argv[1:])) |
200 except KeyboardInterrupt: | 204 except KeyboardInterrupt: |
201 sys.stderr.write('interrupted\n') | 205 sys.stderr.write('interrupted\n') |
202 sys.exit(1) | 206 sys.exit(1) |
OLD | NEW |