diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index 9ffcec9..dc603e5 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -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 */ diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index aaf890d..f08d462 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -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, diff --git a/src/IDF/templates/idf/source/commit.html b/src/IDF/templates/idf/source/commit.html index 94b4554..785e6c0 100644 --- a/src/IDF/templates/idf/source/commit.html +++ b/src/IDF/templates/idf/source/commit.html @@ -31,6 +31,9 @@

{trans 'Change Details'}

{$diff.as_html()} +{aurl 'url', 'IDF_Views_Source::downloadDiff', array($project.shortname, $commit)} +

{trans 'Archive'} {trans 'Download the diff file'}

+ {/if} {/block} {block context}