Commit ae9dd6276267e0df2d9c2da3b89393e4ee212175
1 parent
e219cf72
Exists in
master
and in
4 other branches
Update code to work with gitlab_git 3
Showing
15 changed files
with
54 additions
and
34 deletions
Show diff stats
Gemfile
| @@ -23,7 +23,7 @@ gem 'omniauth-github' | @@ -23,7 +23,7 @@ gem 'omniauth-github' | ||
| 23 | 23 | ||
| 24 | # Extracting information from a git repository | 24 | # Extracting information from a git repository |
| 25 | # Provide access to Gitlab::Git library | 25 | # Provide access to Gitlab::Git library |
| 26 | -gem "gitlab_git", '2.3.1' | 26 | +gem "gitlab_git", "~> 3.0.0.beta1" |
| 27 | 27 | ||
| 28 | # Ruby/Rack Git Smart-HTTP Server Handler | 28 | # Ruby/Rack Git Smart-HTTP Server Handler |
| 29 | gem 'gitlab-grack', '~> 1.0.1', require: 'grack' | 29 | gem 'gitlab-grack', '~> 1.0.1', require: 'grack' |
Gemfile.lock
| @@ -174,7 +174,7 @@ GEM | @@ -174,7 +174,7 @@ GEM | ||
| 174 | gitlab-pygments.rb (0.3.2) | 174 | gitlab-pygments.rb (0.3.2) |
| 175 | posix-spawn (~> 0.3.6) | 175 | posix-spawn (~> 0.3.6) |
| 176 | yajl-ruby (~> 1.1.0) | 176 | yajl-ruby (~> 1.1.0) |
| 177 | - gitlab_git (2.3.1) | 177 | + gitlab_git (3.0.0.beta1) |
| 178 | activesupport (~> 3.2.13) | 178 | activesupport (~> 3.2.13) |
| 179 | github-linguist (~> 2.3.4) | 179 | github-linguist (~> 2.3.4) |
| 180 | gitlab-grit (~> 2.6.0) | 180 | gitlab-grit (~> 2.6.0) |
| @@ -574,7 +574,7 @@ DEPENDENCIES | @@ -574,7 +574,7 @@ DEPENDENCIES | ||
| 574 | gitlab-gollum-lib (~> 1.0.1) | 574 | gitlab-gollum-lib (~> 1.0.1) |
| 575 | gitlab-grack (~> 1.0.1) | 575 | gitlab-grack (~> 1.0.1) |
| 576 | gitlab-pygments.rb (~> 0.3.2) | 576 | gitlab-pygments.rb (~> 0.3.2) |
| 577 | - gitlab_git (= 2.3.1) | 577 | + gitlab_git (~> 3.0.0.beta1) |
| 578 | gitlab_meta (= 6.0) | 578 | gitlab_meta (= 6.0) |
| 579 | gitlab_omniauth-ldap (= 1.0.3) | 579 | gitlab_omniauth-ldap (= 1.0.3) |
| 580 | gon | 580 | gon |
app/controllers/projects/blame_controller.rb
| @@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController | @@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) | 11 | + @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) |
| 12 | @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path) | 12 | @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path) |
| 13 | end | 13 | end |
| 14 | end | 14 | end |
app/controllers/projects/blob_controller.rb
| @@ -8,6 +8,6 @@ class Projects::BlobController < Projects::ApplicationController | @@ -8,6 +8,6 @@ class Projects::BlobController < Projects::ApplicationController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) | 11 | + @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) |
| 12 | end | 12 | end |
| 13 | end | 13 | end |
app/controllers/projects/raw_controller.rb
| @@ -8,9 +8,9 @@ class Projects::RawController < Projects::ApplicationController | @@ -8,9 +8,9 @@ class Projects::RawController < Projects::ApplicationController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) | 11 | + @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) |
| 12 | 12 | ||
| 13 | - if @blob.exists? | 13 | + if @blob |
| 14 | type = if @blob.mime_type =~ /html|javascript/ | 14 | type = if @blob.mime_type =~ /html|javascript/ |
| 15 | 'text/plain; charset=utf-8' | 15 | 'text/plain; charset=utf-8' |
| 16 | else | 16 | else |
app/controllers/projects/refs_controller.rb
| @@ -24,13 +24,14 @@ class Projects::RefsController < Projects::ApplicationController | @@ -24,13 +24,14 @@ class Projects::RefsController < Projects::ApplicationController | ||
| 24 | format.js do | 24 | format.js do |
| 25 | @ref = params[:ref] | 25 | @ref = params[:ref] |
| 26 | define_tree_vars | 26 | define_tree_vars |
| 27 | + tree | ||
| 27 | render "tree" | 28 | render "tree" |
| 28 | end | 29 | end |
| 29 | end | 30 | end |
| 30 | end | 31 | end |
| 31 | 32 | ||
| 32 | def logs_tree | 33 | def logs_tree |
| 33 | - contents = @tree.entries | 34 | + contents = tree.entries |
| 34 | @logs = contents.map do |content| | 35 | @logs = contents.map do |content| |
| 35 | file = params[:path] ? File.join(params[:path], content.name) : content.name | 36 | file = params[:path] ? File.join(params[:path], content.name) : content.name |
| 36 | last_commit = @repo.commits(@commit.id, file, 1).last | 37 | last_commit = @repo.commits(@commit.id, file, 1).last |
app/controllers/projects/tree_controller.rb
| @@ -8,6 +8,8 @@ class Projects::TreeController < Projects::ApplicationController | @@ -8,6 +8,8 @@ class Projects::TreeController < Projects::ApplicationController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | + return not_found! if tree.entries.empty? | ||
| 12 | + | ||
| 11 | respond_to do |format| | 13 | respond_to do |format| |
| 12 | format.html | 14 | format.html |
| 13 | # Disable cache so browser history works | 15 | # Disable cache so browser history works |
app/helpers/tree_helper.rb
| @@ -67,9 +67,9 @@ module TreeHelper | @@ -67,9 +67,9 @@ module TreeHelper | ||
| 67 | end | 67 | end |
| 68 | 68 | ||
| 69 | def tree_breadcrumbs(tree, max_links = 2) | 69 | def tree_breadcrumbs(tree, max_links = 2) |
| 70 | - if tree.path | 70 | + if @path.present? |
| 71 | part_path = "" | 71 | part_path = "" |
| 72 | - parts = tree.path.split("\/") | 72 | + parts = @path.split("\/") |
| 73 | 73 | ||
| 74 | yield('..', nil) if parts.count > max_links | 74 | yield('..', nil) if parts.count > max_links |
| 75 | 75 | ||
| @@ -78,14 +78,14 @@ module TreeHelper | @@ -78,14 +78,14 @@ module TreeHelper | ||
| 78 | part_path = part if part_path.empty? | 78 | part_path = part if part_path.empty? |
| 79 | 79 | ||
| 80 | next unless parts.last(2).include?(part) if parts.count > max_links | 80 | next unless parts.last(2).include?(part) if parts.count > max_links |
| 81 | - yield(part, tree_join(tree.ref, part_path)) | 81 | + yield(part, tree_join(@ref, part_path)) |
| 82 | end | 82 | end |
| 83 | end | 83 | end |
| 84 | end | 84 | end |
| 85 | 85 | ||
| 86 | def up_dir_path tree | 86 | def up_dir_path tree |
| 87 | - file = File.join(tree.path, "..") | ||
| 88 | - tree_join(tree.ref, file) | 87 | + file = File.join(@path, "..") |
| 88 | + tree_join(@ref, file) | ||
| 89 | end | 89 | end |
| 90 | 90 | ||
| 91 | def leave_edit_message | 91 | def leave_edit_message |
app/models/repository.rb
| 1 | class Repository | 1 | class Repository |
| 2 | include Gitlab::ShellAdapter | 2 | include Gitlab::ShellAdapter |
| 3 | 3 | ||
| 4 | - attr_accessor :raw_repository | 4 | + attr_accessor :raw_repository, :path_with_namespace |
| 5 | 5 | ||
| 6 | def initialize(path_with_namespace, default_branch) | 6 | def initialize(path_with_namespace, default_branch) |
| 7 | - @raw_repository = Gitlab::Git::Repository.new(path_with_namespace, default_branch) | 7 | + @path_with_namespace = path_with_namespace |
| 8 | + @raw_repository = Gitlab::Git::Repository.new(path_to_repo) | ||
| 8 | rescue Gitlab::Git::Repository::NoRepository | 9 | rescue Gitlab::Git::Repository::NoRepository |
| 9 | nil | 10 | nil |
| 10 | end | 11 | end |
| 11 | 12 | ||
| 13 | + def path_to_repo | ||
| 14 | + @path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, path_with_namespace + ".git") | ||
| 15 | + end | ||
| 16 | + | ||
| 12 | def exists? | 17 | def exists? |
| 13 | raw_repository | 18 | raw_repository |
| 14 | end | 19 | end |
app/models/tree.rb
| 1 | class Tree | 1 | class Tree |
| 2 | - attr_accessor :raw | 2 | + attr_accessor :entries, :readme |
| 3 | 3 | ||
| 4 | - def initialize(repository, sha, ref = nil, path = nil) | ||
| 5 | - @raw = Gitlab::Git::Tree.new(repository, sha, ref, path) | 4 | + def initialize(repository, sha, path = '/') |
| 5 | + path = '/' if path.blank? | ||
| 6 | + git_repo = repository.raw_repository | ||
| 7 | + @entries = Gitlab::Git::Tree.where(git_repo, sha, path) | ||
| 8 | + | ||
| 9 | + if readme_tree = @entries.find(&:readme?) | ||
| 10 | + @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_tree.name) | ||
| 11 | + end | ||
| 6 | end | 12 | end |
| 7 | 13 | ||
| 8 | - def method_missing(m, *args, &block) | ||
| 9 | - @raw.send(m, *args, &block) | 14 | + def trees |
| 15 | + @entries.select(&:dir?) | ||
| 10 | end | 16 | end |
| 11 | 17 | ||
| 12 | - def respond_to?(method) | ||
| 13 | - return true if @raw.respond_to?(method) | 18 | + def blobs |
| 19 | + @entries.select(&:file?) | ||
| 20 | + end | ||
| 14 | 21 | ||
| 15 | - super | 22 | + def submodules |
| 23 | + @entries.select(&:submodule?) | ||
| 16 | end | 24 | end |
| 17 | end | 25 | end |
app/views/projects/commits/_diffs.html.haml
| @@ -37,9 +37,9 @@ | @@ -37,9 +37,9 @@ | ||
| 37 | - unless @suppress_diff | 37 | - unless @suppress_diff |
| 38 | - diffs.each_with_index do |diff, i| | 38 | - diffs.each_with_index do |diff, i| |
| 39 | - next if diff.diff.empty? | 39 | - next if diff.diff.empty? |
| 40 | - - file = Gitlab::Git::Blob.new(project.repository, @commit.id, @ref, diff.new_path) | ||
| 41 | - - file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) unless file.exists? | ||
| 42 | - - next unless file.exists? | 40 | + - file = find_blob(project.repository, @commit.id, diff.new_path) |
| 41 | + - file = find_blob(project.repository, @commit.parent_id, diff.old_path) unless file | ||
| 42 | + - next unless file | ||
| 43 | .file{id: "diff-#{i}"} | 43 | .file{id: "diff-#{i}"} |
| 44 | .header | 44 | .header |
| 45 | - if diff.deleted_file | 45 | - if diff.deleted_file |
| @@ -64,7 +64,7 @@ | @@ -64,7 +64,7 @@ | ||
| 64 | - if file.text? | 64 | - if file.text? |
| 65 | = render "projects/commits/text_file", diff: diff, index: i | 65 | = render "projects/commits/text_file", diff: diff, index: i |
| 66 | - elsif file.image? | 66 | - elsif file.image? |
| 67 | - - old_file = Gitlab::Git::Blob.new(project.repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id | 67 | + - old_file = find_blob(project.repository, @commit.parent_id, diff.old_path) if @commit.parent_id |
| 68 | = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i | 68 | = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i |
| 69 | - else | 69 | - else |
| 70 | %p.nothing_here_message No preview for this file type | 70 | %p.nothing_here_message No preview for this file type |
app/views/projects/tree/_tree.html.haml
| @@ -28,7 +28,7 @@ | @@ -28,7 +28,7 @@ | ||
| 28 | = truncate(@commit.title, length: 50) | 28 | = truncate(@commit.title, length: 50) |
| 29 | %th= link_to "history", project_commits_path(@project, @id), class: "pull-right" | 29 | %th= link_to "history", project_commits_path(@project, @id), class: "pull-right" |
| 30 | 30 | ||
| 31 | - - if tree.up_dir? | 31 | + - if @path.present? |
| 32 | %tr.tree-item | 32 | %tr.tree-item |
| 33 | %td.tree-item-file-name | 33 | %td.tree-item-file-name |
| 34 | = image_tag "file_empty.png", size: '16x16' | 34 | = image_tag "file_empty.png", size: '16x16' |
config/initializers/5_backend.rb
| @@ -6,6 +6,3 @@ require Rails.root.join("lib", "gitlab", "backend", "shell") | @@ -6,6 +6,3 @@ require Rails.root.join("lib", "gitlab", "backend", "shell") | ||
| 6 | 6 | ||
| 7 | # GitLab shell adapter | 7 | # GitLab shell adapter |
| 8 | require Rails.root.join("lib", "gitlab", "backend", "shell_adapter") | 8 | require Rails.root.join("lib", "gitlab", "backend", "shell_adapter") |
| 9 | - | ||
| 10 | -# Gitlab Git repos path | ||
| 11 | -Gitlab::Git::Repository.repos_path = Gitlab.config.gitlab_shell.repos_path |
lib/extracts_path.rb
| @@ -86,7 +86,6 @@ module ExtractsPath | @@ -86,7 +86,6 @@ module ExtractsPath | ||
| 86 | # - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA) | 86 | # - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA) |
| 87 | # - @path - A string representing the filesystem path | 87 | # - @path - A string representing the filesystem path |
| 88 | # - @commit - A Commit representing the commit from the given ref | 88 | # - @commit - A Commit representing the commit from the given ref |
| 89 | - # - @tree - A Tree representing the tree at the given ref/path | ||
| 90 | # | 89 | # |
| 91 | # If the :id parameter appears to be requesting a specific response format, | 90 | # If the :id parameter appears to be requesting a specific response format, |
| 92 | # that will be handled as well. | 91 | # that will be handled as well. |
| @@ -107,15 +106,18 @@ module ExtractsPath | @@ -107,15 +106,18 @@ module ExtractsPath | ||
| 107 | else | 106 | else |
| 108 | @commit = @repo.commit(@options[:extended_sha1]) | 107 | @commit = @repo.commit(@options[:extended_sha1]) |
| 109 | end | 108 | end |
| 110 | - @tree = Tree.new(@repo, @commit.id, @ref, @path) | 109 | + |
| 111 | @hex_path = Digest::SHA1.hexdigest(@path) | 110 | @hex_path = Digest::SHA1.hexdigest(@path) |
| 112 | @logs_path = logs_file_project_ref_path(@project, @ref, @path) | 111 | @logs_path = logs_file_project_ref_path(@project, @ref, @path) |
| 113 | 112 | ||
| 114 | - raise InvalidPathError unless @tree.exists? | ||
| 115 | rescue RuntimeError, NoMethodError, InvalidPathError | 113 | rescue RuntimeError, NoMethodError, InvalidPathError |
| 116 | not_found! | 114 | not_found! |
| 117 | end | 115 | end |
| 118 | 116 | ||
| 117 | + def tree | ||
| 118 | + @tree ||= Tree.new(@repo, @commit.id, @path) | ||
| 119 | + end | ||
| 120 | + | ||
| 119 | private | 121 | private |
| 120 | 122 | ||
| 121 | def get_id | 123 | def get_id |