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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
9c45b726
Commit
9c45b726
authored
Jan 09, 2020
by
David Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Compare instead of Git::Compare to apply limits
Also, handles missing refs with 404
parent
c93c10ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
10 deletions
+38
-10
lib/api/entities.rb
lib/api/entities.rb
+8
-8
lib/api/repositories.rb
lib/api/repositories.rb
+7
-2
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+23
-0
No files found.
lib/api/entities.rb
View file @
9c45b726
...
...
@@ -1247,20 +1247,20 @@ module API
end
class
Compare
<
Grape
::
Entity
expose
:commit
,
using:
Entities
::
Commit
do
|
compare
,
options
|
::
Commit
.
decorate
(
compare
.
commits
,
nil
)
.
last
expose
:commit
,
using:
Entities
::
Commit
do
|
compare
,
_
|
compare
.
commits
.
last
end
expose
:commits
,
using:
Entities
::
Commit
do
|
compare
,
options
|
::
Commit
.
decorate
(
compare
.
commits
,
nil
)
expose
:commits
,
using:
Entities
::
Commit
do
|
compare
,
_
|
compare
.
commits
end
expose
:diffs
,
using:
Entities
::
Diff
do
|
compare
,
options
|
compare
.
diffs
(
limits:
false
)
.
to_a
expose
:diffs
,
using:
Entities
::
Diff
do
|
compare
,
_
|
compare
.
diffs
.
diffs
.
to_a
end
expose
:compare_timeout
do
|
compare
,
options
|
compare
.
diffs
.
overflow?
expose
:compare_timeout
do
|
compare
,
_
|
compare
.
diffs
.
diffs
.
overflow?
end
expose
:same
,
as: :compare_same_ref
...
...
lib/api/repositories.rb
View file @
9c45b726
...
...
@@ -103,8 +103,13 @@ module API
optional
:straight
,
type:
Boolean
,
desc:
'Comparison method, `true` for direct comparison between `from` and `to` (`from`..`to`), `false` to compare using merge base (`from`...`to`)'
,
default:
false
end
get
':id/repository/compare'
do
compare
=
Gitlab
::
Git
::
Compare
.
new
(
user_project
.
repository
.
raw_repository
,
params
[
:from
],
params
[
:to
],
straight:
params
[
:straight
])
present
compare
,
with:
Entities
::
Compare
compare
=
CompareService
.
new
(
user_project
,
params
[
:to
]).
execute
(
user_project
,
params
[
:from
],
straight:
params
[
:straight
])
if
compare
present
compare
,
with:
Entities
::
Compare
else
not_found!
(
"Ref"
)
end
end
desc
'Get repository contributors'
do
...
...
spec/requests/api/repositories_spec.rb
View file @
9c45b726
...
...
@@ -362,6 +362,29 @@ describe API::Repositories do
expect
(
json_response
[
'diffs'
]).
to
be_empty
expect
(
json_response
[
'compare_same_ref'
]).
to
be_truthy
end
it
"returns an empty string when the diff overflows"
do
stub_const
(
'Gitlab::Git::DiffCollection::DEFAULT_LIMITS'
,
{
max_files:
2
,
max_lines:
2
})
get
api
(
route
,
current_user
),
params:
{
from:
'master'
,
to:
'feature'
}
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_present
expect
(
json_response
[
'diffs'
]).
to
be_present
expect
(
json_response
[
'diffs'
].
first
[
'diff'
]).
to
be_empty
end
it
"returns a 404 when from ref is unknown"
do
get
api
(
route
,
current_user
),
params:
{
from:
'unknown_ref'
,
to:
'master'
}
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
it
"returns a 404 when to ref is unknown"
do
get
api
(
route
,
current_user
),
params:
{
from:
'master'
,
to:
'unknown_ref'
}
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
context
'when unauthenticated'
,
'and project is public'
do
...
...
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