From c76618441ea538fefd4d801b3e32b8514517007d Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 20 Sep 2012 15:10:52 +0400 Subject: [PATCH] #385: revert some changes according to discussion --- .../projects/git/base_controller.rb | 10 +--------- .../projects/git/trees_controller.rb | 20 +++++++++++++------ app/views/projects/base/_repo_block.html.haml | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/projects/git/base_controller.rb b/app/controllers/projects/git/base_controller.rb index b4cef4810..a77c39ffd 100644 --- a/app/controllers/projects/git/base_controller.rb +++ b/app/controllers/projects/git/base_controller.rb @@ -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 diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index fd7696e97..bdd368e1e 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -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 diff --git a/app/views/projects/base/_repo_block.html.haml b/app/views/projects/base/_repo_block.html.haml index 9913c451c..853bd59b3 100644 --- a/app/views/projects/base/_repo_block.html.haml +++ b/app/views/projects/base/_repo_block.html.haml @@ -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')