diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-06-20 21:39:51 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2017-06-21 11:42:08 -0300 |
commit | 0e298c55adb8ca63ca193f60f7dda84df5f627ab (patch) | |
tree | 0a6d5cdaab2b8c9da84ac2df9c5d85712389053e /lib/github/representation/branch.rb | |
parent | 6431118d85d4c3cbe108d5fa6edc202bc619b092 (diff) | |
download | gitlab-ce-0e298c55adb8ca63ca193f60f7dda84df5f627ab.tar.gz |
Fix GitHub importer performance on branch existence check
Diffstat (limited to 'lib/github/representation/branch.rb')
-rw-r--r-- | lib/github/representation/branch.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/github/representation/branch.rb b/lib/github/representation/branch.rb index d1dac6944f0..c6fa928d565 100644 --- a/lib/github/representation/branch.rb +++ b/lib/github/representation/branch.rb @@ -26,13 +26,25 @@ module Github end def exists? - branch_exists? && commit_exists? + @exists ||= branch_exists? && commit_exists? end def valid? sha.present? && ref.present? end + def restore!(name) + repository.create_branch(name, sha) + rescue Gitlab::Git::Repository::InvalidRef => e + Rails.logger.error("#{self.class.name}: Could not restore branch #{name}: #{e}") + end + + def remove!(name) + repository.delete_branch(name) + rescue Rugged::ReferenceError => e + Rails.logger.error("#{self.class.name}: Could not remove branch #{name}: #{e}") + end + private def branch_exists? |