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
b58c4f43
Commit
b58c4f43
authored
Sep 01, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'delete-branches-with-prefixes' into 'master'
Simplify Git interactions in AfterImportService See merge request !13962
parents
7d3e888d
0187018e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
after_import_service.rb
app/services/projects/after_import_service.rb
+2
-7
repository.rb
lib/gitlab/git/repository.rb
+8
-2
No files found.
app/services/projects/after_import_service.rb
View file @
b58c4f43
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 @
b58c4f43
...
...
@@ -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