2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Projects::Git::TreesController < Projects::Git::BaseController
|
2012-09-19 20:29:36 +01:00
|
|
|
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show
|
|
|
|
|
|
|
|
skip_before_filter :set_branch_and_tree, :only => :archive
|
2011-04-04 12:28:33 +01:00
|
|
|
|
2012-07-17 09:02:56 +01:00
|
|
|
def show
|
|
|
|
@tree = @tree / @path if @path.present?
|
|
|
|
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first
|
|
|
|
render 'empty' unless @commit
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
2012-04-17 11:18:03 +01:00
|
|
|
|
|
|
|
def archive
|
2012-09-19 20:29:36 +01:00
|
|
|
format = params[:format]
|
|
|
|
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^[\w]+$/)
|
|
|
|
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
|
2012-09-19 21:38:40 +01:00
|
|
|
@commit = @project.repo.commits(@treeish, 1).first
|
2012-09-19 20:29:36 +01:00
|
|
|
end
|
2012-07-17 09:02:56 +01:00
|
|
|
raise Grit::NoSuchPathError unless @commit
|
2012-09-19 20:29:36 +01:00
|
|
|
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
|
|
|
|
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
|
2012-04-17 11:18:03 +01:00
|
|
|
file = Tempfile.new fullname, 'tmp'
|
2012-09-19 20:29:36 +01:00
|
|
|
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
|
2012-04-17 11:18:03 +01:00
|
|
|
file.close
|
2012-09-19 20:29:36 +01:00
|
|
|
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar-gz' : 'zip'}", :filename => fullname
|
2012-04-17 11:18:03 +01:00
|
|
|
end
|
2012-01-30 20:39:34 +00:00
|
|
|
end
|