Skip to content

Commit d435487

Browse files
committed
Fix flushing of commits to always force flush the last batch
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
1 parent 3d03ea3 commit d435487

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/git_statistics/collector.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def collect(branch, options = {})
1919
extract_commit(commit)
2020
@commits.flush_commits
2121
end
22+
@commits.flush_commits(true)
2223
end
2324

2425
def acquire_commit_meta(commit_summary)

lib/git_statistics/commits.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def files_in_path
3333
Dir.entries(path).reject { |file| %w[. ..].include?(file) }
3434
end
3535

36-
def flush_commits
37-
if size >= limit
36+
def flush_commits(force=false)
37+
if size >= limit || force
3838
file_count = Utilities.number_of_matching_files(path, /\d+\.json/)
3939
save(File.join(path, "#{file_count}.json"), @pretty)
4040
clear
@@ -145,9 +145,9 @@ def save(file, pretty)
145145
# Ensure the path to the file exists
146146
FileUtils.mkdir_p(File.dirname(file))
147147
# Save file in a simple or pretty format
148-
File.open(file, 'w') do |file|
148+
File.open(file, 'w') do |f|
149149
json_content = pretty ? JSON.pretty_generate(self) : self.to_json
150-
file.write(json_content)
150+
f.write(json_content)
151151
end
152152
end
153153
end

0 commit comments

Comments
 (0)