From b8e4618d7aba2f73f286135db32cc971882c1761 Mon Sep 17 00:00:00 2001 From: Heikki Hokkanen Date: Sun, 4 May 2008 09:11:42 +0300 Subject: [PATCH] Allow downloading trees as targz/zip. --- doc/TODO | 1 - index.php | 29 +++++++++++++++++++++++++++++ templates/tree.php | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/doc/TODO b/doc/TODO index 0fe6c0c..8f54433 100644 --- a/doc/TODO +++ b/doc/TODO @@ -1,4 +1,3 @@ -- tree: allow downloading as tar/zip (git-archive) - common navigation bar / path at top - show times in UTC, except also in author's time somewhere diff --git a/index.php b/index.php index 6cdf758..74771f7 100644 --- a/index.php +++ b/index.php @@ -129,6 +129,35 @@ if ($action === 'index') { $page['projects'][] = get_project_info($p); } } +elseif ($action === 'archive') { + $project = $_REQUEST['p']; // TODO validate + $tree = $_REQUEST['h']; // TODO validate + $type = $_REQUEST['t']; + + // TODO check that the data passed is really valid + if ($type === 'targz') { + header("Content-Type: application/x-tar-gz"); + header("Content-Transfer-Encoding: binary"); + header("Content-Disposition: attachment; filename=\"$project-tree-$tree.tar.gz\";"); + $data = join("\n", run_git($project, "git archive --format=tar $tree |gzip")); + header("Content-Length: ". strlen($data)); + echo $data; + } + elseif ($type === 'zip') { + header("Content-Type: application/x-zip"); + header("Content-Transfer-Encoding: binary"); + header("Content-Disposition: attachment; filename=\"$project-tree-$tree.zip\";"); + $data = join("\n", run_git($project, "git archive --format=zip $tree")); + header("Content-Length: ". strlen($data)); + echo $data; + } + else { + die('Invalid archive type requested'); + } + + //"git-archive --format=tar $tree" + die(); +} elseif ($action === 'commit') { $template = 'commit'; $page['project'] = strtolower($_REQUEST['p']); // TODO validate diff --git a/templates/tree.php b/templates/tree.php index 5c5814a..d049547 100644 --- a/templates/tree.php +++ b/templates/tree.php @@ -16,3 +16,5 @@ foreach ($page['entries'] as $e) { ?> +

Download as tar.gz or zip.

+ -- 2.11.4.GIT