1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-27 07:06:13 +01:00

move changes file diff parser to separate function

This commit is contained in:
Ludwig Nussel 2010-02-02 14:12:22 +01:00
parent 048c479a3e
commit f29ffcdaef

View File

@ -4498,7 +4498,6 @@ def get_commit_message_template(pac):
"""
diff = ""
template = []
date_re = re.compile(r'\+(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z]{2}) ( ?[0-9]|[0-3][0-9]) .*')
if pac.todo:
files = filter(lambda file: '.changes' in file and pac.status(file) in ('A', 'M'), pac.todo)
if not files:
@ -4514,21 +4513,27 @@ def get_commit_message_template(pac):
f.close()
if diff:
index = 0
diff = diff.split('\n')
template = parse_diff_for_commit_message(diff)
# The first four lines contains a header of diff
for line in diff[3:]:
# this condition is magical, but it removes all unwanted lines from commit message
if not(line) or (line and line[0] != '+') or \
date_re.match(line) or \
line == '+' or line[0:3] == '+++':
continue
return template
if line == '+-------------------------------------------------------------------':
template.append('')
else:
template.append(line[1:])
def parse_diff_for_commit_message(diff, template = []):
date_re = re.compile(r'\+(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ([A-Z][a-z]{2}) ( ?[0-9]|[0-3][0-9]) .*')
index = 0
diff = diff.split('\n')
# The first four lines contains a header of diff
for line in diff[3:]:
# this condition is magical, but it removes all unwanted lines from commit message
if not(line) or (line and line[0] != '+') or \
date_re.match(line) or \
line == '+' or line[0:3] == '+++':
continue
if line == '+-------------------------------------------------------------------':
template.append('')
else:
template.append(line[1:])
return template