Skip to content

Commit

Permalink
Fix flushing of commits to always force flush the last batch
Browse files Browse the repository at this point in the history
Fix:
 * Flushing commits to take a 'force' param to force the last batch of
   commits to be flushed (the last set was not being saved to JSON)
 * A shadowing issue of the variable 'file' in commits.rb
  • Loading branch information
kevinjalbert committed Sep 22, 2013
1 parent 3d03ea3 commit d435487
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/git_statistics/collector.rb
Expand Up @@ -19,6 +19,7 @@ def collect(branch, options = {})
extract_commit(commit)
@commits.flush_commits
end
@commits.flush_commits(true)
end

def acquire_commit_meta(commit_summary)
Expand Down
8 changes: 4 additions & 4 deletions lib/git_statistics/commits.rb
Expand Up @@ -33,8 +33,8 @@ def files_in_path
Dir.entries(path).reject { |file| %w[. ..].include?(file) }
end

def flush_commits
if size >= limit
def flush_commits(force=false)
if size >= limit || force
file_count = Utilities.number_of_matching_files(path, /\d+\.json/)
save(File.join(path, "#{file_count}.json"), @pretty)
clear
Expand Down Expand Up @@ -145,9 +145,9 @@ def save(file, pretty)
# Ensure the path to the file exists
FileUtils.mkdir_p(File.dirname(file))
# Save file in a simple or pretty format
File.open(file, 'w') do |file|
File.open(file, 'w') do |f|
json_content = pretty ? JSON.pretty_generate(self) : self.to_json
file.write(json_content)
f.write(json_content)
end
end
end
Expand Down

0 comments on commit d435487

Please sign in to comment.