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 84c0017c03
commit 7dfb2ff4e3

110
logdif.py
View File

@ -7,51 +7,60 @@ which should be in the branch where logdif.py is running
import sys import sys
from subprocess import check_output from subprocess import check_output
branches = sys.argv[1:] branches = sys.argv[1:3]
commits = {} commits = {}
log_no = {} log_no = {}
log_title = {}
cursor = {} cursor = {}
short_set = set()
since_info = [] 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:
# a file containing
# YYYY-mm-dd <branch1> <branch2>
# for each date the branches are synced
for line in f:
if line.strip():
info = line.split()
if set(branches) & set(info[1:3]) == set(branches):
since_info.append(info[0])
since = sorted(since_info)[-1] if since_info else None
with open("sync_branches") as f:
# a file containing
# YYYY-mm-dd <branch1> <branch2>
# for each date the branches are synced
for line in f:
if line.strip():
info = line.split()
if set(branches) & set(info[1:3]) == set(branches):
since_info.append(info[0])
gitlog = ['git', 'log', '--oneline'] gitlog = ['git', 'log', '--oneline']
if since_info: if since:
since = sorted(since_info)[-1] gitlog.append(f'--since-as-filter={since}')
print(f'commits since {since}')
gitlog.append(f'--since-as-filter={sorted(since_info)[-1]}')
else: else:
print(f'no info for {branches} found in file sync_branches') print(f'no info for {branches} found in file sync_branches')
for br in branches: for br in branches:
cursor[br] = 0 cursor[br] = 0
output = check_output(gitlog + [br]) # collect hashes of commis newer than since
log_title[br] = bytitle = {} 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 = [] log_no[br] = byno = []
no = 0 no = 0
for line in output.decode('utf-8').split('\n'): for line in output.decode('utf-8').split('\n'):
if line: if line:
hash, title = line.split(' ', 1) commit, title = line.split(' ', 1)
bytitle.setdefault(title, []).append([(no, hash)]) byno.append([commit, title])
byno.append([hash, title])
no += 1 no += 1
# find matches # find matches
for br, byno in log_no.items(): for br, byno in log_no.items():
for no, line in enumerate(byno): for no, line in enumerate(byno):
commits.setdefault(line[1], {}).setdefault(br, []).append((no, line)) commits.setdefault(line[1], {}).setdefault(br, []).append((no, line))
ordered = {} ordered = {}
for title, info in commits.items(): for title, info in commits.items():
@ -62,6 +71,7 @@ commits = ordered
cnt = [0] cnt = [0]
def print_commit(line): def print_commit(line):
if not line[1]: if not line[1]:
return # title cleared: this line is already printed return # title cleared: this line is already printed
@ -69,34 +79,38 @@ def print_commit(line):
info = commits[line[1]] info = commits[line[1]]
output = [] output = []
title = line[1] title = line[1]
visible = False
for br in log_no: for br in log_no:
infolist = info.get(br) infolist = info.get(br)
if infolist: if infolist:
no, iline = infolist.pop(0) no, iline = infolist.pop(0)
if not infolist: if not infolist:
info.pop(br) info.pop(br)
output.append(f'{no:3}:{iline[0]}') if iline[0] in short_set:
iline[1] = '' # clear title visible = True
else: output.append(f'{no:3}:{iline[0]}')
output.append(' ' * 11) iline[1] = '' # clear title
print(' '.join(output), title) else:
cnt[0] += 1 output.append(' ' * 11)
if cnt[0] % 50 == 0: if visible:
input(f' {br0:11s} {br1:11s}') print(' '.join(output), title)
cnt[0] += 1
if cnt[0] % 50 == 0:
input(f' {br0:11s} {br1:11s}')
(br0, log0), (br1, log1) = list(log_no.items()) (br0, log0), (br1, log1) = list(log_no.items())
no1 = 0 no1 = 0
for no0, line0 in enumerate(log0): for no0, line0 in enumerate(log0):
if line0[1]: # line not yet printed if line0[1]: # line not yet printed
infodict = commits[line0[1]] infodict = commits[line0[1]]
if len(infodict) > 1: # found a match if len(infodict) > 1: # found a match
info0 = infodict[br1] info0 = infodict[br1]
# loop over commits in br1 until matched no # loop over commits in br1 until matched no
no1end = info0[0][0] no1end = info0[0][0]
if no1end > no0: if no1end > no0:
for n in range(no0, no1end): for n in range(no0, no1end):
line1 = log1[n] line1 = log1[n]
print_commit(line1) print_commit(line1)
no1 = no1end no1 = no1end
print_commit(line0) print_commit(line0)