exe/gloc in gloc-0.2.1 vs exe/gloc in gloc-0.3.0
- old
+ new
@@ -31,14 +31,15 @@
# looking at the first 16 is fine
# for our purposes... for now :-)
# see buffer_is_binary() function
source_files.delete_if { |file|
(
- File.extname(file) == '.pdf' || # skip bl**dy PDF documents
- !File.exist?(file) || # skip non-existent paths
- !File.file?(file) || # skip directories
- !File.size?(file) || # skip empty files
+ File.extname(file) == '.pdf' || # skip bl**dy PDF documents
+ File.basename(file) =~ /\A\..*\z/ || # skip hidden ".*" files
+ !File.exist?(file) || # skip non-existent paths
+ !File.file?(file) || # skip directories
+ !File.size?(file) || # skip empty files
!File.read(file, 16)["\0"].nil? # skip binary files
) && ( $verbose && warn("SKIPPING #{file}...") ; true )
}
BLANKS = %r{\A\s*\Z}.freeze
@@ -62,11 +63,13 @@
line_count: 0,
blank_count: 0,
comment_count: 0,
})
end
- source_lines = File.read(file).each_line
+ file_content = File.read(file, :encoding => 'UTF-8') # FIXME what about other encodings?
+ file_content = File.read(file, :encoding => 'ISO-8859-1') unless content.valid_encoding?
+ source_lines = file_content.each_line
stats_for_ext.file_count += 1
stats_for_ext.line_count += source_lines.count
stats_for_ext.blank_count += source_lines.grep(BLANKS).count
next unless COMMENTS[file_ext] # only scan for comments if a regex exists!
stats_for_ext.comment_count += source_lines.grep(COMMENTS[file_ext]).count
@@ -92,14 +95,14 @@
stats.send(sort_metric)
}.reverse
]
source_stats["TOTAL"] = OpenStruct.new({
- file_count: source_stats.values.map(&:file_count).reduce(:+),
- line_count: source_stats.values.map(&:line_count).reduce(:+),
- blank_count: source_stats.values.map(&:blank_count).reduce(:+),
- comment_count: source_stats.values.map(&:comment_count).reduce(:+),
- code_count: source_stats.values.map(&:code_count).reduce(:+),
+ file_count: source_stats.values.map(&:file_count).reduce(:+) || 0,
+ line_count: source_stats.values.map(&:line_count).reduce(:+) || 0,
+ blank_count: source_stats.values.map(&:blank_count).reduce(:+) || 0,
+ comment_count: source_stats.values.map(&:comment_count).reduce(:+) || 0,
+ code_count: source_stats.values.map(&:code_count).reduce(:+) || 0,
})
#
# JSON formatting for non-TTY output
#