2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 12:39:24 +00:00
|
|
|
class Git::BlobsController < Git::BaseController
|
2011-04-04 17:50:43 +01:00
|
|
|
before_filter :find_tree
|
2012-02-22 22:11:55 +00:00
|
|
|
before_filter :find_branch
|
2012-02-06 13:58:27 +00:00
|
|
|
before_filter :set_commit_hash
|
2012-02-22 22:11:55 +00:00
|
|
|
before_filter :set_path_blob
|
2011-03-10 12:39:24 +00:00
|
|
|
|
|
|
|
def show
|
2012-03-02 16:48:19 +00:00
|
|
|
redirect_to project_path(@project) and return unless @blob.present?
|
2012-01-20 18:31:01 +00:00
|
|
|
if params[:raw]
|
|
|
|
image_url = Rails.root.to_s + "/" + @path
|
|
|
|
|
|
|
|
response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}"
|
|
|
|
response.headers['Content-Type'] = @blob.mime_type
|
|
|
|
response.headers['Content-Disposition'] = 'inline'
|
|
|
|
|
|
|
|
render(:text => open(image_url).read) and return
|
|
|
|
end
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
|
2012-02-08 17:51:30 +00:00
|
|
|
def edit
|
2012-02-13 19:04:41 +00:00
|
|
|
redirect_to project_repo_path(@project) and return unless @blob.present?
|
2012-02-13 15:21:00 +00:00
|
|
|
authorize! :write, @project
|
2012-02-08 17:51:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-02-13 19:04:41 +00:00
|
|
|
redirect_to project_repo_path(@project) and return unless @blob.present?
|
2012-02-13 15:21:00 +00:00
|
|
|
authorize! :write, @project
|
2012-02-09 00:26:23 +00:00
|
|
|
# Here might be callbacks for notification purposes:
|
|
|
|
# @git_repository.after_update_file do |repo, sha|
|
|
|
|
# end
|
|
|
|
|
2012-02-24 16:34:41 +00:00
|
|
|
res = @git_repository.update_file(params[:path], params[:content].gsub("\r", ''),
|
|
|
|
:message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish)
|
2012-02-09 00:26:23 +00:00
|
|
|
if res
|
|
|
|
flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path].encode_to_default)
|
|
|
|
else
|
|
|
|
flash[:notice] = t("flash.blob.updating_error", :name => params[:path].encode_to_default)
|
|
|
|
end
|
2012-02-08 17:51:30 +00:00
|
|
|
redirect_to :action => :show
|
|
|
|
end
|
|
|
|
|
2011-03-10 12:39:24 +00:00
|
|
|
def blame
|
2011-11-11 21:57:10 +00:00
|
|
|
@blame = Grit::Blob.blame(@git_repository.repo, @commit.try(:id), @path)
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def raw
|
2012-02-13 19:04:41 +00:00
|
|
|
redirect_to project_repo_path(@project) and return unless @blob.present?
|
2011-03-10 12:39:24 +00:00
|
|
|
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
|
|
|
|
render :text => @blob.data, :content_type => @blob.mime_type
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
2012-02-22 22:11:55 +00:00
|
|
|
def find_branch
|
|
|
|
@branch = @project.branch(@treeish)
|
|
|
|
end
|
|
|
|
|
2012-02-06 13:58:27 +00:00
|
|
|
def set_path_blob
|
2011-03-11 10:06:14 +00:00
|
|
|
@path = params[:path]
|
2012-02-27 17:40:46 +00:00
|
|
|
@unenc_path = @path.dup
|
2012-02-09 00:26:23 +00:00
|
|
|
@path.force_encoding(Encoding::ASCII_8BIT)
|
2012-02-27 17:40:46 +00:00
|
|
|
puts @path.inspect
|
2012-02-09 00:26:23 +00:00
|
|
|
@blob = @tree / @path
|
2012-02-27 17:40:46 +00:00
|
|
|
puts @blob.inspect
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_commit_hash
|
|
|
|
@commit_hash = params[:commit_hash].present? ? params[:commit_hash] : nil
|
|
|
|
end
|
2011-04-04 17:50:43 +01:00
|
|
|
|
|
|
|
def find_tree
|
|
|
|
if @commit_hash
|
2011-04-07 14:20:21 +01:00
|
|
|
puts "1"
|
2011-04-04 17:50:43 +01:00
|
|
|
@tree = @git_repository.tree(@commit_hash)
|
|
|
|
@commit = @git_repository.commits(@treeish, 1).first
|
|
|
|
else
|
2011-04-07 14:20:21 +01:00
|
|
|
puts "2"
|
2011-04-04 17:50:43 +01:00
|
|
|
@tree = @git_repository.tree(@treeish)
|
2012-02-22 22:11:55 +00:00
|
|
|
@commit = @git_repository.log(@treeish, @path, :max_count => 1).first # TODO WTF nil ?
|
2011-04-04 17:50:43 +01:00
|
|
|
end
|
2012-02-27 17:40:46 +00:00
|
|
|
puts @tree.inspect
|
|
|
|
puts @commit.inspect
|
2011-04-04 17:50:43 +01:00
|
|
|
end
|
2012-01-20 18:31:01 +00:00
|
|
|
end
|