Add graphs of commits ahead/behind default branch
This MR provides graphs showing the number of commits ahead/behind each branch is compared to the default branch to show how up to date branches are to each other. For each branch, a hash is cached that holds the commits ahead/behind (similar mechanism to other cached items but there is a key for each branch).
I do not quite know if this was the best approach. I tried a Sidekiq job but was having issues with it. I am open to implementation changes if needed.
One oddity from the current implementation: the graph scaling is based on the maximum number of commits displayed on each page, not across all branches of a project.
Review points:
- Implementation of caching with symbol for each branch
- Performance on large repositories (I had only a few second delay for loading branch pages on a repository with 374 branches and places with 4000+ commits not merged)
Affected by CSS:
- ./app/views/projects/branches/_branch.html.haml: .divergence-graph{ :title => "#{number_commits_ahead} commits ahead, #{number_commits_behind} commits behind #{@repository.root_ref}" }
- ./app/views/projects/branches/_branch.html.haml: .graph-side
- ./app/views/projects/branches/_branch.html.haml: .graph-side
- ./app/views/projects/branches/_branch.html.haml: .bar.bar-behind{ :style => "width: #{number_commits_behind * bar_graph_width_factor}%" }
- ./app/views/projects/branches/_branch.html.haml: .bar.bar-ahead{ :style => "width: #{number_commits_ahead * bar_graph_width_factor}%" }
- ./app/views/projects/branches/_branch.html.haml: .bar.bar-behind{ :style => "width: #{number_commits_behind * bar_graph_width_factor}%" }
- ./app/views/projects/branches/_branch.html.haml: .bar.bar-ahead{ :style => "width: #{number_commits_ahead * bar_graph_width_factor}%" }
- ./app/views/projects/branches/_branch.html.haml: %span.count.count-behind= number_commits_behind
- ./app/views/projects/branches/_branch.html.haml: %span.count.count-ahead= number_commits_ahead
- ./app/views/projects/branches/_branch.html.haml: %span.count.count-ahead= number_commits_ahead
- ./app/views/projects/branches/_branch.html.haml: %span.count.count-behind= number_commits_behind
- ./app/views/projects/branches/_branch.html.haml: .graph-separator
These should not be affected per SCSS nesting:
- ./app/views/layouts/nav/_admin.html.haml: %span.count= AbuseReport.count(:all)
- ./app/views/layouts/nav/_dashboard.html.haml: %span.count= current_user.assigned_issues.opened.count
- ./app/views/layouts/nav/_dashboard.html.haml: %span.count= current_user.assigned_merge_requests.opened.count
- ./app/views/layouts/nav/_group.html.haml: %span.count= Issue.opened.of_group(@group).count
- ./app/views/layouts/nav/_group.html.haml: %span.count= MergeRequest.opened.of_group(@group).count
- ./app/views/layouts/nav/_profile.html.haml: %span.count= current_user.emails.count + 1
- ./app/views/layouts/nav/_profile.html.haml: %span.count= current_user.keys.count
- ./app/views/layouts/nav/_project.html.haml: %span.count.builds_counter= @project.ci_builds.running_or_pending.count(:all)
- ./app/views/layouts/nav/_project.html.haml: %span.count.issue_counter= @project.issues.opened.count
- ./app/views/layouts/nav/_project.html.haml: %span.count.merge_counter= @project.merge_requests.opened.count
- ./app/views/projects/buttons/_fork.html.haml: %span.count
- ./app/views/projects/buttons/_fork.html.haml: %span.count
- ./app/views/projects/buttons/_star.html.haml: %span.count
- ./app/views/projects/buttons/_star.html.haml: %span.count
Relevant feature request: http://feedback.gitlab.com/forums/176466-general/suggestions/3461147-show-commits-behind-ahead-when-browsing-branches