diff --git a/tracext/git/PyGIT.py b/tracext/git/PyGIT.py index 8e8f7d3..632461e 100644 --- a/tracext/git/PyGIT.py +++ b/tracext/git/PyGIT.py @@ -18,6 +18,33 @@ import cStringIO import codecs +def terminate(process): + """ + Kills a process, useful on 2.5 where subprocess.Popens don't have a + terminate method. + + + Used here because we're stuck on 2.5 and don't have Popen.terminate + goodness. + """ + + def terminate_win(process): + import win32process + return win32process.TerminateProcess(process._handle, -1) + + def terminate_nix(process): + import signal + return os.kill(process.pid, signal.SIGTERM) + + terminate_default = terminate_nix + + handlers = { + "win32": terminate_win, + "linux2": terminate_nix + } + + return handlers.get(sys.platform, terminate_default)(process) + __all__ = ["git_version", "GitError", "GitErrorSha", "Storage", "StorageFactory"] class GitError(Exception): @@ -61,7 +88,8 @@ def __execute(self, git_cmd, *cmd_args): #print >>sys.stderr, "DEBUG:", git_cmd, cmd_args - p = self.__pipe(git_cmd, *cmd_args, stdout=PIPE, stderr=PIPE) + kwds = dict(stdout=PIPE,stderr=PIPE) + p = self.__pipe(git_cmd, *cmd_args, **kwds) stdout_data, stderr_data = p.communicate() #TODO, do something with p.returncode, e.g. raise exception @@ -72,7 +100,8 @@ def cat_file_batch(self): return self.__pipe('cat-file', '--batch', stdin=PIPE, stdout=PIPE) def log_pipe(self, *cmd_args): - return self.__pipe('log', *cmd_args, stdout=PIPE) + kwds = dict(stdout=PIPE) + return self.__pipe('log', *cmd_args, **kwds) def __getattr__(self, name): if name[0] == '_' or name in ['cat_file_batch', 'log_pipe']: @@ -741,7 +770,7 @@ def name_status_gen(): except ValueError: break f.close() - p[0].terminate() + terminate(p[0]) p[0].wait() p[:] = [] while True: yield None @@ -757,7 +786,7 @@ def historian(path): if p: p[0].stdout.close() - p[0].terminate() + terminate(p[0]) p[0].wait() def last_change(self, sha, path, historian=None): diff --git a/tracext/git/git_fs.py b/tracext/git/git_fs.py index 54eac17..8eedfcd 100644 --- a/tracext/git/git_fs.py +++ b/tracext/git/git_fs.py @@ -4,6 +4,7 @@ # # See COPYING for distribution information +from __future__ import with_statement from trac.core import * from trac.util import TracError, shorten_line from trac.util.datefmt import FixedOffset, to_timestamp, format_datetime