diff options
-rw-r--r-- | git/cmd.py | 7 | ||||
-rw-r--r-- | git/util.py | 21 |
2 files changed, 21 insertions, 7 deletions
@@ -73,6 +73,9 @@ class Git(LazyMixin): self.args = args def __del__(self): + self.proc.stdout.close() + self.proc.stderr.close() + # did the process finish already so we have a return code ? if self.proc.poll() is not None: return @@ -84,6 +87,8 @@ class Git(LazyMixin): # try to kill it try: os.kill(self.proc.pid, 2) # interrupt signal + except OSError: + pass # ignore error when process already died except AttributeError: # try windows # for some reason, providing None for stdout/stderr still prints something. This is why @@ -100,6 +105,8 @@ class Git(LazyMixin): :raise GitCommandError: if the return status is not 0""" status = self.proc.wait() + self.proc.stdout.close() + self.proc.stderr.close() if status != 0: raise GitCommandError(self.args, status, self.proc.stderr.read()) # END status handling diff --git a/git/util.py b/git/util.py index 0e7e4cba..79c6008f 100644 --- a/git/util.py +++ b/git/util.py @@ -20,7 +20,9 @@ from smmap import ( SlidingWindowMapManager, SlidingWindowMapBuffer ) - +# Import the user database on unix based systems +if os.name == "posix": + import pwd __all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", @@ -144,12 +146,17 @@ class _RandomAccessStringIO(object): def get_user_id(): """:return: string identifying the currently active system user as name@node - :note: user can be set with the 'USER' environment variable, usually set on windows""" - ukn = 'UNKNOWN' - username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) - if username == ukn and hasattr(os, 'getlogin'): - username = os.getlogin() - # END get username from login + :note: user can be set with the 'USER' environment variable, usually set on windows + :note: on unix based systems you can use the password database + to get the login name of the effective process user""" + if os.name == "posix": + username = pwd.getpwuid(os.geteuid()).pw_name + else: + ukn = 'UNKNOWN' + username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) + if username == ukn and hasattr(os, 'getlogin'): + username = os.getlogin() + # END get username from login return "%s@%s" % (username, platform.node()) def is_git_dir(d): |