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
eb36fa17
Commit
eb36fa17
authored
Sep 11, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Gitlab::Git::Repository#diff to Gitaly
Closes gitaly#524
parent
36dc65d5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
16 deletions
+61
-16
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+2
-2
lib/gitlab/git/diff.rb
lib/gitlab/git/diff.rb
+4
-0
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+9
-1
lib/gitlab/gitaly_client/commit_service.rb
lib/gitlab/gitaly_client/commit_service.rb
+45
-12
No files found.
GITALY_SERVER_VERSION
View file @
eb36fa17
0.
38
.0
0.
40
.0
lib/gitlab/diff/file.rb
View file @
eb36fa17
...
@@ -5,7 +5,7 @@ module Gitlab
...
@@ -5,7 +5,7 @@ module Gitlab
delegate
:new_file?
,
:deleted_file?
,
:renamed_file?
,
delegate
:new_file?
,
:deleted_file?
,
:renamed_file?
,
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:mode_changed?
,
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:mode_changed?
,
:submodule?
,
:expanded?
,
:too_large?
,
:collapsed?
,
:line_count
,
to: :diff
,
prefix:
false
:submodule?
,
:expanded?
,
:too_large?
,
:collapsed?
,
:line_count
,
:has_binary_notice?
,
to: :diff
,
prefix:
false
# Finding a viewer for a diff file happens based only on extension and whether the
# Finding a viewer for a diff file happens based only on extension and whether the
# diff file blobs are binary or text, which means 1 diff file should only be matched by 1 viewer,
# diff file blobs are binary or text, which means 1 diff file should only be matched by 1 viewer,
...
@@ -166,7 +166,7 @@ module Gitlab
...
@@ -166,7 +166,7 @@ module Gitlab
end
end
def
binary?
def
binary?
old_blob
&
.
binary?
||
new_blob
&
.
binary?
has_binary_notice?
||
old_blob
&
.
binary?
||
new_blob
&
.
binary?
end
end
def
text?
def
text?
...
...
lib/gitlab/git/diff.rb
View file @
eb36fa17
...
@@ -206,6 +206,10 @@ module Gitlab
...
@@ -206,6 +206,10 @@ module Gitlab
Diff
.
binary_message
(
@old_path
,
@new_path
)
Diff
.
binary_message
(
@old_path
,
@new_path
)
end
end
def
has_binary_notice?
@diff
.
start_with?
(
'Binary'
)
end
private
private
def
init_from_rugged
(
rugged
)
def
init_from_rugged
(
rugged
)
...
...
lib/gitlab/git/repository.rb
View file @
eb36fa17
...
@@ -475,7 +475,15 @@ module Gitlab
...
@@ -475,7 +475,15 @@ module Gitlab
# diff options. The +options+ hash can also include :break_rewrites to
# diff options. The +options+ hash can also include :break_rewrites to
# split larger rewrites into delete/add pairs.
# split larger rewrites into delete/add pairs.
def
diff
(
from
,
to
,
options
=
{},
*
paths
)
def
diff
(
from
,
to
,
options
=
{},
*
paths
)
Gitlab
::
Git
::
DiffCollection
.
new
(
diff_patches
(
from
,
to
,
options
,
*
paths
),
options
)
iterator
=
gitaly_migrate
(
:diff_between
)
do
|
is_enabled
|
if
is_enabled
gitaly_commit_client
.
diff
(
from
,
to
,
options
.
merge
(
paths:
paths
))
else
diff_patches
(
from
,
to
,
options
,
*
paths
)
end
end
Gitlab
::
Git
::
DiffCollection
.
new
(
iterator
,
options
)
end
end
# Returns a RefName for a given SHA
# Returns a RefName for a given SHA
...
...
lib/gitlab/gitaly_client/commit_service.rb
View file @
eb36fa17
...
@@ -32,20 +32,38 @@ module Gitlab
...
@@ -32,20 +32,38 @@ module Gitlab
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:commit_is_ancestor
,
request
).
value
GitalyClient
.
call
(
@repository
.
storage
,
:commit_service
,
:commit_is_ancestor
,
request
).
value
end
end
def
diff
(
from
,
to
,
options
=
{})
from_id
=
case
from
when
NilClass
EMPTY_TREE_ID
when
Rugged
::
Commit
from
.
oid
else
from
end
to_id
=
case
to
when
NilClass
EMPTY_TREE_ID
when
Rugged
::
Commit
to
.
oid
else
to
end
request_params
=
diff_between_commits_request_params
(
from_id
,
to_id
,
options
)
call_commit_diff
(
request_params
,
options
)
end
def
diff_from_parent
(
commit
,
options
=
{})
def
diff_from_parent
(
commit
,
options
=
{})
request_params
=
commit_diff_request_params
(
commit
,
options
)
request_params
=
diff_from_parent_request_params
(
commit
,
options
)
request_params
[
:ignore_whitespace_change
]
=
options
.
fetch
(
:ignore_whitespace_change
,
false
)
request_params
[
:enforce_limits
]
=
options
.
fetch
(
:limits
,
true
)
request_params
[
:collapse_diffs
]
=
request_params
[
:enforce_limits
]
||
!
options
.
fetch
(
:expanded
,
true
)
request_params
.
merge!
(
Gitlab
::
Git
::
DiffCollection
.
collection_limits
(
options
).
to_h
)
request
=
Gitaly
::
CommitDiffRequest
.
new
(
request_params
)
call_commit_diff
(
request_params
,
options
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:diff_service
,
:commit_diff
,
request
)
GitalyClient
::
DiffStitcher
.
new
(
response
)
end
end
def
commit_deltas
(
commit
)
def
commit_deltas
(
commit
)
request
=
Gitaly
::
CommitDeltaRequest
.
new
(
commit_diff
_request_params
(
commit
))
request
=
Gitaly
::
CommitDeltaRequest
.
new
(
diff_from_parent
_request_params
(
commit
))
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:diff_service
,
:commit_delta
,
request
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:diff_service
,
:commit_delta
,
request
)
response
.
flat_map
{
|
msg
|
msg
.
deltas
}
response
.
flat_map
{
|
msg
|
msg
.
deltas
}
...
@@ -214,13 +232,28 @@ module Gitlab
...
@@ -214,13 +232,28 @@ module Gitlab
private
private
def
commit_diff_request_params
(
commit
,
options
=
{})
def
call_commit_diff
(
request_params
,
options
=
{})
request_params
[
:ignore_whitespace_change
]
=
options
.
fetch
(
:ignore_whitespace_change
,
false
)
request_params
[
:enforce_limits
]
=
options
.
fetch
(
:limits
,
true
)
request_params
[
:collapse_diffs
]
=
request_params
[
:enforce_limits
]
||
!
options
.
fetch
(
:expanded
,
true
)
request_params
.
merge!
(
Gitlab
::
Git
::
DiffCollection
.
collection_limits
(
options
).
to_h
)
request
=
Gitaly
::
CommitDiffRequest
.
new
(
request_params
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:diff_service
,
:commit_diff
,
request
)
GitalyClient
::
DiffStitcher
.
new
(
response
)
end
def
diff_from_parent_request_params
(
commit
,
options
=
{})
parent_id
=
commit
.
parent_ids
.
first
||
EMPTY_TREE_ID
parent_id
=
commit
.
parent_ids
.
first
||
EMPTY_TREE_ID
diff_between_commits_request_params
(
parent_id
,
commit
.
id
,
options
)
end
def
diff_between_commits_request_params
(
from_id
,
to_id
,
options
)
{
{
repository:
@gitaly_repo
,
repository:
@gitaly_repo
,
left_commit_id:
parent
_id
,
left_commit_id:
from
_id
,
right_commit_id:
commit
.
id
,
right_commit_id:
to_
id
,
paths:
options
.
fetch
(
:paths
,
[]).
map
{
|
path
|
GitalyClient
.
encode
(
path
)
}
paths:
options
.
fetch
(
:paths
,
[]).
map
{
|
path
|
GitalyClient
.
encode
(
path
)
}
}
}
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