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 | 23 | |
| 24 | 24 | # Extracting information from a git repository |
| 25 | 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 | 28 | # Ruby/Rack Git Smart-HTTP Server Handler |
| 29 | 29 | gem 'gitlab-grack', '~> 1.0.1', require: 'grack' | ... | ... |
Gemfile.lock
| ... | ... | @@ -174,7 +174,7 @@ GEM |
| 174 | 174 | gitlab-pygments.rb (0.3.2) |
| 175 | 175 | posix-spawn (~> 0.3.6) |
| 176 | 176 | yajl-ruby (~> 1.1.0) |
| 177 | - gitlab_git (2.3.1) | |
| 177 | + gitlab_git (3.0.0.beta1) | |
| 178 | 178 | activesupport (~> 3.2.13) |
| 179 | 179 | github-linguist (~> 2.3.4) |
| 180 | 180 | gitlab-grit (~> 2.6.0) |
| ... | ... | @@ -574,7 +574,7 @@ DEPENDENCIES |
| 574 | 574 | gitlab-gollum-lib (~> 1.0.1) |
| 575 | 575 | gitlab-grack (~> 1.0.1) |
| 576 | 576 | gitlab-pygments.rb (~> 0.3.2) |
| 577 | - gitlab_git (= 2.3.1) | |
| 577 | + gitlab_git (~> 3.0.0.beta1) | |
| 578 | 578 | gitlab_meta (= 6.0) |
| 579 | 579 | gitlab_omniauth-ldap (= 1.0.3) |
| 580 | 580 | gon | ... | ... |
app/controllers/projects/blame_controller.rb
| ... | ... | @@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController |
| 8 | 8 | before_filter :require_non_empty_project |
| 9 | 9 | |
| 10 | 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 | @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path) |
| 13 | 13 | end |
| 14 | 14 | end | ... | ... |
app/controllers/projects/blob_controller.rb
| ... | ... | @@ -8,6 +8,6 @@ class Projects::BlobController < Projects::ApplicationController |
| 8 | 8 | before_filter :require_non_empty_project |
| 9 | 9 | |
| 10 | 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 | end |
| 13 | 13 | end | ... | ... |
app/controllers/projects/raw_controller.rb
| ... | ... | @@ -8,9 +8,9 @@ class Projects::RawController < Projects::ApplicationController |
| 8 | 8 | before_filter :require_non_empty_project |
| 9 | 9 | |
| 10 | 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 | 14 | type = if @blob.mime_type =~ /html|javascript/ |
| 15 | 15 | 'text/plain; charset=utf-8' |
| 16 | 16 | else | ... | ... |
app/controllers/projects/refs_controller.rb
| ... | ... | @@ -24,13 +24,14 @@ class Projects::RefsController < Projects::ApplicationController |
| 24 | 24 | format.js do |
| 25 | 25 | @ref = params[:ref] |
| 26 | 26 | define_tree_vars |
| 27 | + tree | |
| 27 | 28 | render "tree" |
| 28 | 29 | end |
| 29 | 30 | end |
| 30 | 31 | end |
| 31 | 32 | |
| 32 | 33 | def logs_tree |
| 33 | - contents = @tree.entries | |
| 34 | + contents = tree.entries | |
| 34 | 35 | @logs = contents.map do |content| |
| 35 | 36 | file = params[:path] ? File.join(params[:path], content.name) : content.name |
| 36 | 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 | 8 | before_filter :require_non_empty_project |
| 9 | 9 | |
| 10 | 10 | def show |
| 11 | + return not_found! if tree.entries.empty? | |
| 12 | + | |
| 11 | 13 | respond_to do |format| |
| 12 | 14 | format.html |
| 13 | 15 | # Disable cache so browser history works | ... | ... |
app/helpers/tree_helper.rb
| ... | ... | @@ -67,9 +67,9 @@ module TreeHelper |
| 67 | 67 | end |
| 68 | 68 | |
| 69 | 69 | def tree_breadcrumbs(tree, max_links = 2) |
| 70 | - if tree.path | |
| 70 | + if @path.present? | |
| 71 | 71 | part_path = "" |
| 72 | - parts = tree.path.split("\/") | |
| 72 | + parts = @path.split("\/") | |
| 73 | 73 | |
| 74 | 74 | yield('..', nil) if parts.count > max_links |
| 75 | 75 | |
| ... | ... | @@ -78,14 +78,14 @@ module TreeHelper |
| 78 | 78 | part_path = part if part_path.empty? |
| 79 | 79 | |
| 80 | 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 | 82 | end |
| 83 | 83 | end |
| 84 | 84 | end |
| 85 | 85 | |
| 86 | 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 | 89 | end |
| 90 | 90 | |
| 91 | 91 | def leave_edit_message | ... | ... |
app/models/repository.rb
| 1 | 1 | class Repository |
| 2 | 2 | include Gitlab::ShellAdapter |
| 3 | 3 | |
| 4 | - attr_accessor :raw_repository | |
| 4 | + attr_accessor :raw_repository, :path_with_namespace | |
| 5 | 5 | |
| 6 | 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 | 9 | rescue Gitlab::Git::Repository::NoRepository |
| 9 | 10 | nil |
| 10 | 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 | 17 | def exists? |
| 13 | 18 | raw_repository |
| 14 | 19 | end | ... | ... |
app/models/tree.rb
| 1 | 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 | 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 | 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 | 24 | end |
| 17 | 25 | end | ... | ... |
app/views/projects/commits/_diffs.html.haml
| ... | ... | @@ -37,9 +37,9 @@ |
| 37 | 37 | - unless @suppress_diff |
| 38 | 38 | - diffs.each_with_index do |diff, i| |
| 39 | 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 | 43 | .file{id: "diff-#{i}"} |
| 44 | 44 | .header |
| 45 | 45 | - if diff.deleted_file |
| ... | ... | @@ -64,7 +64,7 @@ |
| 64 | 64 | - if file.text? |
| 65 | 65 | = render "projects/commits/text_file", diff: diff, index: i |
| 66 | 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 | 68 | = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i |
| 69 | 69 | - else |
| 70 | 70 | %p.nothing_here_message No preview for this file type | ... | ... |
app/views/projects/tree/_tree.html.haml
| ... | ... | @@ -28,7 +28,7 @@ |
| 28 | 28 | = truncate(@commit.title, length: 50) |
| 29 | 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 | 32 | %tr.tree-item |
| 33 | 33 | %td.tree-item-file-name |
| 34 | 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 | |
| 7 | 7 | # GitLab shell adapter |
| 8 | 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 | 86 | # - @ref - A string representing the ref (e.g., the branch, tag, or commit SHA) |
| 87 | 87 | # - @path - A string representing the filesystem path |
| 88 | 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 | 90 | # If the :id parameter appears to be requesting a specific response format, |
| 92 | 91 | # that will be handled as well. |
| ... | ... | @@ -107,15 +106,18 @@ module ExtractsPath |
| 107 | 106 | else |
| 108 | 107 | @commit = @repo.commit(@options[:extended_sha1]) |
| 109 | 108 | end |
| 110 | - @tree = Tree.new(@repo, @commit.id, @ref, @path) | |
| 109 | + | |
| 111 | 110 | @hex_path = Digest::SHA1.hexdigest(@path) |
| 112 | 111 | @logs_path = logs_file_project_ref_path(@project, @ref, @path) |
| 113 | 112 | |
| 114 | - raise InvalidPathError unless @tree.exists? | |
| 115 | 113 | rescue RuntimeError, NoMethodError, InvalidPathError |
| 116 | 114 | not_found! |
| 117 | 115 | end |
| 118 | 116 | |
| 117 | + def tree | |
| 118 | + @tree ||= Tree.new(@repo, @commit.id, @path) | |
| 119 | + end | |
| 120 | + | |
| 119 | 121 | private |
| 120 | 122 | |
| 121 | 123 | def get_id | ... | ... |