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
3ce6f03f
Commit
3ce6f03f
authored
Jul 25, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporate Gitaly's CommitService.FindCommit RPC
parent
e363fbf7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
76 additions
and
26 deletions
+76
-26
app/models/repository.rb
app/models/repository.rb
+1
-1
lib/gitlab/conflict/file_collection.rb
lib/gitlab/conflict/file_collection.rb
+2
-2
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+35
-17
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+4
-0
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+14
-3
spec/lib/gitlab/git/commit_spec.rb
spec/lib/gitlab/git/commit_spec.rb
+4
-1
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+14
-0
spec/migrations/migrate_process_commit_worker_jobs_spec.rb
spec/migrations/migrate_process_commit_worker_jobs_spec.rb
+1
-1
spec/models/commit_spec.rb
spec/models/commit_spec.rb
+1
-1
No files found.
app/models/repository.rb
View file @
3ce6f03f
...
@@ -769,7 +769,7 @@ class Repository
...
@@ -769,7 +769,7 @@ class Repository
index
=
Gitlab
::
Git
::
Index
.
new
(
raw_repository
)
index
=
Gitlab
::
Git
::
Index
.
new
(
raw_repository
)
if
start_commit
if
start_commit
index
.
read_tree
(
start_commit
.
r
aw
_commit
.
tree
)
index
.
read_tree
(
start_commit
.
r
ugged
_commit
.
tree
)
parents
=
[
start_commit
.
sha
]
parents
=
[
start_commit
.
sha
]
else
else
parents
=
[]
parents
=
[]
...
...
lib/gitlab/conflict/file_collection.rb
View file @
3ce6f03f
...
@@ -77,8 +77,8 @@ EOM
...
@@ -77,8 +77,8 @@ EOM
def
initialize
(
merge_request
,
project
)
def
initialize
(
merge_request
,
project
)
@merge_request
=
merge_request
@merge_request
=
merge_request
@our_commit
=
merge_request
.
source_branch_head
.
raw
.
r
aw
_commit
@our_commit
=
merge_request
.
source_branch_head
.
raw
.
r
ugged
_commit
@their_commit
=
merge_request
.
target_branch_head
.
raw
.
r
aw
_commit
@their_commit
=
merge_request
.
target_branch_head
.
raw
.
r
ugged
_commit
@project
=
project
@project
=
project
end
end
end
end
...
...
lib/gitlab/git/commit.rb
View file @
3ce6f03f
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
attr_accessor
*
SERIALIZE_KEYS
# rubocop:disable Lint/AmbiguousOperator
attr_accessor
*
SERIALIZE_KEYS
# rubocop:disable Lint/AmbiguousOperator
delegate
:tree
,
to: :r
aw
_commit
delegate
:tree
,
to: :r
ugged
_commit
def
==
(
other
)
def
==
(
other
)
return
false
unless
other
.
is_a?
(
Gitlab
::
Git
::
Commit
)
return
false
unless
other
.
is_a?
(
Gitlab
::
Git
::
Commit
)
...
@@ -50,19 +50,29 @@ module Gitlab
...
@@ -50,19 +50,29 @@ module Gitlab
#
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/321
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/321
def
find
(
repo
,
commit_id
=
"HEAD"
)
def
find
(
repo
,
commit_id
=
"HEAD"
)
# Already a commit?
return
commit_id
if
commit_id
.
is_a?
(
Gitlab
::
Git
::
Commit
)
return
commit_id
if
commit_id
.
is_a?
(
Gitlab
::
Git
::
Commit
)
# A rugged reference?
commit_id
=
Gitlab
::
Git
::
Ref
.
dereference_object
(
commit_id
)
return
decorate
(
repo
,
commit_id
)
if
commit_id
.
is_a?
(
Rugged
::
Commit
)
return
decorate
(
repo
,
commit_id
)
if
commit_id
.
is_a?
(
Rugged
::
Commit
)
obj
=
if
commit_id
.
is_a?
(
String
)
# Some weird thing?
repo
.
rev_parse_target
(
commit_id
)
return
nil
unless
commit_id
.
is_a?
(
String
)
else
Gitlab
::
Git
::
Ref
.
dereference_object
(
commit_id
)
commit
=
repo
.
gitaly_migrate
(
:find_commit
)
do
|
is_enabled
|
end
if
is_enabled
repo
.
gitaly_commit_client
.
find_commit
(
commit_id
)
else
obj
=
repo
.
rev_parse_target
(
commit_id
)
return
nil
unless
obj
.
is_a?
(
Rugged
::
Commit
)
obj
.
is_a?
(
Rugged
::
Commit
)
?
obj
:
nil
end
end
decorate
(
repo
,
obj
)
decorate
(
repo
,
commit
)
if
commit
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
Gitlab
::
Git
::
Repository
::
NoRepository
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
Gitlab
::
Git
::
CommandError
,
Gitlab
::
Git
::
Repository
::
NoRepository
nil
nil
end
end
...
@@ -273,11 +283,11 @@ module Gitlab
...
@@ -273,11 +283,11 @@ module Gitlab
break_rewrites
=
options
[
:break_rewrites
]
break_rewrites
=
options
[
:break_rewrites
]
actual_options
=
Gitlab
::
Git
::
Diff
.
filter_diff_options
(
options
)
actual_options
=
Gitlab
::
Git
::
Diff
.
filter_diff_options
(
options
)
diff
=
if
r
aw
_commit
.
parents
.
empty?
diff
=
if
r
ugged
_commit
.
parents
.
empty?
raw
_commit
.
diff
(
actual_options
.
merge
(
reverse:
true
))
rugged
_commit
.
diff
(
actual_options
.
merge
(
reverse:
true
))
else
else
raw_commit
.
parents
[
0
].
diff
(
raw
_commit
,
actual_options
)
rugged_commit
.
parents
[
0
].
diff
(
rugged
_commit
,
actual_options
)
end
end
diff
.
find_similar!
(
break_rewrites:
break_rewrites
)
diff
.
find_similar!
(
break_rewrites:
break_rewrites
)
diff
diff
...
@@ -340,7 +350,7 @@ module Gitlab
...
@@ -340,7 +350,7 @@ module Gitlab
def
to_patch
(
options
=
{})
def
to_patch
(
options
=
{})
begin
begin
r
aw
_commit
.
to_mbox
(
options
)
r
ugged
_commit
.
to_mbox
(
options
)
rescue
Rugged
::
InvalidError
=>
ex
rescue
Rugged
::
InvalidError
=>
ex
if
ex
.
message
=~
/commit \w+ is a merge commit/i
if
ex
.
message
=~
/commit \w+ is a merge commit/i
'Patch format is not currently supported for merge commits.'
'Patch format is not currently supported for merge commits.'
...
@@ -388,6 +398,14 @@ module Gitlab
...
@@ -388,6 +398,14 @@ module Gitlab
encode!
@committer_email
encode!
@committer_email
end
end
def
rugged_commit
@rugged_commit
||=
if
raw_commit
.
is_a?
(
Rugged
::
Commit
)
raw_commit
else
@repository
.
rev_parse_target
(
id
)
end
end
private
private
def
init_from_hash
(
hash
)
def
init_from_hash
(
hash
)
...
@@ -421,10 +439,10 @@ module Gitlab
...
@@ -421,10 +439,10 @@ module Gitlab
# subject from the message to make it clearer when there's one
# subject from the message to make it clearer when there's one
# available but not the other.
# available but not the other.
@message
=
(
commit
.
body
.
presence
||
commit
.
subject
).
dup
@message
=
(
commit
.
body
.
presence
||
commit
.
subject
).
dup
@authored_date
=
Time
.
at
(
commit
.
author
.
date
.
seconds
)
@authored_date
=
Time
.
at
(
commit
.
author
.
date
.
seconds
)
.
utc
@author_name
=
commit
.
author
.
name
.
dup
@author_name
=
commit
.
author
.
name
.
dup
@author_email
=
commit
.
author
.
email
.
dup
@author_email
=
commit
.
author
.
email
.
dup
@committed_date
=
Time
.
at
(
commit
.
committer
.
date
.
seconds
)
@committed_date
=
Time
.
at
(
commit
.
committer
.
date
.
seconds
)
.
utc
@committer_name
=
commit
.
committer
.
name
.
dup
@committer_name
=
commit
.
committer
.
name
.
dup
@committer_email
=
commit
.
committer
.
email
.
dup
@committer_email
=
commit
.
committer
.
email
.
dup
@parent_ids
=
commit
.
parent_ids
@parent_ids
=
commit
.
parent_ids
...
...
lib/gitlab/gitaly_client.rb
View file @
3ce6f03f
...
@@ -100,5 +100,9 @@ module Gitlab
...
@@ -100,5 +100,9 @@ module Gitlab
path
=
Rails
.
root
.
join
(
SERVER_VERSION_FILE
)
path
=
Rails
.
root
.
join
(
SERVER_VERSION_FILE
)
path
.
read
.
chomp
path
.
read
.
chomp
end
end
def
self
.
encode
(
s
)
s
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
end
end
end
end
end
lib/gitlab/gitaly_client/commit_service.rb
View file @
3ce6f03f
...
@@ -43,7 +43,7 @@ module Gitlab
...
@@ -43,7 +43,7 @@ module Gitlab
request
=
Gitaly
::
TreeEntryRequest
.
new
(
request
=
Gitaly
::
TreeEntryRequest
.
new
(
repository:
@gitaly_repo
,
repository:
@gitaly_repo
,
revision:
ref
,
revision:
ref
,
path:
path
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
),
path:
GitalyClient
.
encode
(
path
),
limit:
limit
.
to_i
limit:
limit
.
to_i
)
)
...
@@ -99,8 +99,8 @@ module Gitlab
...
@@ -99,8 +99,8 @@ module Gitlab
def
last_commit_for_path
(
revision
,
path
)
def
last_commit_for_path
(
revision
,
path
)
request
=
Gitaly
::
LastCommitForPathRequest
.
new
(
request
=
Gitaly
::
LastCommitForPathRequest
.
new
(
repository:
@gitaly_repo
,
repository:
@gitaly_repo
,
revision:
revision
.
force_encoding
(
Encoding
::
ASCII_8BIT
),
revision:
GitalyClient
.
encode
(
revision
),
path:
path
.
to_s
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
path:
GitalyClient
.
encode
(
path
.
to_s
)
)
)
gitaly_commit
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:last_commit_for_path
,
request
).
commit
gitaly_commit
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:last_commit_for_path
,
request
).
commit
...
@@ -151,6 +151,17 @@ module Gitlab
...
@@ -151,6 +151,17 @@ module Gitlab
response
.
reduce
(
""
)
{
|
memo
,
msg
|
memo
<<
msg
.
data
}
response
.
reduce
(
""
)
{
|
memo
,
msg
|
memo
<<
msg
.
data
}
end
end
def
find_commit
(
revision
)
request
=
Gitaly
::
FindCommitRequest
.
new
(
repository:
@gitaly_repo
,
revision:
GitalyClient
.
encode
(
revision
)
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:find_commit
,
request
)
response
.
commit
end
private
private
def
commit_diff_request_params
(
commit
,
options
=
{})
def
commit_diff_request_params
(
commit
,
options
=
{})
...
...
spec/lib/gitlab/git/commit_spec.rb
View file @
3ce6f03f
...
@@ -66,6 +66,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
...
@@ -66,6 +66,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
describe
"Commit info from gitaly commit"
do
describe
"Commit info from gitaly commit"
do
let
(
:id
)
{
'f00'
}
let
(
:id
)
{
'f00'
}
let
(
:parent_ids
)
{
%w(b45 b46)
}
let
(
:subject
)
{
"My commit"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:subject
)
{
"My commit"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:body
)
{
subject
+
"My body"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:body
)
{
subject
+
"My body"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:committer
)
do
let
(
:committer
)
do
...
@@ -88,7 +89,8 @@ describe Gitlab::Git::Commit, seed_helper: true do
...
@@ -88,7 +89,8 @@ describe Gitlab::Git::Commit, seed_helper: true do
subject:
subject
,
subject:
subject
,
body:
body
,
body:
body
,
author:
author
,
author:
author
,
committer:
committer
committer:
committer
,
parent_ids:
parent_ids
)
)
end
end
let
(
:commit
)
{
described_class
.
new
(
repository
,
gitaly_commit
)
}
let
(
:commit
)
{
described_class
.
new
(
repository
,
gitaly_commit
)
}
...
@@ -102,6 +104,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
...
@@ -102,6 +104,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
it
{
expect
(
commit
.
author_name
).
to
eq
(
author
.
name
)
}
it
{
expect
(
commit
.
author_name
).
to
eq
(
author
.
name
)
}
it
{
expect
(
commit
.
committer_name
).
to
eq
(
committer
.
name
)
}
it
{
expect
(
commit
.
committer_name
).
to
eq
(
committer
.
name
)
}
it
{
expect
(
commit
.
committer_email
).
to
eq
(
committer
.
email
)
}
it
{
expect
(
commit
.
committer_email
).
to
eq
(
committer
.
email
)
}
it
{
expect
(
commit
.
parent_ids
).
to
eq
(
parent_ids
)
}
context
'no body'
do
context
'no body'
do
let
(
:body
)
{
""
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:body
)
{
""
.
force_encoding
(
'ASCII-8BIT'
)
}
...
...
spec/lib/gitlab/gitaly_client/commit_service_spec.rb
View file @
3ce6f03f
...
@@ -112,4 +112,18 @@ describe Gitlab::GitalyClient::CommitService do
...
@@ -112,4 +112,18 @@ describe Gitlab::GitalyClient::CommitService do
client
.
tree_entries
(
repository
,
revision
,
path
)
client
.
tree_entries
(
repository
,
revision
,
path
)
end
end
end
end
describe
'#find_commit'
do
let
(
:revision
)
{
'4b825dc642cb6eb9a060e54bf8d69288fbee4904'
}
it
'sends an RPC request'
do
request
=
Gitaly
::
FindCommitRequest
.
new
(
repository:
repository_message
,
revision:
revision
)
expect_any_instance_of
(
Gitaly
::
CommitService
::
Stub
).
to
receive
(
:find_commit
)
.
with
(
request
,
kind_of
(
Hash
)).
and_return
(
double
(
commit:
nil
))
described_class
.
new
(
repository
).
find_commit
(
revision
)
end
end
end
end
spec/migrations/migrate_process_commit_worker_jobs_spec.rb
View file @
3ce6f03f
...
@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20161124141322_migrate_process_commit_
...
@@ -6,7 +6,7 @@ require Rails.root.join('db', 'migrate', '20161124141322_migrate_process_commit_
describe
MigrateProcessCommitWorkerJobs
do
describe
MigrateProcessCommitWorkerJobs
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:commit
)
{
project
.
commit
.
raw
.
r
aw
_commit
}
let
(
:commit
)
{
project
.
commit
.
raw
.
r
ugged
_commit
}
describe
'Project'
do
describe
'Project'
do
describe
'find_including_path'
do
describe
'find_including_path'
do
...
...
spec/models/commit_spec.rb
View file @
3ce6f03f
...
@@ -189,7 +189,7 @@ eos
...
@@ -189,7 +189,7 @@ eos
it
{
expect
(
data
).
to
be_a
(
Hash
)
}
it
{
expect
(
data
).
to
be_a
(
Hash
)
}
it
{
expect
(
data
[
:message
]).
to
include
(
'adds bar folder and branch-test text file to check Repository merged_to_root_ref method'
)
}
it
{
expect
(
data
[
:message
]).
to
include
(
'adds bar folder and branch-test text file to check Repository merged_to_root_ref method'
)
}
it
{
expect
(
data
[
:timestamp
]).
to
eq
(
'2016-09-27T14:37:46
+00:00
'
)
}
it
{
expect
(
data
[
:timestamp
]).
to
eq
(
'2016-09-27T14:37:46
Z
'
)
}
it
{
expect
(
data
[
:added
]).
to
eq
([
"bar/branch-test.txt"
])
}
it
{
expect
(
data
[
:added
]).
to
eq
([
"bar/branch-test.txt"
])
}
it
{
expect
(
data
[
:modified
]).
to
eq
([])
}
it
{
expect
(
data
[
:modified
]).
to
eq
([])
}
it
{
expect
(
data
[
:removed
]).
to
eq
([])
}
it
{
expect
(
data
[
:removed
]).
to
eq
([])
}
...
...
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