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
Léo-Paul Géneau
gitlab-ce
Commits
6f3501fe
Commit
6f3501fe
authored
Aug 01, 2016
by
Sean McGivern
Committed by
Fatih Acet
Aug 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix match line headers at start / end of file
parent
f3cf40b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
16 deletions
+33
-16
lib/gitlab/conflict/file.rb
lib/gitlab/conflict/file.rb
+33
-16
No files found.
lib/gitlab/conflict/file.rb
View file @
6f3501fe
...
...
@@ -77,6 +77,10 @@ module Gitlab
def
sections
return
@sections
if
@sections
candidate_match_headers
=
lines
.
map
do
|
line
|
"
#{
line
.
text
}
"
if
line
.
text
.
match
(
/\A[A-Za-z$_]/
)
&&
line
.
type
.
nil?
end
chunked_lines
=
lines
.
chunk
{
|
line
|
line
.
type
.
nil?
}
last_candidate_match_header
=
nil
match_line_header
=
nil
...
...
@@ -85,40 +89,41 @@ module Gitlab
@sections
=
chunked_lines
.
flat_map
.
with_index
do
|
(
no_conflict
,
lines
),
i
|
section
=
nil
lines
.
each
do
|
line
|
last_candidate_match_header
=
"
#{
line
.
text
}
"
if
line
.
text
.
match
(
/\A[A-Za-z$_]/
)
end
if
no_conflict
conflict_before
=
i
>
0
conflict_after
=
chunked_lines
.
peek
if
conflict_before
&&
conflict_after
if
lines
.
length
>
CONTEXT_LINES
*
2
head_lines
=
lines
.
first
(
CONTEXT_LINES
)
tail_lines
=
lines
.
last
(
CONTEXT_LINES
)
first_tail_line
=
tail_lines
.
first
match_line_header
=
last_candidate_match_header
match_line
=
Gitlab
::
Diff
::
Line
.
new
(
''
,
'match'
,
first_tail_line
.
index
,
first_tail_line
.
old_pos
,
first_tail_line
.
new_pos
)
update_match_line_text
(
match_line
,
head_lines
.
last
,
candidate_match_headers
)
match_line
=
create_match_line
(
tail_lines
.
first
)
update_match_line_text
(
match_line
,
tail_lines
.
last
,
candidate_match_headers
)
section
=
[
{
conflict:
false
,
lines:
lines
.
first
(
CONTEXT_LINES
)
},
{
conflict:
false
,
lines:
head_lines
},
{
conflict:
false
,
lines:
tail_lines
.
unshift
(
match_line
)
}
]
end
elsif
conflict_after
lines
=
lines
.
last
(
CONTEXT_LINES
)
tail_lines
=
lines
.
last
(
CONTEXT_LINES
)
if
lines
.
length
>
CONTEXT_LINES
match_line
=
create_match_line
(
tail_lines
.
first
)
tail_lines
.
unshift
(
match_line
)
end
lines
=
tail_lines
elsif
conflict_before
lines
=
lines
.
first
(
CONTEXT_LINES
)
end
end
if
match_line
&&
!
section
match_line
.
text
=
"@@ -
#{
match_line
.
old_pos
}
,
#{
lines
.
last
.
old_pos
}
+
#{
match_line
.
new_pos
}
,
#{
lines
.
last
.
new_pos
}
@@
#{
match_line_header
}
"
end
update_match_line_text
(
match_line
,
lines
.
last
,
candidate_match_headers
)
unless
section
section
||=
{
conflict:
!
no_conflict
,
lines:
lines
}
section
[
:id
]
=
line_code
(
lines
.
first
)
unless
no_conflict
...
...
@@ -130,6 +135,18 @@ module Gitlab
Gitlab
::
Diff
::
LineCode
.
generate
(
our_path
,
line
.
new_pos
,
line
.
old_pos
)
end
def
create_match_line
(
line
)
Gitlab
::
Diff
::
Line
.
new
(
''
,
'match'
,
line
.
index
,
line
.
old_pos
,
line
.
new_pos
)
end
def
update_match_line_text
(
match_line
,
line
,
headers
)
return
unless
match_line
header
=
headers
.
first
(
line
.
index
).
compact
.
last
match_line
.
text
=
"@@ -
#{
match_line
.
old_pos
}
,
#{
line
.
old_pos
}
+
#{
match_line
.
new_pos
}
,
#{
line
.
new_pos
}
@@
#{
header
}
"
end
def
as_json
(
opts
=
nil
)
{
old_path:
their_path
,
...
...
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