From 6d77989e341e043c9a7f09757000d75701b32d84 Mon Sep 17 00:00:00 2001 From: Adam Waldenberg Date: Mon, 15 May 2017 03:06:53 +0200 Subject: [PATCH] Fix logic error in the threading code of the changes module (Fixes #118). This particular problem is also briefly mentioned in issue #115. The fix resolves the overflow problem resulting in an array with a dangling "None" type at the end. It also takes care of a race condition where two threads by accident could update the same data. --- gitinspector/changes.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/gitinspector/changes.py b/gitinspector/changes.py index 2fbdbfc..f1b39ff 100644 --- a/gitinspector/changes.py +++ b/gitinspector/changes.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU General Public License # along with gitinspector. If not, see . +from __future__ import division from __future__ import unicode_literals import bisect import datetime @@ -195,7 +196,8 @@ class Changes(object): if repo != None: progress_text = "[%s] " % repo.name + progress_text - self.commits = [None] * (len(lines) // CHANGES_PER_THREAD + 1) + chunks = len(lines) // CHANGES_PER_THREAD + self.commits = [None] * (chunks if len(lines) % CHANGES_PER_THREAD == 0 else chunks + 1) first_hash = "" for i, entry in enumerate(lines): @@ -208,9 +210,10 @@ class Changes(object): if format.is_interactive_format(): terminal.output_progress(progress_text, i, len(lines)) else: - entry = entry.decode("utf-8", "replace").strip() - second_hash = entry - ChangesThread.create(hard, self, first_hash, second_hash, i) + if CHANGES_PER_THREAD - 1 != i % CHANGES_PER_THREAD: + entry = entry.decode("utf-8", "replace").strip() + second_hash = entry + ChangesThread.create(hard, self, first_hash, second_hash, i) # Make sure all threads have completed. for i in range(0, NUM_THREADS):