Commit 081e2fce authored by Lin Jen-Shin's avatar Lin Jen-Shin

Try to make reserved ref names more obvious

So that whenever we want to reserve more, we're aware,
and don't mess it up.
parent d1054bd3
...@@ -114,7 +114,7 @@ class Environment < ActiveRecord::Base ...@@ -114,7 +114,7 @@ class Environment < ActiveRecord::Base
end end
def ref_path def ref_path
"refs/environments/#{Shellwords.shellescape(name)}" "refs/#{Repository::REF_ENVIRONMENTS}/#{Shellwords.shellescape(name)}"
end end
def formatted_external_url def formatted_external_url
......
...@@ -797,7 +797,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -797,7 +797,7 @@ class MergeRequest < ActiveRecord::Base
end end
def ref_path def ref_path
"refs/merge-requests/#{iid}/head" "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head"
end end
def ref_fetched? def ref_fetched?
......
require 'securerandom' require 'securerandom'
class Repository class Repository
REF_MERGE_REQUEST = 'merge-requests'
REF_KEEP_AROUND = 'keep-around'
REF_ENVIRONMENTS = 'environments'
RESERVED_REFS_NAMES = %W[
heads
tags
#{REF_ENVIRONMENTS}
#{REF_KEEP_AROUND}
#{REF_ENVIRONMENTS}
].freeze
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include RepositoryMirroring include RepositoryMirroring
...@@ -228,10 +240,10 @@ class Repository ...@@ -228,10 +240,10 @@ class Repository
begin begin
write_ref(keep_around_ref_name(sha), sha) write_ref(keep_around_ref_name(sha), sha)
rescue Rugged::ReferenceError => ex rescue Rugged::ReferenceError => ex
Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}" Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
rescue Rugged::OSError => ex rescue Rugged::OSError => ex
raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/ raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/
Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}" Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
end end
end end
...@@ -1152,7 +1164,7 @@ class Repository ...@@ -1152,7 +1164,7 @@ class Repository
end end
def keep_around_ref_name(sha) def keep_around_ref_name(sha)
"refs/keep-around/#{sha}" "refs/#{REF_KEEP_AROUND}/#{sha}"
end end
def repository_event(event, tags = {}) def repository_event(event, tags = {})
......
module Projects module Projects
class AfterImportService class AfterImportService
RESERVED_REFS_NAMES =
%w[heads tags merge-requests keep-around environments].freeze
RESERVED_REFS_REGEXP = RESERVED_REFS_REGEXP =
%r{\Arefs/(?:#{Regexp.union(*RESERVED_REFS_NAMES)})/} %r{\Arefs/(?:#{Regexp.union(*Repository::RESERVED_REFS_NAMES)})/}
def initialize(project) def initialize(project)
@project = project @project = project
......
...@@ -37,7 +37,7 @@ describe Projects::AfterImportService do ...@@ -37,7 +37,7 @@ describe Projects::AfterImportService do
end end
end end
described_class::RESERVED_REFS_NAMES.each do |name| Repository::RESERVED_REFS_NAMES.each do |name|
context "with a ref in refs/#{name}/tmp" do context "with a ref in refs/#{name}/tmp" do
before do before do
repository.write_ref("refs/#{name}/tmp", sha) repository.write_ref("refs/#{name}/tmp", sha)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment