diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit.rb | 169 | ||||
-rw-r--r-- | app/models/gollum_wiki.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 2 | ||||
-rw-r--r-- | app/models/network/commit.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 4 |
6 files changed, 11 insertions, 170 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 4d0c57b35fd..0164ae663be 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -8,174 +8,15 @@ class Commit # DIFF_SAFE_SIZE = 100 - attr_accessor :commit, :head, :refs + attr_accessor :raw - delegate :message, :authored_date, :committed_date, :parents, :sha, - :date, :committer, :author, :diffs, :tree, :id, :stats, - :to_patch, to: :commit - - class << self - def find_or_first(repo, commit_id = nil, root_ref) - commit = if commit_id - repo.commit(commit_id) - else - repo.commits(root_ref).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 - - 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| 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] = Commit.new(first) - end - - result - end - end - - def initialize(raw_commit, head = nil) + def initialize(raw_commit) raise "Nil as raw commit passed" unless raw_commit - @commit = raw_commit - @head = head - end - - def short_id(length = 10) - id.to_s[0..length] - end - - def safe_message - @safe_message ||= message - end - - def created_at - committed_date - end - - def author_email - author.email - end - - def author_name - author.name - end - - # Was this commit committed by a different person than the original author? - def different_committer? - author_name != committer_name || author_email != committer_email - end - - def committer_name - committer.name - end - - def committer_email - committer.email - end - - def prev_commit - @prev_commit ||= if parents.present? - Commit.new(parents.first) - else - nil - end - end - - def prev_commit_id - prev_commit.try :id - end - - # Shows the diff between the commit's parent and the commit. - # - # Cuts out the header and stats from #to_patch and returns only the diff. - def to_diff - # see Grit::Commit#show - patch = to_patch - - # discard lines before the diff - lines = patch.split("\n") - while !lines.first.start_with?("diff --git") do - lines.shift - end - lines.pop if lines.last =~ /^[\d.]+$/ # Git version - lines.pop if lines.last == "-- " # end of diff - lines.join("\n") + @raw = raw_commit end - def has_zero_stats? - stats.total.zero? - rescue - true + def method_missing(m, *args, &block) + @raw.send(m, *args, &block) end end diff --git a/app/models/gollum_wiki.rb b/app/models/gollum_wiki.rb index a1ee3a0899a..cdfcd567a43 100644 --- a/app/models/gollum_wiki.rb +++ b/app/models/gollum_wiki.rb @@ -50,7 +50,7 @@ class GollumWiki # Returns the last 30 Commit objects across the entire # repository. def recent_history - Commit.fresh_commits(wiki.repo, 30) + Gitlab::Git::Commit.fresh_commits(wiki.repo, 30) end # Finds a page within the repository based on a tile diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 9d42b1e1f32..505f6637d77 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -169,7 +169,7 @@ class MergeRequest < ActiveRecord::Base end def unmerged_commits - self.project.repo. + self.project.repository. commits_between(self.target_branch, self.source_branch). map {|c| Commit.new(c)}. sort_by(&:created_at). diff --git a/app/models/network/commit.rb b/app/models/network/commit.rb index d0bc61c3bf7..3cd0c015fa0 100644 --- a/app/models/network/commit.rb +++ b/app/models/network/commit.rb @@ -8,7 +8,7 @@ module Network attr_accessor :time, :spaces, :parent_spaces def initialize(raw_commit, refs) - @commit = ::Commit.new(raw_commit) + @commit = Gitlab::Git::Commit.new(raw_commit) @time = -1 @spaces = [] @parent_spaces = [] diff --git a/app/models/note.rb b/app/models/note.rb index f26420ca2a0..17ceb541b80 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -130,7 +130,7 @@ class Note < ActiveRecord::Base # override to return commits, which are not active record def noteable if for_commit? - project.repository.commit(commit_id) + Commit.new(project.repository.commit(commit_id)) else super end diff --git a/app/models/project.rb b/app/models/project.rb index 6871afca50a..54abbc3ecb1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -142,11 +142,11 @@ class Project < ActiveRecord::Base def repository if path - @repository ||= Repository.new(path_with_namespace, default_branch) + @repository ||= Gitlab::Git::Repository.new(path_with_namespace, default_branch) else nil end - rescue Grit::NoSuchPathError + rescue Gitlab::Git::NoRepository nil end |