summaryrefslogtreecommitdiff
path: root/app/models/repository.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/repository.rb')
-rw-r--r--app/models/repository.rb42
1 files changed, 29 insertions, 13 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 46a04eb80cd..e56bac509a4 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -163,7 +163,7 @@ class Repository
before_remove_branch
branch = find_branch(branch_name)
- oldrev = branch.try(:target)
+ oldrev = branch.try(:target).try(:id)
newrev = Gitlab::Git::BLANK_SHA
ref = Gitlab::Git::BRANCH_REF_PREFIX + branch_name
@@ -211,11 +211,23 @@ class Repository
return if kept_around?(sha)
- rugged.references.create(keep_around_ref_name(sha), sha)
+ # This will still fail if the file is corrupted (e.g. 0 bytes)
+ begin
+ rugged.references.create(keep_around_ref_name(sha), sha, force: true)
+ rescue Rugged::ReferenceError => ex
+ Rails.logger.error "Unable to create keep-around reference for repository #{path}: #{ex}"
+ rescue Rugged::OSError => ex
+ 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}"
+ end
end
def kept_around?(sha)
- ref_exists?(keep_around_ref_name(sha))
+ begin
+ ref_exists?(keep_around_ref_name(sha))
+ rescue Rugged::ReferenceError
+ false
+ end
end
def tag_names
@@ -360,7 +372,7 @@ class Repository
# We don't want to flush the cache if the commit didn't actually make any
# changes to any of the possible avatar files.
if revision && commit = self.commit(revision)
- return unless commit.diffs.
+ return unless commit.raw_diffs(deltas_only: true).
any? { |diff| AVATAR_FILES.include?(diff.new_path) }
end
@@ -589,7 +601,7 @@ class Repository
commit(sha)
end
- def next_branch(name, opts={})
+ def next_branch(name, opts = {})
branch_ids = self.branch_names.map do |n|
next 1 if n == name
result = n.match(/\A#{name}-([0-9]+)\z/)
@@ -606,11 +618,13 @@ class Repository
# Remove archives older than 2 hours
def branches_sorted_by(value)
case value
- when 'recently_updated'
+ when 'name'
+ branches.sort_by(&:name)
+ when 'updated_desc'
branches.sort do |a, b|
commit(b.target).committed_date <=> commit(a.target).committed_date
end
- when 'last_updated'
+ when 'updated_asc'
branches.sort do |a, b|
commit(a.target).committed_date <=> commit(b.target).committed_date
end
@@ -622,9 +636,7 @@ class Repository
def tags_sorted_by(value)
case value
when 'name'
- # Would be better to use `sort_by` but `version_sorter` only exposes
- # `sort` and `rsort`
- VersionSorter.rsort(tag_names).map { |tag_name| find_tag(tag_name) }
+ VersionSorter.rsort(tags) { |tag| tag.name }
when 'updated_desc'
tags_sorted_by_committed_date.reverse
when 'updated_asc'
@@ -963,7 +975,7 @@ class Repository
was_empty = empty?
if !was_empty && target_branch
- oldrev = target_branch.target
+ oldrev = target_branch.target.id
end
# Make commit
@@ -977,9 +989,13 @@ class Repository
if was_empty || !target_branch
# Create branch
rugged.references.create(ref, newrev)
+
+ # If repo was empty expire cache
+ after_create if was_empty
+ after_create_branch
else
# Update head
- current_head = find_branch(branch).target
+ current_head = find_branch(branch).target.id
# Make sure target branch was not changed during pre-receive hook
if current_head == oldrev
@@ -1025,7 +1041,7 @@ class Repository
private
def cache
- @cache ||= RepositoryCache.new(path_with_namespace)
+ @cache ||= RepositoryCache.new(path_with_namespace, @project.id)
end
def head_exists?