Vi의 답변에서 git-fatfiles 스크립트는 모든 blob의 크기를보고 싶지만 사용할 수 없을 정도로 느립니다. 40 줄 출력 제한을 제거하고 마무리하는 대신 내 컴퓨터의 모든 RAM을 사용하려고했습니다. 그래서 나는 이것을 다시 썼습니다 : 이것은 수천 배 빠르며 기능 (옵션)을 추가했으며 이상한 버그가 제거되었습니다. 오래된 버전은 파일이 사용한 총 공간을보기 위해 출력을 합산하면 정확하지 않은 수를 줄 것입니다.
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open2;
use v5.14;
# Try to get the "format_bytes" function:
my $canFormat = eval {
require Number::Bytes::Human;
Number::Bytes::Human->import('format_bytes');
1;
};
my $format_bytes;
if ($canFormat) {
$format_bytes = \&format_bytes;
}
else {
$format_bytes = sub { return shift; };
}
# parse arguments:
my ($directories, $sum);
{
my $arg = $ARGV[0] // "";
if ($arg eq "--sum" || $arg eq "-s") {
$sum = 1;
}
elsif ($arg eq "--directories" || $arg eq "-d") {
$directories = 1;
$sum = 1;
}
elsif ($arg) {
print "Usage: $0 [ --sum, -s | --directories, -d ]\n";
exit 1;
}
}
# the format is [hash, file]
my %revList = map { (split(' ', $_))[0 => 1]; } qx(git rev-list --all --objects);
my $pid = open2(my $childOut, my $childIn, "git cat-file --batch-check");
# The format is (hash => size)
my %hashSizes = map {
print $childIn $_ . "\n";
my @blobData = split(' ', <$childOut>);
if ($blobData[1] eq 'blob') {
# [hash, size]
$blobData[0] => $blobData[2];
}
else {
();
}
} keys %revList;
close($childIn);
waitpid($pid, 0);
# Need to filter because some aren't files--there are useless directories in this list.
# Format is name => size.
my %fileSizes =
map { exists($hashSizes{$_}) ? ($revList{$_} => $hashSizes{$_}) : () } keys %revList;
my @sortedSizes;
if ($sum) {
my %fileSizeSums;
if ($directories) {
while (my ($name, $size) = each %fileSizes) {
# strip off the trailing part of the filename:
$fileSizeSums{$name =~ s|/[^/]*$||r} += $size;
}
}
else {
while (my ($name, $size) = each %fileSizes) {
$fileSizeSums{$name} += $size;
}
}
@sortedSizes = map { [$_, $fileSizeSums{$_}] }
sort { $fileSizeSums{$a} <=> $fileSizeSums{$b} } keys %fileSizeSums;
}
else {
# Print the space taken by each file/blob, sorted by size
@sortedSizes = map { [$_, $fileSizes{$_}] }
sort { $fileSizes{$a} <=> $fileSizes{$b} } keys %fileSizes;
}
for my $fileSize (@sortedSizes) {
printf "%s\t%s\n", $format_bytes->($fileSize->[1]), $fileSize->[0];
}
이 git-fatfiles.pl의 이름을 지정하고 실행하십시오. 파일의 모든 개정에서 사용 된 디스크 공간을 보려면 --sum옵션을 사용하십시오 . 같은 것을 볼 수 있지만 각 디렉토리 내의 파일에 대해서는 --directories옵션을 사용하십시오 . Number :: Bytes :: Human cpan 모듈 을 설치 하면 ( "cpan Number :: Bytes :: Human"실행) 크기가 "21M /path/to/file.mp4"로 형식이 지정됩니다.