| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 783ad99 commit 45f8f20
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | from git.odict import OrderedDict | |
| 16 | 16 | from contextlib import contextmanager | |
| 17 | 17 | import signal | |
| 18 | + import subprocess | ||
| 18 | 19 | from subprocess import ( | |
| 19 | 20 | call, | |
| 20 | 21 | Popen, | |
@@ -229,6 +230,15 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()): | |||
| 229 | 230 | ||
| 230 | 231 | ## -- End Utilities -- @} | |
| 231 | 232 | ||
| 233 | + # value of Windows process creation flag taken from MSDN | ||
| 234 | + CREATE_NO_WINDOW = 0x08000000 | ||
| 235 | + | ||
| 236 | + ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards, | ||
| 237 | + # seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal | ||
| 238 | + PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP | ||
| 239 | + if sys.platform == 'win32' | ||
| 240 | + else 0) | ||
| 241 | + | ||
| 232 | 242 | ||
| 233 | 243 | class Git(LazyMixin): | |
| 234 | 244 | ||
@@ -267,9 +277,6 @@ def __setstate__(self, d): | |||
| 267 | 277 | # Enables debugging of GitPython's git commands | |
| 268 | 278 | GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False) | |
| 269 | 279 | ||
| 270 | - # value of Windows process creation flag taken from MSDN | ||
| 271 | - CREATE_NO_WINDOW = 0x08000000 | ||
| 272 | - | ||
| 273 | 280 | # Provide the full path to the git executable. Otherwise it assumes git is in the path | |
| 274 | 281 | _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE" | |
| 275 | 282 | GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name) | |
@@ -317,7 +324,7 @@ def __del__(self): | |||
| 317 | 324 | ||
| 318 | 325 | # try to kill it | |
| 319 | 326 | try: | |
| 320 | - os.kill(proc.pid, 2) # interrupt signal | ||
| 327 | + proc.terminate() | ||
| 321 | 328 | proc.wait() # ensure process goes away | |
| 322 | 329 | except (OSError, WindowsError): | |
| 323 | 330 | pass # ignore error when process already died | |
@@ -632,7 +639,6 @@ def execute(self, command, | |||
| 632 | 639 | cmd_not_found_exception = OSError | |
| 633 | 640 | # end handle | |
| 634 | 641 | ||
| 635 | - creationflags = self.CREATE_NO_WINDOW if sys.platform == 'win32' else 0 | ||
| 636 | 642 | try: | |
| 637 | 643 | proc = Popen(command, | |
| 638 | 644 | env=env, | |
@@ -644,7 +650,7 @@ def execute(self, command, | |||
| 644 | 650 | shell=self.USE_SHELL, | |
| 645 | 651 | close_fds=(os.name == 'posix'), # unsupported on windows | |
| 646 | 652 | universal_newlines=universal_newlines, | |
| 647 | - creationflags=creationflags, | ||
| 653 | + creationflags=PROC_CREATIONFLAGS, | ||
| 648 | 654 | **subprocess_kwargs | |
| 649 | 655 | ) | |
| 650 | 656 | except cmd_not_found_exception as err: | |
@@ -655,7 +661,8 @@ def execute(self, command, | |||
| 655 | 661 | ||
| 656 | 662 | def _kill_process(pid): | |
| 657 | 663 | """ Callback method to kill a process. """ | |
| 658 | - p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags=creationflags) | ||
| 664 | + p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, | ||
| 665 | + creationflags=PROC_CREATIONFLAGS) | ||
| 659 | 666 | child_pids = [] | |
| 660 | 667 | for line in p.stdout: | |
| 661 | 668 | if len(line.split()) > 0: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,11 +12,10 @@ | |||
| 12 | 12 | ||
| 13 | 13 | from io import BytesIO | |
| 14 | 14 | import os | |
| 15 | - import sys | ||
| 16 | 15 | import subprocess | |
| 17 | 16 | ||
| 18 | 17 | from git.util import IndexFileSHA1Writer | |
| 19 | - from git.cmd import Git | ||
| 18 | + from git.cmd import PROC_CREATIONFLAGS | ||
| 20 | 19 | from git.exc import ( | |
| 21 | 20 | UnmergedEntriesError, | |
| 22 | 21 | HookExecutionError | |
@@ -78,7 +77,7 @@ def run_commit_hook(name, index): | |||
| 78 | 77 | cwd=index.repo.working_dir, | |
| 79 | 78 | close_fds=(os.name == 'posix'), | |
| 80 | 79 | universal_newlines=True, | |
| 81 | - creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0,) | ||
| 80 | + creationflags=PROC_CREATIONFLAGS,) | ||
| 82 | 81 | stdout, stderr = cmd.communicate() | |
| 83 | 82 | cmd.stdout.close() | |
| 84 | 83 | cmd.stderr.close() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,12 +5,12 @@ | |||
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | from __future__ import print_function | |
| 7 | 7 | import os | |
| 8 | - import sys | ||
| 9 | 8 | from unittest import TestCase | |
| 10 | 9 | import time | |
| 11 | 10 | import tempfile | |
| 12 | 11 | import shutil | |
| 13 | 12 | import io | |
| 13 | + import logging | ||
| 14 | 14 | ||
| 15 | 15 | from git import Repo, Remote, GitCommandError, Git | |
| 16 | 16 | from git.compat import string_types | |
@@ -25,6 +25,8 @@ | |||
| 25 | 25 | 'with_rw_repo', 'with_rw_and_rw_remote_repo', 'TestBase', 'TestCase', 'GIT_REPO', 'GIT_DAEMON_PORT' | |
| 26 | 26 | ) | |
| 27 | 27 | ||
| 28 | + log = logging.getLogger('git.util') | ||
| 29 | + | ||
| 28 | 30 | #{ Routines | |
| 29 | 31 | ||
| 30 | 32 | ||
@@ -120,7 +122,7 @@ def repo_creator(self): | |||
| 120 | 122 | try: | |
| 121 | 123 | return func(self, rw_repo) | |
| 122 | 124 | except: | |
| 123 | - print("Keeping repo after failure: %s" % repo_dir, file=sys.stderr) | ||
| 125 | + log.info("Keeping repo after failure: %s", repo_dir) | ||
| 124 | 126 | repo_dir = None | |
| 125 | 127 | raise | |
| 126 | 128 | finally: | |
@@ -218,7 +220,7 @@ def remote_repo_creator(self): | |||
| 218 | 220 | # on some platforms ? | |
| 219 | 221 | if gd is not None: | |
| 220 | 222 | os.kill(gd.proc.pid, 15) | |
| 221 | - print(str(e)) | ||
| 223 | + log.warning('git-ls-remote failed due to: %s(%s)', type(e), e) | ||
| 222 | 224 | if os.name == 'nt': | |
| 223 | 225 | msg = "git-daemon needs to run this test, but windows does not have one. " | |
| 224 | 226 | msg += 'Otherwise, run: git-daemon "%s"' % temp_dir | |
@@ -239,8 +241,8 @@ def remote_repo_creator(self): | |||
| 239 | 241 | try: | |
| 240 | 242 | return func(self, rw_repo, rw_remote_repo) | |
| 241 | 243 | except: | |
| 242 | - print("Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s" | ||
| 243 | - % (repo_dir, remote_repo_dir), file=sys.stderr) | ||
| 244 | + log.info("Keeping repos after failure: repo_dir = %s, remote_repo_dir = %s", | ||
| 245 | + repo_dir, remote_repo_dir) | ||
| 244 | 246 | repo_dir = remote_repo_dir = None | |
| 245 | 247 | raise | |
| 246 | 248 | finally: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,8 @@ | |||
| 21 | 21 | Git, | |
| 22 | 22 | GitCommandError, | |
| 23 | 23 | GitCommandNotFound, | |
| 24 | - Repo | ||
| 24 | + Repo, | ||
| 25 | + cmd | ||
| 25 | 26 | ) | |
| 26 | 27 | from gitdb.test.lib import with_rw_directory | |
| 27 | 28 | ||
@@ -240,7 +241,7 @@ def counter_stderr(line): | |||
| 240 | 241 | stderr=subprocess.PIPE, | |
| 241 | 242 | shell=False, | |
| 242 | 243 | universal_newlines=True, | |
| 243 | - creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0, | ||
| 244 | + creationflags=cmd.PROC_CREATIONFLAGS, | ||
| 244 | 245 | ) | |
| 245 | 246 | ||
| 246 | 247 | handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments