improve parsing of history
This commit is contained in:
parent
c99941ec5b
commit
8d3163007e
1 changed files with 8 additions and 28 deletions
36
diffido.py
36
diffido.py
|
@ -36,7 +36,8 @@ DEFAULT_CONF = 'conf/diffido.conf'
|
||||||
EMAIL_FROM = 'diffido@localhost'
|
EMAIL_FROM = 'diffido@localhost'
|
||||||
GIT_CMD = 'git'
|
GIT_CMD = 'git'
|
||||||
|
|
||||||
re_commit = re.compile(r'[0-9a-f]{40} ')
|
re_commit = re.compile(r'^(?P<id>[0-9a-f]{40}) (?P<message>.*)\n(?: .* '
|
||||||
|
'(?P<insertions>\d+) insertion.* (?P<deletions>\d+) deletion.*$)?', re.M)
|
||||||
re_insertion = re.compile(r'(\d+) insertion')
|
re_insertion = re.compile(r'(\d+) insertion')
|
||||||
re_deletion = re.compile(r'(\d+) deletion')
|
re_deletion = re.compile(r'(\d+) deletion')
|
||||||
|
|
||||||
|
@ -184,33 +185,12 @@ def get_history(id_):
|
||||||
res = queue.get().decode('utf-8')
|
res = queue.get().decode('utf-8')
|
||||||
p.join()
|
p.join()
|
||||||
history = []
|
history = []
|
||||||
res_io = io.StringIO(res)
|
for match in re_commit.finditer(res):
|
||||||
while True:
|
info = match.groupdict()
|
||||||
commit_line = res_io.readline().strip()
|
info['insertions'] = int(info['insertions'] or 0)
|
||||||
if not commit_line:
|
info['deletions'] = int(info['deletions'] or 0)
|
||||||
break
|
info['changes'] = max(info['insertions'], info['deletions'])
|
||||||
if re_commit.match(commit_line):
|
history.append(info)
|
||||||
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)})
|
|
||||||
lastid = None
|
lastid = None
|
||||||
if history and 'id' in history[0]:
|
if history and 'id' in history[0]:
|
||||||
lastid = history[0]['id']
|
lastid = history[0]['id']
|
||||||
|
|
Loading…
Reference in a new issue