Skip to content

Commit

Permalink
Fix logic error in the threading code of the changes module (Fixes #118
Browse files Browse the repository at this point in the history
…).

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.
  • Loading branch information
adam-waldenberg committed May 15, 2017
1 parent c80c822 commit 6d77989
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gitinspector/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <https://www.gnu.org/licenses/>.

from __future__ import division
from __future__ import unicode_literals
import bisect
import datetime
Expand Down Expand Up @@ -195,7 +196,8 @@ def __init__(self, repo, hard):
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):
Expand All @@ -208,9 +210,10 @@ def __init__(self, repo, hard):
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):
Expand Down

0 comments on commit 6d77989

Please sign in to comment.