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
Boxiang Sun
gitlab-ce
Commits
1ea0ce82
Commit
1ea0ce82
authored
Mar 10, 2017
by
Kim "BKC" Carlbäcker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make GitLab use Gitaly for commit_is_ancestor
- Migration in Repository#is_ancestor?
parent
3e1fb2a5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
1 deletion
+43
-1
app/models/repository.rb
app/models/repository.rb
+7
-1
changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml
.../unreleased/feature-use-gitaly-for-commit-is-ancestor.yml
+4
-0
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+5
-0
lib/gitlab/gitaly_client/commit.rb
lib/gitlab/gitaly_client/commit.rb
+14
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+13
-0
No files found.
app/models/repository.rb
View file @
1ea0ce82
...
@@ -981,7 +981,13 @@ class Repository
...
@@ -981,7 +981,13 @@ class Repository
end
end
def
is_ancestor?
(
ancestor_id
,
descendant_id
)
def
is_ancestor?
(
ancestor_id
,
descendant_id
)
merge_base
(
ancestor_id
,
descendant_id
)
==
ancestor_id
Gitlab
::
GitalyClient
.
migrate
(
:is_ancestor
)
do
|
is_enabled
|
if
is_enabled
raw_repository
.
is_ancestor?
(
ancestor_id
,
descendant_id
)
else
merge_base_commit
(
ancestor_id
,
descendant_id
)
==
ancestor_id
end
end
end
end
def
empty_repo?
def
empty_repo?
...
...
changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml
0 → 100644
View file @
1ea0ce82
---
title
:
Use Gitaly for Repository#is_ancestor
merge_request
:
9864
author
:
lib/gitlab/git/repository.rb
View file @
1ea0ce82
...
@@ -406,6 +406,11 @@ module Gitlab
...
@@ -406,6 +406,11 @@ module Gitlab
rugged
.
merge_base
(
from
,
to
)
rugged
.
merge_base
(
from
,
to
)
end
end
# Returns true is +from+ is direct ancestor to +to+, otherwise false
def
is_ancestor?
(
from
,
to
)
Gitlab
::
GitalyClient
::
Commit
.
is_ancestor
(
self
,
from
,
to
)
end
# Return an array of Diff objects that represent the diff
# Return an array of Diff objects that represent the diff
# between +from+ and +to+. See Diff::filter_diff_options for the allowed
# between +from+ and +to+. See Diff::filter_diff_options for the allowed
# diff options. The +options+ hash can also include :break_rewrites to
# diff options. The +options+ hash can also include :break_rewrites to
...
...
lib/gitlab/gitaly_client/commit.rb
View file @
1ea0ce82
...
@@ -21,6 +21,20 @@ module Gitlab
...
@@ -21,6 +21,20 @@ module Gitlab
Gitlab
::
Git
::
DiffCollection
.
new
(
stub
.
commit_diff
(
request
),
options
)
Gitlab
::
Git
::
DiffCollection
.
new
(
stub
.
commit_diff
(
request
),
options
)
end
end
def
is_ancestor
(
repository
,
ancestor_id
,
child_id
)
project
=
Project
.
find_by_path
(
repository
.
path
)
channel
=
GitalyClient
.
get_channel
(
project
.
repository_storage
)
stub
=
Gitaly
::
Commit
::
Stub
.
new
(
nil
,
nil
,
channel_override:
channel
)
repo
=
Gitaly
::
Repository
.
new
(
path:
repository
.
path_to_repo
)
request
=
Gitaly
::
CommitIsAncestorRequest
.
new
(
repository:
repo
,
ancestor_id:
ancestor_id
,
child_id:
child_id
)
stub
.
commit_is_ancestor
(
request
).
value
end
end
end
end
end
end
end
...
...
spec/models/repository_spec.rb
View file @
1ea0ce82
...
@@ -1851,4 +1851,17 @@ describe Repository, models: true do
...
@@ -1851,4 +1851,17 @@ describe Repository, models: true do
end
end
end
end
end
end
describe
'#is_ancestor?'
do
context
'Gitaly is_ancestor feature enabled'
do
it
'asks Gitaly server if it\'s an ancestor'
do
commit
=
repository
.
commit
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
with
(
:is_ancestor
).
and_return
(
true
)
expect
(
Gitlab
::
GitalyClient
::
Commit
).
to
receive
(
:is_ancestor
).
with
(
repository
.
raw_repository
,
commit
.
id
,
commit
.
id
).
and_return
(
true
)
expect
(
repository
.
is_ancestor?
(
commit
.
id
,
commit
.
id
)).
to
be
true
end
end
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