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.
This commit is contained in:
Adam Waldenberg 2017-05-15 03:06:53 +02:00
parent c80c822892
commit 6d77989e34

View file

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import division
from __future__ import unicode_literals from __future__ import unicode_literals
import bisect import bisect
import datetime import datetime
@ -195,7 +196,8 @@ class Changes(object):
if repo != None: if repo != None:
progress_text = "[%s] " % repo.name + progress_text 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 = "" first_hash = ""
for i, entry in enumerate(lines): for i, entry in enumerate(lines):
@ -208,6 +210,7 @@ class Changes(object):
if format.is_interactive_format(): if format.is_interactive_format():
terminal.output_progress(progress_text, i, len(lines)) terminal.output_progress(progress_text, i, len(lines))
else: else:
if CHANGES_PER_THREAD - 1 != i % CHANGES_PER_THREAD:
entry = entry.decode("utf-8", "replace").strip() entry = entry.decode("utf-8", "replace").strip()
second_hash = entry second_hash = entry
ChangesThread.create(hard, self, first_hash, second_hash, i) ChangesThread.create(hard, self, first_hash, second_hash, i)