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
Jérome Perrin
gitlab-ce
Commits
c843722d
Commit
c843722d
authored
Jul 20, 2015
by
Jeff Stubler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add graphs showing commits ahead and behind default to branches page
parent
8f75200d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
122 additions
and
2 deletions
+122
-2
CHANGELOG
CHANGELOG
+1
-0
app/assets/stylesheets/pages/commits.scss
app/assets/stylesheets/pages/commits.scss
+59
-0
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+6
-0
app/models/project.rb
app/models/project.rb
+2
-0
app/models/repository.rb
app/models/repository.rb
+40
-2
app/views/projects/branches/_branch.html.haml
app/views/projects/branches/_branch.html.haml
+14
-0
No files found.
CHANGELOG
View file @
c843722d
...
@@ -16,6 +16,7 @@ v 8.2.0 (unreleased)
...
@@ -16,6 +16,7 @@ v 8.2.0 (unreleased)
- Fix: 500 error returned if destroy request without HTTP referer (Kazuki Shimizu)
- Fix: 500 error returned if destroy request without HTTP referer (Kazuki Shimizu)
- Remove deprecated CI events from project settings page
- Remove deprecated CI events from project settings page
- Use issue editor as cross reference comment author when issue is edited with a new mention.
- Use issue editor as cross reference comment author when issue is edited with a new mention.
- Add graphs of commits ahead and behind default branch (Jeff Stubler)
v 8.1.1
v 8.1.1
- Fix cloning Wiki repositories via HTTP (Stan Hu)
- Fix cloning Wiki repositories via HTTP (Stan Hu)
...
...
app/assets/stylesheets/pages/commits.scss
View file @
c843722d
...
@@ -113,3 +113,62 @@ li.commit {
...
@@ -113,3 +113,62 @@ li.commit {
}
}
}
}
}
}
.divergence-graph
{
padding
:
12px
12px
0
0
;
float
:
right
;
.graph-side
{
position
:
relative
;
width
:
80px
;
height
:
22px
;
padding
:
5px
0
13px
;
float
:
left
;
.bar
{
position
:
absolute
;
height
:
4px
;
background-color
:
#ccc
;
}
.bar-behind
{
right
:
0
;
border-radius
:
3px
0
0
3px
;
}
.bar-ahead
{
left
:
0
;
border-radius
:
0
3px
3px
0
;
}
.count
{
padding-top
:
6px
;
padding-bottom
:
0px
;
font-size
:
12px
;
color
:
#333
;
display
:
block
;
}
.count-behind
{
padding-right
:
4px
;
text-align
:
right
;
}
.count-ahead
{
padding-left
:
4px
;
text-align
:
left
;
}
}
.graph-separator
{
position
:
relative
;
width
:
1px
;
height
:
18px
;
margin
:
5px
0
0
;
float
:
left
;
background-color
:
#ccc
;
}
}
app/controllers/projects/branches_controller.rb
View file @
c843722d
...
@@ -9,6 +9,12 @@ class Projects::BranchesController < Projects::ApplicationController
...
@@ -9,6 +9,12 @@ class Projects::BranchesController < Projects::ApplicationController
@sort
=
params
[
:sort
]
||
'name'
@sort
=
params
[
:sort
]
||
'name'
@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
|
memo
,
branch
|
diverging_commit_counts
=
repository
.
diverging_commit_counts
(
branch
)
[
memo
,
diverging_commit_counts
[
:behind
],
diverging_commit_counts
[
:ahead
]].
max
end
end
end
def
recent
def
recent
...
...
app/models/project.rb
View file @
c843722d
...
@@ -714,6 +714,8 @@ class Project < ActiveRecord::Base
...
@@ -714,6 +714,8 @@ class Project < ActiveRecord::Base
end
end
def
change_head
(
branch
)
def
change_head
(
branch
)
# Cached divergent commit counts are based on repository head
repository
.
expire_branch_cache
gitlab_shell
.
update_repository_head
(
self
.
path_with_namespace
,
branch
)
gitlab_shell
.
update_repository_head
(
self
.
path_with_namespace
,
branch
)
reload_default_branch
reload_default_branch
end
end
...
...
app/models/repository.rb
View file @
c843722d
...
@@ -147,9 +147,26 @@ class Repository
...
@@ -147,9 +147,26 @@ class Repository
cache
.
fetch
(
:size
)
{
raw_repository
.
size
}
cache
.
fetch
(
:size
)
{
raw_repository
.
size
}
end
end
def
diverging_commit_counts
(
branch
)
branch_cache_key
=
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
cache
.
fetch
(
branch_cache_key
)
do
number_commits_behind
=
commits_between
(
branch
.
name
,
root_ref
).
size
number_commits_ahead
=
commits_between
(
root_ref
,
branch
.
name
).
size
{
behind:
number_commits_behind
,
ahead:
number_commits_ahead
}
end
end
def
cache_keys
def
cache_keys
%i(size branch_names tag_names commit_count
%i(size branch_names tag_names commit_count readme
readme version contribution_guide changelog license)
contribution_guide changelog license)
end
def
branch_cache_keys
branches
.
map
do
|
branch
|
(
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
end
end
end
def
build_cache
def
build_cache
...
@@ -158,12 +175,28 @@ class Repository
...
@@ -158,12 +175,28 @@ class Repository
send
(
key
)
send
(
key
)
end
end
end
end
branches
.
each
do
|
branch
|
unless
cache
.
exist?
((
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
send
(
:diverging_commit_counts
,
branch
)
end
end
end
end
def
expire_cache
def
expire_cache
cache_keys
.
each
do
|
key
|
cache_keys
.
each
do
|
key
|
cache
.
expire
(
key
)
cache
.
expire
(
key
)
end
end
branches
.
each
do
|
branch
|
cache
.
expire
((
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
end
end
def
expire_branch_cache
branches
.
each
do
|
branch
|
cache
.
expire
((
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
end
end
end
def
rebuild_cache
def
rebuild_cache
...
@@ -171,6 +204,11 @@ class Repository
...
@@ -171,6 +204,11 @@ class Repository
cache
.
expire
(
key
)
cache
.
expire
(
key
)
send
(
key
)
send
(
key
)
end
end
branches
.
each
do
|
branch
|
cache
.
expire
((
'diverging_commit_counts_'
+
branch
.
name
).
to_sym
)
send
(
:diverging_commit_counts
,
branch
)
end
end
end
def
lookup_cache
def
lookup_cache
...
...
app/views/projects/branches/_branch.html.haml
View file @
c843722d
-
commit
=
@repository
.
commit
(
branch
.
target
)
-
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
]
%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
...
@@ -29,6 +32,17 @@
...
@@ -29,6 +32,17 @@
=
link_to
namespace_project_branch_path
(
@project
.
namespace
,
@project
,
branch
.
name
),
class:
'btn btn-grouped btn-xs btn-remove remove-row'
,
method: :delete
,
data:
{
confirm:
'Removed branch cannot be restored. Are you sure?'
},
remote:
true
do
=
link_to
namespace_project_branch_path
(
@project
.
namespace
,
@project
,
branch
.
name
),
class:
'btn btn-grouped btn-xs btn-remove remove-row'
,
method: :delete
,
data:
{
confirm:
'Removed branch cannot be restored. Are you sure?'
},
remote:
true
do
=
icon
(
"trash-o"
)
=
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}"
}
.graph-side
.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}%"
}
%span
.count.count-ahead
=
number_commits_ahead
-
if
commit
-
if
commit
=
render
'projects/branches/commit'
,
commit:
commit
,
project:
@project
=
render
'projects/branches/commit'
,
commit:
commit
,
project:
@project
-
else
-
else
...
...
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