summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-03-09 21:43:46 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-03-09 21:43:46 +0200
commitcd06d6edacac73ea798d05754fb47c110d9ae0de (patch)
tree22022dba25d5025ed480e6946858770224214734 /app
parent9988282e845f76733b43de15d303ef05d38c44ad (diff)
downloadgitlab-ce-cd06d6edacac73ea798d05754fb47c110d9ae0de.tar.gz
Project model refactored
Diffstat (limited to 'app')
-rw-r--r--app/models/commit.rb60
-rw-r--r--app/models/project.rb47
-rw-r--r--app/models/repository.rb13
3 files changed, 67 insertions, 53 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index a59e880370a..8e0681f01ae 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -20,6 +20,66 @@ class Commit
:id,
:to => :commit
+
+ class << self
+ def find_or_first(repo, commit_id = nil)
+ commit = if commit_id
+ repo.commit(commit_id)
+ else
+ repo.commits.first
+ end
+ 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| Commit.new(c, h) }
+ end.flatten.uniq { |c| c.id }
+
+ commits.sort! do |x, y|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits[0...n]
+ end
+
+ def commits_with_refs(repo, n = 20)
+ commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
+
+ commits.sort! do |x, y|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits[0..n]
+ end
+
+ def commits_since(repo, date)
+ commits = repo.heads.map do |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|
+ y.committed_date <=> x.committed_date
+ end
+
+ commits
+ end
+
+ def commits(repo, ref, path = nil, limit = nil, offset = nil)
+ if path
+ repo.log(ref, path, :max_count => limit, :skip => offset)
+ elsif limit && offset
+ repo.commits(ref, limit, offset)
+ else
+ repo.commits(ref)
+ end.map{ |c| Commit.new(c) }
+ end
+
+ def commits_between(repo, from, to)
+ repo.commits_between(from, to).map { |c| Commit.new(c) }
+ end
+ end
+
def persisted?
false
end
diff --git a/app/models/project.rb b/app/models/project.rb
index b7445db06c1..2ba0c9077bc 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -69,7 +69,7 @@ class Project < ActiveRecord::Base
:project => self,
:action => Event::Pushed,
:data => data,
- :author_id => Key.find_by_identifier(author_key_id).user.id
+ :author_id => data[:user_id]
)
end
@@ -259,60 +259,27 @@ class Project < ActiveRecord::Base
end
def commit(commit_id = nil)
- commit = if commit_id
- repo.commit(commit_id)
- else
- repo.commits.first
- end
- Commit.new(commit) if commit
+ Commit.find_or_first(repo, commit_id)
end
def fresh_commits(n = 10)
- commits = heads.map do |h|
- repo.commits(h.name, n).map { |c| Commit.new(c, h) }
- end.flatten.uniq { |c| c.id }
-
- commits.sort! do |x, y|
- y.committed_date <=> x.committed_date
- end
-
- commits[0...n]
+ Commit.fresh_commits(repo, n)
end
def commits_with_refs(n = 20)
- commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) }
-
- commits.sort! do |x, y|
- y.committed_date <=> x.committed_date
- end
-
- commits[0..n]
+ Commit.commits_with_refs(repo, n)
end
def commits_since(date)
- commits = heads.map do |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|
- y.committed_date <=> x.committed_date
- end
-
- commits
+ Commit.commits_since(repo, date)
end
def commits(ref, path = nil, limit = nil, offset = nil)
- if path
- repo.log(ref, path, :max_count => limit, :skip => offset)
- elsif limit && offset
- repo.commits(ref, limit, offset)
- else
- repo.commits(ref)
- end.map{ |c| Commit.new(c) }
+ Commit.commits(repo, ref, path, limit, offset)
end
def commits_between(from, to)
- repo.commits_between(from, to).map { |c| Commit.new(c) }
+ Commit.commits_between(repo, from, to)
end
def project_id
diff --git a/app/models/repository.rb b/app/models/repository.rb
deleted file mode 100644
index f18b8302715..00000000000
--- a/app/models/repository.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require File.join(Rails.root, "lib", "gitlabhq", "git_host")
-
-class Repository
- attr_accessor :project
-
- def self.default_ref
- "master"
- end
-
- def self.access_options
- {}
- end
-end