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
Tatuya Kamada
gitlab-ce
Commits
23706716
Commit
23706716
authored
Sep 06, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now refactor all to work properly.
parent
13cfa49a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
111 deletions
+69
-111
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+43
-77
app/views/projects/commits/_parallel_view.html.haml
app/views/projects/commits/_parallel_view.html.haml
+26
-34
No files found.
app/helpers/commits_helper.rb
View file @
23706716
...
@@ -23,13 +23,55 @@ module CommitsHelper
...
@@ -23,13 +23,55 @@ module CommitsHelper
end
end
end
end
def
side
_diff_line
(
diff
,
index
)
def
parallel
_diff_line
(
diff
,
index
)
Gitlab
::
DiffParser
.
new
(
diff
.
diff
.
lines
.
to_a
,
diff
.
new_path
)
Gitlab
::
DiffParser
.
new
(
diff
.
diff
.
lines
.
to_a
,
diff
.
new_path
)
.
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
.
each
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
)
yield
(
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
)
end
end
end
end
def
parallel_diff
(
diff
,
index
)
lines
=
[]
skip_next
=
false
# Building array of lines
#
# [left_type, left_line_number, left_line_content, right_line_type, right_line_number, right_line_content]
#
parallel_diff_line
(
diff
,
index
)
do
|
full_line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
line
=
[
type
,
line_old
,
full_line
,
next_type
,
line_new
]
if
type
==
'match'
||
type
.
nil?
# line in the right panel is the same as in the left one
line
=
[
type
,
line_old
,
full_line
,
type
,
line_new
,
full_line
]
lines
.
push
(
line
)
elsif
type
==
'old'
if
next_type
==
'new'
# Left side has text removed, right side has text added
line
.
push
(
next_line
)
lines
.
push
(
line
)
skip_next
=
true
elsif
next_type
==
'old'
||
next_type
.
nil?
# Left side has text removed, right side doesn't have any change
line
.
pop
# remove the newline
line
.
push
(
nil
)
# no line number on the right panel
line
.
push
(
" "
)
# empty line on the right panel
lines
.
push
(
line
)
end
elsif
type
==
'new'
if
skip_next
# Change has been already included in previous line so no need to do it again
skip_next
=
false
next
else
# Change is only on the right side, left side has no change
line
=
[
nil
,
nil
,
" "
,
type
,
line_new
,
full_line
]
lines
.
push
(
line
)
end
end
end
lines
end
def
each_diff_line_near
(
diff
,
index
,
expected_line_code
)
def
each_diff_line_near
(
diff
,
index
,
expected_line_code
)
max_number_of_lines
=
16
max_number_of_lines
=
16
...
@@ -112,82 +154,6 @@ module CommitsHelper
...
@@ -112,82 +154,6 @@ module CommitsHelper
branches
.
sort
.
map
{
|
branch
|
link_to
(
branch
,
project_tree_path
(
project
,
branch
))
}.
join
(
", "
).
html_safe
branches
.
sort
.
map
{
|
branch
|
link_to
(
branch
,
project_tree_path
(
project
,
branch
))
}.
join
(
", "
).
html_safe
end
end
def
parallel_diff_lines
(
project
,
commit
,
diff
,
file
)
old_file
=
project
.
repository
.
blob_at
(
commit
.
parent_id
,
diff
.
old_path
)
if
commit
.
parent_id
deleted_lines
=
{}
added_lines
=
{}
each_diff_line
(
diff
,
0
)
do
|
line
,
type
,
line_code
,
line_new
,
line_old
|
if
type
==
"old"
deleted_lines
[
line_old
]
=
{
line_code:
line_code
,
type:
type
,
line:
line
}
elsif
type
==
"new"
added_lines
[
line_new
]
=
{
line_code:
line_code
,
type:
type
,
line:
line
}
end
end
max_length
=
old_file
?
[
old_file
.
loc
,
file
.
loc
].
max
:
file
.
loc
offset1
=
0
offset2
=
0
old_lines
=
[]
new_lines
=
[]
max_length
.
times
do
|
line_index
|
line_index1
=
line_index
-
offset1
line_index2
=
line_index
-
offset2
deleted_line
=
deleted_lines
[
line_index1
+
1
]
added_line
=
added_lines
[
line_index2
+
1
]
old_line
=
old_file
.
lines
[
line_index1
]
if
old_file
new_line
=
file
.
lines
[
line_index2
]
if
deleted_line
&&
added_line
elsif
deleted_line
new_line
=
nil
offset2
+=
1
elsif
added_line
old_line
=
nil
offset1
+=
1
end
old_lines
[
line_index
]
=
DiffLine
.
new
new_lines
[
line_index
]
=
DiffLine
.
new
# old
if
line_index
==
0
&&
diff
.
new_file
old_lines
[
line_index
].
type
=
:file_created
old_lines
[
line_index
].
content
=
'File was created'
elsif
deleted_line
old_lines
[
line_index
].
type
=
:deleted
old_lines
[
line_index
].
content
=
old_line
old_lines
[
line_index
].
num
=
line_index1
+
1
old_lines
[
line_index
].
code
=
deleted_line
[
:line_code
]
elsif
old_line
old_lines
[
line_index
].
type
=
:no_change
old_lines
[
line_index
].
content
=
old_line
old_lines
[
line_index
].
num
=
line_index1
+
1
else
old_lines
[
line_index
].
type
=
:added
end
# new
if
line_index
==
0
&&
diff
.
deleted_file
new_lines
[
line_index
].
type
=
:file_deleted
new_lines
[
line_index
].
content
=
"File was deleted"
elsif
added_line
new_lines
[
line_index
].
type
=
:added
new_lines
[
line_index
].
num
=
line_index2
+
1
new_lines
[
line_index
].
content
=
new_line
new_lines
[
line_index
].
code
=
added_line
[
:line_code
]
elsif
new_line
new_lines
[
line_index
].
type
=
:no_change
new_lines
[
line_index
].
num
=
line_index2
+
1
new_lines
[
line_index
].
content
=
new_line
else
new_lines
[
line_index
].
type
=
:deleted
end
end
return
old_lines
,
new_lines
end
def
link_to_browse_code
(
project
,
commit
)
def
link_to_browse_code
(
project
,
commit
)
if
current_controller?
(
:projects
,
:commits
)
if
current_controller?
(
:projects
,
:commits
)
if
@repo
.
blob_at
(
commit
.
id
,
@path
)
if
@repo
.
blob_at
(
commit
.
id
,
@path
)
...
...
app/views/projects/commits/_parallel_view.html.haml
View file @
23706716
/ Side-by-side diff view
/ Side-by-side diff view
%div
.text-file
%div
.text-file
%table
%table
-
side_diff_line
(
diff
,
index
)
do
|
line
,
type
,
line_code
,
line_new
,
line_old
,
raw_line
,
next_type
,
next_line
|
-
parallel_diff
(
diff
,
index
).
each
do
|
line
|
%tr
.line_holder.parallel
{
id:
line_code
}
-
type_left
=
line
[
0
]
-
if
type
==
"match"
-
line_number_left
=
line
[
1
]
=
render
"projects/commits/diffs/match_line_parallel"
,
{
line:
line
,
-
line_content_left
=
line
[
2
]
line_old:
line_old
,
line_new:
line_new
,
bottom:
false
}
-
type_right
=
line
[
3
]
-
else
-
line_number_right
=
line
[
4
]
-
if
diff
.
new_file
-
line_content_right
=
line
[
5
]
%tr
.line_holder.parallel
-
if
type_left
==
'match'
=
render
"projects/commits/diffs/match_line_parallel"
,
{
line:
line_content_left
,
line_old:
line_number_left
,
line_new:
line_number_right
,
bottom:
false
}
-
elsif
type_left
==
'old'
%td
.old_line
{
class:
"old"
}
=
link_to
raw
(
line_number_left
)
%td
.line_content
{
class:
"parallel noteable_line old"
}=
raw
line_content_left
%td
.new_line
{
class:
"#{type_right == 'new' ? 'new' : nil}"
,
data:
{
linenumber:
line_number_right
}}
=
link_to
raw
(
line_number_right
)
%td
.line_content.parallel
{
class:
"noteable_line #{type_right == 'new' ? 'new' : nil}"
}=
raw
line_content_right
-
elsif
type_left
.
nil?
%td
.old_line
%td
.old_line
%td
.line_content.parallel
=
raw
" "
=
link_to
raw
(
line_number_left
)
-
else
%td
.line_content
{
class:
"parallel noteable_line"
}=
raw
line_content_left
-
next
if
type
==
'new'
%td
.new_line
{
class:
"#{type_right == 'new' ? 'new' : nil}"
,
data:
{
linenumber:
line_number_right
}}
%td
.old_line
{
class:
"#{type}"
}
=
link_to
raw
(
line_number_right
)
=
link_to
raw
(
line_old
),
"#
#{
line_code
}
"
,
id:
line_code
%td
.line_content.parallel
{
class:
"noteable_line #{type_right == 'new' ? 'new' : nil}"
}=
raw
line_content_right
-
if
type
==
'old'
%td
.line_content
{
class:
"parallel noteable_line old #{line_code}"
,
"line_code"
=>
line_code
}=
raw
line
-
else
%td
.line_content.parallel
=
raw
line
-
if
diff
.
deleted_file
%td
.new_line
{
data:
{
linenumber:
line_new
}}
%td
.line_content.parallel
=
raw
" "
-
else
-
if
type
==
'old'
%td
.new_line
{
class:
"#{next_type == 'new' ? 'new' : nil}"
,
data:
{
linenumber:
line_new
}}
-
if
next_type
==
'new'
-
content
=
next_line
=
link_to
raw
(
line_new
)
,
"#
#{
line_code
}
"
,
id:
line_code
%td
.line_content.parallel
{
class:
"noteable_line new #{line_code}"
,
"line_code"
=>
line_code
}=
raw
content
-
else
-
content
=
" "
%td
.line_content.parallel
{
class:
"noteable_line #{line_code}"
,
"line_code"
=>
line_code
}=
raw
content
-
else
%td
.new_line
{
class:
"#{type}"
,
data:
{
linenumber:
line_new
}}
=
link_to
raw
(
line_new
)
,
"#
#{
line_code
}
"
,
id:
line_code
%td
.line_content.parallel
{
class:
"#{type}"
}=
raw
line
-
if
diff
.
diff
.
blank?
&&
diff_file_mode_changed?
(
diff
)
-
if
diff
.
diff
.
blank?
&&
diff_file_mode_changed?
(
diff
)
.file-mode-changed
.file-mode-changed
...
...
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