-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_large.py
More file actions
44 lines (37 loc) · 1.29 KB
/
Copy pathfind_large.py
File metadata and controls
44 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import subprocess
from pathlib import Path
def get_large_files():
# Get all objects
out = subprocess.check_output(['git', 'rev-list', '--objects', '--all']).decode('utf-8', errors='ignore')
objects = {}
for line in out.strip().split('\n'):
parts = line.split(maxsplit=1)
if len(parts) > 1:
objects[parts[0]] = parts[1]
# Find pack files
pack_dir = Path('.git/objects/pack')
idx_files = list(pack_dir.glob('*.idx'))
if not idx_files:
print("No pack files found.")
return
# Run verify-pack on all idx files
verify_out = []
for idx in idx_files:
try:
res = subprocess.check_output(['git', 'verify-pack', '-v', str(idx)]).decode('utf-8', errors='ignore')
verify_out.extend(res.split('\n'))
except:
pass
# Parse sizes
sizes = []
for line in verify_out:
parts = line.split()
if len(parts) >= 3 and parts[2].isdigit():
sizes.append((parts[0], int(parts[2])))
# Sort and print top 20
sizes.sort(key=lambda x: x[1], reverse=True)
for obj, size in sizes[:20]:
print(f"{size/1024/1024:.2f} MB: {objects.get(obj, obj)}")
if __name__ == '__main__':
get_large_files()