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
Jérome Perrin
gitlab-ce
Commits
8710739e
Commit
8710739e
authored
Oct 20, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correctly find last known blob for file deleted in MR.
parent
904c11ef
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
38 additions
and
19 deletions
+38
-19
app/controllers/projects/compare_controller.rb
app/controllers/projects/compare_controller.rb
+2
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+4
-1
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+2
-1
app/models/commit.rb
app/models/commit.rb
+8
-4
app/models/merge_request.rb
app/models/merge_request.rb
+13
-1
app/models/merge_request_diff.rb
app/models/merge_request_diff.rb
+4
-0
app/models/repository.rb
app/models/repository.rb
+1
-7
app/views/projects/diffs/_diffs.html.haml
app/views/projects/diffs/_diffs.html.haml
+2
-2
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+2
-2
No files found.
app/controllers/projects/compare_controller.rb
View file @
8710739e
...
...
@@ -17,9 +17,10 @@ class Projects::CompareController < Projects::ApplicationController
execute
(
@project
,
head_ref
,
@project
,
base_ref
)
if
compare_result
@commits
=
compare_result
.
commits
@commits
=
Commit
.
decorate
(
compare_result
.
commits
,
@project
)
@diffs
=
compare_result
.
diffs
@commit
=
@commits
.
last
@first_commit
=
@commits
.
first
@line_notes
=
[]
end
end
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
8710739e
...
...
@@ -56,6 +56,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def
diffs
@commit
=
@merge_request
.
last_commit
@first_commit
=
@merge_request
.
first_commit
@comments_allowed
=
@reply_allowed
=
true
@comments_target
=
{
noteable_type:
'MergeRequest'
,
...
...
@@ -89,7 +91,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@target_project
=
merge_request
.
target_project
@source_project
=
merge_request
.
source_project
@commits
=
@merge_request
.
compare_commits
@commit
=
@merge_request
.
compare_commits
.
last
@commit
=
@merge_request
.
last_commit
@first_commit
=
@merge_request
.
first_commit
@diffs
=
@merge_request
.
compare_diffs
@note_counts
=
Note
.
where
(
commit_id:
@commits
.
map
(
&
:id
)).
group
(
:commit_id
).
count
...
...
app/helpers/diff_helper.rb
View file @
8710739e
...
...
@@ -170,7 +170,8 @@ module DiffHelper
def
commit_for_diff
(
diff
)
if
diff
.
deleted_file
@merge_request
?
@merge_request
.
commits
.
last
:
@commit
.
parents
.
first
first_commit
=
@first_commit
||
@commit
first_commit
.
parent
else
@commit
end
...
...
app/models/commit.rb
View file @
8710739e
...
...
@@ -164,6 +164,14 @@ class Commit
@committer
||=
User
.
find_by_any_email
(
committer_email
)
end
def
parents
@parents
||=
parent_ids
.
map
{
|
id
|
project
.
commit
(
id
)
}
end
def
parent
@parent
||=
project
.
commit
(
self
.
parent_id
)
if
self
.
parent_id
end
def
notes
project
.
notes
.
for_commit_id
(
self
.
id
)
end
...
...
@@ -181,10 +189,6 @@ class Commit
@raw
.
short_id
(
7
)
end
def
parents
@parents
||=
Commit
.
decorate
(
super
,
project
)
end
def
ci_commit
project
.
ci_commit
(
sha
)
end
...
...
app/models/merge_request.rb
View file @
8710739e
...
...
@@ -40,7 +40,7 @@ class MergeRequest < ActiveRecord::Base
after_create
:create_merge_request_diff
after_update
:update_merge_request_diff
delegate
:commits
,
:diffs
,
:last_commit
,
:last_commit_short_sha
,
to: :merge_request_diff
,
prefix:
nil
delegate
:commits
,
:diffs
,
to: :merge_request_diff
,
prefix:
nil
# When this attribute is true some MR validation is ignored
# It allows us to close or modify broken merge requests
...
...
@@ -157,6 +157,18 @@ class MergeRequest < ActiveRecord::Base
reference
end
def
last_commit
merge_request_diff
?
merge_request_diff
.
last_commit
:
compare_commits
.
last
end
def
first_commit
merge_request_diff
?
merge_request_diff
.
first_commit
:
compare_commits
.
first
end
def
last_commit_short_sha
last_commit
.
short_id
end
def
validate_branches
if
target_project
==
source_project
&&
target_branch
==
source_branch
errors
.
add
:branch_conflict
,
"You can not use same project/branch for source and target"
...
...
app/models/merge_request_diff.rb
View file @
8710739e
...
...
@@ -55,6 +55,10 @@ class MergeRequestDiff < ActiveRecord::Base
commits
.
first
end
def
first_commit
commits
.
last
end
def
last_commit_short_sha
@last_commit_short_sha
||=
last_commit
.
short_id
end
...
...
app/models/repository.rb
View file @
8710739e
...
...
@@ -312,13 +312,7 @@ class Repository
end
def
blob_for_diff
(
commit
,
diff
)
file
=
blob_at
(
commit
.
id
,
diff
.
new_path
)
unless
file
file
=
prev_blob_for_diff
(
commit
,
diff
)
end
file
blob_at
(
commit
.
id
,
diff
.
file_path
)
end
def
prev_blob_for_diff
(
commit
,
diff
)
...
...
app/views/projects/diffs/_diffs.html.haml
View file @
8710739e
...
...
@@ -15,8 +15,8 @@
.files
-
diff_files
.
each_with_index
do
|
diff_file
,
index
|
-
diff_commit
=
commit_for_diff
(
diff_file
.
diff
)
-
blob
=
project
.
repository
.
blob_for_diff
(
diff_commit
,
diff_file
.
diff
)
-
diff_commit
=
commit_for_diff
(
diff_file
)
-
blob
=
project
.
repository
.
blob_for_diff
(
diff_commit
,
diff_file
)
-
next
unless
blob
=
render
'projects/diffs/file'
,
i:
index
,
project:
project
,
...
...
app/views/projects/diffs/_file.html.haml
View file @
8710739e
.diff-file
{
id:
"diff-#{i}"
,
data:
diff_file_html_data
(
project
,
diff_commit
,
diff_file
)}
.diff-header
{
id:
"file-path-#{hexdigest(diff_file.
new_path || diff_file.old
_path)}"
}
.diff-header
{
id:
"file-path-#{hexdigest(diff_file.
file
_path)}"
}
-
if
diff_file
.
diff
.
submodule?
%span
-
submodule_item
=
project
.
repository
.
blob_at
(
@commit
.
id
,
diff_file
.
file_path
)
...
...
@@ -38,7 +38,7 @@
-
else
=
render
"projects/diffs/text_file"
,
diff_file:
diff_file
,
index:
i
-
elsif
blob
.
image?
-
old_file
=
project
.
repository
.
prev_blob_for_diff
(
@
commit
,
diff_file
)
-
old_file
=
project
.
repository
.
prev_blob_for_diff
(
diff_
commit
,
diff_file
)
=
render
"projects/diffs/image"
,
diff_file:
diff_file
,
old_file:
old_file
,
file:
blob
,
index:
i
-
else
.nothing-here-block
No preview for this file type
...
...
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