Commit 49b024f5f5b88d406b895f050943db1e75adfa2a
1 parent
bb06e905
Exists in
master
and in
4 other branches
Use Gitlab::Git:: for git features across application
Showing
11 changed files
with
32 additions
and
64 deletions
Show diff stats
app/controllers/blame_controller.rb
| @@ -8,7 +8,6 @@ class BlameController < ProjectResourceController | @@ -8,7 +8,6 @@ class BlameController < ProjectResourceController | ||
| 8 | before_filter :require_non_empty_project | 8 | before_filter :require_non_empty_project |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - @repo = @project.repo | ||
| 12 | - @blame = Grit::Blob.blame(@repo, @commit.id, @path) | 11 | + @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path) |
| 13 | end | 12 | end |
| 14 | end | 13 | end |
app/controllers/compare_controller.rb
| @@ -8,12 +8,12 @@ class CompareController < ProjectResourceController | @@ -8,12 +8,12 @@ class CompareController < ProjectResourceController | ||
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | def show | 10 | def show |
| 11 | - result = Commit.compare(project, params[:from], params[:to]) | 11 | + compare = Gitlab::Git::Compare.new(project.repository, params[:from], params[:to]) |
| 12 | 12 | ||
| 13 | - @commits = result[:commits] | ||
| 14 | - @commit = result[:commit] | ||
| 15 | - @diffs = result[:diffs] | ||
| 16 | - @refs_are_same = result[:same] | 13 | + @commits = compare.commits |
| 14 | + @commit = compare.commit | ||
| 15 | + @diffs = compare.diffs | ||
| 16 | + @refs_are_same = compare.same | ||
| 17 | @line_notes = [] | 17 | @line_notes = [] |
| 18 | end | 18 | end |
| 19 | 19 |
app/models/commit.rb
| @@ -8,6 +8,10 @@ class Commit | @@ -8,6 +8,10 @@ class Commit | ||
| 8 | # | 8 | # |
| 9 | DIFF_SAFE_SIZE = 100 | 9 | DIFF_SAFE_SIZE = 100 |
| 10 | 10 | ||
| 11 | + def self.decorate(commits) | ||
| 12 | + commits.map { |c| self.new(c) } | ||
| 13 | + end | ||
| 14 | + | ||
| 11 | attr_accessor :raw | 15 | attr_accessor :raw |
| 12 | 16 | ||
| 13 | def initialize(raw_commit) | 17 | def initialize(raw_commit) |
app/models/gollum_wiki.rb
| @@ -114,5 +114,4 @@ class GollumWiki | @@ -114,5 +114,4 @@ class GollumWiki | ||
| 114 | def path_to_repo | 114 | def path_to_repo |
| 115 | @path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, "#{path_with_namespace}.git") | 115 | @path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, "#{path_with_namespace}.git") |
| 116 | end | 116 | end |
| 117 | - | ||
| 118 | end | 117 | end |
app/models/repository.rb
| @@ -13,13 +13,13 @@ class Repository | @@ -13,13 +13,13 @@ class Repository | ||
| 13 | 13 | ||
| 14 | def commits(ref, path = nil, limit = nil, offset = nil) | 14 | def commits(ref, path = nil, limit = nil, offset = nil) |
| 15 | commits = raw_repository.commits(ref, path, limit, offset) | 15 | commits = raw_repository.commits(ref, path, limit, offset) |
| 16 | - commits = decorate_commits(commits) if commits.present? | 16 | + commits = Commit.decorate(commits) if commits.present? |
| 17 | commits | 17 | commits |
| 18 | end | 18 | end |
| 19 | 19 | ||
| 20 | def commits_between(target, source) | 20 | def commits_between(target, source) |
| 21 | commits = raw_repository.commits_between(target, source) | 21 | commits = raw_repository.commits_between(target, source) |
| 22 | - commits = decorate_commits(commits) if commits.present? | 22 | + commits = Commit.decorate(commits) if commits.present? |
| 23 | commits | 23 | commits |
| 24 | end | 24 | end |
| 25 | 25 | ||
| @@ -32,10 +32,4 @@ class Repository | @@ -32,10 +32,4 @@ class Repository | ||
| 32 | 32 | ||
| 33 | super | 33 | super |
| 34 | end | 34 | end |
| 35 | - | ||
| 36 | - protected | ||
| 37 | - | ||
| 38 | - def decorate_commits(commits) | ||
| 39 | - commits.map { |c| Commit.new(c) } | ||
| 40 | - end | ||
| 41 | end | 35 | end |
app/models/wiki_page.rb
| @@ -79,14 +79,14 @@ class WikiPage | @@ -79,14 +79,14 @@ class WikiPage | ||
| 79 | def version | 79 | def version |
| 80 | return nil unless persisted? | 80 | return nil unless persisted? |
| 81 | 81 | ||
| 82 | - @version ||= Commit.new(@page.version) | 82 | + @version ||= Commit.new(Gitlab::Git::Commit.new(@page.version)) |
| 83 | end | 83 | end |
| 84 | 84 | ||
| 85 | # Returns an array of Gitlab Commit instances. | 85 | # Returns an array of Gitlab Commit instances. |
| 86 | def versions | 86 | def versions |
| 87 | return [] unless persisted? | 87 | return [] unless persisted? |
| 88 | 88 | ||
| 89 | - @page.versions.map { |v| Commit.new(v) } | 89 | + @page.versions.map { |v| Commit.new(Gitlab::Git::Commit.new(v)) } |
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | # Returns the Date that this latest version was | 92 | # Returns the Date that this latest version was |
app/views/blame/show.html.haml
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | %i.icon-angle-right | 6 | %i.icon-angle-right |
| 7 | = link_to project_tree_path(@project, @ref) do | 7 | = link_to project_tree_path(@project, @ref) do |
| 8 | = @project.name | 8 | = @project.name |
| 9 | - - @tree.breadcrumbs(6) do |link| | 9 | + - tree_breadcrumbs(@tree, 6) do |link| |
| 10 | \/ | 10 | \/ |
| 11 | %li= link | 11 | %li= link |
| 12 | .clear | 12 | .clear |
app/views/compare/show.html.haml
| @@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
| 16 | %div.ui-box | 16 | %div.ui-box |
| 17 | %h5.title | 17 | %h5.title |
| 18 | Commits (#{@commits.count}) | 18 | Commits (#{@commits.count}) |
| 19 | - %ul.well-list= render @commits | 19 | + %ul.well-list= render Commit.decorate(@commits) |
| 20 | 20 | ||
| 21 | - unless @diffs.empty? | 21 | - unless @diffs.empty? |
| 22 | %h4 Diff | 22 | %h4 Diff |
app/views/wikis/show.html.haml
| @@ -13,5 +13,4 @@ | @@ -13,5 +13,4 @@ | ||
| 13 | = preserve do | 13 | = preserve do |
| 14 | = render_wiki_content(@wiki) | 14 | = render_wiki_content(@wiki) |
| 15 | 15 | ||
| 16 | -- commit = Commit.new(@wiki.version) | ||
| 17 | -%p.time Last edited by #{commit_author_link(commit, avatar: true, size: 16)} #{time_ago_in_words @wiki.created_at} ago | 16 | +%p.time Last edited by #{commit_author_link(@wiki.version, avatar: true, size: 16)} #{time_ago_in_words @wiki.created_at} ago |
lib/gitlab/git/commit.rb
| 1 | -# Gitlab::Git::Gitlab::Git::Commit is a wrapper around native Grit::Commit object | 1 | +# Gitlab::Git::Commit is a wrapper around native Grit::Commit object |
| 2 | # We dont want to use grit objects inside app/ | 2 | # We dont want to use grit objects inside app/ |
| 3 | # It helps us easily migrate to rugged in future | 3 | # It helps us easily migrate to rugged in future |
| 4 | module Gitlab | 4 | module Gitlab |
| 5 | module Git | 5 | module Git |
| 6 | - class Gitlab::Git::Commit | 6 | + class Commit |
| 7 | attr_accessor :raw_commit, :head, :refs | 7 | attr_accessor :raw_commit, :head, :refs |
| 8 | 8 | ||
| 9 | delegate :message, :authored_date, :committed_date, :parents, :sha, | 9 | delegate :message, :authored_date, :committed_date, :parents, :sha, |
| @@ -18,12 +18,12 @@ module Gitlab | @@ -18,12 +18,12 @@ module Gitlab | ||
| 18 | repo.commits(root_ref).first | 18 | repo.commits(root_ref).first |
| 19 | end | 19 | end |
| 20 | 20 | ||
| 21 | - Gitlab::Git::Commit.new(commit) if commit | 21 | + Commit.new(commit) if commit |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | def fresh_commits(repo, n = 10) | 24 | def fresh_commits(repo, n = 10) |
| 25 | commits = repo.heads.map do |h| | 25 | commits = repo.heads.map do |h| |
| 26 | - repo.commits(h.name, n).map { |c| Gitlab::Git::Commit.new(c, h) } | 26 | + repo.commits(h.name, n).map { |c| Commit.new(c, h) } |
| 27 | end.flatten.uniq { |c| c.id } | 27 | end.flatten.uniq { |c| c.id } |
| 28 | 28 | ||
| 29 | commits.sort! do |x, y| | 29 | commits.sort! do |x, y| |
| @@ -34,7 +34,7 @@ module Gitlab | @@ -34,7 +34,7 @@ module Gitlab | ||
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | def commits_with_refs(repo, n = 20) | 36 | def commits_with_refs(repo, n = 20) |
| 37 | - commits = repo.branches.map { |ref| Gitlab::Git::Commit.new(ref.commit, ref) } | 37 | + commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) } |
| 38 | 38 | ||
| 39 | commits.sort! do |x, y| | 39 | commits.sort! do |x, y| |
| 40 | y.committed_date <=> x.committed_date | 40 | y.committed_date <=> x.committed_date |
| @@ -45,7 +45,7 @@ module Gitlab | @@ -45,7 +45,7 @@ module Gitlab | ||
| 45 | 45 | ||
| 46 | def commits_since(repo, date) | 46 | def commits_since(repo, date) |
| 47 | commits = repo.heads.map do |h| | 47 | commits = repo.heads.map do |h| |
| 48 | - repo.log(h.name, nil, since: date).each { |c| Gitlab::Git::Commit.new(c, h) } | 48 | + repo.log(h.name, nil, since: date).each { |c| Commit.new(c, h) } |
| 49 | end.flatten.uniq { |c| c.id } | 49 | end.flatten.uniq { |c| c.id } |
| 50 | 50 | ||
| 51 | commits.sort! do |x, y| | 51 | commits.sort! do |x, y| |
| @@ -62,41 +62,11 @@ module Gitlab | @@ -62,41 +62,11 @@ module Gitlab | ||
| 62 | repo.commits(ref, limit, offset) | 62 | repo.commits(ref, limit, offset) |
| 63 | else | 63 | else |
| 64 | repo.commits(ref) | 64 | repo.commits(ref) |
| 65 | - end.map{ |c| Gitlab::Git::Commit.new(c) } | 65 | + end.map{ |c| Commit.new(c) } |
| 66 | end | 66 | end |
| 67 | 67 | ||
| 68 | def commits_between(repo, from, to) | 68 | def commits_between(repo, from, to) |
| 69 | - repo.commits_between(from, to).map { |c| Gitlab::Git::Commit.new(c) } | ||
| 70 | - end | ||
| 71 | - | ||
| 72 | - def compare(project, from, to) | ||
| 73 | - result = { | ||
| 74 | - commits: [], | ||
| 75 | - diffs: [], | ||
| 76 | - commit: nil, | ||
| 77 | - same: false | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - return result unless from && to | ||
| 81 | - | ||
| 82 | - first = project.repository.commit(to.try(:strip)) | ||
| 83 | - last = project.repository.commit(from.try(:strip)) | ||
| 84 | - | ||
| 85 | - if first && last | ||
| 86 | - result[:same] = (first.id == last.id) | ||
| 87 | - result[:commits] = project.repo.commits_between(last.id, first.id).map {|c| Gitlab::Git::Commit.new(c)} | ||
| 88 | - | ||
| 89 | - # Dont load diff for 100+ commits | ||
| 90 | - result[:diffs] = if result[:commits].size > 100 | ||
| 91 | - [] | ||
| 92 | - else | ||
| 93 | - project.repo.diff(last.id, first.id) rescue [] | ||
| 94 | - end | ||
| 95 | - | ||
| 96 | - result[:commit] = Gitlab::Git::Commit.new(first) | ||
| 97 | - end | ||
| 98 | - | ||
| 99 | - result | 69 | + repo.commits_between(from, to).map { |c| Commit.new(c) } |
| 100 | end | 70 | end |
| 101 | end | 71 | end |
| 102 | 72 | ||
| @@ -142,7 +112,7 @@ module Gitlab | @@ -142,7 +112,7 @@ module Gitlab | ||
| 142 | 112 | ||
| 143 | def prev_commit | 113 | def prev_commit |
| 144 | @prev_commit ||= if parents.present? | 114 | @prev_commit ||= if parents.present? |
| 145 | - Gitlab::Git::Commit.new(parents.first) | 115 | + Commit.new(parents.first) |
| 146 | else | 116 | else |
| 147 | nil | 117 | nil |
| 148 | end | 118 | end |
| @@ -156,7 +126,7 @@ module Gitlab | @@ -156,7 +126,7 @@ module Gitlab | ||
| 156 | # | 126 | # |
| 157 | # Cuts out the header and stats from #to_patch and returns only the diff. | 127 | # Cuts out the header and stats from #to_patch and returns only the diff. |
| 158 | def to_diff | 128 | def to_diff |
| 159 | - # see Grit::Gitlab::Git::Commit#show | 129 | + # see Grit::Commit#show |
| 160 | patch = to_patch | 130 | patch = to_patch |
| 161 | 131 | ||
| 162 | # discard lines before the diff | 132 | # discard lines before the diff |
spec/support/test_env.rb
| @@ -17,15 +17,18 @@ module TestEnv | @@ -17,15 +17,18 @@ module TestEnv | ||
| 17 | repos_path = Rails.root.join('tmp', 'test-git-base-path') | 17 | repos_path = Rails.root.join('tmp', 'test-git-base-path') |
| 18 | Gitlab.config.gitlab_shell.stub(repos_path: repos_path) | 18 | Gitlab.config.gitlab_shell.stub(repos_path: repos_path) |
| 19 | 19 | ||
| 20 | + Gitlab::Shell.any_instance.stub(:add_repository) do |path| | ||
| 21 | + create_temp_repo(File.join(repos_path, "#{path}.git")) | ||
| 22 | + end | ||
| 23 | + | ||
| 20 | Gitlab::Shell.any_instance.stub( | 24 | Gitlab::Shell.any_instance.stub( |
| 21 | - add_repository: ->(path) { create_temp_repo(File.join(repos_path, "#{path}.git")) }, | ||
| 22 | mv_repository: true, | 25 | mv_repository: true, |
| 23 | remove_repository: true, | 26 | remove_repository: true, |
| 24 | add_key: true, | 27 | add_key: true, |
| 25 | remove_key: true | 28 | remove_key: true |
| 26 | ) | 29 | ) |
| 27 | 30 | ||
| 28 | - fake_satellite = double( | 31 | + fake_satellite = stub( |
| 29 | exists?: true, | 32 | exists?: true, |
| 30 | destroy: true, | 33 | destroy: true, |
| 31 | create: true | 34 | create: true |