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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
Hide 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
@commits
=
Commit
.
decorate
(
compare_result
.
commits
,
@project
)
@diffs
=
compare_result
.
diffs
@commit
=
@project
.
commit
(
head_ref
)
@
first
_commit
=
@project
.
commit
(
base_ref
)
@diff_refs
=
[
@
first
_commit
,
@commit
]
@
base
_commit
=
@project
.
commit
(
base_ref
)
@diff_refs
=
[
@
base
_commit
,
@commit
]
@line_notes
=
[]
end
end
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
577f2fb4
...
...
@@ -58,7 +58,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
diffs
@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_target
=
{
...
...
@@ -102,7 +106,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@source_project
=
merge_request
.
source_project
@commits
=
@merge_request
.
compare_commits
.
reverse
@commit
=
@merge_request
.
last_commit
@
first_commit
=
@merge_request
.
first
_commit
@
base_commit
=
@merge_request
.
diff_base
_commit
@diffs
=
@merge_request
.
compare_diffs
@ci_commit
=
@merge_request
.
ci_commit
...
...
app/helpers/diff_helper.rb
View file @
577f2fb4
...
...
@@ -102,8 +102,7 @@ module DiffHelper
def
commit_for_diff
(
diff
)
if
diff
.
deleted_file
first_commit
=
@first_commit
||
@commit
first_commit
.
parent
||
@first_commit
@base_commit
||
@commit
.
parent
||
@commit
else
@commit
end
...
...
app/models/merge_request.rb
View file @
577f2fb4
...
...
@@ -180,6 +180,14 @@ class MergeRequest < ActiveRecord::Base
merge_request_diff
?
merge_request_diff
.
first_commit
:
compare_commits
.
first
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
last_commit
.
short_id
end
...
...
@@ -477,8 +485,7 @@ class MergeRequest < ActiveRecord::Base
end
def
target_sha
@target_sha
||=
target_project
.
repository
.
commit
(
target_branch
).
sha
@target_sha
||=
target_project
.
repository
.
commit
(
target_branch
).
sha
end
def
source_sha
...
...
@@ -519,6 +526,8 @@ class MergeRequest < ActiveRecord::Base
end
def
diff_refs
[
first_commit
.
parent
||
first_commit
,
last_commit
]
return
nil
unless
diff_base_commit
[
diff_base_commit
,
last_commit
]
end
end
app/models/merge_request_diff.rb
View file @
577f2fb4
...
...
@@ -73,6 +73,12 @@ class MergeRequestDiff < ActiveRecord::Base
commits
.
last
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
@last_commit_short_sha
||=
last_commit
.
short_id
end
...
...
@@ -156,6 +162,9 @@ class MergeRequestDiff < ActiveRecord::Base
end
self
.
st_diffs
=
new_diffs
self
.
base_commit_sha
=
merge_request
.
target_project
.
commit
(
target_branch
).
try
(
:sha
)
self
.
save
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 @@
#
# 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
enable_extension
"plpgsql"
...
...
@@ -490,6 +490,7 @@ ActiveRecord::Schema.define(version: 20160119145451) do
t
.
integer
"merge_request_id"
,
null:
false
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
string
"base_commit_sha"
end
add_index
"merge_request_diffs"
,
[
"merge_request_id"
],
name:
"index_merge_request_diffs_on_merge_request_id"
,
unique:
true
,
using: :btree
...
...
@@ -725,19 +726,19 @@ ActiveRecord::Schema.define(version: 20160119145451) do
t
.
string
"type"
t
.
string
"title"
t
.
integer
"project_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
boolean
"active"
,
null:
false
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
boolean
"active"
,
null:
false
t
.
text
"properties"
t
.
boolean
"template"
,
default:
false
t
.
boolean
"push_events"
,
default:
true
t
.
boolean
"issues_events"
,
default:
true
t
.
boolean
"merge_requests_events"
,
default:
true
t
.
boolean
"tag_push_events"
,
default:
true
t
.
boolean
"note_events"
,
default:
true
,
null:
false
t
.
boolean
"build_events"
,
default:
false
,
null:
false
t
.
string
"category"
,
default:
"common"
,
null:
false
t
.
boolean
"default"
,
default:
false
t
.
boolean
"template"
,
default:
false
t
.
boolean
"push_events"
,
default:
true
t
.
boolean
"issues_events"
,
default:
true
t
.
boolean
"merge_requests_events"
,
default:
true
t
.
boolean
"tag_push_events"
,
default:
true
t
.
boolean
"note_events"
,
default:
true
,
null:
false
t
.
boolean
"build_events"
,
default:
false
,
null:
false
t
.
string
"category"
,
default:
"common"
,
null:
false
t
.
boolean
"default"
,
default:
false
end
add_index
"services"
,
[
"category"
],
name:
"index_services_on_category"
,
using: :btree
...
...
@@ -854,7 +855,7 @@ ActiveRecord::Schema.define(version: 20160119145451) do
t
.
boolean
"hide_project_limit"
,
default:
false
t
.
string
"unlock_token"
t
.
datetime
"otp_grace_period_started_at"
t
.
boolean
"ldap_email"
,
default:
false
,
null:
false
t
.
boolean
"ldap_email"
,
default:
false
,
null:
false
end
add_index
"users"
,
[
"admin"
],
name:
"index_users_on_admin"
,
using: :btree
...
...
lib/gitlab/diff/file.rb
View file @
577f2fb4
module
Gitlab
module
Diff
class
File
attr_reader
:diff
,
:
new_ref
,
:old_ref
attr_reader
:diff
,
:
diff_refs
delegate
:new_file
,
:deleted_file
,
:renamed_file
,
:old_path
,
:new_path
,
to: :diff
,
prefix:
false
def
initialize
(
diff
,
diff_refs
)
@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
# Array of Gitlab::DIff::Line objects
...
...
lib/gitlab/diff/highlight.rb
View file @
577f2fb4
...
...
@@ -31,6 +31,8 @@ module Gitlab
private
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
:
' '
case
diff_line
.
type
...
...
@@ -42,7 +44,7 @@ module Gitlab
# Only update text if line is found. This will prevent
# 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
def
inline_diffs
...
...
@@ -63,6 +65,11 @@ module Gitlab
[
ref
.
project
.
repository
,
ref
.
id
,
path
]
end
def
html_escape
(
str
)
replacements
=
{
'&'
=>
'&'
,
'>'
=>
'>'
,
'<'
=>
'<'
,
'"'
=>
'"'
,
"'"
=>
'''
}
str
.
gsub
(
/[&"'><]/
,
replacements
)
end
end
end
end
lib/gitlab/diff/inline_diff_marker.rb
View file @
577f2fb4
...
...
@@ -9,17 +9,18 @@ module Gitlab
end
def
mark
(
line_inline_diffs
)
offset
=
0
marker_ranges
=
[]
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
inline_diff_positions
=
position_mapping
[
inline_diff_range
].
flatten
# Turn the array of character positions into ranges
marker_ranges
=
collapse_ranges
(
inline_diff_positions
)
marker_ranges
.
concat
(
collapse_ranges
(
inline_diff_positions
))
end
# Mark each range
marker_ranges
.
each
do
|
range
|
offset
=
insert_around_range
(
rich_line
,
range
,
"<span class='idiff'>"
,
"</span>"
,
offset
)
end
offset
=
0
# Mark each range
marker_ranges
.
each
do
|
range
|
offset
=
insert_around_range
(
rich_line
,
range
,
"<span class='idiff'>"
,
"</span>"
,
offset
)
end
rich_line
...
...
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