Commit 4018d9e8 authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Add routine/entrypoint to get the estimated repository size, convert to

mebi (using Blockstore.pm routine) and do not permit repositories over
5MiB for now. This is clearly temporary.
parent 3748fd56
......@@ -93,6 +93,7 @@ use libEmulab;
use libtestbed;
use WebTask;
use APT_Profile;
use Blockstore;
# Protos
sub fatal($);
......@@ -106,7 +107,9 @@ sub DoTagList();
sub DoCommitList();
sub DoCommitInfo();
sub DoGetSource();
sub DoGetRepoSize();
sub GetRepoSource($;$);
sub GetRepoSize($);
sub GetBranchList($);
sub GetTagList($);
sub GetCommitList($$);
......@@ -187,6 +190,9 @@ elsif ($action eq "commitlist") {
elsif ($action eq "commitinfo") {
DoCommitInfo();
}
elsif ($action eq "reposize") {
DoGetRepoSize();
}
else {
usage();
}
......@@ -290,6 +296,20 @@ sub DoClone()
if ($debug) {
print $output;
}
#
# Basic size check.
#
my $size = GetRepoSize($reponame);
if (!defined($size)) {
RemoveRepo($reponame);
fatal("Could not estimate repository size");
}
if ($size > 5) {
RemoveRepo($reponame);
UserError("Repository is too big: greate then 5MiB");
}
#
# Now get the geni-lib script or rspec, write it to the file or stdout.
#
......@@ -307,6 +327,7 @@ sub DoClone()
my $hash = GetCommitField($reponame, undef, "%H");
$webtask->log($log);
$webtask->hash($hash);
$webtask->size("$size MiB");
}
if (defined($ofile)) {
if ($ofile eq "-") {
......@@ -403,6 +424,18 @@ sub DoUpdate()
if ($debug) {
print $output;
}
#
# Basic size check.
#
my $size = GetRepoSize($reponame);
if (!defined($size)) {
fatal("Could not estimate repository size");
}
if ($size > 5) {
UserError("Repository is too big: greater then 5MiB");
}
#
# Now get the geni-lib script or rspec write it to the file or stdout.
#
......@@ -420,6 +453,7 @@ sub DoUpdate()
chomp($hash);
$webtask->log($log);
$webtask->hash($hash);
$webtask->size("$size MiB");
}
if (defined($ofile)) {
......@@ -933,11 +967,15 @@ sub DoCommitInfo()
}
chomp($output);
my ($hash,$author,$when,$log) = split(/\x1f/, $output);
my $size = GetRepoSize($reponame);
if (!defined($size)) {
$size = "???";
}
my $blob = {"hash" => $hash,
"author" => $author,
"when" => $when,
"log" => $log};
"log" => $log,
"size" => "$size MiB"};
if (defined($webtask)) {
$webtask->commitinfo($blob);
......@@ -984,6 +1022,78 @@ sub GetRepoName($)
return $reponame;
}
#
# Estimated Repo size.
#
sub DoGetRepoSize()
{
my $optlist = "n:p:";
my $which;
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
my $reponame = GetRepoName(\%options);
if (@ARGV) {
$which = shift(@ARGV);
# Silly taint check.
if ($which =~ /^(.*)$/) {
$which = $1;
}
}
if (! -e "$REPODIR/$reponame") {
fatal("Repository does not exist.");
}
my $size = GetRepoSize($reponame);
if (!defined($size)) {
fatal("Could not determine Repository size");
}
if (defined($webtask)) {
$webtask->reposize("$size Mib");
$webtask->Exited(0);
}
else {
print "$size Mib\n";
}
exit(0);
}
#
# Get estimated repository size.
#
sub GetRepoSize($)
{
my ($reponame) = @_;
chdir("$REPODIR/$reponame") or
fatal("Could not chdir to $REPODIR/$reponame");
my $gitsize = `$GIT count-objects -v -H | grep size-pack`;
if ($?) {
return undef;
}
if ($gitsize !~ /^size-pack:\s+([\w\.]+)\s+(\w+)$/) {
print STDERR "Could not parse object size: '$gitsize'\n";
return undef;
}
my $size = int($1);
my $unit = $2;
if ($unit eq "bytes") {
$unit = "B";
}
my $mebi = Blockstore::ConvertToMebi("${size}${unit}");
if ($mebi < 0) {
print STDERR "Could not convert size to MiB: ".
"${size}${unit}, '$gitsize'\n";
return undef;
}
# Zero is silly.
$mebi = 1
if ($mebi == 0);
return $mebi;
}
sub fatal($)
{
my ($mesg) = @_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment