From e0eafc47c307ff0bf589ce43b623bd24fad744fd Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 13 Jun 2016 15:26:18 +0100 Subject: [PATCH 1/7] 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(-) diff --git a/git/refs/log.py b/git/refs/log.py index fed136087..3078355d6 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -114,7 +114,7 @@ def from_line(cls, line): 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 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message): 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) From a7f403b1e82d4ada20d0e747032c7382e2a6bf63 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 13 Jun 2016 15:36:51 +0100 Subject: [PATCH 2/7] fix flake8 found problems --- git/cmd.py | 2 +- git/remote.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index 9a141297c..b4f987ef9 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -614,7 +614,7 @@ def execute(self, command, 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 347d2844b..e30debb70 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, From 0d9390866f9ce42870d3116094cd49e0019a970a Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Fri, 29 Jul 2016 14:04:27 +0100 Subject: [PATCH 3/7] 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(-) diff --git a/git/cmd.py b/git/cmd.py index d84695651..a7f4285aa 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -609,6 +609,12 @@ def execute(self, command, # 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 @@ def execute(self, command, 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 @@ def execute(self, command, 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: From d79951fba0994654104128b1f83990387d44ac22 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 10:39:55 +0100 Subject: [PATCH 4/7] Must pass creationflags as a keywork --- git/cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/cmd.py b/git/cmd.py index a7f4285aa..5c4cd5e9e 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -642,7 +642,7 @@ def _kill_process(pid): 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: From 572ebd6e92cca39100183db7bbeb6b724dde0211 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 11:09:20 +0100 Subject: [PATCH 5/7] creationflags must be set to 0 on non-windows platforms --- git/cmd.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index 5c4cd5e9e..00a73e33c 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -43,6 +43,9 @@ 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 @@ def execute(self, command, 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 @@ def execute(self, command, 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 = [] From 8bde1038e19108ec90f899ce4aff7f31c1e387eb Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 12:21:11 +0100 Subject: [PATCH 6/7] 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(-) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 87887bad7..b1a58fd40 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -775,12 +775,23 @@ def test_empty_repo(self, rw_dir): 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' From d8ef023a5bab377764343c954bf453869def4807 Mon Sep 17 00:00:00 2001 From: Barry Scott Date: Mon, 1 Aug 2016 12:29:12 +0100 Subject: [PATCH 7/7] fix flake8 problems --- git/test/test_repo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index b1a58fd40..48900c26a 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -781,13 +781,13 @@ def test_empty_repo(self, rw_dir): 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' pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy