Skip to content

Commit 13e9a44

Browse files
committed
update all files if any file is newer
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.
1 parent 1093303 commit 13e9a44

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

lib/rdoc/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ def parse argv
755755

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

lib/rdoc/rdoc.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,17 @@ def gather_files files
112112

113113
file_list = normalized_file_list files, true, @options.exclude
114114

115-
file_list = file_list.uniq
116-
117-
file_list = remove_unparseable file_list
118-
119-
file_list.sort
115+
file_list = remove_unparseable(file_list)
116+
117+
if file_list.count {|name, mtime|
118+
file_list[name] = @last_modified[name] unless mtime
119+
mtime
120+
} > 0
121+
@last_modified.replace file_list
122+
file_list.keys.sort
123+
else
124+
[]
125+
end
120126
end
121127

122128
##
@@ -254,11 +260,11 @@ def parse_dot_doc_file in_dir, filename
254260
# read and strip comments
255261
patterns = File.read(filename).gsub(/#.*/, '')
256262

257-
result = []
263+
result = {}
258264

259265
patterns.split.each do |patt|
260266
candidates = Dir.glob(File.join(in_dir, patt))
261-
result.concat normalized_file_list(candidates, false, @options.exclude)
267+
result.update normalized_file_list(candidates, false, @options.exclude)
262268
end
263269

264270
result
@@ -278,21 +284,21 @@ def parse_dot_doc_file in_dir, filename
278284

279285
def normalized_file_list(relative_files, force_doc = false,
280286
exclude_pattern = nil)
281-
file_list = []
287+
file_list = {}
282288

283289
relative_files.each do |rel_file_name|
290+
rel_file_name = rel_file_name.sub(/^\.\//, '')
284291
next if rel_file_name.end_with? 'created.rid'
285292
next if exclude_pattern && exclude_pattern =~ rel_file_name
286293
stat = File.stat rel_file_name rescue next
287294

288295
case type = stat.ftype
289296
when "file" then
290-
next if last_modified = @last_modified[rel_file_name] and
291-
stat.mtime.to_i <= last_modified.to_i
297+
mtime = (stat.mtime unless (last_modified = @last_modified[rel_file_name] and
298+
stat.mtime.to_i <= last_modified.to_i))
292299

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

305311
if File.file? dot_doc then
306-
file_list << parse_dot_doc_file(rel_file_name, dot_doc)
312+
file_list.update(parse_dot_doc_file(rel_file_name, dot_doc))
307313
else
308-
file_list << list_files_in_directory(rel_file_name)
314+
file_list.update(list_files_in_directory(rel_file_name))
309315
end
310316
else
311317
warn "rdoc can't parse the #{type} #{rel_file_name}"
312318
end
313319
end
314320

315-
file_list.flatten
321+
file_list
316322
end
317323

318324
##
@@ -427,7 +433,7 @@ def parse_files files
427433
# files for emacs and vim.
428434

429435
def remove_unparseable files
430-
files.reject do |file|
436+
files.reject do |file, *|
431437
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
432438
(file =~ /tags$/i and
433439
open(file, 'rb') { |io|

test/rdoc/test_rdoc_rdoc.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def test_gather_files
7373
b = File.expand_path '../test_rdoc_text.rb', __FILE__
7474

7575
assert_equal [a, b], @rdoc.gather_files([b, a, b])
76+
77+
assert_empty @rdoc.gather_files([b, a, b])
78+
79+
@rdoc.last_modified[a] -= 10
80+
assert_equal [a, b], @rdoc.gather_files([b, a, b])
7681
end
7782

7883
def test_handle_pipe
@@ -146,7 +151,7 @@ def test_normalized_file_list
146151
@rdoc.normalized_file_list [test_path, flag_file]
147152
end
148153

149-
files = files.map { |file| File.expand_path file }
154+
files = files.map { |file, *| File.expand_path file }
150155

151156
assert_equal [test_path], files
152157
end
@@ -156,7 +161,9 @@ def test_normalized_file_list_not_modified
156161

157162
files = @rdoc.normalized_file_list [__FILE__]
158163

159-
assert_empty files
164+
files = files.collect {|file, mtime| file if mtime}.compact
165+
166+
assert_empty(files)
160167
end
161168

162169
def test_normalized_file_list_non_file_directory
@@ -205,7 +212,7 @@ def test_normalized_file_list_with_dot_doc
205212
@rdoc.normalized_file_list [File.realpath(dir)]
206213
end
207214

208-
files = files.map { |file| File.expand_path file }
215+
files = files.map { |file, *| File.expand_path file }
209216

210217
assert_equal expected_files, files
211218
end
@@ -236,7 +243,7 @@ def test_normalized_file_list_with_dot_doc_overridden_by_exclude_option
236243
@rdoc.normalized_file_list [File.realpath(dir)]
237244
end
238245

239-
files = files.map { |file| File.expand_path file }
246+
files = files.map { |file, *| File.expand_path file }
240247

241248
assert_equal expected_files, files
242249
end

0 commit comments

Comments
 (0)