Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
7af277f6
Commit
7af277f6
authored
Jul 29, 2016
by
Sean McGivern
Committed by
Fatih Acet
Aug 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-highlight conflict when rich_text is called
parent
d7721635
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
18 deletions
+28
-18
lib/gitlab/conflict/file.rb
lib/gitlab/conflict/file.rb
+5
-8
lib/gitlab/conflict/parser.rb
lib/gitlab/conflict/parser.rb
+3
-3
lib/gitlab/diff/line.rb
lib/gitlab/diff/line.rb
+9
-2
spec/lib/gitlab/conflict/file_spec.rb
spec/lib/gitlab/conflict/file_spec.rb
+11
-5
No files found.
lib/gitlab/conflict/file.rb
View file @
7af277f6
...
...
@@ -21,7 +21,8 @@ module Gitlab
def
lines
@lines
||=
Gitlab
::
Conflict
::
Parser
.
new
.
parse
(
merge_file_result
[
:data
],
our_path:
our_path
,
their_path:
their_path
)
their_path:
their_path
,
parent:
self
)
end
def
resolve!
(
resolution
,
index
:,
rugged
:)
...
...
@@ -57,27 +58,23 @@ module Gitlab
end
.
compact
end
def
highlighted_lines
return
@highlighted_lines
if
@highlighted_lines
def
highlight_lines!
their_highlight
=
Gitlab
::
Highlight
.
highlight_lines
(
repository
,
their_ref
,
their_path
)
our_highlight
=
Gitlab
::
Highlight
.
highlight_lines
(
repository
,
our_ref
,
our_path
)
@highlighted_lines
=
lines
.
map
do
|
line
|
line
=
line
.
dup
lines
.
each
do
|
line
|
if
line
.
type
==
'old'
line
.
rich_text
=
their_highlight
[
line
.
old_line
-
1
]
else
line
.
rich_text
=
our_highlight
[
line
.
new_line
-
1
]
end
line
end
end
def
sections
return
@sections
if
@sections
chunked_lines
=
highlighted_
lines
.
chunk
{
|
line
|
line
.
type
.
nil?
}
chunked_lines
=
lines
.
chunk
{
|
line
|
line
.
type
.
nil?
}
match_line
=
nil
@sections
=
chunked_lines
.
flat_map
.
with_index
do
|
(
no_conflict
,
lines
),
i
|
...
...
lib/gitlab/conflict/parser.rb
View file @
7af277f6
...
...
@@ -7,7 +7,7 @@ module Gitlab
class
MissingEndDelimiter
<
StandardError
end
def
parse
(
text
,
our_path
:,
their_path
:)
def
parse
(
text
,
our_path
:,
their_path
:
,
parent:
nil
)
return
[]
if
text
.
blank?
line_obj_index
=
0
...
...
@@ -36,9 +36,9 @@ module Gitlab
type
=
nil
elsif
line
[
0
]
==
'\\'
type
=
'nonewline'
lines
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
lines
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
,
parent:
parent
)
else
lines
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
)
lines
<<
Gitlab
::
Diff
::
Line
.
new
(
full_line
,
type
,
line_obj_index
,
line_old
,
line_new
,
parent:
parent
)
line_old
+=
1
if
type
!=
'new'
line_new
+=
1
if
type
!=
'old'
...
...
lib/gitlab/diff/line.rb
View file @
7af277f6
...
...
@@ -2,12 +2,13 @@ module Gitlab
module
Diff
class
Line
attr_reader
:type
,
:index
,
:old_pos
,
:new_pos
attr_writer
:rich_text
attr_accessor
:text
attr_accessor
:rich_text
def
initialize
(
text
,
type
,
index
,
old_pos
,
new_pos
)
def
initialize
(
text
,
type
,
index
,
old_pos
,
new_pos
,
parent:
nil
)
@text
,
@type
,
@index
=
text
,
type
,
index
@old_pos
,
@new_pos
=
old_pos
,
new_pos
@parent
=
parent
end
def
self
.
init_from_hash
(
hash
)
...
...
@@ -44,6 +45,12 @@ module Gitlab
type
==
'old'
end
def
rich_text
@parent
.
highlight_lines!
if
@parent
&&
!
@rich_text
@rich_text
end
def
meta?
type
==
'match'
||
type
==
'nonewline'
end
...
...
spec/lib/gitlab/conflict/file_spec.rb
View file @
7af277f6
...
...
@@ -63,17 +63,23 @@ describe Gitlab::Conflict::File, lib: true do
end
end
describe
'#highlight
ed_lines
'
do
describe
'#highlight
_lines!
'
do
def
html_to_text
(
html
)
CGI
.
unescapeHTML
(
ActionView
::
Base
.
full_sanitizer
.
sanitize
(
html
)).
delete
(
"
\n
"
)
end
it
'
returns lines with rich_text
'
do
expect
(
conflict_file
.
highlighted_lines
).
to
all
(
have_attributes
(
rich_text:
a_kind_of
(
String
)))
it
'
modifies the existing lines
'
do
expect
{
conflict_file
.
highlight_lines!
}.
to
change
{
conflict_file
.
lines
.
map
(
&
:instance_variables
)
}
end
it
'returns lines with rich_text matching the text content of the line'
do
conflict_file
.
highlighted_lines
.
each
do
|
line
|
it
'is called implicitly when rich_text is accessed on a line'
do
expect
(
conflict_file
).
to
receive
(
:highlight_lines!
).
once
.
and_call_original
conflict_file
.
lines
.
each
(
&
:rich_text
)
end
it
'sets the rich_text of the lines matching the text content'
do
conflict_file
.
lines
.
each
do
|
line
|
expect
(
line
.
text
).
to
eq
(
html_to_text
(
line
.
rich_text
))
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment