Update code to work with gitlab_git 3
This commit is contained in:
parent
e219cf7246
commit
ae9dd62762
2
Gemfile
2
Gemfile
|
|
@ -23,7 +23,7 @@ gem 'omniauth-github'
|
||||||
|
|
||||||
# Extracting information from a git repository
|
# Extracting information from a git repository
|
||||||
# Provide access to Gitlab::Git library
|
# Provide access to Gitlab::Git library
|
||||||
gem "gitlab_git", '2.3.1'
|
gem "gitlab_git", "~> 3.0.0.beta1"
|
||||||
|
|
||||||
# Ruby/Rack Git Smart-HTTP Server Handler
|
# Ruby/Rack Git Smart-HTTP Server Handler
|
||||||
gem 'gitlab-grack', '~> 1.0.1', require: 'grack'
|
gem 'gitlab-grack', '~> 1.0.1', require: 'grack'
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ GEM
|
||||||
gitlab-pygments.rb (0.3.2)
|
gitlab-pygments.rb (0.3.2)
|
||||||
posix-spawn (~> 0.3.6)
|
posix-spawn (~> 0.3.6)
|
||||||
yajl-ruby (~> 1.1.0)
|
yajl-ruby (~> 1.1.0)
|
||||||
gitlab_git (2.3.1)
|
gitlab_git (3.0.0.beta1)
|
||||||
activesupport (~> 3.2.13)
|
activesupport (~> 3.2.13)
|
||||||
github-linguist (~> 2.3.4)
|
github-linguist (~> 2.3.4)
|
||||||
gitlab-grit (~> 2.6.0)
|
gitlab-grit (~> 2.6.0)
|
||||||
|
|
@ -574,7 +574,7 @@ DEPENDENCIES
|
||||||
gitlab-gollum-lib (~> 1.0.1)
|
gitlab-gollum-lib (~> 1.0.1)
|
||||||
gitlab-grack (~> 1.0.1)
|
gitlab-grack (~> 1.0.1)
|
||||||
gitlab-pygments.rb (~> 0.3.2)
|
gitlab-pygments.rb (~> 0.3.2)
|
||||||
gitlab_git (= 2.3.1)
|
gitlab_git (~> 3.0.0.beta1)
|
||||||
gitlab_meta (= 6.0)
|
gitlab_meta (= 6.0)
|
||||||
gitlab_omniauth-ldap (= 1.0.3)
|
gitlab_omniauth-ldap (= 1.0.3)
|
||||||
gon
|
gon
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController
|
||||||
before_filter :require_non_empty_project
|
before_filter :require_non_empty_project
|
||||||
|
|
||||||
def show
|
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)
|
@blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,6 @@ class Projects::BlobController < Projects::ApplicationController
|
||||||
before_filter :require_non_empty_project
|
before_filter :require_non_empty_project
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path)
|
@blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ class Projects::RawController < Projects::ApplicationController
|
||||||
before_filter :require_non_empty_project
|
before_filter :require_non_empty_project
|
||||||
|
|
||||||
def show
|
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/
|
type = if @blob.mime_type =~ /html|javascript/
|
||||||
'text/plain; charset=utf-8'
|
'text/plain; charset=utf-8'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,14 @@ class Projects::RefsController < Projects::ApplicationController
|
||||||
format.js do
|
format.js do
|
||||||
@ref = params[:ref]
|
@ref = params[:ref]
|
||||||
define_tree_vars
|
define_tree_vars
|
||||||
|
tree
|
||||||
render "tree"
|
render "tree"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def logs_tree
|
def logs_tree
|
||||||
contents = @tree.entries
|
contents = tree.entries
|
||||||
@logs = contents.map do |content|
|
@logs = contents.map do |content|
|
||||||
file = params[:path] ? File.join(params[:path], content.name) : content.name
|
file = params[:path] ? File.join(params[:path], content.name) : content.name
|
||||||
last_commit = @repo.commits(@commit.id, file, 1).last
|
last_commit = @repo.commits(@commit.id, file, 1).last
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ class Projects::TreeController < Projects::ApplicationController
|
||||||
before_filter :require_non_empty_project
|
before_filter :require_non_empty_project
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
return not_found! if tree.entries.empty?
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
# Disable cache so browser history works
|
# Disable cache so browser history works
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
module BlobsHelper
|
||||||
|
def find_blob(repository, sha, path)
|
||||||
|
Gitlab::Git::Blob.find(repository, sha, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -67,9 +67,9 @@ module TreeHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def tree_breadcrumbs(tree, max_links = 2)
|
def tree_breadcrumbs(tree, max_links = 2)
|
||||||
if tree.path
|
if @path.present?
|
||||||
part_path = ""
|
part_path = ""
|
||||||
parts = tree.path.split("\/")
|
parts = @path.split("\/")
|
||||||
|
|
||||||
yield('..', nil) if parts.count > max_links
|
yield('..', nil) if parts.count > max_links
|
||||||
|
|
||||||
|
|
@ -78,14 +78,14 @@ module TreeHelper
|
||||||
part_path = part if part_path.empty?
|
part_path = part if part_path.empty?
|
||||||
|
|
||||||
next unless parts.last(2).include?(part) if parts.count > max_links
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def up_dir_path tree
|
def up_dir_path tree
|
||||||
file = File.join(tree.path, "..")
|
file = File.join(@path, "..")
|
||||||
tree_join(tree.ref, file)
|
tree_join(@ref, file)
|
||||||
end
|
end
|
||||||
|
|
||||||
def leave_edit_message
|
def leave_edit_message
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
class Repository
|
class Repository
|
||||||
include Gitlab::ShellAdapter
|
include Gitlab::ShellAdapter
|
||||||
|
|
||||||
attr_accessor :raw_repository
|
attr_accessor :raw_repository, :path_with_namespace
|
||||||
|
|
||||||
def initialize(path_with_namespace, default_branch)
|
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
|
rescue Gitlab::Git::Repository::NoRepository
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def path_to_repo
|
||||||
|
@path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, path_with_namespace + ".git")
|
||||||
|
end
|
||||||
|
|
||||||
def exists?
|
def exists?
|
||||||
raw_repository
|
raw_repository
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,25 @@
|
||||||
class Tree
|
class Tree
|
||||||
attr_accessor :raw
|
attr_accessor :entries, :readme
|
||||||
|
|
||||||
def initialize(repository, sha, ref = nil, path = nil)
|
def initialize(repository, sha, path = '/')
|
||||||
@raw = Gitlab::Git::Tree.new(repository, sha, ref, 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
|
end
|
||||||
|
|
||||||
def method_missing(m, *args, &block)
|
def trees
|
||||||
@raw.send(m, *args, &block)
|
@entries.select(&:dir?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to?(method)
|
def blobs
|
||||||
return true if @raw.respond_to?(method)
|
@entries.select(&:file?)
|
||||||
|
end
|
||||||
|
|
||||||
super
|
def submodules
|
||||||
|
@entries.select(&:submodule?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@
|
||||||
- unless @suppress_diff
|
- unless @suppress_diff
|
||||||
- diffs.each_with_index do |diff, i|
|
- diffs.each_with_index do |diff, i|
|
||||||
- next if diff.diff.empty?
|
- next if diff.diff.empty?
|
||||||
- file = Gitlab::Git::Blob.new(project.repository, @commit.id, @ref, diff.new_path)
|
- file = find_blob(project.repository, @commit.id, diff.new_path)
|
||||||
- file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) unless file.exists?
|
- file = find_blob(project.repository, @commit.parent_id, diff.old_path) unless file
|
||||||
- next unless file.exists?
|
- next unless file
|
||||||
.file{id: "diff-#{i}"}
|
.file{id: "diff-#{i}"}
|
||||||
.header
|
.header
|
||||||
- if diff.deleted_file
|
- if diff.deleted_file
|
||||||
|
|
@ -64,7 +64,7 @@
|
||||||
- if file.text?
|
- if file.text?
|
||||||
= render "projects/commits/text_file", diff: diff, index: i
|
= render "projects/commits/text_file", diff: diff, index: i
|
||||||
- elsif file.image?
|
- 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
|
= render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
|
||||||
- else
|
- else
|
||||||
%p.nothing_here_message No preview for this file type
|
%p.nothing_here_message No preview for this file type
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
= truncate(@commit.title, length: 50)
|
= truncate(@commit.title, length: 50)
|
||||||
%th= link_to "history", project_commits_path(@project, @id), class: "pull-right"
|
%th= link_to "history", project_commits_path(@project, @id), class: "pull-right"
|
||||||
|
|
||||||
- if tree.up_dir?
|
- if @path.present?
|
||||||
%tr.tree-item
|
%tr.tree-item
|
||||||
%td.tree-item-file-name
|
%td.tree-item-file-name
|
||||||
= image_tag "file_empty.png", size: '16x16'
|
= image_tag "file_empty.png", size: '16x16'
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,3 @@ require Rails.root.join("lib", "gitlab", "backend", "shell")
|
||||||
|
|
||||||
# GitLab shell adapter
|
# GitLab shell adapter
|
||||||
require Rails.root.join("lib", "gitlab", "backend", "shell_adapter")
|
require Rails.root.join("lib", "gitlab", "backend", "shell_adapter")
|
||||||
|
|
||||||
# Gitlab Git repos path
|
|
||||||
Gitlab::Git::Repository.repos_path = Gitlab.config.gitlab_shell.repos_path
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,6 @@ module ExtractsPath
|
||||||
# - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA)
|
# - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA)
|
||||||
# - @path - A string representing the filesystem path
|
# - @path - A string representing the filesystem path
|
||||||
# - @commit - A Commit representing the commit from the given ref
|
# - @commit - A Commit representing the commit from the given ref
|
||||||
# - @tree - A Tree representing the tree at the given ref/path
|
|
||||||
#
|
#
|
||||||
# If the :id parameter appears to be requesting a specific response format,
|
# If the :id parameter appears to be requesting a specific response format,
|
||||||
# that will be handled as well.
|
# that will be handled as well.
|
||||||
|
|
@ -107,15 +106,18 @@ module ExtractsPath
|
||||||
else
|
else
|
||||||
@commit = @repo.commit(@options[:extended_sha1])
|
@commit = @repo.commit(@options[:extended_sha1])
|
||||||
end
|
end
|
||||||
@tree = Tree.new(@repo, @commit.id, @ref, @path)
|
|
||||||
@hex_path = Digest::SHA1.hexdigest(@path)
|
@hex_path = Digest::SHA1.hexdigest(@path)
|
||||||
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
|
@logs_path = logs_file_project_ref_path(@project, @ref, @path)
|
||||||
|
|
||||||
raise InvalidPathError unless @tree.exists?
|
|
||||||
rescue RuntimeError, NoMethodError, InvalidPathError
|
rescue RuntimeError, NoMethodError, InvalidPathError
|
||||||
not_found!
|
not_found!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tree
|
||||||
|
@tree ||= Tree.new(@repo, @commit.id, @path)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_id
|
def get_id
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue