public function archive($owner, $project, $format, $branch)
{
$repository = $project->getRepository();
$tree = $repository->getBranchTree($branch);
if (false === $tree) {
throw new HttpException(401);
}
$file = config('gitamin.cache_archives') . DIRECTORY_SEPARATOR . $project . DIRECTORY_SEPARATOR . substr($tree, 0, 2) . DIRECTORY_SEPARATOR . substr($tree, 2) . '.' . $format;
if (!file_exists($file)) {
$repository->createArchive($tree, $file, $format);
}
$filename = strtolower($project . '_' . $branch);
$filename = preg_replace('#[^a-z0-9]+#', '_', $filename);
$filename = $filename . '.' . $format;
return Response::download($file, $filename);
}