Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-01 18:00:28 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-10-01 18:00:28 +0400
commitae9dd6276267e0df2d9c2da3b89393e4ee212175 (patch)
tree4db4314bd54eda3bce6b3c67b719f1f5097fb68a /app
parente219cf7246c6a0495e4507deaffeba11e79f13b8 (diff)
Update code to work with gitlab_git 3
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/blame_controller.rb2
-rw-r--r--app/controllers/projects/blob_controller.rb2
-rw-r--r--app/controllers/projects/raw_controller.rb4
-rw-r--r--app/controllers/projects/refs_controller.rb3
-rw-r--r--app/controllers/projects/tree_controller.rb2
-rw-r--r--app/helpers/blobs_helper.rb5
-rw-r--r--app/helpers/tree_helper.rb10
-rw-r--r--app/models/repository.rb9
-rw-r--r--app/models/tree.rb24
-rw-r--r--app/views/projects/commits/_diffs.html.haml8
-rw-r--r--app/views/projects/tree/_tree.html.haml2
11 files changed, 46 insertions, 25 deletions
diff --git a/app/controllers/projects/blame_controller.rb b/app/controllers/projects/blame_controller.rb
index e58b4507202..f22c6497cbf 100644
--- a/app/controllers/projects/blame_controller.rb
+++ b/app/controllers/projects/blame_controller.rb
@@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController
before_filter :require_non_empty_project
def show
- @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
+ @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
@blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path)
end
end
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index b1329c01ce7..33dbc869996 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -8,6 +8,6 @@ class Projects::BlobController < Projects::ApplicationController
before_filter :require_non_empty_project
def show
- @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
+ @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
end
end
diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb
index 0c23d411f4c..8633b225b64 100644
--- a/app/controllers/projects/raw_controller.rb
+++ b/app/controllers/projects/raw_controller.rb
@@ -8,9 +8,9 @@ class Projects::RawController < Projects::ApplicationController
before_filter :require_non_empty_project
def show
- @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
+ @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
- if @blob.exists?
+ if @blob
type = if @blob.mime_type =~ /html|javascript/
'text/plain; charset=utf-8'
else
diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb
index e5c090e1f4d..16621c0371e 100644
--- a/app/controllers/projects/refs_controller.rb
+++ b/app/controllers/projects/refs_controller.rb
@@ -24,13 +24,14 @@ class Projects::RefsController < Projects::ApplicationController
format.js do
@ref = params[:ref]
define_tree_vars
+ tree
render "tree"
end
end
end
def logs_tree
- contents = @tree.entries
+ contents = tree.entries
@logs = contents.map do |content|
file = params[:path] ? File.join(params[:path], content.name) : content.name
last_commit = @repo.commits(@commit.id, file, 1).last
diff --git a/app/controllers/projects/tree_controller.rb b/app/controllers/projects/tree_controller.rb
index 5d543f35665..1150efbea9d 100644
--- a/app/controllers/projects/tree_controller.rb
+++ b/app/controllers/projects/tree_controller.rb
@@ -8,6 +8,8 @@ class Projects::TreeController < Projects::ApplicationController
before_filter :require_non_empty_project
def show
+ return not_found! if tree.entries.empty?
+
respond_to do |format|
format.html
# Disable cache so browser history works
diff --git a/app/helpers/blobs_helper.rb b/app/helpers/blobs_helper.rb
new file mode 100644
index 00000000000..26605d81026
--- /dev/null
+++ b/app/helpers/blobs_helper.rb
@@ -0,0 +1,5 @@
+module BlobsHelper
+ def find_blob(repository, sha, path)
+ Gitlab::Git::Blob.find(repository, sha, path)
+ end
+end
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index 73d36d0801c..2dbc1cffb16 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -67,9 +67,9 @@ module TreeHelper
end
def tree_breadcrumbs(tree, max_links = 2)
- if tree.path
+ if @path.present?
part_path = ""
- parts = tree.path.split("\/")
+ parts = @path.split("\/")
yield('..', nil) if parts.count > max_links
@@ -78,14 +78,14 @@ module TreeHelper
part_path = part if part_path.empty?
next unless parts.last(2).include?(part) if parts.count > max_links
- yield(part, tree_join(tree.ref, part_path))
+ yield(part, tree_join(@ref, part_path))
end
end
end
def up_dir_path tree
- file = File.join(tree.path, "..")
- tree_join(tree.ref, file)
+ file = File.join(@path, "..")
+ tree_join(@ref, file)
end
def leave_edit_message
diff --git a/app/models/repository.rb b/app/models/repository.rb
index aeec48ee5cc..734d060095e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -1,14 +1,19 @@
class Repository
include Gitlab::ShellAdapter
- attr_accessor :raw_repository
+ attr_accessor :raw_repository, :path_with_namespace
def initialize(path_with_namespace, default_branch)
- @raw_repository = Gitlab::Git::Repository.new(path_with_namespace, default_branch)
+ @path_with_namespace = path_with_namespace
+ @raw_repository = Gitlab::Git::Repository.new(path_to_repo)
rescue Gitlab::Git::Repository::NoRepository
nil
end
+ def path_to_repo
+ @path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, path_with_namespace + ".git")
+ end
+
def exists?
raw_repository
end
diff --git a/app/models/tree.rb b/app/models/tree.rb
index 042050527c1..5fbad19b468 100644
--- a/app/models/tree.rb
+++ b/app/models/tree.rb
@@ -1,17 +1,25 @@
class Tree
- attr_accessor :raw
+ attr_accessor :entries, :readme
- def initialize(repository, sha, ref = nil, path = nil)
- @raw = Gitlab::Git::Tree.new(repository, sha, ref, path)
+ def initialize(repository, sha, path = '/')
+ path = '/' if path.blank?
+ git_repo = repository.raw_repository
+ @entries = Gitlab::Git::Tree.where(git_repo, sha, path)
+
+ if readme_tree = @entries.find(&:readme?)
+ @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_tree.name)
+ end
end
- def method_missing(m, *args, &block)
- @raw.send(m, *args, &block)
+ def trees
+ @entries.select(&:dir?)
end
- def respond_to?(method)
- return true if @raw.respond_to?(method)
+ def blobs
+ @entries.select(&:file?)
+ end
- super
+ def submodules
+ @entries.select(&:submodule?)
end
end
diff --git a/app/views/projects/commits/_diffs.html.haml b/app/views/projects/commits/_diffs.html.haml
index c51f1b6eff5..f60c4661100 100644
--- a/app/views/projects/commits/_diffs.html.haml
+++ b/app/views/projects/commits/_diffs.html.haml
@@ -37,9 +37,9 @@
- unless @suppress_diff
- diffs.each_with_index do |diff, i|
- next if diff.diff.empty?
- - file = Gitlab::Git::Blob.new(project.repository, @commit.id, @ref, diff.new_path)
- - file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) unless file.exists?
- - next unless file.exists?
+ - file = find_blob(project.repository, @commit.id, diff.new_path)
+ - file = find_blob(project.repository, @commit.parent_id, diff.old_path) unless file
+ - next unless file
.file{id: "diff-#{i}"}
.header
- if diff.deleted_file
@@ -64,7 +64,7 @@
- if file.text?
= render "projects/commits/text_file", diff: diff, index: i
- elsif file.image?
- - old_file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id
+ - old_file = find_blob(project.repository, @commit.parent_id, diff.old_path) if @commit.parent_id
= render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
- else
%p.nothing_here_message No preview for this file type
diff --git a/app/views/projects/tree/_tree.html.haml b/app/views/projects/tree/_tree.html.haml
index ae5f30c0004..eadfd33bd3c 100644
--- a/app/views/projects/tree/_tree.html.haml
+++ b/app/views/projects/tree/_tree.html.haml
@@ -28,7 +28,7 @@
= truncate(@commit.title, length: 50)
%th= link_to "history", project_commits_path(@project, @id), class: "pull-right"
- - if tree.up_dir?
+ - if @path.present?
%tr.tree-item
%td.tree-item-file-name
= image_tag "file_empty.png", size: '16x16'