Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 17:04:35 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-01 17:04:35 +0400
commit49b024f5f5b88d406b895f050943db1e75adfa2a (patch)
tree65d9b34ebcaab38ecfc81da0acf0cc8e6c36d900
parentbb06e905efb1722502d71059c21add8cfde851aa (diff)
Use Gitlab::Git:: for git features across application
-rw-r--r--app/controllers/blame_controller.rb3
-rw-r--r--app/controllers/compare_controller.rb10
-rw-r--r--app/models/commit.rb4
-rw-r--r--app/models/gollum_wiki.rb1
-rw-r--r--app/models/repository.rb10
-rw-r--r--app/models/wiki_page.rb4
-rw-r--r--app/views/blame/show.html.haml2
-rw-r--r--app/views/compare/show.html.haml2
-rw-r--r--app/views/wikis/show.html.haml3
-rw-r--r--lib/gitlab/git/commit.rb50
-rw-r--r--spec/support/test_env.rb7
11 files changed, 32 insertions, 64 deletions
diff --git a/app/controllers/blame_controller.rb b/app/controllers/blame_controller.rb
index 76caa4a69c4..310b567cfe6 100644
--- a/app/controllers/blame_controller.rb
+++ b/app/controllers/blame_controller.rb
@@ -8,7 +8,6 @@ class BlameController < ProjectResourceController
before_filter :require_non_empty_project
def show
- @repo = @project.repo
- @blame = Grit::Blob.blame(@repo, @commit.id, @path)
+ @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path)
end
end
diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb
index b72da783d08..750e9c2380e 100644
--- a/app/controllers/compare_controller.rb
+++ b/app/controllers/compare_controller.rb
@@ -8,12 +8,12 @@ class CompareController < ProjectResourceController
end
def show
- result = Commit.compare(project, params[:from], params[:to])
+ compare = Gitlab::Git::Compare.new(project.repository, params[:from], params[:to])
- @commits = result[:commits]
- @commit = result[:commit]
- @diffs = result[:diffs]
- @refs_are_same = result[:same]
+ @commits = compare.commits
+ @commit = compare.commit
+ @diffs = compare.diffs
+ @refs_are_same = compare.same
@line_notes = []
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 96c8577f90e..e3363350997 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -8,6 +8,10 @@ class Commit
#
DIFF_SAFE_SIZE = 100
+ def self.decorate(commits)
+ commits.map { |c| self.new(c) }
+ end
+
attr_accessor :raw
def initialize(raw_commit)
diff --git a/app/models/gollum_wiki.rb b/app/models/gollum_wiki.rb
index cdfcd567a43..647058e8ec9 100644
--- a/app/models/gollum_wiki.rb
+++ b/app/models/gollum_wiki.rb
@@ -114,5 +114,4 @@ class GollumWiki
def path_to_repo
@path_to_repo ||= File.join(Gitlab.config.gitlab_shell.repos_path, "#{path_with_namespace}.git")
end
-
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index be6502ebf5c..0a4431f14c1 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -13,13 +13,13 @@ class Repository
def commits(ref, path = nil, limit = nil, offset = nil)
commits = raw_repository.commits(ref, path, limit, offset)
- commits = decorate_commits(commits) if commits.present?
+ commits = Commit.decorate(commits) if commits.present?
commits
end
def commits_between(target, source)
commits = raw_repository.commits_between(target, source)
- commits = decorate_commits(commits) if commits.present?
+ commits = Commit.decorate(commits) if commits.present?
commits
end
@@ -32,10 +32,4 @@ class Repository
super
end
-
- protected
-
- def decorate_commits(commits)
- commits.map { |c| Commit.new(c) }
- end
end
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index adc77b22231..497d69e8e90 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -79,14 +79,14 @@ class WikiPage
def version
return nil unless persisted?
- @version ||= Commit.new(@page.version)
+ @version ||= Commit.new(Gitlab::Git::Commit.new(@page.version))
end
# Returns an array of Gitlab Commit instances.
def versions
return [] unless persisted?
- @page.versions.map { |v| Commit.new(v) }
+ @page.versions.map { |v| Commit.new(Gitlab::Git::Commit.new(v)) }
end
# Returns the Date that this latest version was
diff --git a/app/views/blame/show.html.haml b/app/views/blame/show.html.haml
index b07a514fdf7..96d153e627f 100644
--- a/app/views/blame/show.html.haml
+++ b/app/views/blame/show.html.haml
@@ -6,7 +6,7 @@
%i.icon-angle-right
= link_to project_tree_path(@project, @ref) do
= @project.name
- - @tree.breadcrumbs(6) do |link|
+ - tree_breadcrumbs(@tree, 6) do |link|
\/
%li= link
.clear
diff --git a/app/views/compare/show.html.haml b/app/views/compare/show.html.haml
index 476be2550af..56c4a113ea0 100644
--- a/app/views/compare/show.html.haml
+++ b/app/views/compare/show.html.haml
@@ -16,7 +16,7 @@
%div.ui-box
%h5.title
Commits (#{@commits.count})
- %ul.well-list= render @commits
+ %ul.well-list= render Commit.decorate(@commits)
- unless @diffs.empty?
%h4 Diff
diff --git a/app/views/wikis/show.html.haml b/app/views/wikis/show.html.haml
index 4102182e923..b237bc524ed 100644
--- a/app/views/wikis/show.html.haml
+++ b/app/views/wikis/show.html.haml
@@ -13,5 +13,4 @@
= preserve do
= render_wiki_content(@wiki)
-- commit = Commit.new(@wiki.version)
-%p.time Last edited by #{commit_author_link(commit, avatar: true, size: 16)} #{time_ago_in_words @wiki.created_at} ago
+%p.time Last edited by #{commit_author_link(@wiki.version, avatar: true, size: 16)} #{time_ago_in_words @wiki.created_at} ago
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb
index 023672f986b..d7e1a5ca770 100644
--- a/lib/gitlab/git/commit.rb
+++ b/lib/gitlab/git/commit.rb
@@ -1,9 +1,9 @@
-# Gitlab::Git::Gitlab::Git::Commit is a wrapper around native Grit::Commit object
+# Gitlab::Git::Commit is a wrapper around native Grit::Commit object
# We dont want to use grit objects inside app/
# It helps us easily migrate to rugged in future
module Gitlab
module Git
- class Gitlab::Git::Commit
+ class Commit
attr_accessor :raw_commit, :head, :refs
delegate :message, :authored_date, :committed_date, :parents, :sha,
@@ -18,12 +18,12 @@ module Gitlab
repo.commits(root_ref).first
end
- Gitlab::Git::Commit.new(commit) if commit
+ Commit.new(commit) if commit
end
def fresh_commits(repo, n = 10)
commits = repo.heads.map do |h|
- repo.commits(h.name, n).map { |c| Gitlab::Git::Commit.new(c, h) }
+ repo.commits(h.name, n).map { |c| Commit.new(c, h) }
end.flatten.uniq { |c| c.id }
commits.sort! do |x, y|
@@ -34,7 +34,7 @@ module Gitlab
end
def commits_with_refs(repo, n = 20)
- commits = repo.branches.map { |ref| Gitlab::Git::Commit.new(ref.commit, ref) }
+ commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
commits.sort! do |x, y|
y.committed_date <=> x.committed_date
@@ -45,7 +45,7 @@ module Gitlab
def commits_since(repo, date)
commits = repo.heads.map do |h|
- repo.log(h.name, nil, since: date).each { |c| Gitlab::Git::Commit.new(c, h) }
+ repo.log(h.name, nil, since: date).each { |c| Commit.new(c, h) }
end.flatten.uniq { |c| c.id }
commits.sort! do |x, y|
@@ -62,41 +62,11 @@ module Gitlab
repo.commits(ref, limit, offset)
else
repo.commits(ref)
- end.map{ |c| Gitlab::Git::Commit.new(c) }
+ end.map{ |c| Commit.new(c) }
end
def commits_between(repo, from, to)
- repo.commits_between(from, to).map { |c| Gitlab::Git::Commit.new(c) }
- end
-
- def compare(project, from, to)
- result = {
- commits: [],
- diffs: [],
- commit: nil,
- same: false
- }
-
- return result unless from && to
-
- first = project.repository.commit(to.try(:strip))
- last = project.repository.commit(from.try(:strip))
-
- if first && last
- result[:same] = (first.id == last.id)
- result[:commits] = project.repo.commits_between(last.id, first.id).map {|c| Gitlab::Git::Commit.new(c)}
-
- # Dont load diff for 100+ commits
- result[:diffs] = if result[:commits].size > 100
- []
- else
- project.repo.diff(last.id, first.id) rescue []
- end
-
- result[:commit] = Gitlab::Git::Commit.new(first)
- end
-
- result
+ repo.commits_between(from, to).map { |c| Commit.new(c) }
end
end
@@ -142,7 +112,7 @@ module Gitlab
def prev_commit
@prev_commit ||= if parents.present?
- Gitlab::Git::Commit.new(parents.first)
+ Commit.new(parents.first)
else
nil
end
@@ -156,7 +126,7 @@ module Gitlab
#
# Cuts out the header and stats from #to_patch and returns only the diff.
def to_diff
- # see Grit::Gitlab::Git::Commit#show
+ # see Grit::Commit#show
patch = to_patch
# discard lines before the diff
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index 769405b6ffb..0f81347dd6b 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -17,15 +17,18 @@ module TestEnv
repos_path = Rails.root.join('tmp', 'test-git-base-path')
Gitlab.config.gitlab_shell.stub(repos_path: repos_path)
+ Gitlab::Shell.any_instance.stub(:add_repository) do |path|
+ create_temp_repo(File.join(repos_path, "#{path}.git"))
+ end
+
Gitlab::Shell.any_instance.stub(
- add_repository: ->(path) { create_temp_repo(File.join(repos_path, "#{path}.git")) },
mv_repository: true,
remove_repository: true,
add_key: true,
remove_key: true
)
- fake_satellite = double(
+ fake_satellite = stub(
exists?: true,
destroy: true,
create: true