summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-08-30 21:15:06 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-08-30 22:01:23 +0800
commitc5553ce772371295d2d7652cec899633042fae07 (patch)
treeeb8f9a5ede93f7edaa8dd1eeb8960b95f9697dd0 /lib
parent86149a82168e9aead7ce6841c69705662f8a6e54 (diff)
downloadgitlab-ce-c5553ce772371295d2d7652cec899633042fae07.tar.gz
Use `git update-ref --stdin -z` to delete refs36807-gc-unwanted-refs-after-import
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb18
-rw-r--r--lib/tasks/gitlab/cleanup.rake2
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 8b39e92cc65..fb6504bdea0 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -17,6 +17,7 @@ module Gitlab
NoRepository = Class.new(StandardError)
InvalidBlobName = Class.new(StandardError)
InvalidRef = Class.new(StandardError)
+ GitError = Class.new(StandardError)
class << self
# Unlike `new`, `create` takes the storage path, not the storage name
@@ -598,8 +599,21 @@ module Gitlab
rugged.branches.delete(branch_name)
end
- def delete_refs(ref_names)
- ref_names.each { |ref| rugged.references.delete(ref) }
+ def delete_refs(*ref_names)
+ instructions = ref_names.map do |ref|
+ "delete #{ref}\x00\x00"
+ end
+
+ command = %W[#{Gitlab.config.git.bin_path} update-ref --stdin -z]
+ message, status = Gitlab::Popen.popen(
+ command,
+ path) do |stdin|
+ stdin.write(instructions.join)
+ end
+
+ unless status.zero?
+ raise GitError.new("Could not delete refs #{ref_names}: #{message}")
+ end
end
# Create a new branch named **ref+ based on **stat_point+, HEAD by default
diff --git a/lib/tasks/gitlab/cleanup.rake b/lib/tasks/gitlab/cleanup.rake
index f76bef5f4bf..8ae1b6a626a 100644
--- a/lib/tasks/gitlab/cleanup.rake
+++ b/lib/tasks/gitlab/cleanup.rake
@@ -111,7 +111,7 @@ namespace :gitlab do
next unless id > max_iid
project.deployments.find(id).create_ref
- rugged.references.delete(ref)
+ project.repository.delete_refs(ref)
end
end
end