@@ -134,11 +134,10 @@ def find_git():
134
134
return git_path
135
135
GIT = find_git ()
136
136
137
- commands_working = 0
138
- def are_commands_working ():
139
- return commands_working != 0
140
137
141
138
class CommandThread (threading .Thread ):
139
+ command_lock = threading .Lock ()
140
+
142
141
def __init__ (self , command , on_done , working_dir = "" , fallback_encoding = "" , ** kwargs ):
143
142
threading .Thread .__init__ (self )
144
143
self .command = command
@@ -156,12 +155,11 @@ def __init__(self, command, on_done, working_dir="", fallback_encoding="", **kwa
156
155
self .kwargs = kwargs
157
156
158
157
def run (self ):
159
- global commands_working
160
158
# Ignore directories that no longer exist
161
159
if not os .path .isdir (self .working_dir ):
162
160
return
163
161
164
- commands_working = commands_working + 1
162
+ self . command_lock . acquire ()
165
163
output = ''
166
164
callback = self .on_done
167
165
try :
@@ -200,7 +198,7 @@ def run(self):
200
198
else :
201
199
output = e .strerror
202
200
finally :
203
- commands_working = commands_working - 1
201
+ self . command_lock . release ()
204
202
main_thread (callback , output , ** self .kwargs )
205
203
206
204
class GitScratchOutputCommand (sublime_plugin .TextCommand ):
@@ -216,23 +214,14 @@ class GitCommand(object):
216
214
may_change_files = False
217
215
218
216
def run_command (self , command , callback = None , show_status = True ,
219
- filter_empty_args = True , no_save = False , wait_for_lock = True , ** kwargs ):
217
+ filter_empty_args = True , no_save = False , ** kwargs ):
220
218
if filter_empty_args :
221
219
command = [arg for arg in command if arg ]
222
220
if 'working_dir' not in kwargs :
223
221
kwargs ['working_dir' ] = self .get_working_dir ()
224
222
if 'fallback_encoding' not in kwargs and self .active_view () and self .active_view ().settings ().get ('fallback_encoding' ):
225
223
kwargs ['fallback_encoding' ] = self .active_view ().settings ().get ('fallback_encoding' ).rpartition ('(' )[2 ].rpartition (')' )[0 ]
226
224
227
- root = git_root (self .get_working_dir ())
228
- if wait_for_lock and root and os .path .exists (os .path .join (root , '.git' , 'index.lock' )):
229
- print ("waiting for index.lock" , command )
230
- do_when (lambda : not os .path .exists (os .path .join (root , '.git' , 'index.lock' )),
231
- self .run_command , command , callback = callback ,
232
- show_status = show_status , filter_empty_args = filter_empty_args ,
233
- no_save = no_save , wait_for_lock = wait_for_lock , ** kwargs )
234
- return
235
-
236
225
s = sublime .load_settings ("Git.sublime-settings" )
237
226
if s .get ('save_first' ) and self .active_view () and self .active_view ().is_dirty () and not no_save :
238
227
self .active_view ().run_command ('save' )
0 commit comments