# -*- coding: utf-8 -*- r'''量一下仓库体积,找出推送 413 的原因。''' from __future__ import annotations import subprocess import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") GIT = r"C:\Program Files\Git\bin\git.exe" def git(*args: str) -> str: r = subprocess.run([GIT] + list(args), cwd=str(ROOT), capture_output=True, text=True, encoding="utf-8", errors="replace") return r.stdout or "" def main() -> int: print(" 一、仓库对象统计") print(" " + git("count-objects", "-vH").replace("\n", "\n ").strip()) print() print(" 二、各提交的树体积(找有没有混进大文件)") # 列出所有 blob 及大小 out = git("rev-list", "--objects", "--all") lines = [ln for ln in out.splitlines() if ln.strip()] print(" 对象条目 %d 个" % len(lines)) # 批量查类型和大小 payload = "\n".join(ln.split(" ", 1)[0] for ln in lines) r = subprocess.run([GIT, "cat-file", "--batch-check=%(objecttype) %(objectsize) %(objectname)"], cwd=str(ROOT), input=payload, capture_output=True, text=True, encoding="utf-8", errors="replace") info = {} for line in (r.stdout or "").splitlines(): parts = line.split() if len(parts) >= 3 and parts[0] == "blob": info[parts[2]] = int(parts[1]) blobs = [] for ln in lines: sha, _, name = ln.partition(" ") if sha in info: blobs.append((info[sha], name or "(无名)")) # 同一个 blob 可能出现多次,去重 seen = set() uniq = [] for size, name in blobs: key = (size, name) if key in seen: continue seen.add(key) uniq.append((size, name)) uniq.sort(reverse=True) total = sum(s for s, _ in uniq) print(" 去重后 %d 个 blob,合计 %.2f MB" % (len(uniq), total / 1024 / 1024)) print() print(" 最大的 15 个:") for size, name in uniq[:15]: print(" %9.1f KB %s" % (size / 1024, name[:70])) print() print(" 三、结论") biggest = uniq[0][0] if uniq else 0 if total > 20 * 1024 * 1024: print(" 仓库历史 %.1f MB,偏大 —— 推送会被 nginx 的" " client_max_body_size 拦(413)" % (total / 1024 / 1024)) print(" 最大单个文件 %.1f MB" / 1024 / 1024 % (biggest / 1024 / 1024) if False else " 最大单个文件 %.1f MB" % (biggest / 1024 / 1024)) else: print(" 仓库历史 %.2f MB,不算大" % (total / 1024 / 1024)) print() print(" 四、本机 Gitee 推得动说明不是仓库本身的问题,") print(" 是 EzHub 那边的 nginx 上限比 Gitee 小。") return 0 if __name__ == "__main__": sys.exit(main())