Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
hgitaly
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
heptapod
hgitaly
Commits
625a62c2
Commit
625a62c2
authored
4 years ago
by
Sushil Khanchi
Browse files
Options
Downloads
Patches
Plain Diff
Commit: implement CountDivergingCommits
parent
2857aa14
No related branches found
No related tags found
1 merge request
!16
Commit: implement CountDivergingCommits
Pipeline
#13320
passed with warnings
4 years ago
Stage: main
Stage: compat
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hgitaly/service/commit.py
+31
-2
31 additions, 2 deletions
hgitaly/service/commit.py
hgitaly/service/tests/test_commit.py
+41
-0
41 additions, 0 deletions
hgitaly/service/tests/test_commit.py
with
72 additions
and
2 deletions
hgitaly/service/commit.py
+
31
−
2
View file @
625a62c2
...
...
@@ -182,6 +182,10 @@
count
=
max_count
return
CountCommitsResponse
(
count
=
count
)
# CountDivergingCommits counts the diverging commits between from and to.
# Important to note that when --max-count is applied, the counts are not
# guaranteed to be accurate.
def
CountDivergingCommits
(
self
,
request
:
CountDivergingCommitsRequest
,
context
)
->
CountDivergingCommitsResponse
:
...
...
@@ -185,8 +189,33 @@
def
CountDivergingCommits
(
self
,
request
:
CountDivergingCommitsRequest
,
context
)
->
CountDivergingCommitsResponse
:
return
not_implemented
(
context
,
CountDivergingCommitsResponse
,
issue
=
17
)
# pragma no cover
repo
=
self
.
load_repo
(
request
.
repository
,
context
)
rev_from
=
gitlab_revision_changeset
(
repo
,
getattr
(
request
,
'
from
'
))
rev_to
=
gitlab_revision_changeset
(
repo
,
getattr
(
request
,
'
to
'
))
max_count
=
request
.
max_count
if
rev_from
is
None
:
logger
.
warning
(
"
cannot resolve
'
from
'
revision in %r
"
,
request
)
if
rev_to
is
None
:
logger
.
warning
(
"
cannot resolve
'
to
'
revision in %r
"
,
request
)
if
rev_from
is
None
or
rev_to
is
None
:
return
CountDivergingCommitsResponse
(
left_count
=
0
,
right_count
=
0
)
left
=
rev_from
.
rev
()
right
=
rev_to
.
rev
()
branchpoint
=
repo
.
revs
(
b
"
ancestor(%d, %d)
"
%
(
left
,
right
)).
first
()
left_count
=
len
(
repo
.
revs
(
b
"
%d::%d - %d
"
%
(
branchpoint
,
left
,
branchpoint
)))
right_count
=
len
(
repo
.
revs
(
b
"
%d::%d - %d
"
%
(
branchpoint
,
right
,
branchpoint
)))
if
max_count
and
(
left_count
+
right_count
)
>
max_count
:
delta
=
(
left_count
+
right_count
)
-
max_count
if
left_count
>=
delta
:
left_count
-=
delta
else
:
delta
-=
left_count
left_count
=
0
right_count
-=
delta
return
CountDivergingCommitsResponse
(
left_count
=
left_count
,
right_count
=
right_count
)
def
GetTreeEntries
(
self
,
request
:
GetTreeEntriesRequest
,
context
)
->
GetTreeEntriesResponse
:
...
...
This diff is collapsed.
Click to expand it.
hgitaly/service/tests/test_commit.py
+
41
−
0
View file @
625a62c2
...
...
@@ -21,6 +21,7 @@
FindCommitRequest
,
FindCommitsRequest
,
CountCommitsRequest
,
CountDivergingCommitsRequest
,
LastCommitForPathRequest
,
ListCommitsByOidRequest
,
ListCommitsByRefNameRequest
,
...
...
@@ -252,6 +253,46 @@
assert
resp
[
b
"
topic/default/feature
"
]
==
ctx3
.
hex
()
def
test_count_divergening_commits
(
grpc_channel
,
server_repos_root
):
grpc_stub
=
CommitServiceStub
(
grpc_channel
)
wrapper
,
grpc_repo
=
make_empty_repo
(
server_repos_root
)
def
do_rpc
(
gl_from
,
gl_to
,
max_count
=
None
):
request
=
CountDivergingCommitsRequest
(
repository
=
grpc_repo
,
to
=
gl_to
,
max_count
=
max_count
)
setattr
(
request
,
'
from
'
,
gl_from
)
response
=
grpc_stub
.
CountDivergingCommits
(
request
)
return
[
response
.
left_count
,
response
.
right_count
]
# prepare repo as:
#
# 2 (branch/default)
# |
# 1
# | 3 (topic/default/feature)
# | /
# 0
#
ctx0
=
wrapper
.
write_commit
(
'
foo
'
)
wrapper
.
write_commit
(
'
bar
'
)
wrapper
.
write_commit
(
'
baz
'
)
wrapper
.
write_commit
(
'
animals
'
,
topic
=
'
feature
'
,
parent
=
ctx0
)
assert
do_rpc
(
b
"
branch/default
"
,
b
"
topic/default/feature
"
)
==
[
2
,
1
]
# count 0 for the same "from" and "to"
assert
do_rpc
(
b
"
branch/default
"
,
b
"
branch/default
"
)
==
[
0
,
0
]
# when one of them is invalid ref
assert
do_rpc
(
b
"
branch/default
"
,
b
"
does-not-exists
"
)
==
[
0
,
0
]
assert
do_rpc
(
b
"
does-not-exists
"
,
b
"
branch/default
"
)
==
[
0
,
0
]
# count bounded with max_count
for
max_count
in
[
1
,
2
,
3
]:
resp
=
do_rpc
(
b
"
branch/default
"
,
b
"
topic/default/feature
"
,
max_count
)
assert
(
resp
[
0
]
+
resp
[
1
])
==
max_count
resp
=
do_rpc
(
b
"
topic/default/feature
"
,
b
"
branch/default
"
,
max_count
)
assert
(
resp
[
0
]
+
resp
[
1
])
==
max_count
def
test_count_commits
(
grpc_channel
,
server_repos_root
):
grpc_stub
=
CommitServiceStub
(
grpc_channel
)
wrapper
,
grpc_repo
=
make_empty_repo
(
server_repos_root
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment