logdif.py: only one commit needs to be new enough

+ fixe intendation

Change-Id: I4b0c393767925532e1f105e80a215839a02214af
This commit is contained in:
zolliker 2024-01-29 15:48:43 +01:00
parent 715fcf4d36
commit 4ca7bf0a7d

View File

@ -7,13 +7,20 @@ which should be in the branch where logdif.py is running
import sys
from subprocess import check_output
branches = sys.argv[1:]
branches = sys.argv[1:3]
commits = {}
log_no = {}
log_title = {}
cursor = {}
short_set = set()
if len(sys.argv) < 3:
print('Usage: python3 logdif.py <branch1> <branch2> [<YYYY-mm-dd>]')
sys.exit(0)
if len(sys.argv) > 3:
since = sys.argv[3]
else:
since_info = []
with open("sync_branches") as f:
@ -23,31 +30,32 @@ with open("sync_branches") as f:
for line in f:
if line.strip():
info = line.split()
if set(branches) & set(info[1:]) == set(branches):
if set(branches) & set(info[1:3]) == set(branches):
since_info.append(info[0])
since = sorted(since_info)[-1] if since_info else None
gitlog = ['git', 'log', '--oneline']
if since_info:
since = sorted(since_info)[-1]
print(f'commits since {since}')
gitlog.append(f'--since-as-filter={sorted(since_info)[-1]}')
if since:
gitlog.append(f'--since-as-filter={since}')
else:
print(f'no info for {branches} found in file sync_branches')
for br in branches:
cursor[br] = 0
output = check_output(gitlog + [br])
log_title[br] = bytitle = {}
# collect hashes of commis newer than since
short_output = check_output(gitlog + [br])
for line in short_output.decode('utf-8').split('\n'):
if line:
short_set.add(line.split(' ', 1)[0])
output = check_output(gitlog[:3] + [br])
log_no[br] = byno = []
no = 0
for line in output.decode('utf-8').split('\n'):
if line:
hash, title = line.split(' ', 1)
bytitle.setdefault(title, []).append([(no, hash)])
byno.append([hash, title])
commit, title = line.split(' ', 1)
byno.append([commit, title])
no += 1
# find matches
for br, byno in log_no.items():
for no, line in enumerate(byno):
@ -62,6 +70,7 @@ commits = ordered
cnt = [0]
def print_commit(line):
if not line[1]:
return # title cleared: this line is already printed
@ -69,16 +78,20 @@ def print_commit(line):
info = commits[line[1]]
output = []
title = line[1]
visible = False
for br in log_no:
infolist = info.get(br)
if infolist:
no, iline = infolist.pop(0)
if not infolist:
info.pop(br)
if iline[0] in short_set:
visible = True
output.append(f'{no:3}:{iline[0]}')
iline[1] = '' # clear title
else:
output.append(' ' * 11)
if visible:
print(' '.join(output), title)
cnt[0] += 1
if cnt[0] % 50 == 0: