summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-08 12:22:09 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-08 12:22:09 +0300
commit4537623d12fb7372262267be5d6ec3b41f3f476c (patch)
treeccd0494b1112c388114e032f994505a2344123be /app/models
parentc7e490ebd5ab69fe043cd39145bd6ef3850a6921 (diff)
parent1a83fea711961844adc7ddb21ce007143fefc144 (diff)
downloadgitlab-ce-4537623d12fb7372262267be5d6ec3b41f3f476c.tar.gz
Merge branch 'master' into karlhungus-mr-on-fork
Conflicts: app/contexts/filter_context.rb app/contexts/search_context.rb app/models/merge_request.rb app/models/note.rb app/views/shared/_merge_requests.html.haml spec/controllers/commit_controller_spec.rb spec/services/notification_service_spec.rb
Diffstat (limited to 'app/models')
-rw-r--r--app/models/deprecated/user_team.rb2
-rw-r--r--app/models/deprecated/user_team_project_relationship.rb2
-rw-r--r--app/models/deprecated/user_team_user_relationship.rb2
-rw-r--r--app/models/merge_request.rb11
-rw-r--r--app/models/note.rb52
-rw-r--r--app/models/repository.rb20
6 files changed, 72 insertions, 17 deletions
diff --git a/app/models/deprecated/user_team.rb b/app/models/deprecated/user_team.rb
index a036cedc4c7..822884297d4 100644
--- a/app/models/deprecated/user_team.rb
+++ b/app/models/deprecated/user_team.rb
@@ -1,3 +1,5 @@
+# Will be removed in 6.1 with tables
+#
# == Schema Information
#
# Table name: user_teams
diff --git a/app/models/deprecated/user_team_project_relationship.rb b/app/models/deprecated/user_team_project_relationship.rb
index 991510be936..e93223f3e24 100644
--- a/app/models/deprecated/user_team_project_relationship.rb
+++ b/app/models/deprecated/user_team_project_relationship.rb
@@ -1,3 +1,5 @@
+# Will be removed in 6.1 with tables
+#
# == Schema Information
#
# Table name: user_team_project_relationships
diff --git a/app/models/deprecated/user_team_user_relationship.rb b/app/models/deprecated/user_team_user_relationship.rb
index 1f7e2625f5f..ae4c789994a 100644
--- a/app/models/deprecated/user_team_user_relationship.rb
+++ b/app/models/deprecated/user_team_user_relationship.rb
@@ -1,3 +1,5 @@
+# Will be removed in 6.1 with tables
+#
# == Schema Information
#
# Table name: user_team_user_relationships
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 703032649b9..b3c7aa39cf8 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -149,11 +149,12 @@ class MergeRequest < ActiveRecord::Base
end
def unmerged_diffs
- if for_fork?
- diffs = Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite
- else
- diffs = target_project.repository.diffs_between(source_branch, target_branch)
- end
+ diffs = if for_fork?
+ Gitlab::Satellite::MergeAction.new(author, self).diffs_between_satellite
+ else
+ Gitlab::Git::Diff.between(project.repository, source_branch, target_branch)
+ end
+
diffs ||= []
diffs
end
diff --git a/app/models/note.rb b/app/models/note.rb
index fecee950713..c0bf79237c1 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -50,6 +50,9 @@ class Note < ActiveRecord::Base
scope :inc_author_project, ->{ includes(:project, :author) }
scope :inc_author, ->{ includes(:author) }
+ serialize :st_diff
+ before_create :set_diff, if: ->(n) { n.line_code.present? }
+
def self.create_status_change_note(noteable, project, author, status)
create({
noteable: noteable,
@@ -67,28 +70,61 @@ class Note < ActiveRecord::Base
nil
end
- def diff
- if noteable.diffs.present?
- noteable.diffs.select do |d|
- if d.new_path
- Digest::SHA1.hexdigest(d.new_path) == diff_file_index
- end
- end.first
+ def find_diff
+ return nil unless noteable && noteable.diffs.present?
+
+ @diff ||= noteable.diffs.find do |d|
+ Digest::SHA1.hexdigest(d.new_path) == diff_file_index if d.new_path
end
end
+ def set_diff
+ # First lets find notes with same diff
+ # before iterating over all mr diffs
+ diff = Note.where(noteable_id: self.noteable_id, noteable_type: self.noteable_type, line_code: self.line_code).last.try(:diff)
+ diff ||= find_diff
+
+ self.st_diff = diff.to_hash if diff
+ end
+
+ def diff
+ @diff ||= Gitlab::Git::Diff.new(st_diff) if st_diff.respond_to?(:map)
+ end
+
+ def active?
+ # TODO: determine if discussion is outdated
+ # according to recent MR diff or not
+ true
+ end
+
def diff_file_index
line_code.split('_')[0]
end
def diff_file_name
- diff.new_path
+ diff.new_path if diff
+ end
+
+ def diff_old_line
+ line_code.split('_')[1].to_i
end
def diff_new_line
line_code.split('_')[2].to_i
end
+ def diff_line
+ return @diff_line if @diff_line
+
+ if diff
+ Gitlab::DiffParser.new(diff).each do |full_line, type, line_code, line_new, line_old|
+ @diff_line = full_line if line_code == self.line_code
+ end
+ end
+
+ @diff_line
+ end
+
def discussion_id
@discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 588cabfbae0..a2fd91bbec1 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -18,19 +18,25 @@ class Repository
end
def commit(id = nil)
- commit = raw_repository.commit(id)
+ commit = Gitlab::Git::Commit.find(raw_repository, id)
commit = Commit.new(commit) if commit
commit
end
def commits(ref, path = nil, limit = nil, offset = nil)
- commits = raw_repository.commits(ref, path, limit, offset)
+ commits = Gitlab::Git::Commit.where(
+ repo: raw_repository,
+ ref: ref,
+ path: path,
+ limit: limit,
+ offset: offset,
+ )
commits = Commit.decorate(commits) if commits.present?
commits
end
- def commits_between(target, source)
- commits = raw_repository.commits_between(target, source)
+ def commits_between(from, to)
+ commits = Gitlab::Git::Commit.between(raw_repository, from, to)
commits = Commit.decorate(commits) if commits.present?
commits
end
@@ -43,6 +49,12 @@ class Repository
tags.find { |tag| tag.name == name }
end
+ def recent_branches(limit = 20)
+ branches.sort do |a, b|
+ a.commit.committed_date <=> b.commit.committed_date
+ end[0..limit]
+ end
+
def add_branch(branch_name, ref)
Rails.cache.delete(cache_key(:branch_names))