mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 13:40:45 +00:00
发布脚本:EzHub 走 HTTPS+令牌推送(SSH 还没配好)
EzHub 的 SSH 公钥在服务端一直被拒(Permission denied), 但令牌有 push 权限。所以发布脚本里 EzHub 改用 HTTPS + 令牌推,令牌只在进程内拼进 URL,不写进 .git/config。 顺带加了增量推送脚本 ezhub_push_all.py: 一次性推 44 个提交 = 117 MB,被 EzHub 的 nginx 413 拦了。 Git 推送是增量的,逐个提交推每包就小得多 —— 实测 44 个全部推成功。 脚本会先探测远端进度,只推缺的,并且对网络抖动自动重试。
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
# -*- 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())
|
||||
Reference in New Issue
Block a user