Skip to content

Instantly share code, notes, and snippets.

@tildejustin
Last active January 29, 2025 22:04
Show Gist options
  • Save tildejustin/746e54dfa8f4ccf8bca77378b11ea171 to your computer and use it in GitHub Desktop.
Save tildejustin/746e54dfa8f4ccf8bca77378b11ea171 to your computer and use it in GitHub Desktop.
import csv
import git
import hashlib
import json
import os
def run():
with open("legal-builds.csv", "r") as f:
reader = csv.reader(f)
fields = next(reader)
curr = list(reader)
for path, _, file in os.walk("legal-mods"):
# should be assert but there was one broken commit
if len(file) != 1 or path.count("/") != 2:
continue
file = file[0]
if file.endswith(".json"):
with open(os.path.join(path, file), "r") as f:
data = json.load(f)
file = data["link"][data["link"].rfind("/") + 1 :]
hash = data["hash"]
else:
with open(os.path.join(path, file), "rb") as f:
hash = hashlib.sha512(f.read()).hexdigest()
curr_entry = None
modid = path[path.index("/") + 1 : path.rindex("/")]
for l in curr:
if l[0] == modid and l[4] == hash:
curr_entry = l
break
if curr_entry is not None:
if curr_entry[1] != file:
print(f"changing filename from {curr_entry[0]} to {file}")
curr_entry[1] = file
else:
print(f"adding {file}")
time = repo.head.commit.committed_date
date = repo.head.commit.committed_datetime.date().isoformat()
modid = path[path.index("/") + 1 : path.rindex("/")]
curr.append([modid, file, time, date, hash])
with open("legal-builds.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(fields)
writer.writerows(curr)
with open("legal-builds.csv", "w+") as f:
csv.writer(f).writerow(["modid", "filename", "timestamp", "date", "hash"])
with open("significant_commits.txt") as f:
commits = [s.strip() for s in f.readlines()]
repo = git.Repo(".")
for commit in commits[::-1]:
repo.git.checkout(commit)
print(commit)
run()
repo.git.checkout("main")
@tildejustin
Copy link
Author

tildejustin commented Jan 19, 2025

significant commits generated with git log --pretty=format:"%h" --abbrev=99 -- legal-mods > significant_commits.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment