summaryrefslogtreecommitdiff
path: root/lib/extracts_path.rb
diff options
context:
space:
mode:
authorSato Hiroyuki <sathiroyuki@gmail.com>2013-04-14 12:08:16 +0000
committerSato Hiroyuki <sathiroyuki@gmail.com>2013-05-13 18:41:04 +0900
commit97a9c2293affaeeba6f448b8760bb5dffd170f2c (patch)
tree4ac47980672bd8589afaeb9457e58b6178284224 /lib/extracts_path.rb
parentedcdbd671b3a1f01f0e1052d5867e4a14c90278b (diff)
downloadgitlab-ce-97a9c2293affaeeba6f448b8760bb5dffd170f2c.tar.gz
Refactor: remove dup code
Diffstat (limited to 'lib/extracts_path.rb')
-rw-r--r--lib/extracts_path.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 1b7c698d0a8..6025bb2a9f6 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -94,16 +94,28 @@ module ExtractsPath
# Automatically renders `not_found!` if a valid tree path could not be
# resolved (e.g., when a user inserts an invalid path or ref).
def assign_ref_vars
- @id = params[:id]
+ @id = get_id
@ref, @path = extract_ref(@id)
- @commit = @project.repository.commit(@ref)
+ @repo = @project.repository
- @tree = Tree.new(@project.repository, @commit.id, @ref, @path)
+ @commit = @repo.commit(@ref)
+
+ @tree = Tree.new(@repo, @commit.id, @ref, @path)
+ @hex_path = Digest::SHA1.hexdigest(@path)
+ @logs_path = logs_file_project_ref_path(@project, @ref, @path)
raise InvalidPathError unless @tree.exists?
rescue RuntimeError, NoMethodError, InvalidPathError
not_found!
end
+
+ private
+
+ def get_id
+ id = params[:id] || params[:ref]
+ id += "/" + params[:path] unless params[:path].blank?
+ id
+ end
end