Added the download of a commit diff.
This fixes issue 50.
This commit is contained in:
parent
6bee793704
commit
4dc0747769
@ -232,6 +232,25 @@ class IDF_Views_Source
|
||||
$request);
|
||||
}
|
||||
|
||||
public $downloadDiff_precond = array('IDF_Precondition::accessSource');
|
||||
public function downloadDiff($request, $match)
|
||||
{
|
||||
$scm = IDF_Scm::get($request);
|
||||
$commit = $match[2];
|
||||
$branches = $scm->getBranches();
|
||||
if ('commit' != $scm->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);
|
||||
}
|
||||
$cobject = $scm->getCommit($commit);
|
||||
$rep = new Pluf_HTTP_Response($cobject->changes, 'text/plain');
|
||||
$rep->headers['Content-Disposition'] = 'attachment; filename="'.$commit.'.diff"';
|
||||
return $rep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should only be called through self::tree
|
||||
*/
|
||||
|
@ -171,6 +171,12 @@ $ctl[] = array('regex' => '#^/p/([\-\w]+)/source/commit/([^/]+)/$#',
|
||||
'model' => 'IDF_Views_Source',
|
||||
'method' => 'commit');
|
||||
|
||||
$ctl[] = array('regex' => '#^/p/([\-\w]+)/source/ddiff/([^/]+)/$#',
|
||||
'base' => $base,
|
||||
'priority' => 4,
|
||||
'model' => 'IDF_Views_Source',
|
||||
'method' => 'downloadDiff');
|
||||
|
||||
$ctl[] = array('regex' => '#^/p/([\-\w]+)/source/download/([^/]+)/$#',
|
||||
'base' => $base,
|
||||
'priority' => 4,
|
||||
|
@ -31,6 +31,9 @@
|
||||
<h2>{trans 'Change Details'}</h2>
|
||||
|
||||
{$diff.as_html()}
|
||||
{aurl 'url', 'IDF_Views_Source::downloadDiff', array($project.shortname, $commit)}
|
||||
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download the diff file'}</a></p>
|
||||
|
||||
{/if}
|
||||
{/block}
|
||||
{block context}
|
||||
|
Loading…
Reference in New Issue
Block a user