Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1612 handle concurrency of rugged and cli git #1677

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions git/lib/git_update.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'json'
require File.join(File.expand_path('../../../lib', __FILE__), 'subprocess')
require 'ontohub_net'
require File.join(File.expand_path('../../../lib', __FILE__), 'git_repository')

class GitUpdate

Expand All @@ -26,6 +27,12 @@ def initialize(repo_path, key_id, refs)
end

def exec
Semaphore.exclusively("#{GitRepository::LOCK_NAMESPACE}:#{@repo_name}") do
exec_without_lock
end
end

def exec_without_lock

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has too many lines. [23/10]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to the PR, so don't mind.

# If its push over ssh
# we need to check user persmission per branch first
if ssh?
Expand Down
2 changes: 2 additions & 0 deletions lib/git_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class GitRepository
include GitRepository::Committing
include GitRepository::History

LOCK_NAMESPACE = 'git'.freeze

attr_reader :repo

delegate :path, :empty?, to: :repo
Expand Down
5 changes: 3 additions & 2 deletions lib/git_repository/cloning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def git_exec(*args)
args.push \
GIT_DIR: local_path.to_s,
LANG: 'C'

Subprocess.run *args
Semaphore.exclusively("#{GitRepository::LOCK_NAMESPACE}:#{repo}") do
Subprocess.run(*args)
end
end

# Yields the given block and returns the head OID
Expand Down
16 changes: 15 additions & 1 deletion lib/git_repository/committing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ def add_file(userinfo, tmp_path, target_path, message, &block)
&block)
end

# change a single file and commit the change
def commit_file(userinfo, file_contents, target_path, message, &block)
Semaphore.exclusively("#{GitRepository::LOCK_NAMESPACE}:#{repo}") do
commit_file_without_lock(userinfo,
file_contents,
target_path,
message,
&block)
end
end

# change a single file and commit the change
def commit_file_without_lock(userinfo,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has too many lines. [26/10]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to the PR, so don't mind.

file_contents,
target_path,
message,
&block)
# throw exception if path is below a file
if points_through_file?(target_path)
raise GitRepository::PathBelowFileException
Expand Down