From 8d3163007e190709eebbddbc93ff4a024e94bc84 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 24 Jan 2018 23:27:19 +0100 Subject: [PATCH] improve parsing of history --- diffido.py | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/diffido.py b/diffido.py index 0db6b4a..7f65cda 100755 --- a/diffido.py +++ b/diffido.py @@ -36,7 +36,8 @@ DEFAULT_CONF = 'conf/diffido.conf' EMAIL_FROM = 'diffido@localhost' GIT_CMD = 'git' -re_commit = re.compile(r'[0-9a-f]{40} ') +re_commit = re.compile(r'^(?P[0-9a-f]{40}) (?P.*)\n(?: .* ' + '(?P\d+) insertion.* (?P\d+) deletion.*$)?', re.M) re_insertion = re.compile(r'(\d+) insertion') re_deletion = re.compile(r'(\d+) deletion') @@ -184,33 +185,12 @@ def get_history(id_): res = queue.get().decode('utf-8') p.join() history = [] - res_io = io.StringIO(res) - while True: - commit_line = res_io.readline().strip() - if not commit_line: - break - if re_commit.match(commit_line): - commit_id, message = commit_line.split(' ', 1) - if len(commit_id) != 40: - continue - changes_line = res_io.readline().strip() - if re_commit.match(changes_line): - commit_id, message = changes_line.split(' ', 1) - insert = 0 - delete = 0 - else: - insert = re_insertion.findall(changes_line) - if insert: - insert = int(insert[0]) - else: - insert = 0 - delete = re_deletion.findall(changes_line) - if delete: - delete = int(delete[0]) - else: - delete = 0 - history.append({'id': commit_id, 'message': message, 'insertions': insert, 'deletions': delete, - 'changes': max(insert, delete)}) + for match in re_commit.finditer(res): + info = match.groupdict() + info['insertions'] = int(info['insertions'] or 0) + info['deletions'] = int(info['deletions'] or 0) + info['changes'] = max(info['insertions'], info['deletions']) + history.append(info) lastid = None if history and 'id' in history[0]: lastid = history[0]['id']