Use rstrip when getting footer tags

A quick bugfix was made in cc29098042 that removed trailing empty lines
when getting tags out of the git log.  This preserved the behavior that
tags with trailing whitespace would retain said whitespace.

This change instead simplifies the logic that removes trailing
whitespace with the side effect that whitespace at the end of the last
tag is also stripped.  The unittests are adjusted accordingly

Bug: 1130601
Change-Id: I26d39736179b36ac2573de1ca003a5bc09f30a28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2423050
Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@google.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
changes/50/2423050/2
Shahbaz Youssefi 5 years ago committed by LUCI CQ
parent 02ffb6f47a
commit 407b5a54a9

@ -65,13 +65,7 @@ def split_footers(message):
There could be fewer parsed_footers than footer lines if some lines in
last paragraph are malformed.
"""
message_lines = list(message.splitlines())
# First, remove trailing empty lines from the change to get to the footer
while len(message_lines) > 0 and (message_lines[-1] == ''
or message_lines[-1].isspace()):
message_lines.pop()
message_lines = list(message.rstrip().splitlines())
footer_lines = []
maybe_footer_lines = []
for line in reversed(message_lines):

@ -46,9 +46,15 @@ My commit message is my best friend. It is my life. I must master it.
git_footers.split_footers('H\n\nBug:\nAlso: footer'),
(['H', ''], ['Bug:', 'Also: footer'],
[('Bug', ''), ('Also', 'footer')]))
self.assertEqual(git_footers.split_footers('H\n\nBug: '),
(['H', ''], ['Bug:'], [('Bug', '')]))
self.assertEqual(git_footers.split_footers('H\n\nBug: 1234 '),
(['H', ''], ['Bug: 1234'], [('Bug', '1234')]))
self.assertEqual(
git_footers.split_footers('H\n\nBug: '),
(['H', ''], ['Bug: '], [('Bug', '')]))
git_footers.split_footers('H\n\nBug: 1234\nChange-Id: Ib4321 '),
(['H', ''], ['Bug: 1234', 'Change-Id: Ib4321'], [('Bug', '1234'),
('Change-Id', 'Ib4321')
]))
self.assertEqual(
git_footers.parse_footers(self._message), {})

Loading…
Cancel
Save