Skip to content

Isolate Dir.chdir to a new process, or mutex #372

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

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wrap calls to in a semaphore
Signed-off-by: Joshua Liebowitz <taquitos@google.com>
  • Loading branch information
Joshua Liebowitz committed Jun 25, 2018
commit 22ae6097c928ec579cbe28be4c8bd9165c4a7ed4
29 changes: 21 additions & 8 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class GitExecuteError < StandardError
class Lib

@@semaphore = Mutex.new
@@config_semaphore = Mutex.new
Copy link
Contributor Author

Choose a reason for hiding this comment

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

calls to config also should be protected, but it might be heavy handed to fork


def initialize(base = nil, logger = nil)
@git_dir = nil
Expand Down Expand Up @@ -438,23 +439,35 @@ def config_remote(name)
end

def config_get(name)
do_get = lambda do |path|
command('config', ['--get', name])
end
@@config_semaphore.synchronize do
do_get = lambda do |path|
command('config', ['--get', name])
end

do_get.call(@git_dir)
if @git_dir
Dir.chdir(@git_dir, &do_get)
else
do_get.call
end
end
end

def global_config_get(name)
command('config', ['--global', '--get', name], false)
end

def config_list
build_list = lambda do |path|
parse_config_list command_lines('config', ['--list'])
end
@@config_semaphore.synchronize do
build_list = lambda do |path|
parse_config_list command_lines('config', ['--list'])
end

build_list.call(@git_dir)
if @git_dir
Dir.chdir(@git_dir, &build_list)
else
build_list.call
end
end
end

def global_config_list
Expand Down