Commit 0ebcc60a33f5aba9e7740f43a108b96461dd3fbf
1 parent
0e9d4f30
Exists in
master
and in
4 other branches
Move locking from Satellite::Action to Satellite and add checks
Showing
2 changed files
with
27 additions
and
22 deletions
Show diff stats
lib/gitlab/satellite/action.rb
| ... | ... | @@ -18,18 +18,8 @@ module Gitlab |
| 18 | 18 | # * Yields the prepared satellite repo |
| 19 | 19 | def in_locked_and_timed_satellite |
| 20 | 20 | Grit::Git.with_timeout(options[:git_timeout]) do |
| 21 | - File.open(lock_file, "w+") do |f| | |
| 22 | - f.flock(File::LOCK_EX) | |
| 23 | - | |
| 24 | - unless project.satellite.exists? | |
| 25 | - raise "Satellite doesn't exist" | |
| 26 | - end | |
| 27 | - | |
| 28 | - Dir.chdir(project.satellite.path) do | |
| 29 | - repo = Grit::Repo.new('.') | |
| 30 | - | |
| 31 | - return yield repo | |
| 32 | - end | |
| 21 | + project.satellite.lock do | |
| 22 | + return yield project.satellite.repo | |
| 33 | 23 | end |
| 34 | 24 | end |
| 35 | 25 | rescue Errno::ENOMEM => ex |
| ... | ... | @@ -40,10 +30,6 @@ module Gitlab |
| 40 | 30 | return false |
| 41 | 31 | end |
| 42 | 32 | |
| 43 | - def lock_file | |
| 44 | - Rails.root.join("tmp", "#{project.path}.lock") | |
| 45 | - end | |
| 46 | - | |
| 47 | 33 | # * Clears the satellite |
| 48 | 34 | # * Updates the satellite from Gitolite |
| 49 | 35 | # * Sets up Git variables for the user | ... | ... |
lib/gitlab/satellite/satellite.rb
| ... | ... | @@ -10,6 +10,8 @@ module Gitlab |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | 12 | def clear_and_update! |
| 13 | + raise "Satellite doesn't exist" unless exists? | |
| 14 | + | |
| 13 | 15 | delete_heads! |
| 14 | 16 | clear_working_dir! |
| 15 | 17 | update_from_source! |
| ... | ... | @@ -23,10 +25,31 @@ module Gitlab |
| 23 | 25 | File.exists? path |
| 24 | 26 | end |
| 25 | 27 | |
| 28 | + # Locks the satellite and yields | |
| 29 | + def lock | |
| 30 | + raise "Satellite doesn't exist" unless exists? | |
| 31 | + | |
| 32 | + File.open(lock_file, "w+") do |f| | |
| 33 | + f.flock(File::LOCK_EX) | |
| 34 | + | |
| 35 | + return yield | |
| 36 | + end | |
| 37 | + end | |
| 38 | + | |
| 39 | + def lock_file | |
| 40 | + Rails.root.join("tmp", "#{project.path}.lock") | |
| 41 | + end | |
| 42 | + | |
| 26 | 43 | def path |
| 27 | 44 | Rails.root.join("tmp", "repo_satellites", project.path) |
| 28 | 45 | end |
| 29 | 46 | |
| 47 | + def repo | |
| 48 | + raise "Satellite doesn't exist" unless exists? | |
| 49 | + | |
| 50 | + @repo ||= Grit::Repo.new(path) | |
| 51 | + end | |
| 52 | + | |
| 30 | 53 | private |
| 31 | 54 | |
| 32 | 55 | # Clear the working directory |
| ... | ... | @@ -39,7 +62,7 @@ module Gitlab |
| 39 | 62 | # This ensures we have no name clashes or issues updating branches when |
| 40 | 63 | # working with the satellite. |
| 41 | 64 | def delete_heads! |
| 42 | - heads = repo.heads.map{|head| head.name} | |
| 65 | + heads = repo.heads.map(&:name) | |
| 43 | 66 | |
| 44 | 67 | # update or create the parking branch |
| 45 | 68 | if heads.include? PARKING_BRANCH |
| ... | ... | @@ -54,15 +77,11 @@ module Gitlab |
| 54 | 77 | heads.each { |head| repo.git.branch({D: true}, head) } |
| 55 | 78 | end |
| 56 | 79 | |
| 57 | - def repo | |
| 58 | - @repo ||= Grit::Repo.new(path) | |
| 59 | - end | |
| 60 | - | |
| 61 | 80 | # Updates the satellite from Gitolite |
| 62 | 81 | # |
| 63 | 82 | # Note: this will only update remote branches (i.e. origin/*) |
| 64 | 83 | def update_from_source! |
| 65 | - repo.git.fetch({}, :origin) | |
| 84 | + repo.git.fetch({timeout: true}, :origin) | |
| 66 | 85 | end |
| 67 | 86 | end |
| 68 | 87 | end | ... | ... |