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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
49e9347e
Commit
49e9347e
authored
Jan 22, 2018
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Gitlab::Git::Repository#run_git private
parent
dcb79741
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
83 deletions
+97
-83
app/models/repository.rb
app/models/repository.rb
+15
-66
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+82
-17
No files found.
app/models/repository.rb
View file @
49e9347e
...
@@ -166,16 +166,10 @@ class Repository
...
@@ -166,16 +166,10 @@ class Repository
return
[]
return
[]
end
end
raw_repository
.
gitaly_migrate
(
:commits_by_message
)
do
|
is_enabled
|
commits
=
raw_repository
.
find_commits_by_message
(
query
,
ref
,
path
,
limit
,
offset
).
map
do
|
c
|
commits
=
commit
(
c
)
if
is_enabled
find_commits_by_message_by_gitaly
(
query
,
ref
,
path
,
limit
,
offset
)
else
find_commits_by_message_by_shelling_out
(
query
,
ref
,
path
,
limit
,
offset
)
end
CommitCollection
.
new
(
project
,
commits
,
ref
)
end
end
CommitCollection
.
new
(
project
,
commits
,
ref
)
end
end
def
find_branch
(
name
,
fresh_repo:
true
)
def
find_branch
(
name
,
fresh_repo:
true
)
...
@@ -740,23 +734,6 @@ class Repository
...
@@ -740,23 +734,6 @@ class Repository
Commit
.
order_by
(
collection:
commits
,
order_by:
order_by
,
sort:
sort
)
Commit
.
order_by
(
collection:
commits
,
order_by:
order_by
,
sort:
sort
)
end
end
def
refs_contains_sha
(
ref_type
,
sha
)
args
=
%W(
#{
ref_type
}
--contains
#{
sha
}
)
names
=
run_git
(
args
).
first
if
names
.
respond_to?
(
:split
)
names
=
names
.
split
(
"
\n
"
).
map
(
&
:strip
)
names
.
each
do
|
name
|
name
.
slice!
'* '
end
names
else
[]
end
end
def
branch_names_contains
(
sha
)
def
branch_names_contains
(
sha
)
refs_contains_sha
(
'branch'
,
sha
)
refs_contains_sha
(
'branch'
,
sha
)
end
end
...
@@ -921,25 +898,6 @@ class Repository
...
@@ -921,25 +898,6 @@ class Repository
end
end
end
end
def
search_files_by_content
(
query
,
ref
)
return
[]
if
empty?
||
query
.
blank?
offset
=
2
args
=
%W(grep -i -I -n -z --before-context
#{
offset
}
--after-context
#{
offset
}
-E -e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_ref
}
)
run_git
(
args
).
first
.
scrub
.
split
(
/^--$/
)
end
def
search_files_by_name
(
query
,
ref
)
safe_query
=
Regexp
.
escape
(
query
.
sub
(
/^\/*/
,
""
))
return
[]
if
empty?
||
safe_query
.
blank?
args
=
%W(ls-tree --full-tree -r
#{
ref
||
root_ref
}
--name-status |
#{
safe_query
}
)
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
end
def
fetch_as_mirror
(
url
,
forced:
false
,
refmap: :all_refs
,
remote_name:
nil
)
def
fetch_as_mirror
(
url
,
forced:
false
,
refmap: :all_refs
,
remote_name:
nil
)
unless
remote_name
unless
remote_name
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
remote_name
=
"tmp-
#{
SecureRandom
.
hex
}
"
...
@@ -973,6 +931,18 @@ class Repository
...
@@ -973,6 +931,18 @@ class Repository
raw_repository
.
ls_files
(
actual_ref
)
raw_repository
.
ls_files
(
actual_ref
)
end
end
def
search_files_by_content
(
query
,
ref
)
return
[]
if
empty?
||
query
.
blank?
raw_repository
.
search_files_by_content
(
query
,
ref
)
end
def
search_files_by_name
(
query
,
ref
)
return
[]
if
empty?
raw_repository
.
search_files_by_name
(
query
,
ref
)
end
def
copy_gitattributes
(
ref
)
def
copy_gitattributes
(
ref
)
actual_ref
=
ref
||
root_ref
actual_ref
=
ref
||
root_ref
begin
begin
...
@@ -1133,25 +1103,4 @@ class Repository
...
@@ -1133,25 +1103,4 @@ class Repository
def
rugged_can_be_merged?
(
their_commit
,
our_commit
)
def
rugged_can_be_merged?
(
their_commit
,
our_commit
)
!
rugged
.
merge_commits
(
our_commit
,
their_commit
).
conflicts?
!
rugged
.
merge_commits
(
our_commit
,
their_commit
).
conflicts?
end
end
def
find_commits_by_message_by_shelling_out
(
query
,
ref
,
path
,
limit
,
offset
)
ref
||=
root_ref
args
=
%W(
log
#{
ref
}
--pretty=%H --skip
#{
offset
}
--max-count
#{
limit
}
--grep=
#{
query
}
--regexp-ignore-case
)
args
=
args
.
concat
(
%W(--
#{
path
}
)
)
if
path
.
present?
git_log_results
=
run_git
(
args
).
first
.
lines
git_log_results
.
map
{
|
c
|
commit
(
c
.
chomp
)
}.
compact
end
def
find_commits_by_message_by_gitaly
(
query
,
ref
,
path
,
limit
,
offset
)
raw_repository
.
gitaly_commit_client
.
commits_by_message
(
query
,
revision:
ref
,
path:
path
,
limit:
limit
,
offset:
offset
)
.
map
{
|
c
|
commit
(
c
)
}
end
end
end
lib/gitlab/git/repository.rb
View file @
49e9347e
...
@@ -1109,23 +1109,6 @@ module Gitlab
...
@@ -1109,23 +1109,6 @@ module Gitlab
target_ref
target_ref
end
end
# Refactoring aid; allows us to copy code from app/models/repository.rb
def
run_git
(
args
,
chdir:
path
,
env:
{},
nice:
false
,
&
block
)
cmd
=
[
Gitlab
.
config
.
git
.
bin_path
,
*
args
]
cmd
.
unshift
(
"nice"
)
if
nice
circuit_breaker
.
perform
do
popen
(
cmd
,
chdir
,
env
,
&
block
)
end
end
def
run_git!
(
args
,
chdir:
path
,
env:
{},
nice:
false
,
&
block
)
output
,
status
=
run_git
(
args
,
chdir:
chdir
,
env:
env
,
nice:
nice
,
&
block
)
raise
GitError
,
output
unless
status
.
zero?
output
end
# Refactoring aid; allows us to copy code from app/models/repository.rb
# Refactoring aid; allows us to copy code from app/models/repository.rb
def
run_git_with_timeout
(
args
,
timeout
,
env:
{})
def
run_git_with_timeout
(
args
,
timeout
,
env:
{})
circuit_breaker
.
perform
do
circuit_breaker
.
perform
do
...
@@ -1349,6 +1332,52 @@ module Gitlab
...
@@ -1349,6 +1332,52 @@ module Gitlab
raise
CommandError
.
new
(
e
)
raise
CommandError
.
new
(
e
)
end
end
def
refs_contains_sha
(
ref_type
,
sha
)
args
=
%W(
#{
ref_type
}
--contains
#{
sha
}
)
names
=
run_git
(
args
).
first
if
names
.
respond_to?
(
:split
)
names
=
names
.
split
(
"
\n
"
).
map
(
&
:strip
)
names
.
each
do
|
name
|
name
.
slice!
'* '
end
names
else
[]
end
end
def
search_files_by_content
(
query
,
ref
)
return
[]
if
empty?
||
query
.
blank?
offset
=
2
args
=
%W(grep -i -I -n -z --before-context
#{
offset
}
--after-context
#{
offset
}
-E -e
#{
Regexp
.
escape
(
query
)
}
#{
ref
||
root_ref
}
)
run_git
(
args
).
first
.
scrub
.
split
(
/^--$/
)
end
def
search_files_by_name
(
query
,
ref
)
safe_query
=
Regexp
.
escape
(
query
.
sub
(
/^\/*/
,
""
))
return
[]
if
empty?
||
safe_query
.
blank?
args
=
%W(ls-tree --full-tree -r
#{
ref
||
root_ref
}
--name-status |
#{
safe_query
}
)
run_git
(
args
).
first
.
lines
.
map
(
&
:strip
)
end
def
find_commits_by_message
(
query
,
ref
,
path
,
limit
,
offset
)
gitaly_migrate
(
:commits_by_message
)
do
|
is_enabled
|
if
is_enabled
find_commits_by_message_by_gitaly
(
query
,
ref
,
path
,
limit
,
offset
)
else
find_commits_by_message_by_shelling_out
(
query
,
ref
,
path
,
limit
,
offset
)
end
end
end
private
private
def
shell_write_ref
(
ref_path
,
ref
,
old_ref
)
def
shell_write_ref
(
ref_path
,
ref
,
old_ref
)
...
@@ -1370,6 +1399,22 @@ module Gitlab
...
@@ -1370,6 +1399,22 @@ module Gitlab
Rails
.
logger
.
error
"Unable to create
#{
ref_path
}
reference for repository
#{
path
}
:
#{
ex
}
"
Rails
.
logger
.
error
"Unable to create
#{
ref_path
}
reference for repository
#{
path
}
:
#{
ex
}
"
end
end
def
run_git
(
args
,
chdir:
path
,
env:
{},
nice:
false
,
&
block
)
cmd
=
[
Gitlab
.
config
.
git
.
bin_path
,
*
args
]
cmd
.
unshift
(
"nice"
)
if
nice
circuit_breaker
.
perform
do
popen
(
cmd
,
chdir
,
env
,
&
block
)
end
end
def
run_git!
(
args
,
chdir:
path
,
env:
{},
nice:
false
,
&
block
)
output
,
status
=
run_git
(
args
,
chdir:
chdir
,
env:
env
,
nice:
nice
,
&
block
)
raise
GitError
,
output
unless
status
.
zero?
output
end
def
fresh_worktree?
(
path
)
def
fresh_worktree?
(
path
)
File
.
exist?
(
path
)
&&
!
clean_stuck_worktree
(
path
)
File
.
exist?
(
path
)
&&
!
clean_stuck_worktree
(
path
)
end
end
...
@@ -2124,6 +2169,26 @@ module Gitlab
...
@@ -2124,6 +2169,26 @@ module Gitlab
def
gitlab_projects_error
def
gitlab_projects_error
raise
CommandError
,
@gitlab_projects
.
output
raise
CommandError
,
@gitlab_projects
.
output
end
end
def
find_commits_by_message_by_shelling_out
(
query
,
ref
,
path
,
limit
,
offset
)
ref
||=
root_ref
args
=
%W(
log
#{
ref
}
--pretty=%H --skip
#{
offset
}
--max-count
#{
limit
}
--grep=
#{
query
}
--regexp-ignore-case
)
args
=
args
.
concat
(
%W(--
#{
path
}
)
)
if
path
.
present?
git_log_results
=
run_git
(
args
).
first
.
lines
git_log_results
.
map
{
|
c
|
commit
(
c
.
chomp
)
}.
compact
end
def
find_commits_by_message_by_gitaly
(
query
,
ref
,
path
,
limit
,
offset
)
gitaly_commit_client
.
commits_by_message
(
query
,
revision:
ref
,
path:
path
,
limit:
limit
,
offset:
offset
)
.
map
{
|
c
|
commit
(
c
)
}
end
end
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