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
577f2fb4
Commit
577f2fb4
authored
Jan 20, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save and use actual diff base commit for MR diff highlighting
parent
26f7d023
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
75 additions
and
32 deletions
+75
-32
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+2
-2
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+6
-2
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+1
-2
app/models/merge_request.rb
app/models/merge_request.rb
+12
-3
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+9
-0
db/migrate/20160120172143_add_base_commit_sha_to_merge_request_diffs.rb
...60120172143_add_base_commit_sha_to_merge_request_diffs.rb
+5
-0
db/schema.rb
db/schema.rb
+15
-14
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+10
-2
lib/gitlab/diff/highlight.rb
lib/gitlab/diff/highlight.rb
+8
-1
lib/gitlab/diff/inline_diff_marker.rb
lib/gitlab/diff/inline_diff_marker.rb
+7
-6
No files found.
app/controllers/projects/compare_controller.rb
View file @
577f2fb4
...
@@ -21,8 +21,8 @@ class Projects::CompareController < Projects::ApplicationController
...
@@ -21,8 +21,8 @@ class Projects::CompareController < Projects::ApplicationController
@commits
=
Commit
.
decorate
(
compare_result
.
commits
,
@project
)
@commits
=
Commit
.
decorate
(
compare_result
.
commits
,
@project
)
@diffs
=
compare_result
.
diffs
@diffs
=
compare_result
.
diffs
@commit
=
@project
.
commit
(
head_ref
)
@commit
=
@project
.
commit
(
head_ref
)
@
first
_commit
=
@project
.
commit
(
base_ref
)
@
base
_commit
=
@project
.
commit
(
base_ref
)
@diff_refs
=
[
@
first
_commit
,
@commit
]
@diff_refs
=
[
@
base
_commit
,
@commit
]
@line_notes
=
[]
@line_notes
=
[]
end
end
end
end
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
577f2fb4
...
@@ -58,7 +58,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -58,7 +58,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
diffs
def
diffs
@commit
=
@merge_request
.
last_commit
@commit
=
@merge_request
.
last_commit
@first_commit
=
@merge_request
.
first_commit
@base_commit
=
@merge_request
.
diff_base_commit
# MRs created before 8.4 don't have a diff_base_commit,
# but we need it for the "View file @ ..." link by deleted files
@base_commit
||=
@merge_request
.
first_commit
.
parent
||
@merge_request
.
first_commit
@comments_allowed
=
@reply_allowed
=
true
@comments_allowed
=
@reply_allowed
=
true
@comments_target
=
{
@comments_target
=
{
...
@@ -102,7 +106,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
...
@@ -102,7 +106,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@source_project
=
merge_request
.
source_project
@source_project
=
merge_request
.
source_project
@commits
=
@merge_request
.
compare_commits
.
reverse
@commits
=
@merge_request
.
compare_commits
.
reverse
@commit
=
@merge_request
.
last_commit
@commit
=
@merge_request
.
last_commit
@
first_commit
=
@merge_request
.
first
_commit
@
base_commit
=
@merge_request
.
diff_base
_commit
@diffs
=
@merge_request
.
compare_diffs
@diffs
=
@merge_request
.
compare_diffs
@ci_commit
=
@merge_request
.
ci_commit
@ci_commit
=
@merge_request
.
ci_commit
...
...
app/helpers/diff_helper.rb
View file @
577f2fb4
...
@@ -102,8 +102,7 @@ module DiffHelper
...
@@ -102,8 +102,7 @@ module DiffHelper
def
commit_for_diff
(
diff
)
def
commit_for_diff
(
diff
)
if
diff
.
deleted_file
if
diff
.
deleted_file
first_commit
=
@first_commit
||
@commit
@base_commit
||
@commit
.
parent
||
@commit
first_commit
.
parent
||
@first_commit
else
else
@commit
@commit
end
end
...
...
app/models/merge_request.rb
View file @
577f2fb4
...
@@ -180,6 +180,14 @@ class MergeRequest < ActiveRecord::Base
...
@@ -180,6 +180,14 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff
?
merge_request_diff
.
first_commit
:
compare_commits
.
first
merge_request_diff
?
merge_request_diff
.
first_commit
:
compare_commits
.
first
end
end
def
diff_base_commit
if
merge_request_diff
merge_request_diff
.
base_commit
else
self
.
target_project
.
commit
(
self
.
target_branch
)
end
end
def
last_commit_short_sha
def
last_commit_short_sha
last_commit
.
short_id
last_commit
.
short_id
end
end
...
@@ -477,8 +485,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -477,8 +485,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
target_sha
def
target_sha
@target_sha
||=
target_project
.
@target_sha
||=
target_project
.
repository
.
commit
(
target_branch
).
sha
repository
.
commit
(
target_branch
).
sha
end
end
def
source_sha
def
source_sha
...
@@ -519,6 +526,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -519,6 +526,8 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diff_refs
def
diff_refs
[
first_commit
.
parent
||
first_commit
,
last_commit
]
return
nil
unless
diff_base_commit
[
diff_base_commit
,
last_commit
]
end
end
end
end
app/models/merge_request_diff.rb
View file @
577f2fb4
...
@@ -73,6 +73,12 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -73,6 +73,12 @@ class MergeRequestDiff < ActiveRecord::Base
commits
.
last
commits
.
last
end
end
def
base_commit
return
nil
unless
self
.
base_commit_sha
merge_request
.
target_project
.
commit
(
self
.
base_commit_sha
)
end
def
last_commit_short_sha
def
last_commit_short_sha
@last_commit_short_sha
||=
last_commit
.
short_id
@last_commit_short_sha
||=
last_commit
.
short_id
end
end
...
@@ -156,6 +162,9 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -156,6 +162,9 @@ class MergeRequestDiff < ActiveRecord::Base
end
end
self
.
st_diffs
=
new_diffs
self
.
st_diffs
=
new_diffs
self
.
base_commit_sha
=
merge_request
.
target_project
.
commit
(
target_branch
).
try
(
:sha
)
self
.
save
self
.
save
end
end
...
...
db/migrate/20160120172143_add_base_commit_sha_to_merge_request_diffs.rb
0 → 100644
View file @
577f2fb4
class
AddBaseCommitShaToMergeRequestDiffs
<
ActiveRecord
::
Migration
def
change
add_column
:merge_request_diffs
,
:base_commit_sha
,
:string
end
end
db/schema.rb
View file @
577f2fb4
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201601
19145451
)
do
ActiveRecord
::
Schema
.
define
(
version:
201601
20172143
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -490,6 +490,7 @@ ActiveRecord::Schema.define(version: 20160119145451) do
...
@@ -490,6 +490,7 @@ ActiveRecord::Schema.define(version: 20160119145451) do
t
.
integer
"merge_request_id"
,
null:
false
t
.
integer
"merge_request_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"updated_at"
t
.
string
"base_commit_sha"
end
end
add_index
"merge_request_diffs"
,
[
"merge_request_id"
],
name:
"index_merge_request_diffs_on_merge_request_id"
,
unique:
true
,
using: :btree
add_index
"merge_request_diffs"
,
[
"merge_request_id"
],
name:
"index_merge_request_diffs_on_merge_request_id"
,
unique:
true
,
using: :btree
...
...
lib/gitlab/diff/file.rb
View file @
577f2fb4
module
Gitlab
module
Gitlab
module
Diff
module
Diff
class
File
class
File
attr_reader
:diff
,
:
new_ref
,
:old_ref
attr_reader
:diff
,
:
diff_refs
delegate
:new_file
,
:deleted_file
,
:renamed_file
,
delegate
:new_file
,
:deleted_file
,
:renamed_file
,
:old_path
,
:new_path
,
to: :diff
,
prefix:
false
:old_path
,
:new_path
,
to: :diff
,
prefix:
false
def
initialize
(
diff
,
diff_refs
)
def
initialize
(
diff
,
diff_refs
)
@diff
=
diff
@diff
=
diff
@old_ref
,
@new_ref
=
diff_refs
@diff_refs
=
diff_refs
end
def
old_ref
diff_refs
[
0
]
if
diff_refs
end
def
new_ref
diff_refs
[
1
]
if
diff_refs
end
end
# Array of Gitlab::DIff::Line objects
# Array of Gitlab::DIff::Line objects
...
...
lib/gitlab/diff/highlight.rb
View file @
577f2fb4
...
@@ -31,6 +31,8 @@ module Gitlab
...
@@ -31,6 +31,8 @@ module Gitlab
private
private
def
highlight_line
(
diff_line
,
index
)
def
highlight_line
(
diff_line
,
index
)
return
html_escape
(
diff_line
.
text
)
unless
diff_file
.
diff_refs
line_prefix
=
diff_line
.
text
.
match
(
/\A([+-])/
)
?
$1
:
' '
line_prefix
=
diff_line
.
text
.
match
(
/\A([+-])/
)
?
$1
:
' '
case
diff_line
.
type
case
diff_line
.
type
...
@@ -42,7 +44,7 @@ module Gitlab
...
@@ -42,7 +44,7 @@ module Gitlab
# Only update text if line is found. This will prevent
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
# issues with submodules given the line only exists in diff content.
rich_line
?
line_prefix
+
rich_line
:
diff_line
.
text
rich_line
?
line_prefix
+
rich_line
:
html_escape
(
diff_line
.
text
)
end
end
def
inline_diffs
def
inline_diffs
...
@@ -63,6 +65,11 @@ module Gitlab
...
@@ -63,6 +65,11 @@ module Gitlab
[
ref
.
project
.
repository
,
ref
.
id
,
path
]
[
ref
.
project
.
repository
,
ref
.
id
,
path
]
end
end
def
html_escape
(
str
)
replacements
=
{
'&'
=>
'&'
,
'>'
=>
'>'
,
'<'
=>
'<'
,
'"'
=>
'"'
,
"'"
=>
'''
}
str
.
gsub
(
/[&"'><]/
,
replacements
)
end
end
end
end
end
end
end
lib/gitlab/diff/inline_diff_marker.rb
View file @
577f2fb4
...
@@ -9,18 +9,19 @@ module Gitlab
...
@@ -9,18 +9,19 @@ module Gitlab
end
end
def
mark
(
line_inline_diffs
)
def
mark
(
line_inline_diffs
)
offset
=
0
marker_ranges
=
[]
line_inline_diffs
.
each
do
|
inline_diff_range
|
line_inline_diffs
.
each
do
|
inline_diff_range
|
# Map the inline-diff range based on the raw line to character positions in the rich line
# Map the inline-diff range based on the raw line to character positions in the rich line
inline_diff_positions
=
position_mapping
[
inline_diff_range
].
flatten
inline_diff_positions
=
position_mapping
[
inline_diff_range
].
flatten
# Turn the array of character positions into ranges
# Turn the array of character positions into ranges
marker_ranges
=
collapse_ranges
(
inline_diff_positions
)
marker_ranges
.
concat
(
collapse_ranges
(
inline_diff_positions
))
end
offset
=
0
# Mark each range
# Mark each range
marker_ranges
.
each
do
|
range
|
marker_ranges
.
each
do
|
range
|
offset
=
insert_around_range
(
rich_line
,
range
,
"<span class='idiff'>"
,
"</span>"
,
offset
)
offset
=
insert_around_range
(
rich_line
,
range
,
"<span class='idiff'>"
,
"</span>"
,
offset
)
end
end
end
rich_line
rich_line
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