From 9525cdeba888d2ecceba86a7b87c816c890e0f6b Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Tue, 17 Feb 2015 21:18:52 +0200 Subject: [PATCH] thread saety fix --- lib/github_changelog_generator.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/github_changelog_generator.rb b/lib/github_changelog_generator.rb index a2c1b76..53e4b6f 100755 --- a/lib/github_changelog_generator.rb +++ b/lib/github_changelog_generator.rb @@ -161,10 +161,15 @@ module GitHubChangelogGenerator def generate_log_for_all_tags log = '' + if @options[:verbose] + puts "Fetching tags dates.." + end + # Async fetching tags: threads = [] @all_tags.each { |tag| - threads << Thread.new { self.get_time_of_tag(tag) } + # explicit set @tag_times_hash to write data safety. + threads << Thread.new { self.get_time_of_tag(tag, @tag_times_hash) } } threads.each { |thr| thr.join } @@ -394,19 +399,18 @@ module GitHubChangelogGenerator log end - def get_time_of_tag(tag_name) + def get_time_of_tag(tag_name, tag_times_hash = @tag_times_hash) if tag_name.nil? return nil end - if @tag_times_hash[tag_name['name']] + if tag_times_hash[tag_name['name']] return @tag_times_hash[tag_name['name']] end github_git_data_commits_get = @github.git_data.commits.get @options[:user], @options[:project], tag_name['commit']['sha'] time_string = github_git_data_commits_get['committer']['date'] - Time.parse(time_string) @tag_times_hash[tag_name['name']] = Time.parse(time_string) end