Commit e0c64fac authored by Jeff Stubler's avatar Jeff Stubler

Refactor for style issues

parent 860e24cc
...@@ -10,8 +10,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -10,8 +10,7 @@ class Projects::BranchesController < Projects::ApplicationController
@branches = @repository.branches_sorted_by(@sort) @branches = @repository.branches_sorted_by(@sort)
@branches = Kaminari.paginate_array(@branches).page(params[:page]).per(PER_PAGE) @branches = Kaminari.paginate_array(@branches).page(params[:page]).per(PER_PAGE)
@max_commits = @branches.reduce(0) do @max_commits = @branches.reduce(0) do |memo, branch|
|memo, branch|
diverging_commit_counts = repository.diverging_commit_counts(branch) diverging_commit_counts = repository.diverging_commit_counts(branch)
[memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max [memo, diverging_commit_counts[:behind], diverging_commit_counts[:ahead]].max
end end
......
...@@ -148,8 +148,7 @@ class Repository ...@@ -148,8 +148,7 @@ class Repository
end end
def diverging_commit_counts(branch) def diverging_commit_counts(branch)
branch_cache_key = ('diverging_commit_counts_' + branch.name).to_sym cache.fetch(:"diverging_commit_counts_#{branch.name}") do
cache.fetch(branch_cache_key) do
number_commits_behind = commits_between(branch.name, root_ref).size number_commits_behind = commits_between(branch.name, root_ref).size
number_commits_ahead = commits_between(root_ref, branch.name).size number_commits_ahead = commits_between(root_ref, branch.name).size
...@@ -158,14 +157,13 @@ class Repository ...@@ -158,14 +157,13 @@ class Repository
end end
def cache_keys def cache_keys
%i(size branch_names tag_names commit_count readme %i(size branch_names tag_names commit_count
contribution_guide changelog license) readme version contribution_guide changelog license)
end end
def branch_cache_keys def branch_cache_keys
branches.map do branches.map do |branch|
|branch| :"diverging_commit_counts_#{branch.name}"
('diverging_commit_counts_' + branch.name).to_sym
end end
end end
...@@ -177,7 +175,7 @@ class Repository ...@@ -177,7 +175,7 @@ class Repository
end end
branches.each do |branch| 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) send(:diverging_commit_counts, branch)
end end
end end
...@@ -188,14 +186,12 @@ class Repository ...@@ -188,14 +186,12 @@ class Repository
cache.expire(key) cache.expire(key)
end end
branches.each do |branch| expire_branch_cache
cache.expire(('diverging_commit_counts_' + branch.name).to_sym)
end
end end
def expire_branch_cache def expire_branch_cache
branches.each do |branch| branches.each do |branch|
cache.expire(('diverging_commit_counts_' + branch.name).to_sym) cache.expire(:"diverging_commit_counts_#{branch.name}")
end end
end end
...@@ -206,8 +202,8 @@ class Repository ...@@ -206,8 +202,8 @@ class Repository
end end
branches.each do |branch| branches.each do |branch|
cache.expire(('diverging_commit_counts_' + branch.name).to_sym) cache.expire(:"diverging_commit_counts_#{branch.name}")
send(:diverging_commit_counts, branch) diverging_commit_counts(branch)
end end
end end
......
- commit = @repository.commit(branch.target) - commit = @repository.commit(branch.target)
- bar_graph_width_factor = @max_commits > 0 ? 100.0/@max_commits : 0 - bar_graph_width_factor = @max_commits > 0 ? 100.0/@max_commits : 0
- number_commits_behind = @repository.diverging_commit_counts(branch)[:behind] - diverging_commit_counts = @repository.diverging_commit_counts(branch)
- number_commits_ahead = @repository.diverging_commit_counts(branch)[:ahead] - number_commits_behind = diverging_commit_counts[:behind]
- number_commits_ahead = diverging_commit_counts[:ahead]
%li(class="js-branch-#{branch.name}") %li(class="js-branch-#{branch.name}")
%div %div
= link_to namespace_project_tree_path(@project.namespace, @project, branch.name) do = link_to namespace_project_tree_path(@project.namespace, @project, branch.name) do
...@@ -33,13 +34,13 @@ ...@@ -33,13 +34,13 @@
= icon("trash-o") = icon("trash-o")
- if branch.name != @repository.root_ref - 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 .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 %span.count.count-behind= number_commits_behind
.graph-separator .graph-separator
.graph-side .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 %span.count.count-ahead= number_commits_ahead
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment