Commit 154e54b46e01615bc13f5e3ac2d0f07f7a27464d
1 parent
d444a23a
Exists in
master
and in
4 other branches
Remove grit logic from app/
Showing
6 changed files
with
11 additions
and
170 deletions
Show diff stats
app/models/commit.rb
| ... | ... | @@ -8,174 +8,15 @@ class Commit |
| 8 | 8 | # |
| 9 | 9 | DIFF_SAFE_SIZE = 100 |
| 10 | 10 | |
| 11 | - attr_accessor :commit, :head, :refs | |
| 11 | + attr_accessor :raw | |
| 12 | 12 | |
| 13 | - delegate :message, :authored_date, :committed_date, :parents, :sha, | |
| 14 | - :date, :committer, :author, :diffs, :tree, :id, :stats, | |
| 15 | - :to_patch, to: :commit | |
| 16 | - | |
| 17 | - class << self | |
| 18 | - def find_or_first(repo, commit_id = nil, root_ref) | |
| 19 | - commit = if commit_id | |
| 20 | - repo.commit(commit_id) | |
| 21 | - else | |
| 22 | - repo.commits(root_ref).first | |
| 23 | - end | |
| 24 | - | |
| 25 | - Commit.new(commit) if commit | |
| 26 | - end | |
| 27 | - | |
| 28 | - def fresh_commits(repo, n = 10) | |
| 29 | - commits = repo.heads.map do |h| | |
| 30 | - repo.commits(h.name, n).map { |c| Commit.new(c, h) } | |
| 31 | - end.flatten.uniq { |c| c.id } | |
| 32 | - | |
| 33 | - commits.sort! do |x, y| | |
| 34 | - y.committed_date <=> x.committed_date | |
| 35 | - end | |
| 36 | - | |
| 37 | - commits[0...n] | |
| 38 | - end | |
| 39 | - | |
| 40 | - def commits_with_refs(repo, n = 20) | |
| 41 | - commits = repo.branches.map { |ref| Commit.new(ref.commit, ref) } | |
| 42 | - | |
| 43 | - commits.sort! do |x, y| | |
| 44 | - y.committed_date <=> x.committed_date | |
| 45 | - end | |
| 46 | - | |
| 47 | - commits[0..n] | |
| 48 | - end | |
| 49 | - | |
| 50 | - def commits_since(repo, date) | |
| 51 | - commits = repo.heads.map do |h| | |
| 52 | - repo.log(h.name, nil, since: date).each { |c| Commit.new(c, h) } | |
| 53 | - end.flatten.uniq { |c| c.id } | |
| 54 | - | |
| 55 | - commits.sort! do |x, y| | |
| 56 | - y.committed_date <=> x.committed_date | |
| 57 | - end | |
| 58 | - | |
| 59 | - commits | |
| 60 | - end | |
| 61 | - | |
| 62 | - def commits(repo, ref, path = nil, limit = nil, offset = nil) | |
| 63 | - if path | |
| 64 | - repo.log(ref, path, max_count: limit, skip: offset) | |
| 65 | - elsif limit && offset | |
| 66 | - repo.commits(ref, limit, offset) | |
| 67 | - else | |
| 68 | - repo.commits(ref) | |
| 69 | - end.map{ |c| Commit.new(c) } | |
| 70 | - end | |
| 71 | - | |
| 72 | - def commits_between(repo, from, to) | |
| 73 | - repo.commits_between(from, to).map { |c| Commit.new(c) } | |
| 74 | - end | |
| 75 | - | |
| 76 | - def compare(project, from, to) | |
| 77 | - result = { | |
| 78 | - commits: [], | |
| 79 | - diffs: [], | |
| 80 | - commit: nil, | |
| 81 | - same: false | |
| 82 | - } | |
| 83 | - | |
| 84 | - return result unless from && to | |
| 85 | - | |
| 86 | - first = project.repository.commit(to.try(:strip)) | |
| 87 | - last = project.repository.commit(from.try(:strip)) | |
| 88 | - | |
| 89 | - if first && last | |
| 90 | - result[:same] = (first.id == last.id) | |
| 91 | - result[:commits] = project.repo.commits_between(last.id, first.id).map {|c| Commit.new(c)} | |
| 92 | - | |
| 93 | - # Dont load diff for 100+ commits | |
| 94 | - result[:diffs] = if result[:commits].size > 100 | |
| 95 | - [] | |
| 96 | - else | |
| 97 | - project.repo.diff(last.id, first.id) rescue [] | |
| 98 | - end | |
| 99 | - | |
| 100 | - result[:commit] = Commit.new(first) | |
| 101 | - end | |
| 102 | - | |
| 103 | - result | |
| 104 | - end | |
| 105 | - end | |
| 106 | - | |
| 107 | - def initialize(raw_commit, head = nil) | |
| 13 | + def initialize(raw_commit) | |
| 108 | 14 | raise "Nil as raw commit passed" unless raw_commit |
| 109 | 15 | |
| 110 | - @commit = raw_commit | |
| 111 | - @head = head | |
| 112 | - end | |
| 113 | - | |
| 114 | - def short_id(length = 10) | |
| 115 | - id.to_s[0..length] | |
| 116 | - end | |
| 117 | - | |
| 118 | - def safe_message | |
| 119 | - @safe_message ||= message | |
| 120 | - end | |
| 121 | - | |
| 122 | - def created_at | |
| 123 | - committed_date | |
| 124 | - end | |
| 125 | - | |
| 126 | - def author_email | |
| 127 | - author.email | |
| 128 | - end | |
| 129 | - | |
| 130 | - def author_name | |
| 131 | - author.name | |
| 132 | - end | |
| 133 | - | |
| 134 | - # Was this commit committed by a different person than the original author? | |
| 135 | - def different_committer? | |
| 136 | - author_name != committer_name || author_email != committer_email | |
| 137 | - end | |
| 138 | - | |
| 139 | - def committer_name | |
| 140 | - committer.name | |
| 141 | - end | |
| 142 | - | |
| 143 | - def committer_email | |
| 144 | - committer.email | |
| 145 | - end | |
| 146 | - | |
| 147 | - def prev_commit | |
| 148 | - @prev_commit ||= if parents.present? | |
| 149 | - Commit.new(parents.first) | |
| 150 | - else | |
| 151 | - nil | |
| 152 | - end | |
| 153 | - end | |
| 154 | - | |
| 155 | - def prev_commit_id | |
| 156 | - prev_commit.try :id | |
| 157 | - end | |
| 158 | - | |
| 159 | - # Shows the diff between the commit's parent and the commit. | |
| 160 | - # | |
| 161 | - # Cuts out the header and stats from #to_patch and returns only the diff. | |
| 162 | - def to_diff | |
| 163 | - # see Grit::Commit#show | |
| 164 | - patch = to_patch | |
| 165 | - | |
| 166 | - # discard lines before the diff | |
| 167 | - lines = patch.split("\n") | |
| 168 | - while !lines.first.start_with?("diff --git") do | |
| 169 | - lines.shift | |
| 170 | - end | |
| 171 | - lines.pop if lines.last =~ /^[\d.]+$/ # Git version | |
| 172 | - lines.pop if lines.last == "-- " # end of diff | |
| 173 | - lines.join("\n") | |
| 16 | + @raw = raw_commit | |
| 174 | 17 | end |
| 175 | 18 | |
| 176 | - def has_zero_stats? | |
| 177 | - stats.total.zero? | |
| 178 | - rescue | |
| 179 | - true | |
| 19 | + def method_missing(m, *args, &block) | |
| 20 | + @raw.send(m, *args, &block) | |
| 180 | 21 | end |
| 181 | 22 | end | ... | ... |
app/models/gollum_wiki.rb
| ... | ... | @@ -50,7 +50,7 @@ class GollumWiki |
| 50 | 50 | # Returns the last 30 Commit objects across the entire |
| 51 | 51 | # repository. |
| 52 | 52 | def recent_history |
| 53 | - Commit.fresh_commits(wiki.repo, 30) | |
| 53 | + Gitlab::Git::Commit.fresh_commits(wiki.repo, 30) | |
| 54 | 54 | end |
| 55 | 55 | |
| 56 | 56 | # Finds a page within the repository based on a tile | ... | ... |
app/models/merge_request.rb
| ... | ... | @@ -169,7 +169,7 @@ class MergeRequest < ActiveRecord::Base |
| 169 | 169 | end |
| 170 | 170 | |
| 171 | 171 | def unmerged_commits |
| 172 | - self.project.repo. | |
| 172 | + self.project.repository. | |
| 173 | 173 | commits_between(self.target_branch, self.source_branch). |
| 174 | 174 | map {|c| Commit.new(c)}. |
| 175 | 175 | sort_by(&:created_at). | ... | ... |
app/models/network/commit.rb
app/models/note.rb
| ... | ... | @@ -130,7 +130,7 @@ class Note < ActiveRecord::Base |
| 130 | 130 | # override to return commits, which are not active record |
| 131 | 131 | def noteable |
| 132 | 132 | if for_commit? |
| 133 | - project.repository.commit(commit_id) | |
| 133 | + Commit.new(project.repository.commit(commit_id)) | |
| 134 | 134 | else |
| 135 | 135 | super |
| 136 | 136 | end | ... | ... |
app/models/project.rb
| ... | ... | @@ -142,11 +142,11 @@ class Project < ActiveRecord::Base |
| 142 | 142 | |
| 143 | 143 | def repository |
| 144 | 144 | if path |
| 145 | - @repository ||= Repository.new(path_with_namespace, default_branch) | |
| 145 | + @repository ||= Gitlab::Git::Repository.new(path_with_namespace, default_branch) | |
| 146 | 146 | else |
| 147 | 147 | nil |
| 148 | 148 | end |
| 149 | - rescue Grit::NoSuchPathError | |
| 149 | + rescue Gitlab::Git::NoRepository | |
| 150 | 150 | nil |
| 151 | 151 | end |
| 152 | 152 | ... | ... |