7
7
module Git
8
8
class Lib
9
9
10
- @@semaphore = Mutex . new
11
-
12
10
# The path to the Git working copy. The default is '"./.git"'.
13
11
#
14
12
# @return [Pathname] the path to the Git working copy.
@@ -442,10 +440,7 @@ def worktree_prune
442
440
def list_files ( ref_dir )
443
441
dir = File . join ( @git_dir , 'refs' , ref_dir )
444
442
files = [ ]
445
- begin
446
- files = Dir . glob ( '**/*' , base : dir ) . select { |f | File . file? ( File . join ( dir , f ) ) }
447
- rescue
448
- end
443
+ files = Dir . glob ( File . join ( dir , '**/*' ) ) . select { |f | File . file? ( f ) } rescue nil
449
444
files
450
445
end
451
446
@@ -1146,41 +1141,14 @@ def command_lines(cmd, *opts, chdir: nil)
1146
1141
op . split ( "\n " )
1147
1142
end
1148
1143
1149
- # Takes the current git's system ENV variables and store them.
1150
- def store_git_system_env_variables
1151
- @git_system_env_variables = { }
1152
- ENV_VARIABLE_NAMES . each do |env_variable_name |
1153
- @git_system_env_variables [ env_variable_name ] = ENV [ env_variable_name ]
1154
- end
1155
- end
1156
-
1157
- # Takes the previously stored git's ENV variables and set them again on ENV.
1158
- def restore_git_system_env_variables
1159
- ENV_VARIABLE_NAMES . each do |env_variable_name |
1160
- ENV [ env_variable_name ] = @git_system_env_variables [ env_variable_name ]
1161
- end
1162
- end
1163
-
1164
- # Sets git's ENV variables to the custom values for the current instance.
1165
- def set_custom_git_env_variables
1166
- ENV [ 'GIT_DIR' ] = @git_dir
1167
- ENV [ 'GIT_WORK_TREE' ] = @git_work_dir
1168
- ENV [ 'GIT_INDEX_FILE' ] = @git_index_file
1169
- ENV [ 'GIT_SSH' ] = Git ::Base . config . git_ssh
1170
- end
1171
-
1172
- # Runs a block inside an environment with customized ENV variables.
1173
- # It restores the ENV after execution.
1174
- #
1175
- # @param [Proc] block block to be executed within the customized environment
1176
- def with_custom_env_variables ( &block )
1177
- @@semaphore . synchronize do
1178
- store_git_system_env_variables ( )
1179
- set_custom_git_env_variables ( )
1180
- return block . call ( )
1181
- end
1182
- ensure
1183
- restore_git_system_env_variables ( )
1144
+ # git's ENV variables for the current instance.
1145
+ def custom_git_env_variables
1146
+ {
1147
+ 'GIT_DIR' => @git_dir ,
1148
+ 'GIT_WORK_TREE' => @git_work_dir ,
1149
+ 'GIT_INDEX_FILE' => @git_index_file ,
1150
+ 'GIT_SSH' => Git ::Base . config . git_ssh ,
1151
+ }
1184
1152
end
1185
1153
1186
1154
def command ( *cmd , redirect : '' , chomp : true , chdir : nil , &block )
@@ -1200,18 +1168,7 @@ def command(*cmd, redirect: '', chomp: true, chdir: nil, &block)
1200
1168
1201
1169
git_cmd = "#{ Git ::Base . config . binary_path } #{ global_opts } #{ escaped_cmd } #{ redirect } 2>&1"
1202
1170
1203
- output = nil
1204
-
1205
- command_thread = nil ;
1206
-
1207
- status = nil
1208
-
1209
- with_custom_env_variables do
1210
- command_thread = Thread . new do
1211
- output , status = run_command ( git_cmd , chdir , &block )
1212
- end
1213
- command_thread . join
1214
- end
1171
+ output , status = run_command ( git_cmd , chdir , &block )
1215
1172
1216
1173
@logger . info ( git_cmd )
1217
1174
@logger . debug ( output )
@@ -1298,9 +1255,7 @@ def run_command(git_cmd, chdir=nil, &block)
1298
1255
opts = { }
1299
1256
opts [ :chdir ] = File . expand_path ( chdir ) if chdir
1300
1257
1301
- Open3 . popen2 ( git_cmd , opts ) do |stdin , stdout , wait_thr |
1302
- [ block . call ( stdout ) , wait_thr . value ]
1303
- end
1258
+ [ IO . popen ( custom_git_env_variables , git_cmd , opts , &block ) , $?]
1304
1259
end
1305
1260
1306
1261
def escape ( s )
0 commit comments