BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8384d0d8
Commit
8384d0d8
authored
Dec 08, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce Repository#with_tmp_ref which we need
commits from the other repository. We'll cleanup the tmp ref after we're done with our business.
parent
23032467
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
29 deletions
+54
-29
compare_controller.rb
app/controllers/projects/compare_controller.rb
+2
-1
merge_request_diff.rb
app/models/merge_request_diff.rb
+2
-1
repository.rb
app/models/repository.rb
+15
-0
compare_service.rb
app/services/compare_service.rb
+18
-12
git_operation_service.rb
app/services/git_operation_service.rb
+7
-8
build_service.rb
app/services/merge_requests/build_service.rb
+3
-2
emails_on_push_worker.rb
app/workers/emails_on_push_worker.rb
+4
-2
compare_service_spec.rb
spec/services/compare_service_spec.rb
+3
-3
No files found.
app/controllers/projects/compare_controller.rb
View file @
8384d0d8
...
@@ -37,7 +37,8 @@ class Projects::CompareController < Projects::ApplicationController
...
@@ -37,7 +37,8 @@ class Projects::CompareController < Projects::ApplicationController
end
end
def
define_diff_vars
def
define_diff_vars
@compare
=
CompareService
.
new
.
execute
(
@project
,
@head_ref
,
@project
,
@start_ref
)
@compare
=
CompareService
.
new
(
@project
,
@head_ref
).
execute
(
@project
,
@start_ref
)
if
@compare
if
@compare
@commits
=
@compare
.
commits
@commits
=
@compare
.
commits
...
...
app/models/merge_request_diff.rb
View file @
8384d0d8
...
@@ -169,7 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base
...
@@ -169,7 +169,8 @@ class MergeRequestDiff < ActiveRecord::Base
# When compare merge request versions we want diff A..B instead of A...B
# When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user does squash and rebase of the commits between versions.
# so we handle cases when user does squash and rebase of the commits between versions.
# For this reason we set straight to true by default.
# For this reason we set straight to true by default.
CompareService
.
new
.
execute
(
project
,
head_commit_sha
,
project
,
sha
,
straight:
straight
)
CompareService
.
new
(
project
,
head_commit_sha
).
execute
(
project
,
sha
,
straight:
straight
)
end
end
def
commits_count
def
commits_count
...
...
app/models/repository.rb
View file @
8384d0d8
...
@@ -1099,6 +1099,21 @@ class Repository
...
@@ -1099,6 +1099,21 @@ class Repository
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
lines
.
map
(
&
:strip
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
).
first
.
lines
.
map
(
&
:strip
)
end
end
def
with_tmp_ref
(
source_repository
,
source_branch_name
)
random_string
=
SecureRandom
.
hex
fetch_ref
(
source_repository
.
path_to_repo
,
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
source_branch_name
}
"
,
"refs/tmp/
#{
random_string
}
/head"
)
yield
ensure
FileUtils
.
rm_rf
(
"
#{
path_to_repo
}
/refs/tmp/
#{
random_string
}
"
)
end
def
fetch_ref
(
source_path
,
source_ref
,
target_ref
)
def
fetch_ref
(
source_path
,
source_ref
,
target_ref
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch --no-tags -f
#{
source_path
}
#{
source_ref
}
:
#{
target_ref
}
)
args
=
%W(
#{
Gitlab
.
config
.
git
.
bin_path
}
fetch --no-tags -f
#{
source_path
}
#{
source_ref
}
:
#{
target_ref
}
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
)
Gitlab
::
Popen
.
popen
(
args
,
path_to_repo
)
...
...
app/services/compare_service.rb
View file @
8384d0d8
...
@@ -3,23 +3,29 @@ require 'securerandom'
...
@@ -3,23 +3,29 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories
# Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs
# and return Gitlab::Git::Compare object that responds to commits and diffs
class
CompareService
class
CompareService
def
execute
(
source_project
,
source_branch
,
target_project
,
target_branch
,
straight:
false
)
attr_reader
:source_project
,
:source_sha
source_commit
=
source_project
.
commit
(
source_branch
)
return
unless
source_commit
source_sha
=
source_commit
.
sha
def
initialize
(
new_source_project
,
source_branch
)
@source_project
=
new_source_project
@source_sha
=
new_source_project
.
commit
(
source_branch
).
try
(
:sha
)
end
# If compare with other project we need to fetch ref first
def
execute
(
target_project
,
target_branch
,
straight:
false
)
unless
target_project
==
source_project
return
unless
source_sha
random_string
=
SecureRandom
.
hex
target_project
.
repository
.
fetch_ref
(
# If compare with other project we need to fetch ref first
source_project
.
repository
.
path_to_repo
,
if
target_project
==
source_project
"refs/heads/
#{
source_branch
}
"
,
compare
(
target_project
,
target_branch
,
straight
)
"refs/tmp/
#{
random_string
}
/head"
else
)
target_project
.
repository
.
with_tmp_ref
(
source_project
,
source_branch
)
do
compare
(
target_project
,
target_branch
,
straight
)
end
end
end
end
private
def
compare
(
target_project
,
target_branch
,
straight
)
raw_compare
=
Gitlab
::
Git
::
Compare
.
new
(
raw_compare
=
Gitlab
::
Git
::
Compare
.
new
(
target_project
.
repository
.
raw_repository
,
target_project
.
repository
.
raw_repository
,
target_branch
,
target_branch
,
...
...
app/services/git_operation_service.rb
View file @
8384d0d8
...
@@ -38,15 +38,14 @@ GitOperationService = Struct.new(:user, :repository) do
...
@@ -38,15 +38,14 @@ GitOperationService = Struct.new(:user, :repository) do
branch_name
,
source_branch_name
,
source_project
)
branch_name
,
source_branch_name
,
source_project
)
update_branch_with_hooks
(
branch_name
)
do
|
ref
|
update_branch_with_hooks
(
branch_name
)
do
|
ref
|
if
repository
.
project
!=
source_project
if
repository
.
project
==
source_project
repository
.
fetch_ref
(
source_project
.
repository
.
path_to_repo
,
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
source_branch_name
}
"
,
"
#{
Gitlab
::
Git
::
BRANCH_REF_PREFIX
}#{
branch_name
}
"
)
end
yield
(
ref
)
yield
(
ref
)
else
repository
.
with_tmp_ref
(
source_project
.
repository
,
source_branch_name
)
do
yield
(
ref
)
end
end
end
end
end
end
...
...
app/services/merge_requests/build_service.rb
View file @
8384d0d8
...
@@ -16,9 +16,10 @@ module MergeRequests
...
@@ -16,9 +16,10 @@ module MergeRequests
messages
=
validate_branches
(
merge_request
)
messages
=
validate_branches
(
merge_request
)
return
build_failed
(
merge_request
,
messages
)
unless
messages
.
empty?
return
build_failed
(
merge_request
,
messages
)
unless
messages
.
empty?
compare
=
CompareService
.
new
.
execute
(
compare
=
CompareService
.
new
(
merge_request
.
source_project
,
merge_request
.
source_project
,
merge_request
.
source_branch
,
merge_request
.
source_branch
).
execute
(
merge_request
.
target_project
,
merge_request
.
target_project
,
merge_request
.
target_branch
,
merge_request
.
target_branch
,
)
)
...
...
app/workers/emails_on_push_worker.rb
View file @
8384d0d8
...
@@ -33,13 +33,15 @@ class EmailsOnPushWorker
...
@@ -33,13 +33,15 @@ class EmailsOnPushWorker
reverse_compare
=
false
reverse_compare
=
false
if
action
==
:push
if
action
==
:push
compare
=
CompareService
.
new
.
execute
(
project
,
after_sha
,
project
,
before_sha
)
compare
=
CompareService
.
new
(
project
,
after_sha
).
execute
(
project
,
before_sha
)
diff_refs
=
compare
.
diff_refs
diff_refs
=
compare
.
diff_refs
return
false
if
compare
.
same
return
false
if
compare
.
same
if
compare
.
commits
.
empty?
if
compare
.
commits
.
empty?
compare
=
CompareService
.
new
.
execute
(
project
,
before_sha
,
project
,
after_sha
)
compare
=
CompareService
.
new
(
project
,
before_sha
).
execute
(
project
,
after_sha
)
diff_refs
=
compare
.
diff_refs
diff_refs
=
compare
.
diff_refs
reverse_compare
=
true
reverse_compare
=
true
...
...
spec/services/compare_service_spec.rb
View file @
8384d0d8
...
@@ -3,17 +3,17 @@ require 'spec_helper'
...
@@ -3,17 +3,17 @@ require 'spec_helper'
describe
CompareService
,
services:
true
do
describe
CompareService
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
described_class
.
new
}
let
(
:service
)
{
described_class
.
new
(
project
,
'feature'
)
}
describe
'#execute'
do
describe
'#execute'
do
context
'compare with base, like feature...fix'
do
context
'compare with base, like feature...fix'
do
subject
{
service
.
execute
(
project
,
'f
eature'
,
project
,
'f
ix'
,
straight:
false
)
}
subject
{
service
.
execute
(
project
,
'fix'
,
straight:
false
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
1
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
1
)
}
end
end
context
'straight compare, like feature..fix'
do
context
'straight compare, like feature..fix'
do
subject
{
service
.
execute
(
project
,
'f
eature'
,
project
,
'f
ix'
,
straight:
true
)
}
subject
{
service
.
execute
(
project
,
'fix'
,
straight:
true
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
3
)
}
it
{
expect
(
subject
.
diffs
.
size
).
to
eq
(
3
)
}
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