-
Notifications
You must be signed in to change notification settings - Fork 533
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
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3d789f7
[WIP]Start replacing Dir.chdir with paths
3ad8851
Merge branch 'master' into 355
taquitos ba1df97
Merge branch 'master' into 355
taquitos f3f7518
fork() when using Dir.chdir, otherwise, use a mutex
f1cd6de
Merge pull request #1 from taquitos/355
taquitos df31b57
fork() when using Dir.chdir, otherwise, use a mutex
22ae609
wrap calls to in a semaphore
5449c01
Merge pull request #2 from taquitos/355
taquitos ae1baa3
Merge remote-tracking branch 'upstream/master'
e57f46f
Merge remote-tracking branch 'upstream/master'
0d32576
Revert "355"
taquitos a100a36
Merge pull request #3 from taquitos/revert-2-355
taquitos 1cdc5fd
Revert "355"
taquitos cdcc6a5
Merge pull request #4 from taquitos/revert-1-355
taquitos 0fb9798
Isolate Dir.chdir to a new process, or mutex
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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. calls to config also should be protected, but it might be heavy handed to |
||
|
||
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) | ||
else | ||
build_list.call | ||
end | ||
end | ||
end | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Very good fix, absolutely no reason to
chdir
in this case. 🤦♂️