BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c6b13536
Commit
c6b13536
authored
Apr 27, 2017
by
Douwe Maan
Committed by
Lin Jen-Shin
Apr 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch '30973-fix-network-graph-ordering' into 'master'
Fix ordering of commits in the network graph. Closes #30973 See merge request !10936
parent
2d0e9173
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
7 deletions
+73
-7
graph.rb
app/models/network/graph.rb
+2
-1
30973-fix-network-graph-ordering.yml
changelogs/unreleased/30973-fix-network-graph-ordering.yml
+4
-0
repository.rb
lib/gitlab/git/repository.rb
+17
-6
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+29
-0
graph_spec.rb
spec/models/network/graph_spec.rb
+21
-0
No files found.
app/models/network/graph.rb
View file @
c6b13536
...
...
@@ -107,7 +107,8 @@ module Network
def
find_commits
(
skip
=
0
)
opts
=
{
max_count:
self
.
class
.
max_count
,
skip:
skip
skip:
skip
,
order: :date
}
opts
[
:ref
]
=
@commit
.
id
if
@filter_ref
...
...
changelogs/unreleased/30973-fix-network-graph-ordering.yml
0 → 100644
View file @
c6b13536
---
title
:
Fix ordering of commits in the network graph
merge_request
:
10936
author
:
lib/gitlab/git/repository.rb
View file @
c6b13536
...
...
@@ -486,7 +486,9 @@ module Gitlab
# :contains is the commit contained by the refs from which to begin (SHA1 or name)
# :max_count is the maximum number of commits to fetch
# :skip is the number of commits to skip
# :order is the commits order and allowed value is :date(default) or :topo
# :order is the commits order and allowed value is :none (default), :date, or :topo
# commit ordering types are documented here:
# http://www.rubydoc.info/github/libgit2/rugged/Rugged#SORT_NONE-constant)
#
def
find_commits
(
options
=
{})
actual_options
=
options
.
dup
...
...
@@ -514,11 +516,8 @@ module Gitlab
end
end
if
actual_options
[
:order
]
==
:topo
walker
.
sorting
(
Rugged
::
SORT_TOPO
)
else
walker
.
sorting
(
Rugged
::
SORT_NONE
)
end
sort_type
=
rugged_sort_type
(
actual_options
[
:order
])
walker
.
sorting
(
sort_type
)
commits
=
[]
offset
=
actual_options
[
:skip
]
...
...
@@ -1265,6 +1264,18 @@ module Gitlab
def
gitaly_ref_client
@gitaly_ref_client
||=
Gitlab
::
GitalyClient
::
Ref
.
new
(
self
)
end
# Returns the `Rugged` sorting type constant for a given
# sort type key. Valid keys are `:none`, `:topo`, and `:date`
def
rugged_sort_type
(
key
)
@rugged_sort_types
||=
{
none:
Rugged
::
SORT_NONE
,
topo:
Rugged
::
SORT_TOPO
,
date:
Rugged
::
SORT_DATE
}
@rugged_sort_types
.
fetch
(
key
,
Rugged
::
SORT_NONE
)
end
end
end
end
spec/lib/gitlab/git/repository_spec.rb
View file @
c6b13536
...
...
@@ -1028,6 +1028,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#find_commits'
do
it
'should return a return a collection of commits'
do
commits
=
repository
.
find_commits
expect
(
commits
).
not_to
be_empty
expect
(
commits
).
to
all
(
be_a_kind_of
(
Gitlab
::
Git
::
Commit
)
)
end
context
'while applying a sort order based on the `order` option'
do
it
"allows ordering topologically (no parents shown before their children)"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_TOPO
)
repository
.
find_commits
(
order: :topo
)
end
it
"allows ordering by date"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_DATE
)
repository
.
find_commits
(
order: :date
)
end
it
"applies no sorting by default"
do
expect_any_instance_of
(
Rugged
::
Walker
).
to
receive
(
:sorting
).
with
(
Rugged
::
SORT_NONE
)
repository
.
find_commits
end
end
end
describe
'#branches with deleted branch'
do
before
(
:each
)
do
ref
=
double
()
...
...
spec/models/network/graph_spec.rb
View file @
c6b13536
...
...
@@ -9,4 +9,25 @@ describe Network::Graph, models: true do
expect
(
graph
.
notes
).
to
eq
(
{
note_on_commit
.
commit_id
=>
1
}
)
end
describe
"#commits"
do
let
(
:graph
)
{
described_class
.
new
(
project
,
'refs/heads/master'
,
project
.
repository
.
commit
,
nil
)
}
it
"returns a list of commits"
do
commits
=
graph
.
commits
expect
(
commits
).
not_to
be_empty
expect
(
commits
).
to
all
(
be_kind_of
(
Network
::
Commit
)
)
end
it
"sorts the commits by commit date (descending)"
do
# Remove duplicate timestamps because they make it harder to
# assert that the commits are sorted as expected.
commits
=
graph
.
commits
.
uniq
(
&
:date
)
sorted_commits
=
commits
.
sort_by
(
&
:date
).
reverse
expect
(
commits
).
not_to
be_empty
expect
(
commits
.
map
(
&
:id
)).
to
eq
(
sorted_commits
.
map
(
&
:id
))
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