#385: removed before_filter
This commit is contained in:
parent
c76618441e
commit
07f5224e76
|
@ -1,7 +1,6 @@
|
|||
# -*- encoding : utf-8 -*-
|
||||
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 :set_sha
|
||||
skip_before_filter :set_branch_and_tree, :only => :archive
|
||||
|
||||
def show
|
||||
|
@ -12,24 +11,17 @@ class Projects::Git::TreesController < Projects::Git::BaseController
|
|||
|
||||
def archive
|
||||
format = params[:format]
|
||||
if (@sha =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@sha =~ /[\s]+/) && (format =~ /^[\w]+$/)
|
||||
@sha = @sha.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
||||
@commit = @project.repo.commits(@sha, 1).first
|
||||
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^[\w]+$/)
|
||||
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
||||
@commit = @project.repo.commits(@treeish, 1).first
|
||||
end
|
||||
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'}"
|
||||
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
|
||||
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_sha
|
||||
commit = @project.repo.commits(@treeish, 1).first
|
||||
@sha = commit ? commit.id : @treeish
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
=image_tag 'zip.png', :alt => 'ZIP'
|
||||
%b.caret
|
||||
%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 "zip", archive_path(project, file_name, 'zip')
|
||||
|
||||
|
|
Loading…
Reference in New Issue