Last active
October 27, 2021 14:59
-
-
Save hikarin522/8bdd16a7d3e2de145be661227f17e094 to your computer and use it in GitHub Desktop.
git_find_big.sh の改良版 (PowerShell 7)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S pwsh -nop | |
$blobs = Start-ThreadJob { | |
gci "$(git rev-parse --git-common-dir)/objects/pack/pack-*.idx" | % -Parallel { | |
git verify-pack -v $_ | % { | |
if ($_ -match '^([\da-f]+) blob +(\d+) (\d+)') { | |
$blob = @{ | |
hash = $Matches[1] | |
file_size = [long]$Matches[2] | |
pack_size = [long]$Matches[3] | |
} | |
# 100KB以上 | |
if ($blob.file_size -ge (100 * 1024)) { | |
Write-Output $blob | |
} | |
} | |
} | |
} | sort -Property file_size, pack_size -Descending | |
} | |
$files = @{} | |
git rev-list --all --objects | % { | |
if ($_ -match '^([\da-f]+) (.+)$') { | |
$files.Add($Matches[1], $Matches[2]) | |
} | |
} | |
foreach ($blob in Receive-Job -Wait -AutoRemoveJob $blobs) { | |
$name = $files[$blob.hash] | |
if ($null -ne $name) { | |
Write-Host ("blob: {0}, size: {1:0,,.00}[MB], pack: {2:0,}[KB], {3}" -f $blob.hash, $blob.file_size, $blob.pack_size, $name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment