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

Side by Side Diff: git_footers.py

Issue 1812803002: Gerrit git cl: fix change-id appending. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: nit Created 4 years, 9 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
« no previous file with comments | « no previous file | tests/git_footers_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 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
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
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)
OLDNEW
« no previous file with comments | « no previous file | tests/git_footers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698