Skip to content

Commit b3b9817

Browse files
committed
Merge branch 'osw-revert-comment-in-any-diff-line' into 'master'
Revert "Merge branch 'osw-comment-on-any-line-on-diffs' into 'master'" See merge request gitlab-org/gitlab-ce!22891
2 parents 32c4d77 + 198402b commit b3b9817

26 files changed

+89
-1234
lines changed

app/assets/javascripts/diffs/components/diff_line_gutter_content.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export default {
5555
required: false,
5656
default: false,
5757
},
58+
isContextLine: {
59+
type: Boolean,
60+
required: false,
61+
default: false,
62+
},
5863
isHover: {
5964
type: Boolean,
6065
required: false,
@@ -76,6 +81,7 @@ export default {
7681
this.showCommentButton &&
7782
this.isHover &&
7883
!this.isMatchLine &&
84+
!this.isContextLine &&
7985
!this.isMetaLine &&
8086
!this.hasDiscussions
8187
);

app/assets/javascripts/diffs/components/diff_table_cell.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mapGetters } from 'vuex';
33
import DiffLineGutterContent from './diff_line_gutter_content.vue';
44
import {
55
MATCH_LINE_TYPE,
6+
CONTEXT_LINE_TYPE,
67
EMPTY_CELL_TYPE,
78
OLD_LINE_TYPE,
89
OLD_NO_NEW_LINE_TYPE,
@@ -70,6 +71,9 @@ export default {
7071
isMatchLine() {
7172
return this.line.type === MATCH_LINE_TYPE;
7273
},
74+
isContextLine() {
75+
return this.line.type === CONTEXT_LINE_TYPE;
76+
},
7377
isMetaLine() {
7478
const { type } = this.line;
7579
@@ -84,7 +88,11 @@ export default {
8488
[type]: type,
8589
[LINE_UNFOLD_CLASS_NAME]: this.isMatchLine,
8690
[LINE_HOVER_CLASS_NAME]:
87-
this.isLoggedIn && this.isHover && !this.isMatchLine && !this.isMetaLine,
91+
this.isLoggedIn &&
92+
this.isHover &&
93+
!this.isMatchLine &&
94+
!this.isContextLine &&
95+
!this.isMetaLine,
8896
};
8997
},
9098
lineNumber() {

app/assets/javascripts/diffs/components/inline_diff_table_row.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import DiffTableCell from './diff_table_cell.vue';
44
import {
55
NEW_LINE_TYPE,
66
OLD_LINE_TYPE,
7+
CONTEXT_LINE_TYPE,
8+
CONTEXT_LINE_CLASS_NAME,
79
PARALLEL_DIFF_VIEW_TYPE,
810
LINE_POSITION_LEFT,
911
LINE_POSITION_RIGHT,
@@ -39,9 +41,13 @@ export default {
3941
},
4042
computed: {
4143
...mapGetters('diffs', ['isInlineView']),
44+
isContextLine() {
45+
return this.line.type === CONTEXT_LINE_TYPE;
46+
},
4247
classNameMap() {
4348
return {
4449
[this.line.type]: this.line.type,
50+
[CONTEXT_LINE_CLASS_NAME]: this.isContextLine,
4551
[PARALLEL_DIFF_VIEW_TYPE]: this.isParallelView,
4652
};
4753
},

app/assets/javascripts/diffs/components/parallel_diff_table_row.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import DiffTableCell from './diff_table_cell.vue';
55
import {
66
NEW_LINE_TYPE,
77
OLD_LINE_TYPE,
8+
CONTEXT_LINE_TYPE,
9+
CONTEXT_LINE_CLASS_NAME,
810
OLD_NO_NEW_LINE_TYPE,
911
PARALLEL_DIFF_VIEW_TYPE,
1012
NEW_NO_NEW_LINE_TYPE,
@@ -41,8 +43,12 @@ export default {
4143
};
4244
},
4345
computed: {
46+
isContextLine() {
47+
return this.line.left && this.line.left.type === CONTEXT_LINE_TYPE;
48+
},
4449
classNameMap() {
4550
return {
51+
[CONTEXT_LINE_CLASS_NAME]: this.isContextLine,
4652
[PARALLEL_DIFF_VIEW_TYPE]: true,
4753
};
4854
},

app/assets/javascripts/diffs/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export const PARALLEL_DIFF_VIEW_TYPE = 'parallel';
33
export const MATCH_LINE_TYPE = 'match';
44
export const OLD_NO_NEW_LINE_TYPE = 'old-nonewline';
55
export const NEW_NO_NEW_LINE_TYPE = 'new-nonewline';
6+
export const CONTEXT_LINE_TYPE = 'context';
67
export const EMPTY_CELL_TYPE = 'empty-cell';
78
export const COMMENT_FORM_TYPE = 'commentForm';
89
export const DIFF_NOTE_TYPE = 'DiffNote';
@@ -21,6 +22,7 @@ export const LINE_SIDE_RIGHT = 'right-side';
2122
export const DIFF_VIEW_COOKIE_NAME = 'diff_view';
2223
export const LINE_HOVER_CLASS_NAME = 'is-over';
2324
export const LINE_UNFOLD_CLASS_NAME = 'unfold js-unfold';
25+
export const CONTEXT_LINE_CLASS_NAME = 'diff-expanded';
2426

2527
export const UNFOLD_COUNT = 20;
2628
export const COUNT_OF_AVATARS_IN_GUTTER = 3;

app/assets/javascripts/diffs/store/mutations.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ export default {
6565
const { highlightedDiffLines, parallelDiffLines } = diffFile;
6666

6767
removeMatchLine(diffFile, lineNumbers, bottom);
68-
69-
const lines = addLineReferences(contextLines, lineNumbers, bottom).map(line => ({
70-
...line,
71-
lineCode: line.lineCode || `${fileHash}_${line.oldLine}_${line.newLine}`,
72-
discussions: line.discussions || [],
73-
}));
74-
68+
const lines = addLineReferences(contextLines, lineNumbers, bottom);
7569
addContextLines({
7670
inlineLines: highlightedDiffLines,
7771
parallelLines: parallelDiffLines,

app/controllers/projects/blob_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def render_diff_lines
122122
@lines.map! do |line|
123123
# These are marked as context lines but are loaded from blobs.
124124
# We also have context lines loaded from diffs in other places.
125-
diff_line = Gitlab::Diff::Line.new(line, nil, nil, nil, nil)
125+
diff_line = Gitlab::Diff::Line.new(line, 'context', nil, nil, nil)
126126
diff_line.rich_text = line
127127
diff_line
128128
end

app/controllers/projects/merge_requests/diffs_controller.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ def diff_for_path
2222

2323
def render_diffs
2424
@environment = @merge_request.environments_for(current_user).last
25-
notes_grouped_by_path = @notes.group_by { |note| note.position.file_path }
26-
27-
@diffs.diff_files.each do |diff_file|
28-
notes = notes_grouped_by_path.fetch(diff_file.file_path, [])
29-
notes.each { |note| diff_file.unfold_diff_lines(note.position) }
30-
end
3125

3226
@diffs.write_cache
3327

app/models/diff_note.rb

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ def created_at_diff?(diff_refs)
6666
self.original_position.diff_refs == diff_refs
6767
end
6868

69-
def discussion_first_note?
70-
self == discussion.first_note
71-
end
72-
7369
private
7470

7571
def enqueue_diff_file_creation_job
@@ -82,33 +78,26 @@ def enqueue_diff_file_creation_job
8278
end
8379

8480
def should_create_diff_file?
85-
on_text? && note_diff_file.nil? && discussion_first_note?
81+
on_text? && note_diff_file.nil? && self == discussion.first_note
8682
end
8783

8884
def fetch_diff_file
89-
file =
90-
if note_diff_file
91-
diff = Gitlab::Git::Diff.new(note_diff_file.to_hash)
92-
Gitlab::Diff::File.new(diff,
93-
repository: project.repository,
94-
diff_refs: original_position.diff_refs)
95-
elsif created_at_diff?(noteable.diff_refs)
96-
# We're able to use the already persisted diffs (Postgres) if we're
97-
# presenting a "current version" of the MR discussion diff.
98-
# So no need to make an extra Gitaly diff request for it.
99-
# As an extra benefit, the returned `diff_file` already
100-
# has `highlighted_diff_lines` data set from Redis on
101-
# `Diff::FileCollection::MergeRequestDiff`.
102-
noteable.diffs(original_position.diff_options).diff_files.first
103-
else
104-
original_position.diff_file(self.project.repository)
105-
end
106-
107-
# Since persisted diff files already have its content "unfolded"
108-
# there's no need to make it pass through the unfolding process.
109-
file&.unfold_diff_lines(position) unless note_diff_file
110-
111-
file
85+
if note_diff_file
86+
diff = Gitlab::Git::Diff.new(note_diff_file.to_hash)
87+
Gitlab::Diff::File.new(diff,
88+
repository: project.repository,
89+
diff_refs: original_position.diff_refs)
90+
elsif created_at_diff?(noteable.diff_refs)
91+
# We're able to use the already persisted diffs (Postgres) if we're
92+
# presenting a "current version" of the MR discussion diff.
93+
# So no need to make an extra Gitaly diff request for it.
94+
# As an extra benefit, the returned `diff_file` already
95+
# has `highlighted_diff_lines` data set from Redis on
96+
# `Diff::FileCollection::MergeRequestDiff`.
97+
noteable.diffs(original_position.diff_options).diff_files.first
98+
else
99+
original_position.diff_file(self.project.repository)
100+
end
112101
end
113102

114103
def supported?

app/services/merge_requests/reload_diffs_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def update_diff_discussion_positions(old_diff_refs)
2929

3030
# rubocop: disable CodeReuse/ActiveRecord
3131
def clear_cache(new_diff)
32+
# Executing the iteration we cache highlighted diffs for each diff file of
33+
# MergeRequestDiff.
34+
cacheable_collection(new_diff).write_cache
35+
3236
# Remove cache for all diffs on this MR. Do not use the association on the
3337
# model, as that will interfere with other actions happening when
3438
# reloading the diff.

app/services/notes/base_service.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/services/notes/create_service.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Notes
4-
class CreateService < ::Notes::BaseService
4+
class CreateService < ::BaseService
55
def execute
66
merge_request_diff_head_sha = params.delete(:merge_request_diff_head_sha)
77

@@ -35,7 +35,6 @@ def execute
3535

3636
if !only_commands && note.save
3737
todo_service.new_note(note, current_user)
38-
clear_noteable_diffs_cache(note)
3938
end
4039

4140
if command_params.present?

app/services/notes/destroy_service.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# frozen_string_literal: true
22

33
module Notes
4-
class DestroyService < ::Notes::BaseService
4+
class DestroyService < BaseService
55
def execute(note)
66
TodoService.new.destroy_target(note) do |note|
77
note.destroy
88
end
9-
10-
clear_noteable_diffs_cache(note)
119
end
1210
end
1311
end

changelogs/unreleased/osw-comment-on-any-line-on-diffs.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/gitlab/diff/file.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def initialize(diff, repository:, diff_refs: nil, fallback_diff_refs: nil, stats
2626
@repository = repository
2727
@diff_refs = diff_refs
2828
@fallback_diff_refs = fallback_diff_refs
29-
@unfolded = false
3029

3130
# Ensure items are collected in the the batch
3231
new_blob_lazy
@@ -136,24 +135,6 @@ def diff_lines
136135
Gitlab::Diff::Parser.new.parse(raw_diff.each_line, diff_file: self).to_a
137136
end
138137

139-
# Changes diff_lines according to the given position. That is,
140-
# it checks whether the position requires blob lines into the diff
141-
# in order to be presented.
142-
def unfold_diff_lines(position)
143-
return unless position
144-
145-
unfolder = Gitlab::Diff::LinesUnfolder.new(self, position)
146-
147-
if unfolder.unfold_required?
148-
@diff_lines = unfolder.unfolded_diff_lines
149-
@unfolded = true
150-
end
151-
end
152-
153-
def unfolded?
154-
@unfolded
155-
end
156-
157138
def highlighted_diff_lines
158139
@highlighted_diff_lines ||=
159140
Gitlab::Diff::Highlight.new(self, repository: self.repository).highlight

lib/gitlab/diff/line.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module Diff
33
class Line
44
SERIALIZE_KEYS = %i(line_code rich_text text type index old_pos new_pos).freeze
55

6-
attr_reader :line_code, :type, :old_pos, :new_pos
6+
attr_reader :line_code, :type, :index, :old_pos, :new_pos
77
attr_writer :rich_text
8-
attr_accessor :text, :index
8+
attr_accessor :text
99

1010
def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil, rich_text: nil)
1111
@text, @type, @index = text, type, index
@@ -19,14 +19,7 @@ def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code:
1919
end
2020

2121
def self.init_from_hash(hash)
22-
new(hash[:text],
23-
hash[:type],
24-
hash[:index],
25-
hash[:old_pos],
26-
hash[:new_pos],
27-
parent_file: hash[:parent_file],
28-
line_code: hash[:line_code],
29-
rich_text: hash[:rich_text])
22+
new(hash[:text], hash[:type], hash[:index], hash[:old_pos], hash[:new_pos], line_code: hash[:line_code], rich_text: hash[:rich_text])
3023
end
3124

3225
def to_hash

0 commit comments

Comments
 (0)