-
Notifications
You must be signed in to change notification settings - Fork 533
Reduce and isolate usage of Dir.chdir #383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ class GitExecuteError < StandardError | |
class Lib | ||
|
||
@@semaphore = Mutex.new | ||
@@config_semaphore = Mutex.new | ||
|
||
def initialize(base = nil, logger = nil) | ||
@git_dir = nil | ||
|
@@ -310,7 +311,7 @@ def branches_all | |
def list_files(ref_dir) | ||
dir = File.join(@git_dir, 'refs', ref_dir) | ||
files = [] | ||
Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } } rescue nil | ||
files = Dir.glob(File.join(dir, '**/*')).select { |f| File.file?(f) } rescue nil | ||
files | ||
end | ||
|
||
|
@@ -441,14 +442,16 @@ 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 | ||
|
||
if @git_dir | ||
Dir.chdir(@git_dir, &do_get) | ||
else | ||
do_get.call | ||
if @git_dir | ||
Dir.chdir(@git_dir, &do_get) | ||
else | ||
do_get.call | ||
end | ||
end | ||
end | ||
|
||
|
@@ -457,14 +460,16 @@ def global_config_get(name) | |
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 | ||
|
||
if @git_dir | ||
Dir.chdir(@git_dir, &build_list) | ||
else | ||
build_list.call | ||
if @git_dir | ||
Dir.chdir(@git_dir, &build_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, not thread-safe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I thought I took care of these, might just be a merge issue. I'm offline for a week now, but will take a look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
else | ||
build_list.call | ||
end | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is still non-threadsafe - was this intentional?