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
Boxiang Sun
gitlab-ce
Commits
e0c64fac
Commit
e0c64fac
authored
Nov 11, 2015
by
Jeff Stubler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor for style issues
parent
860e24cc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
21 deletions
+17
-21
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+1
-2
app/models/repository.rb
app/models/repository.rb
+10
-14
app/views/projects/branches/_branch.html.haml
app/views/projects/branches/_branch.html.haml
+6
-5
No files found.
app/controllers/projects/branches_controller.rb
View file @
e0c64fac
...
...
@@ -10,8 +10,7 @@ class Projects::BranchesController < Projects::ApplicationController
@branches
=
@repository
.
branches_sorted_by
(
@sort
)
@branches
=
Kaminari
.
paginate_array
(
@branches
).
page
(
params
[
:page
]).
per
(
PER_PAGE
)
@max_commits
=
@branches
.
reduce
(
0
)
do
|
memo
,
branch
|
@max_commits
=
@branches
.
reduce
(
0
)
do
|
memo
,
branch
|
diverging_commit_counts
=
repository
.
diverging_commit_counts
(
branch
)
[
memo
,
diverging_commit_counts
[
:behind
],
diverging_commit_counts
[
:ahead
]].
max
end
...
...
app/models/repository.rb
View file @
e0c64fac
...
...
@@ -148,8 +148,7 @@ class Repository
end
def
diverging_commit_counts
(
branch
)
branch_cache_key
=
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
cache
.
fetch
(
branch_cache_key
)
do
cache
.
fetch
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
do
number_commits_behind
=
commits_between
(
branch
.
name
,
root_ref
).
size
number_commits_ahead
=
commits_between
(
root_ref
,
branch
.
name
).
size
...
...
@@ -158,14 +157,13 @@ class Repository
end
def
cache_keys
%i(size branch_names tag_names commit_count
readme
contribution_guide changelog license)
%i(size branch_names tag_names commit_count
readme version
contribution_guide changelog license)
end
def
branch_cache_keys
branches
.
map
do
|
branch
|
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
branches
.
map
do
|
branch
|
:"diverging_commit_counts_
#{
branch
.
name
}
"
end
end
...
...
@@ -177,7 +175,7 @@ class Repository
end
branches
.
each
do
|
branch
|
unless
cache
.
exist?
(
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
unless
cache
.
exist?
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
send
(
:diverging_commit_counts
,
branch
)
end
end
...
...
@@ -188,14 +186,12 @@ class Repository
cache
.
expire
(
key
)
end
branches
.
each
do
|
branch
|
cache
.
expire
((
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
end
expire_branch_cache
end
def
expire_branch_cache
branches
.
each
do
|
branch
|
cache
.
expire
(
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
cache
.
expire
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
end
end
...
...
@@ -206,8 +202,8 @@ class Repository
end
branches
.
each
do
|
branch
|
cache
.
expire
(
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
send
(
:diverging_commit_counts
,
branch
)
cache
.
expire
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
diverging_commit_counts
(
branch
)
end
end
...
...
app/views/projects/branches/_branch.html.haml
View file @
e0c64fac
-
commit
=
@repository
.
commit
(
branch
.
target
)
-
bar_graph_width_factor
=
@max_commits
>
0
?
100.0
/
@max_commits
:
0
-
number_commits_behind
=
@repository
.
diverging_commit_counts
(
branch
)[
:behind
]
-
number_commits_ahead
=
@repository
.
diverging_commit_counts
(
branch
)[
:ahead
]
-
diverging_commit_counts
=
@repository
.
diverging_commit_counts
(
branch
)
-
number_commits_behind
=
diverging_commit_counts
[
:behind
]
-
number_commits_ahead
=
diverging_commit_counts
[
:ahead
]
%li
(
class=
"js-branch-#{branch.name}"
)
%div
=
link_to
namespace_project_tree_path
(
@project
.
namespace
,
@project
,
branch
.
name
)
do
...
...
@@ -33,13 +34,13 @@
=
icon
(
"trash-o"
)
-
if
branch
.
name
!=
@repository
.
root_ref
.divergence-graph
{
:title
=>
"#{number_commits_ahead} commits ahead, #{number_commits_behind} commits behind #{@repository.root_ref}"
}
.divergence-graph
{
title:
"#{number_commits_ahead} commits ahead, #{number_commits_behind} commits behind #{@repository.root_ref}"
}
.graph-side
.bar.bar-behind
{
:style
=>
"width: #{number_commits_behind * bar_graph_width_factor}%"
}
.bar.bar-behind
{
style:
"width: #{number_commits_behind * bar_graph_width_factor}%"
}
%span
.count.count-behind
=
number_commits_behind
.graph-separator
.graph-side
.bar.bar-ahead
{
:style
=>
"width: #{number_commits_ahead * bar_graph_width_factor}%"
}
.bar.bar-ahead
{
style:
"width: #{number_commits_ahead * bar_graph_width_factor}%"
}
%span
.count.count-ahead
=
number_commits_ahead
...
...
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