#385: revert some changes according to discussion

This commit is contained in:
Vokhmin Alexey V 2012-09-20 15:10:52 +04:00
parent 805521c486
commit c76618441e
3 changed files with 16 additions and 16 deletions

View File

@ -10,21 +10,13 @@ class Projects::Git::BaseController < Projects::BaseController
protected
def set_treeish_and_path
@treeish = params[:treeish].presence
unless @treeish
commit = @project.repo.commits(@project.default_branch, 1).first
@treeish = commit ? commit.id : @project.default_branch
end
@treeish = params[:treeish].presence || @project.default_branch
@path = params[:path]
end
def set_branch_and_tree
@branch = @project.repo.branches.detect{|b| b.name == @treeish}
@tree = @project.repo.tree(@treeish)
if @branch
commit = @project.repo.commits(@treeish, 1).first
@treeish = commit.id if commit
end
# raise Grit::NoSuchPathError if @tree.blobs.blank?
end
end

View File

@ -1,7 +1,7 @@
# -*- 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,16 +12,24 @@ class Projects::Git::TreesController < Projects::Git::BaseController
def archive
format = params[:format]
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
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
end
raise Grit::NoSuchPathError unless @commit
name = "#{@project.owner.uname}-#{@project.name}-#{@treeish}"
name = "#{@project.owner.uname}-#{@project.name}-#{@sha}"
fullname = "#{name}.#{format == 'tar' ? 'tar.gz' : 'zip'}"
file = Tempfile.new fullname, 'tmp'
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@treeish} #{format == 'tar' ? ' | gzip -9' : ''} > #{file.path}")
system("cd #{@project.path}; git archive --format=#{format} --prefix=#{name}/ #{@sha} #{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

View File

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