Skip to content

Commit

Permalink
update all files if any file is newer
Browse files Browse the repository at this point in the history
Cross references need parse all files which define the subject
names.  This commit makes `--force-update` option enforce to parse
all files if any file is newer than the previous parse, not only
updated files.
  • Loading branch information
nobu committed Oct 25, 2019
1 parent 9d4c227 commit 185eb90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def parse argv

opt.on("--[no-]force-update", "-U",
"Forces rdoc to scan all sources even if",
"newer than the flag file.") do |value|
"no files are newer than the flag file.") do |value|
@force_update = value
end

Expand Down
38 changes: 22 additions & 16 deletions lib/rdoc/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,17 @@ def gather_files files

file_list = normalized_file_list files, true, @options.exclude

file_list = file_list.uniq

file_list = remove_unparseable file_list

file_list.sort
file_list = remove_unparseable(file_list)

if file_list.count {|name, mtime|
file_list[name] = @last_modified[name] unless mtime
mtime
} > 0
@last_modified.replace file_list
file_list.keys.sort
else
[]
end
end

##
Expand Down Expand Up @@ -254,11 +260,11 @@ def parse_dot_doc_file in_dir, filename
# read and strip comments
patterns = File.read(filename).gsub(/#.*/, '')

result = []
result = {}

patterns.split.each do |patt|
candidates = Dir.glob(File.join(in_dir, patt))
result.concat normalized_file_list(candidates, false, @options.exclude)
result.update normalized_file_list(candidates, false, @options.exclude)
end

result
Expand All @@ -278,21 +284,21 @@ def parse_dot_doc_file in_dir, filename

def normalized_file_list(relative_files, force_doc = false,
exclude_pattern = nil)
file_list = []
file_list = {}

relative_files.each do |rel_file_name|
rel_file_name = rel_file_name.sub(/^\.\//, '')
next if rel_file_name.end_with? 'created.rid'
next if exclude_pattern && exclude_pattern =~ rel_file_name
stat = File.stat rel_file_name rescue next

case type = stat.ftype
when "file" then
next if last_modified = @last_modified[rel_file_name] and
stat.mtime.to_i <= last_modified.to_i
mtime = (stat.mtime unless (last_modified = @last_modified[rel_file_name] and
stat.mtime.to_i <= last_modified.to_i))

if force_doc or RDoc::Parser.can_parse(rel_file_name) then
file_list << rel_file_name.sub(/^\.\//, '')
@last_modified[rel_file_name] = stat.mtime
file_list[rel_file_name] = mtime
end
when "directory" then
next if rel_file_name == "CVS" || rel_file_name == ".svn"
Expand All @@ -303,16 +309,16 @@ def normalized_file_list(relative_files, force_doc = false,
dot_doc = File.join rel_file_name, RDoc::DOT_DOC_FILENAME

if File.file? dot_doc then
file_list << parse_dot_doc_file(rel_file_name, dot_doc)
file_list.update(parse_dot_doc_file(rel_file_name, dot_doc))
else
file_list << list_files_in_directory(rel_file_name)
file_list.update(list_files_in_directory(rel_file_name))
end
else
warn "rdoc can't parse the #{type} #{rel_file_name}"
end
end

file_list.flatten
file_list
end

##
Expand Down Expand Up @@ -427,7 +433,7 @@ def parse_files files
# files for emacs and vim.

def remove_unparseable files
files.reject do |file|
files.reject do |file, *|
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
(file =~ /tags$/i and
open(file, 'rb') { |io|
Expand Down
15 changes: 11 additions & 4 deletions test/rdoc/test_rdoc_rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def test_gather_files
b = File.expand_path '../test_rdoc_text.rb', __FILE__

assert_equal [a, b], @rdoc.gather_files([b, a, b])

assert_empty @rdoc.gather_files([b, a, b])

@rdoc.last_modified[a] -= 10
assert_equal [a, b], @rdoc.gather_files([b, a, b])
end

def test_handle_pipe
Expand Down Expand Up @@ -146,7 +151,7 @@ def test_normalized_file_list
@rdoc.normalized_file_list [test_path, flag_file]
end

files = files.map { |file| File.expand_path file }
files = files.map { |file, *| File.expand_path file }

assert_equal [test_path], files
end
Expand All @@ -158,7 +163,9 @@ def test_normalized_file_list_not_modified

files = @rdoc.normalized_file_list [__FILE__]

assert_empty files
files = files.collect {|file, mtime| file if mtime}.compact

assert_empty(files)
end

def test_normalized_file_list_non_file_directory
Expand Down Expand Up @@ -203,7 +210,7 @@ def test_normalized_file_list_with_dot_doc
@rdoc.normalized_file_list [File.realpath(dir)]
end

files = files.map { |file| File.expand_path file }
files = files.map { |file, *| File.expand_path file }

assert_equal expected_files, files
end
Expand All @@ -230,7 +237,7 @@ def test_normalized_file_list_with_dot_doc_overridden_by_exclude_option
@rdoc.normalized_file_list [File.realpath(dir)]
end

files = files.map { |file| File.expand_path file }
files = files.map { |file, *| File.expand_path file }

assert_equal expected_files, files
end
Expand Down

0 comments on commit 185eb90

Please sign in to comment.