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
Léo-Paul Géneau
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
Show 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
index
=
Gitlab
::
Git
::
Index
.
new
(
raw_repository
)
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
]
else
parents
=
[]
...
...
lib/gitlab/conflict/file_collection.rb
View file @
3ce6f03f
...
...
@@ -77,8 +77,8 @@ EOM
def
initialize
(
merge_request
,
project
)
@merge_request
=
merge_request
@our_commit
=
merge_request
.
source_branch_head
.
raw
.
r
aw
_commit
@their_commit
=
merge_request
.
target_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
ugged
_commit
@project
=
project
end
end
...
...
lib/gitlab/git/commit.rb
View file @
3ce6f03f
...
...
@@ -14,7 +14,7 @@ module Gitlab
attr_accessor
*
SERIALIZE_KEYS
# rubocop:disable Lint/AmbiguousOperator
delegate
:tree
,
to: :r
aw
_commit
delegate
:tree
,
to: :r
ugged
_commit
def
==
(
other
)
return
false
unless
other
.
is_a?
(
Gitlab
::
Git
::
Commit
)
...
...
@@ -50,19 +50,29 @@ module Gitlab
#
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/321
def
find
(
repo
,
commit_id
=
"HEAD"
)
# Already a 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
)
obj
=
if
commit_id
.
is_a?
(
String
)
repo
.
rev_parse_target
(
commit_id
)
# Some weird thing?
return
nil
unless
commit_id
.
is_a?
(
String
)
commit
=
repo
.
gitaly_migrate
(
:find_commit
)
do
|
is_enabled
|
if
is_enabled
repo
.
gitaly_commit_client
.
find_commit
(
commit_id
)
else
Gitlab
::
Git
::
Ref
.
dereference_object
(
commit_id
)
end
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
)
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
Gitlab
::
Git
::
Repository
::
NoRepository
decorate
(
repo
,
commit
)
if
commit
rescue
Rugged
::
ReferenceError
,
Rugged
::
InvalidError
,
Rugged
::
ObjectError
,
Gitlab
::
Git
::
CommandError
,
Gitlab
::
Git
::
Repository
::
NoRepository
nil
end
...
...
@@ -273,10 +283,10 @@ module Gitlab
break_rewrites
=
options
[
:break_rewrites
]
actual_options
=
Gitlab
::
Git
::
Diff
.
filter_diff_options
(
options
)
diff
=
if
r
aw
_commit
.
parents
.
empty?
raw
_commit
.
diff
(
actual_options
.
merge
(
reverse:
true
))
diff
=
if
r
ugged
_commit
.
parents
.
empty?
rugged
_commit
.
diff
(
actual_options
.
merge
(
reverse:
true
))
else
raw_commit
.
parents
[
0
].
diff
(
raw
_commit
,
actual_options
)
rugged_commit
.
parents
[
0
].
diff
(
rugged
_commit
,
actual_options
)
end
diff
.
find_similar!
(
break_rewrites:
break_rewrites
)
...
...
@@ -340,7 +350,7 @@ module Gitlab
def
to_patch
(
options
=
{})
begin
r
aw
_commit
.
to_mbox
(
options
)
r
ugged
_commit
.
to_mbox
(
options
)
rescue
Rugged
::
InvalidError
=>
ex
if
ex
.
message
=~
/commit \w+ is a merge commit/i
'Patch format is not currently supported for merge commits.'
...
...
@@ -388,6 +398,14 @@ module Gitlab
encode!
@committer_email
end
def
rugged_commit
@rugged_commit
||=
if
raw_commit
.
is_a?
(
Rugged
::
Commit
)
raw_commit
else
@repository
.
rev_parse_target
(
id
)
end
end
private
def
init_from_hash
(
hash
)
...
...
@@ -421,10 +439,10 @@ module Gitlab
# subject from the message to make it clearer when there's one
# available but not the other.
@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_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_email
=
commit
.
committer
.
email
.
dup
@parent_ids
=
commit
.
parent_ids
...
...
lib/gitlab/gitaly_client.rb
View file @
3ce6f03f
...
...
@@ -100,5 +100,9 @@ module Gitlab
path
=
Rails
.
root
.
join
(
SERVER_VERSION_FILE
)
path
.
read
.
chomp
end
def
self
.
encode
(
s
)
s
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
end
end
end
lib/gitlab/gitaly_client/commit_service.rb
View file @
3ce6f03f
...
...
@@ -43,7 +43,7 @@ module Gitlab
request
=
Gitaly
::
TreeEntryRequest
.
new
(
repository:
@gitaly_repo
,
revision:
ref
,
path:
path
.
dup
.
force_encoding
(
Encoding
::
ASCII_8BIT
),
path:
GitalyClient
.
encode
(
path
),
limit:
limit
.
to_i
)
...
...
@@ -99,8 +99,8 @@ module Gitlab
def
last_commit_for_path
(
revision
,
path
)
request
=
Gitaly
::
LastCommitForPathRequest
.
new
(
repository:
@gitaly_repo
,
revision:
revision
.
force_encoding
(
Encoding
::
ASCII_8BIT
),
path:
path
.
to_s
.
force_encoding
(
Encoding
::
ASCII_8BIT
)
revision:
GitalyClient
.
encode
(
revision
),
path:
GitalyClient
.
encode
(
path
.
to_s
)
)
gitaly_commit
=
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:last_commit_for_path
,
request
).
commit
...
...
@@ -151,6 +151,17 @@ module Gitlab
response
.
reduce
(
""
)
{
|
memo
,
msg
|
memo
<<
msg
.
data
}
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
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
describe
"Commit info from gitaly commit"
do
let
(
:id
)
{
'f00'
}
let
(
:parent_ids
)
{
%w(b45 b46)
}
let
(
:subject
)
{
"My commit"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:body
)
{
subject
+
"My body"
.
force_encoding
(
'ASCII-8BIT'
)
}
let
(
:committer
)
do
...
...
@@ -88,7 +89,8 @@ describe Gitlab::Git::Commit, seed_helper: true do
subject:
subject
,
body:
body
,
author:
author
,
committer:
committer
committer:
committer
,
parent_ids:
parent_ids
)
end
let
(
:commit
)
{
described_class
.
new
(
repository
,
gitaly_commit
)
}
...
...
@@ -102,6 +104,7 @@ describe Gitlab::Git::Commit, seed_helper: true do
it
{
expect
(
commit
.
author_name
).
to
eq
(
author
.
name
)
}
it
{
expect
(
commit
.
committer_name
).
to
eq
(
committer
.
name
)
}
it
{
expect
(
commit
.
committer_email
).
to
eq
(
committer
.
email
)
}
it
{
expect
(
commit
.
parent_ids
).
to
eq
(
parent_ids
)
}
context
'no body'
do
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
client
.
tree_entries
(
repository
,
revision
,
path
)
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
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_
describe
MigrateProcessCommitWorkerJobs
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:commit
)
{
project
.
commit
.
raw
.
r
aw
_commit
}
let
(
:commit
)
{
project
.
commit
.
raw
.
r
ugged
_commit
}
describe
'Project'
do
describe
'find_including_path'
do
...
...
spec/models/commit_spec.rb
View file @
3ce6f03f
...
...
@@ -189,7 +189,7 @@ eos
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
[
: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
[
:modified
]).
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