要計算回購中每個提交的大小,檢出每個提交的速度會很慢。一方面,您複製了很多工作,因爲您將重新計算未更改文件的大小。此外,你會錘擊你的文件系統不斷檢查出來的東西。 這是一個腳本,它查詢git repo以獲取所需的信息。主要好處是你從來沒有真正看過任何blob來計算它們的大小,而只是要求git告訴你。而且,你只需要查詢每個blob的git(通過Memoize的魔術)。
毫無疑問,這個腳本需要工作(一個自動抓取任何git失敗將是一個好主意),但它應該給你一個開始的地方。 (我已經從原始發佈中修改了這個參數來包含一個可以用作refspec的參數,如果沒有參數調用,這會輸出歷史記錄中每次提交的信息,您可以將一個ref-spec傳遞給rev-list例如,如果你有標籤v0和v1,你可以通過「v0..v1」作爲第一個參數。)
#!/usr/bin/env perl
use warnings;
use strict;
use Memoize;
my $rev_list = $ARGV[ 0 ] || "--all";
# Query git for the size of a blob. This is memoized, so we only
# ask for any blob once.
sub get_blob_size($) {
my $hash = shift;
my $size = qx(git cat-file -s $hash);
return int($size);
}
memoize('get_blob_size');
# Recursively compute the size of a tree. Note that git cat-file -s
# does not give the cumulative size of all the blobs in a tree.
sub compute_tree_size($);
sub compute_tree_size($) {
my $sha = shift;
my $size;
open my $objects, '-|', "git cat-file -p $sha";
while(<$objects>) {
my ($mode, $type, $hash, $name) = split;
if($type eq 'blob') {
$size += get_blob_size($hash);
} elsif($type eq 'tree') {
$size += compute_tree_size($hash);
}
}
return $size;
}
memoize('compute_tree_size');
# Generate a list of all commits
open my $objects, '-|', "git rev-list $rev_list |
git cat-file --batch-check";
# Traverse the commit list and report on the size of each.
while(<$objects>) {
my($commit, $type, $size) = split;
my($tree, $date) = split('@',
qx(git show --format="%[email protected]%ci" $commit | sed 1q));
chop $date;
printf "$date: %d\n", compute_tree_size $tree;
}
謝謝,我最終使用的東西非常接近這個。 – Philippe 2012-02-06 11:03:27