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
0187018e
Commit
0187018e
authored
Sep 01, 2017
by
Jacob Vosmaer (GitLab)
Committed by
Douwe Maan
Sep 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify Git interactions in AfterImportService
parent
7d3e888d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
app/services/projects/after_import_service.rb
app/services/projects/after_import_service.rb
+2
-7
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+8
-2
No files found.
app/services/projects/after_import_service.rb
View file @
0187018e
module
Projects
class
AfterImportService
RESERVED_REFS_REGEXP
=
%r{
\A
refs/(?:
#{
Regexp
.
union
(
*
Repository
::
RESERVED_REFS_NAMES
)
}
)/}
RESERVED_REF_PREFIXES
=
Repository
::
RESERVED_REFS_NAMES
.
map
{
|
n
|
File
.
join
(
'refs'
,
n
,
'/'
)
}
def
initialize
(
project
)
@project
=
project
...
...
@@ -9,7 +8,7 @@ module Projects
def
execute
Projects
::
HousekeepingService
.
new
(
@project
).
execute
do
repository
.
delete_
refs
(
*
garbage_refs
)
repository
.
delete_
all_refs_except
(
RESERVED_REF_PREFIXES
)
end
rescue
Projects
::
HousekeepingService
::
LeaseTaken
=>
e
Rails
.
logger
.
info
(
...
...
@@ -18,10 +17,6 @@ module Projects
private
def
garbage_refs
@garbage_refs
||=
repository
.
all_ref_names_except
(
RESERVED_REFS_REGEXP
)
end
def
repository
@repository
||=
@project
.
repository
end
...
...
lib/gitlab/git/repository.rb
View file @
0187018e
...
...
@@ -250,11 +250,17 @@ module Gitlab
branch_names
+
tag_names
end
def
delete_all_refs_except
(
prefixes
)
delete_refs
(
*
all_ref_names_except
(
prefixes
))
end
# Returns an Array of all ref names, except when it's matching pattern
#
# regexp - The pattern for ref names we don't want
def
all_ref_names_except
(
regexp
)
rugged
.
references
.
reject
{
|
ref
|
ref
.
name
=~
regexp
}.
map
(
&
:name
)
def
all_ref_names_except
(
prefixes
)
rugged
.
references
.
reject
do
|
ref
|
prefixes
.
any?
{
|
p
|
ref
.
name
.
start_with?
(
p
)
}
end
.
map
(
&
:name
)
end
# Discovers the default branch based on the repository's available branches
...
...
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