|
#!/usr/bin/env python3 |
|
|
|
import sys |
|
from subprocess import Popen, PIPE |
|
from datetime import datetime |
|
|
|
def runCommand(cmd) -> list[str]: |
|
p = Popen(cmd, stdout=PIPE) |
|
outB, errB = p.communicate() |
|
out = outB.decode("utf-8") |
|
if errB: |
|
print(errB.decode("utf-8")) |
|
sys.exit(1) |
|
return out.split("\n") |
|
|
|
|
|
def getObject(objId: str) -> dict[str, str]: |
|
data = {} |
|
for line in runCommand(["git", "cat-file", "-p", objId]): |
|
if not line: |
|
break |
|
key, _, value = line.partition(" ") |
|
data[key] = value |
|
return data |
|
|
|
|
|
table = [] |
|
|
|
for tag in runCommand(["git", "tag"]): |
|
if not tag: |
|
continue |
|
targetDict = getObject(tag) |
|
targetType = targetDict.get("type") |
|
if targetType: |
|
targetId = targetDict["object"] |
|
targetDict2 = getObject(targetId) |
|
else: |
|
targetId = runCommand(["git", "rev-parse", tag])[0] |
|
targetDict2 = targetDict |
|
if "committer" in targetDict: |
|
targetType = "lw:commit" |
|
else: |
|
targetType = "lw:other" |
|
|
|
timeStr = "" |
|
committerName = "" |
|
committer = targetDict2.get("committer") |
|
if committer: |
|
_, _, commiterTimeRaw = committer.partition("> ") |
|
timeStr = datetime.fromtimestamp(int(commiterTimeRaw.split(" ")[0])).strftime("%Y-%m-%d %H:%M:%S") |
|
committerName, _, _ = committer.partition(" <") |
|
|
|
table.append(( |
|
timeStr, |
|
targetType, |
|
tag, |
|
targetId, |
|
)) |
|
|
|
|
|
table.sort(reverse=True) |
|
|
|
for timeStr, targetType, tag, targetId in table: |
|
print(f"{timeStr} {targetType:12s} {targetId[:7]} {tag:15s} {committerName}") |
|
|