🔒 Repository is read-only – file editing is disabled.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
#!/usr/bin/env python3
"""Weryfikacja zmiany http:// -> https:// po fakcie (poprawne parowanie hunkow).
Git w obrebie hunka wypisuje najpierw wszystkie linie '-', potem wszystkie '+',
wiec parujemy je per-hunk, a nie linia-po-linii.
"""
import subprocess
import sys
R = "/var/lib/pagan-sync/recipes"
def git(*a):
return subprocess.run(["git", "-C", R] + list(a), capture_output=True, text=True).stdout
diff = git("diff", "-U0", "--no-color")
if not diff.strip():
print("brak zmian w git diff")
sys.exit(0)
minus, plus = [], []
pairs_ok = 0
bad = []
len_mismatch = []
def flush(fname):
global minus, plus, pairs_ok
if not minus and not plus:
minus, plus = [], []
return
if len(minus) != len(plus):
len_mismatch.append((fname, len(minus), len(plus), list(minus), list(plus)))
else:
for m, p in zip(minus, plus):
expect = m.replace("http://", "https://", 1)
if p == expect:
pairs_ok += 1
else:
bad.append((fname, m, p))
minus, plus = [], []
fname = "?"
for line in diff.splitlines():
if line.startswith("diff --git"):
flush(fname)
fname = line.split(" b/")[-1]
continue
if line.startswith("@@"):
flush(fname)
continue
if line.startswith(("--- ", "+++ ", "index ", "new file", "deleted", "old mode", "new mode",
"similarity", "rename", "Binary")):
continue
if line.startswith("-"):
minus.append(line[1:])
elif line.startswith("+"):
plus.append(line[1:])
flush(fname)
print(f"par -/+ zgodnych z zamiana schematu: {pairs_ok}")
print(f"par niezgodnych (tresc sie zmienila inaczej): {len(bad)}")
for f, m, p in bad[:20]:
print(f" [{f}]")
print(" MINUS:", m[:120])
print(" PLUS :", p[:120])
print(f"hunkow z rozna liczba -/+ (dodane/usuniete linie): {len(len_mismatch)}")
for f, a, b, ms, ps in len_mismatch[:10]:
print(f" [{f}] -={a} +={b}")
for x in ms[:6]:
print(" M:", x[:110])
for x in ps[:6]:
print(" P:", x[:110])