Added the ability to download a zip file of the code at a given commit.
This commit is contained in:
parent
d46ddea543
commit
49f339c7c5
@ -301,4 +301,19 @@ class IDF_Git
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the command to create a zip archive at a given commit.
|
||||
*
|
||||
* @param string Commit
|
||||
* @param string Prefix ('git-repo-dump')
|
||||
* @return string Command
|
||||
*/
|
||||
public function getArchiveCommand($commit, $prefix='git-repo-dump/')
|
||||
{
|
||||
return sprintf('GIT_DIR=%s git archive --format=zip --prefix=%s %s',
|
||||
escapeshellarg($this->repo),
|
||||
escapeshellarg($prefix),
|
||||
escapeshellarg($commit));
|
||||
}
|
||||
|
||||
}
|
@ -148,7 +148,6 @@ class IDF_Views_Source
|
||||
|
||||
public function commit($request, $match)
|
||||
{
|
||||
|
||||
$git = new IDF_Git(Pluf::f('git_repository'));
|
||||
$commit = $match[2];
|
||||
$branches = $git->getBranches();
|
||||
@ -176,7 +175,29 @@ class IDF_Views_Source
|
||||
$request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a zip archive of the current commit.
|
||||
*
|
||||
*/
|
||||
public function download($request, $match)
|
||||
{
|
||||
$commit = trim($match[2]);
|
||||
$git = new IDF_Git(Pluf::f('git_repository'));
|
||||
$branches = $git->getBranches();
|
||||
if ('commit' != $git->testHash($commit)) {
|
||||
// Redirect to the first branch
|
||||
$url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase',
|
||||
array($request->project->shortname,
|
||||
$branches[0]));
|
||||
return new Pluf_HTTP_Response_Redirect($url);
|
||||
}
|
||||
$base = $request->project->shortname.'-'.$commit;
|
||||
$cmd = $git->getArchiveCommand($commit, $base.'/');
|
||||
$rep = new Pluf_HTTP_Response_CommandPassThru($cmd, 'application/x-zip');
|
||||
$rep->headers['Content-Transfer-Encoding'] = 'binary';
|
||||
$rep->headers['Content-Disposition'] = 'attachment; filename="'.$base.'.zip"';
|
||||
return $rep;
|
||||
}
|
||||
}
|
||||
|
||||
function IDF_Views_Source_PrettySize($size)
|
||||
|
@ -141,6 +141,12 @@ $ctl[] = array('regex' => '#^/p/(\w+)/source/commit/(\w+)/$#',
|
||||
'model' => 'IDF_Views_Source',
|
||||
'method' => 'commit');
|
||||
|
||||
$ctl[] = array('regex' => '#^/p/(\w+)/source/download/(\w+)/$#',
|
||||
'base' => $base,
|
||||
'priority' => 4,
|
||||
'model' => 'IDF_Views_Source',
|
||||
'method' => 'download');
|
||||
|
||||
|
||||
// ---------- ADMIN --------------------------------------
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
{block docclass}yui-t1{assign $inSourceTree=true}{/block}
|
||||
{block body}
|
||||
<h2><a href="{url 'IDF_Views_Source::treeBase', array($project.shortname, $commit)}">{trans 'Root'}</a><span class="sep">/</span>{if $breadcrumb}{$breadcrumb|safe}{/if}</h2>
|
||||
|
||||
<table summary="" class="tree-list">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -41,6 +42,8 @@
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
{aurl 'url', 'IDF_Views_Source::download', array($project.shortname, $commit)}
|
||||
<p class="right"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download this version'}</a></p>
|
||||
|
||||
{/block}
|
||||
{block context}
|
||||
|
BIN
www/media/idf/img/package.png
Normal file
BIN
www/media/idf/img/package.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 540 B |
Loading…
Reference in New Issue
Block a user