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
cbdf372e
Commit
cbdf372e
authored
Oct 13, 2017
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented using an ivar, and added specs
parent
528f9cde
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
11 deletions
+78
-11
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+7
-2
app/views/projects/commit/branches.html.haml
app/views/projects/commit/branches.html.haml
+5
-5
spec/controllers/projects/commit_controller_spec.rb
spec/controllers/projects/commit_controller_spec.rb
+22
-4
spec/views/projects/commit/branches.html.haml_spec.rb
spec/views/projects/commit/branches.html.haml_spec.rb
+44
-0
No files found.
app/controllers/projects/commit_controller.rb
View file @
cbdf372e
...
...
@@ -16,6 +16,8 @@ class Projects::CommitController < Projects::ApplicationController
before_action
:define_note_vars
,
only:
[
:show
,
:diff_for_path
]
before_action
:authorize_edit_tree!
,
only:
[
:revert
,
:cherry_pick
]
BRANCH_SEARCH_LIMIT
=
1000
def
show
apply_diff_view_cookie!
...
...
@@ -59,8 +61,11 @@ class Projects::CommitController < Projects::ApplicationController
# branch_names_contains/tag_names_contains can take a long time when there are thousands of
# branches/tags - each `git branch --contains xxx` request can consume a cpu core.
# so only do the query when there are a manageable number of branches/tags
@branches
=
@project
.
repository
.
branch_count
>
1000
?
[
:limit_exceeded
]
:
@project
.
repository
.
branch_names_contains
(
commit
.
id
)
@tags
=
@project
.
repository
.
tag_count
>
1000
?
[
:limit_exceeded
]
:
@project
.
repository
.
tag_names_contains
(
commit
.
id
)
@branches_limit_exceeded
=
@project
.
repository
.
branch_count
>
BRANCH_SEARCH_LIMIT
@branches
=
@branches_limit_exceeded
?
[]
:
@project
.
repository
.
branch_names_contains
(
commit
.
id
)
@tags_limit_exceeded
=
@project
.
repository
.
tag_count
>
BRANCH_SEARCH_LIMIT
@tags
=
@tags_limit_exceeded
?
[]
:
@project
.
repository
.
tag_names_contains
(
commit
.
id
)
render
layout:
false
end
...
...
app/views/projects/commit/branches.html.haml
View file @
cbdf372e
-
if
@branches
.
any?
-
branch
=
commit_default_branch
(
@project
,
@branches
)
-
if
branch
==
:limit_exceeded
-
if
@branches
.
any?
||
@branches_limit_exceeded
-
if
@branches_limit_exceeded
=
commit_branch_link
(
'#'
,
_
(
'Too many branches to search'
))
-
else
-
branch
=
commit_default_branch
(
@project
,
@branches
)
=
commit_branch_link
(
project_ref_path
(
@project
,
branch
),
branch
)
-# `commit_default_branch` deletes the default branch from `@branches`,
-# so only render this if we have more branches or tags left
-
if
@branches
.
any?
||
@tags
.
any?
-
if
@branches
.
any?
||
@tags
.
any?
||
@tags_limit_exceeded
%span
=
link_to
"…"
,
"#"
,
class:
"js-details-expand label label-gray"
%span
.js-details-content.hide
=
commit_branches_links
(
@project
,
@branches
)
if
@branches
.
any?
-
if
@tags
.
first
==
:
limit_exceeded
-
if
@tags
_
limit_exceeded
=
commit_tag_link
(
'#'
,
_
(
'Too many tags to search'
))
-
elsif
@tags
.
any?
=
commit_tags_links
(
@project
,
@tags
)
spec/controllers/projects/commit_controller_spec.rb
View file @
cbdf372e
...
...
@@ -134,8 +134,8 @@ describe Projects::CommitController do
end
end
describe
"GET branches"
do
it
"contains branch and tags information"
do
describe
'GET branches'
do
it
'contains branch and tags information'
do
commit
=
project
.
commit
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
get
(
:branches
,
...
...
@@ -143,8 +143,26 @@ describe Projects::CommitController do
project_id:
project
,
id:
commit
.
id
)
expect
(
assigns
(
:branches
)).
to
include
(
"master"
,
"feature_conflict"
)
expect
(
assigns
(
:tags
)).
to
include
(
"v1.1.0"
)
expect
(
assigns
(
:branches
)).
to
include
(
'master'
,
'feature_conflict'
)
expect
(
assigns
(
:branches_limit_exceeded
)).
to
be_falsey
expect
(
assigns
(
:tags
)).
to
include
(
'v1.1.0'
)
expect
(
assigns
(
:tags_limit_exceeded
)).
to
be_falsey
end
it
'returns :limit_exceeded when number of branches/tags reach a threshhold'
do
commit
=
project
.
commit
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:branch_count
).
and_return
(
1001
)
allow_any_instance_of
(
Repository
).
to
receive
(
:tag_count
).
and_return
(
1001
)
get
(
:branches
,
namespace_id:
project
.
namespace
,
project_id:
project
,
id:
commit
.
id
)
expect
(
assigns
(
:branches
)).
to
eq
([])
expect
(
assigns
(
:branches_limit_exceeded
)).
to
be_truthy
expect
(
assigns
(
:tags
)).
to
eq
([])
expect
(
assigns
(
:tags_limit_exceeded
)).
to
be_truthy
end
end
...
...
spec/views/projects/commit/branches.html.haml_spec.rb
0 → 100644
View file @
cbdf372e
require
'spec_helper'
describe
'projects/commit/branches.html.haml'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
assign
(
:project
,
project
)
end
context
'branches and tags'
do
before
do
assign
(
:branches
,
[
'master'
,
'test-branch'
])
assign
(
:branches_limit_exceeded
,
false
)
assign
(
:tags
,
[
'tag1'
])
assign
(
:tags_limit_exceeded
,
false
)
render
end
it
'shows branch and tag links'
do
expect
(
rendered
).
to
have_selector
(
'.js-details-expand'
)
expect
(
rendered
).
to
have_link
(
'master'
)
expect
(
rendered
).
to
have_link
(
'test-branch'
)
expect
(
rendered
).
to
have_link
(
'tag1'
)
end
end
context
'throttled branches and tags'
do
before
do
assign
(
:branches
,
[])
assign
(
:branches_limit_exceeded
,
true
)
assign
(
:tags
,
[])
assign
(
:tags_limit_exceeded
,
true
)
render
end
it
'shows too many to search'
do
expect
(
rendered
).
to
have_selector
(
'.js-details-expand'
)
expect
(
rendered
).
to
have_link
(
'Too many branches to search'
,
href:
'#'
)
expect
(
rendered
).
to
have_link
(
'Too many tags to search'
,
href:
'#'
)
end
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