#385: removed before_filter

This commit is contained in:
Vokhmin Alexey V 2012-09-20 15:21:54 +04:00
parent c76618441e
commit 07f5224e76
2 changed files with 6 additions and 14 deletions

View File

@ -1,7 +1,6 @@
# -*- encoding : utf-8 -*- # -*- encoding : utf-8 -*-
class Projects::Git::TreesController < Projects::Git::BaseController class Projects::Git::TreesController < Projects::Git::BaseController
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show
before_filter :set_sha
skip_before_filter :set_branch_and_tree, :only => :archive skip_before_filter :set_branch_and_tree, :only => :archive
def show def show
@ -12,24 +11,17 @@ class Projects::Git::TreesController < Projects::Git::BaseController
def archive def archive
format = params[:format] format = params[:format]
if (@sha =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@sha =~ /[\s]+/) && (format =~ /^[\w]+$/) if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^[\w]+$/)
@sha = @sha.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '') @treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
@commit = @project.repo.commits(@sha, 1).first @commit = @project.repo.commits(@treeish, 1).first
end end
raise Grit::NoSuchPathError unless @commit raise Grit::NoSuchPathError unless @commit
name = "#{@project.owner.uname}-#{@project.name}-#{@sha}" name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}" fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
file = Tempfile.new fullname, 'tmp' file = Tempfile.new fullname, 'tmp'
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@sha} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}") system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
file.close file.close
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
end end
private
def set_sha
commit = @project.repo.commits(@treeish, 1).first
@sha = commit ? commit.id : @treeish
end
end end

View File

@ -6,7 +6,7 @@
=image_tag 'zip.png', :alt => 'ZIP' =image_tag 'zip.png', :alt => 'ZIP'
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
- file_name = "#{@project.owner.uname}-#{@project.name}-#{@sha}" - file_name = "#{@project.owner.uname}-#{@project.name}-#{@commit.id}"
%li=link_to "tar.gz", archive_path(project, file_name, 'tar') %li=link_to "tar.gz", archive_path(project, file_name, 'tar')
%li=link_to "zip", archive_path(project, file_name, 'zip') %li=link_to "zip", archive_path(project, file_name, 'zip')