diff options
author | Rubén Dávila <rdavila84@gmail.com> | 2016-01-15 00:38:37 +0300 |
---|---|---|
committer | Rubén Dávila <rdavila84@gmail.com> | 2016-01-15 00:47:55 +0300 |
commit | 6b9c730e91962a6d6343bcb7fc4dc75c99b41bde (patch) | |
tree | b9f7cafa96b131b6039e858e2c2503011551cfd6 /lib | |
parent | 70bc322415b33a4789067b81387d30f1411c9091 (diff) |
More refactoring from last code review. #3945
* Use commit objects instead of IDs when generating diffs
* Use proper references when generating MR's source and target
* Update broken specs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/file.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/diff/highlight.rb | 17 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index c1a6e16da5a..a6a7fc8ff4c 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -1,14 +1,13 @@ module Gitlab module Diff class File - attr_reader :diff, :repository, :new_ref, :old_ref + attr_reader :diff, :new_ref, :old_ref delegate :new_file, :deleted_file, :renamed_file, :old_path, :new_path, to: :diff, prefix: false - def initialize(diff, diff_refs, repository) + def initialize(diff, diff_refs) @diff = diff - @repository = repository @old_ref, @new_ref = diff_refs end diff --git a/lib/gitlab/diff/highlight.rb b/lib/gitlab/diff/highlight.rb index e21f496102d..fb79a2a69de 100644 --- a/lib/gitlab/diff/highlight.rb +++ b/lib/gitlab/diff/highlight.rb @@ -3,8 +3,7 @@ module Gitlab class Highlight attr_reader :diff_file - delegate :repository, :old_path, :new_path, :old_ref, :new_ref, - to: :diff_file, prefix: :diff + delegate :old_path, :new_path, :old_ref, :new_ref, to: :diff_file, prefix: :diff def initialize(diff_file) @diff_file = diff_file @@ -141,11 +140,11 @@ module Gitlab end def old_lines - @old_lines ||= Gitlab::Highlight.highlight_lines(diff_repository, diff_old_ref, diff_old_path) + @old_lines ||= self.class.process_file(*processing_args(:old)) end def new_lines - @new_lines ||= Gitlab::Highlight.highlight_lines(diff_repository, diff_new_ref, diff_new_path) + @new_lines ||= self.class.process_file(*processing_args(:new)) end def longest_common_suffix(a, b) @@ -200,6 +199,16 @@ module Gitlab offset end + + private + + def processing_args(version) + ref = send("diff_#{version}_ref") + path = send("diff_#{version}_path") + + [ref.project.repository, ref.id, path] + end + end end end |