./lib/dolt/sinatra/actions.rb in dolt-0.20.0 vs ./lib/dolt/sinatra/actions.rb in dolt-0.21.0
- old
+ new
@@ -20,12 +20,12 @@
require "cgi"
module Dolt
module Sinatra
module Actions
- def redirect(url)
- response.status = 302
+ def redirect(url, status = 302)
+ response.status = status
response["Location"] = url
body ""
end
def error(error, repo, ref)
@@ -53,11 +53,11 @@
HTML
end
def raw(repo, ref, path, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(raw_url(repo, oid, path)) and return
+ redirect(raw_url(repo, oid, path), 307) and return
end
blob(repo, ref, path, custom_data, {
:template => :raw,
:content_type => "text/plain",
@@ -65,103 +65,89 @@
})
end
def blob(repo, ref, path, custom_data = {}, options = { :template => :blob })
if oid = lookup_ref_oid(repo, ref)
- redirect(blob_url(repo, oid, path)) and return
+ redirect(blob_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.blob(repo, u(ref), path))
blob = data[:blob]
return redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/
add_headers(response, options.merge(:ref => ref))
tpl_options = options[:template_options] || {}
body(renderer.render(options[:template], data, tpl_options))
- rescue Exception => err
- error(err, repo, ref)
end
def tree(repo, ref, path, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(tree_url(repo, oid, path)) and return
+ redirect(tree_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.tree(repo, u(ref), path))
tree = data[:tree]
return redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/
add_headers(response, :ref => ref)
body(renderer.render(:tree, data))
- rescue Exception => err
- error(err, repo, ref)
end
def tree_entry(repo, ref, path, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(tree_entry_url(repo, oid, path)) and return
+ redirect(tree_entry_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.tree_entry(repo, u(ref), path))
add_headers(response, :ref => ref)
body(renderer.render(data.key?(:tree) ? :tree : :blob, data))
- rescue Exception => err
- error(err, repo, ref)
end
def blame(repo, ref, path, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(blame_url(repo, oid, path)) and return
+ redirect(blame_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.blame(repo, u(ref), path))
add_headers(response, :ref => ref)
body(renderer.render(:blame, data))
- rescue Exception => err
- error(err, repo, ref)
end
def history(repo, ref, path, count, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(history_url(repo, oid, path)) and return
+ redirect(history_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.history(repo, u(ref), path, count))
add_headers(response, :ref => ref)
body(renderer.render(:commits, data))
- rescue Exception => err
- error(err, repo, ref)
end
def refs(repo, custom_data = {})
data = (custom_data || {}).merge(actions.refs(repo))
add_headers(response, :content_type => "application/json")
body(renderer.render(:refs, data, :layout => nil))
- rescue Exception => err
- error(err, repo, nil)
end
def tree_history(repo, ref, path, count = 1, custom_data = {})
if oid = lookup_ref_oid(repo, ref)
- redirect(tree_history_url(repo, oid, path)) and return
+ redirect(tree_history_url(repo, oid, path), 307) and return
end
data = (custom_data || {}).merge(actions.tree_history(repo, u(ref), path, count))
add_headers(response, :content_type => "application/json", :ref => ref)
body(renderer.render(:tree_history, data, :layout => nil))
- rescue Exception => err
- error(err, repo, ref)
end
def resolve_repository(repo)
@cache ||= {}
@cache[repo] ||= actions.resolve_repository(repo)
end
- private
def lookup_ref_oid(repo, ref)
return if !respond_to?(:redirect_refs?) || !redirect_refs? || ref.length == 40
actions.rev_parse_oid(repo, ref)
end
+ private
def u(str)
# Temporarily swap the + out with a magic byte, so
# filenames/branches with +'s won't get unescaped to a space
CGI.unescape(str.gsub("+", "\001")).gsub("\001", '+')
end