@@ -115,20 +115,22 @@ def _git_command(self, command1, command2=None):
115115 """
116116 if command2 :
117117 # pipe the two commands and return output
118- proc1 = subprocess .Popen (command1 , stdout = subprocess .PIPE ,
119- cwd = self .repository )
120- proc2 = subprocess .Popen (command2 , stdin = proc1 .stdout ,
121- stdout = subprocess .PIPE ,
122- cwd = self .repository )
123- proc1 .stdout .close ()
124- return (proc2 .communicate ()[0 ].decode ('utf-8' , errors = 'ignore' )
125- .strip ().split ('\n ' ))
118+ with subprocess .Popen (command1 , stdout = subprocess .PIPE ,
119+ cwd = self .repository ) as proc1 :
120+ with subprocess .Popen (command2 , stdin = proc1 .stdout ,
121+ stdout = subprocess .PIPE ,
122+ cwd = self .repository ) as proc2 :
123+ proc1 .stdout .close ()
124+ return (proc2 .communicate ()[0 ]
125+ .decode ('utf-8' , errors = 'ignore' )
126+ .strip ().split ('\n ' ))
126127
127128 # execute a single git command and return output
128- proc = subprocess .Popen (command1 , stdout = subprocess .PIPE ,
129- cwd = self .repository )
130- return (proc .communicate ()[0 ].decode ('utf-8' , errors = 'ignore' )
131- .strip ().split ('\n ' ))
129+ with subprocess .Popen (command1 , stdout = subprocess .PIPE ,
130+ cwd = self .repository ) as proc :
131+ return (proc .communicate ()[0 ]
132+ .decode ('utf-8' , errors = 'ignore' )
133+ .strip ().split ('\n ' ))
132134
133135 def _git_command_log (self , arguments , command2 = None ):
134136 """
0 commit comments