From e0eafc47c307ff0bf589ce43b623bd24fad744fd Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 13 Jun 2016 15:26:18 +0100 Subject: Fix corruption of the ref logs file It must only have the first line of the commit messages, not the while multiple line log. --- git/refs/log.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git') diff --git a/git/refs/log.py b/git/refs/log.py index fed13608..3078355d 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -114,7 +114,7 @@ class RefLogEntry(tuple): newhexsha = info[41:81] for hexsha in (oldhexsha, newhexsha): if not cls._re_hexsha_only.match(hexsha): - raise ValueError("Invalid hexsha: %s" % hexsha) + raise ValueError("Invalid hexsha: %r" % (hexsha,)) # END if hexsha re doesn't match # END for each hexsha @@ -274,11 +274,12 @@ class RefLog(list, Serializable): raise ValueError("Shas need to be given in binary format") # END handle sha type assure_directory_exists(filepath, is_file=True) + first_line = message.split('\n')[0] committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader) entry = RefLogEntry(( bin_to_hex(oldbinsha).decode('ascii'), bin_to_hex(newbinsha).decode('ascii'), - committer, (int(time.time()), time.altzone), message + committer, (int(time.time()), time.altzone), first_line )) lf = LockFile(filepath) -- cgit v1.2.3 From a7f403b1e82d4ada20d0e747032c7382e2a6bf63 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 13 Jun 2016 15:36:51 +0100 Subject: fix flake8 found problems --- git/cmd.py | 2 +- git/remote.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index 9a141297..b4f987ef 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -614,7 +614,7 @@ class Git(LazyMixin): cwd=cwd, bufsize=-1, stdin=istream, - stderr=PIPE, + stderr=PIPE, stdout=PIPE if with_stdout else open(os.devnull, 'wb'), shell=self.USE_SHELL, close_fds=(os.name == 'posix'), # unsupported on windows diff --git a/git/remote.py b/git/remote.py index 347d2844..e30debb7 100644 --- a/git/remote.py +++ b/git/remote.py @@ -8,7 +8,6 @@ import re import os -from .exc import GitCommandError from .config import ( SectionConstraint, cp, -- cgit v1.2.3 From 0d9390866f9ce42870d3116094cd49e0019a970a Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Fri, 29 Jul 2016 14:04:27 +0100 Subject: Prevent CMD windows being shown when starting git in a subprocess. This fixes a UI problem with using GitPython from a GUI python probgram. Each repo that is opened creates a git cat-file processs and that provess will create a console window with out this change. --- git/cmd.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index d8469565..a7f4285a 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -609,6 +609,12 @@ class Git(LazyMixin): # end handle try: + if sys.platform == 'win32': + CREATE_NO_WINDOW = 0x08000000 + creationflags = CREATE_NO_WINDOW + else: + creationflags = None + proc = Popen(command, env=env, cwd=cwd, @@ -619,6 +625,7 @@ class Git(LazyMixin): shell=self.USE_SHELL, close_fds=(os.name == 'posix'), # unsupported on windows universal_newlines=universal_newlines, + creationflags=creationflags, **subprocess_kwargs ) except cmd_not_found_exception as err: @@ -629,7 +636,13 @@ class Git(LazyMixin): def _kill_process(pid): """ Callback method to kill a process. """ - p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE) + if sys.platform == 'win32': + CREATE_NO_WINDOW = 0x08000000 + creationflags = CREATE_NO_WINDOW + else: + creationflags = None + + p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags) child_pids = [] for line in p.stdout: if len(line.split()) > 0: -- cgit v1.2.3 From d79951fba0994654104128b1f83990387d44ac22 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 10:39:55 +0100 Subject: Must pass creationflags as a keywork --- git/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index a7f4285a..5c4cd5e9 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -642,7 +642,7 @@ class Git(LazyMixin): else: creationflags = None - p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags) + p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags=creationflags) child_pids = [] for line in p.stdout: if len(line.split()) > 0: -- cgit v1.2.3 From 572ebd6e92cca39100183db7bbeb6b724dde0211 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 11:09:20 +0100 Subject: creationflags must be set to 0 on non-windows platforms --- git/cmd.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index 5c4cd5e9..00a73e33 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -43,6 +43,9 @@ from git.compat import ( safe_decode, ) +# value of Windows process creation flag taken from MSDN +CREATE_NO_WINDOW = 0x08000000 + execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', 'with_exceptions', 'as_process', 'stdout_as_string', 'output_stream', 'with_stdout', 'kill_after_timeout', @@ -610,10 +613,9 @@ class Git(LazyMixin): try: if sys.platform == 'win32': - CREATE_NO_WINDOW = 0x08000000 creationflags = CREATE_NO_WINDOW else: - creationflags = None + creationflags = 0 proc = Popen(command, env=env, @@ -637,10 +639,9 @@ class Git(LazyMixin): def _kill_process(pid): """ Callback method to kill a process. """ if sys.platform == 'win32': - CREATE_NO_WINDOW = 0x08000000 creationflags = CREATE_NO_WINDOW else: - creationflags = None + creationflags = 0 p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags=creationflags) child_pids = [] -- cgit v1.2.3 From 8bde1038e19108ec90f899ce4aff7f31c1e387eb Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 12:21:11 +0100 Subject: add test to detect the corrupt log - add a second line to commit messages with the "BAD MESSAGE" text - read in the log and confirm that the seond line is not in the log file --- git/test/test_repo.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'git') diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 87887bad..b1a58fd4 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -775,12 +775,23 @@ class TestRepo(TestBase): new_file_path = os.path.join(rw_dir, "new_file.ext") touch(new_file_path) r.index.add([new_file_path]) - r.index.commit("initial commit") + r.index.commit("initial commit\nBAD MESSAGE 1\n") # Now a branch should be creatable nb = r.create_head('foo') assert nb.is_valid() + with open( new_file_path, 'w' ) as f: + f.write( 'Line 1\n' ) + + r.index.add([new_file_path]) + r.index.commit("add line 1\nBAD MESSAGE 2\n") + + with open( '%s/.git/logs/refs/heads/master' % (rw_dir,), 'r' ) as f: + contents = f.read() + + assert 'BAD MESSAGE' not in contents, 'log is corrupt' + def test_merge_base(self): repo = self.rorepo c1 = 'f6aa8d1' -- cgit v1.2.3 From d8ef023a5bab377764343c954bf453869def4807 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 12:29:12 +0100 Subject: fix flake8 problems --- git/test/test_repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git') diff --git a/git/test/test_repo.py b/git/test/test_repo.py index b1a58fd4..48900c26 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -781,13 +781,13 @@ class TestRepo(TestBase): nb = r.create_head('foo') assert nb.is_valid() - with open( new_file_path, 'w' ) as f: - f.write( 'Line 1\n' ) + with open(new_file_path, 'w') as f: + f.write('Line 1\n') r.index.add([new_file_path]) r.index.commit("add line 1\nBAD MESSAGE 2\n") - with open( '%s/.git/logs/refs/heads/master' % (rw_dir,), 'r' ) as f: + with open('%s/.git/logs/refs/heads/master' % (rw_dir,), 'r') as f: contents = f.read() assert 'BAD MESSAGE' not in contents, 'log is corrupt' -- cgit v1.2.3 From df958981ad63edae6fceb69650c1fb9890c2b14f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 2 Aug 2016 05:46:45 +0200 Subject: refactor(cmd): streamline usage of creationflags --- git/cmd.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'git') diff --git a/git/cmd.py b/git/cmd.py index 00a73e33..62eef9e4 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -43,9 +43,6 @@ from git.compat import ( safe_decode, ) -# value of Windows process creation flag taken from MSDN -CREATE_NO_WINDOW = 0x08000000 - execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', 'with_exceptions', 'as_process', 'stdout_as_string', 'output_stream', 'with_stdout', 'kill_after_timeout', @@ -249,6 +246,9 @@ class Git(LazyMixin): # Enables debugging of GitPython's git commands GIT_PYTHON_TRACE = os.environ.get("GIT_PYTHON_TRACE", False) + # value of Windows process creation flag taken from MSDN + CREATE_NO_WINDOW = 0x08000000 + # Provide the full path to the git executable. Otherwise it assumes git is in the path _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE" GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name) @@ -611,12 +611,8 @@ class Git(LazyMixin): cmd_not_found_exception = OSError # end handle + creationflags = self.CREATE_NO_WINDOW if sys.platform == 'win32' else 0 try: - if sys.platform == 'win32': - creationflags = CREATE_NO_WINDOW - else: - creationflags = 0 - proc = Popen(command, env=env, cwd=cwd, @@ -638,11 +634,6 @@ class Git(LazyMixin): def _kill_process(pid): """ Callback method to kill a process. """ - if sys.platform == 'win32': - creationflags = CREATE_NO_WINDOW - else: - creationflags = 0 - p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE, creationflags=creationflags) child_pids = [] for line in p.stdout: -- cgit v1.2.3