Commit 68d89548cd7d796c78e7b9d3f7b64702d39d0f5c

Authored by Dmitriy Zaporozhets
2 parents e219cf72 1d3f03fb

Merge branch 'improve/gitlab_git_3' of /home/git/repositories/gitlab/gitlabhq

@@ -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'
@@ -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/assets/stylesheets/gitlab_bootstrap/files.scss
@@ -69,6 +69,12 @@ @@ -69,6 +69,12 @@
69 69
70 } 70 }
71 71
  72 + &.blob-no-preview {
  73 + background: #eee;
  74 + text-shadow: 0 1px 2px #FFF;
  75 + padding: 100px 0;
  76 + }
  77 +
72 /** 78 /**
73 * Blame file 79 * Blame file
74 */ 80 */
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,8 @@ class Projects::BlobController < Projects::ApplicationController @@ -8,6 +8,8 @@ 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 +
  13 + not_found! unless @blob
12 end 14 end
13 end 15 end
app/controllers/projects/edit_tree_controller.rb
@@ -32,9 +32,9 @@ class Projects::EditTreeController < Projects::ApplicationController @@ -32,9 +32,9 @@ class Projects::EditTreeController < Projects::ApplicationController
32 private 32 private
33 33
34 def edit_requirements 34 def edit_requirements
35 - @blob = Gitlab::Git::Blob.new(@repository, @commit.id, @ref, @path) 35 + @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
36 36
37 - unless @blob.exists? && @blob.text? 37 + unless @blob
38 redirect_to project_blob_path(@project, @id), notice: "You can only edit text files" 38 redirect_to project_blob_path(@project, @id), notice: "You can only edit text files"
39 end 39 end
40 40
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/blobs_helper.rb 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +module BlobsHelper
  2 + def find_blob(repository, sha, path)
  3 + Gitlab::Git::Blob.find(repository, sha, path)
  4 + end
  5 +end
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) if path_with_namespace
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/blob/_download.html.haml
1 -.file-content.blob_file 1 +.file-content.blob_file.blob-no-preview
2 %center 2 %center
3 = link_to project_raw_path(@project, @id) do 3 = link_to project_raw_path(@project, @id) do
4 - %div.padded  
5 - %h4  
6 - %i.icon-download-alt  
7 - %br  
8 - Download (#{number_to_human_size blob.size}) 4 + %h1.light
  5 + %i.icon-download-alt
  6 + %h4
  7 + Download (#{number_to_human_size blob.size})
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/api/repositories.rb
@@ -139,7 +139,7 @@ module API @@ -139,7 +139,7 @@ module API
139 path = params[:path] || nil 139 path = params[:path] || nil
140 140
141 commit = user_project.repository.commit(ref) 141 commit = user_project.repository.commit(ref)
142 - tree = Tree.new(user_project.repository, commit.id, ref, path) 142 + tree = Tree.new(user_project.repository, commit.id, path)
143 143
144 trees = [] 144 trees = []
145 145
@@ -168,8 +168,8 @@ module API @@ -168,8 +168,8 @@ module API
168 commit = repo.commit(ref) 168 commit = repo.commit(ref)
169 not_found! "Commit" unless commit 169 not_found! "Commit" unless commit
170 170
171 - blob = Gitlab::Git::Blob.new(repo, commit.id, ref, params[:filepath])  
172 - not_found! "File" unless blob.exists? 171 + blob = Gitlab::Git::Blob.find(repo, commit.id, params[:filepath])
  172 + not_found! "File" unless blob
173 173
174 env['api.format'] = :txt 174 env['api.format'] = :txt
175 175
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,20 @@ module ExtractsPath @@ -107,15 +106,20 @@ 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 +
  110 + raise InvalidPathError unless @commit
  111 +
111 @hex_path = Digest::SHA1.hexdigest(@path) 112 @hex_path = Digest::SHA1.hexdigest(@path)
112 @logs_path = logs_file_project_ref_path(@project, @ref, @path) 113 @logs_path = logs_file_project_ref_path(@project, @ref, @path)
113 114
114 - raise InvalidPathError unless @tree.exists?  
115 rescue RuntimeError, NoMethodError, InvalidPathError 115 rescue RuntimeError, NoMethodError, InvalidPathError
116 not_found! 116 not_found!
117 end 117 end
118 118
  119 + def tree
  120 + @tree ||= Tree.new(@repo, @commit.id, @path)
  121 + end
  122 +
119 private 123 private
120 124
121 def get_id 125 def get_id