Skip to content

Commit 455715e

Browse files
committed
Sort by CommitDate if available
1 parent 1821628 commit 455715e

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

lib/rdoc/parser/changelog.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ def parse_info(info)
217217
def parse_entries
218218
entries = []
219219

220-
@content.scan(/^commit\s+(\h{20})\h*\n *Author: *(.+)\n *Date: *(.+)\n\n((?: {4}.*\n+)*)/) do
221-
entry_name, author, date, entry_body = $1, $2, $3, $4.gsub(/^ {4}/, '')
222-
if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~ date
220+
@content.scan(/^commit\s+(\h{20})\h*\n((?:.+\n)*)\n((?: {4}.*\n+)*)/) do
221+
entry_name, header, entry_body = $1, $2, $3.gsub(/^ {4}/, '')
222+
# header = header.scan(/^ *(\S+?): +(.*)/).to_h
223+
# date = header["CommitDate"] || header["Date"]
224+
date = header[/^ *(?:Author)?Date: +(.*)/, 1]
225+
author = header[/^ *Author: +(.*)/, 1]
226+
if /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d)/ =~
227+
(header[/^ *CommitDate: +(.*)/, 1] || date)
223228
time = Time.new($1, $2, $3, $4, $5, $6, "#{$7}:#{$8}")
224229
@time_cache[entry_name] = time
225230
author.sub!(/\s*<(.*)>/, '')

test/rdoc/test_rdoc_parser_changelog.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,46 @@ def test_scan_git
398398
assert_equal expected, @top_level.comment
399399
end
400400

401+
def test_scan_git_commit_date
402+
parser = util_parser <<-ChangeLog
403+
commit\ ee1e690a2df901adb279d7a63fbd92c64e0a5ae6
404+
Author: Igor Zubkov <igor.zubkov@gmail.com>
405+
AuthorDate: 2016-10-25 03:56:11 +0900
406+
Commit: Nobuyoshi Nakada <nobu@ruby-lang.org>
407+
CommitDate: 2021-01-07 13:40:42 +0900
408+
409+
We don't need "require 'uri'" after "require 'net/http'".
410+
411+
commit\ 4d0985a7bd8f591dff4b430e288bfd83af782e51
412+
Author: git <svn-admin@ruby-lang.org>
413+
AuthorDate: 2021-01-07 10:21:34 +0900
414+
Commit: git <svn-admin@ruby-lang.org>
415+
CommitDate: 2021-01-07 10:21:34 +0900
416+
417+
* 2021-01-07 [ci skip]
418+
ChangeLog
419+
420+
parser.scan
421+
422+
expected = doc(
423+
head(1, File.basename(@tempfile.path)),
424+
blank_line,
425+
head(2, "2021-01-07"),
426+
blank_line,
427+
log_entry(nil, 'ee1e690a2df901adb279',
428+
'Igor Zubkov', 'igor.zubkov@gmail.com',
429+
'2016-10-25 03:56:11 +0900',
430+
[head(4, %[We don't need "require 'uri'" after "require 'net/http'".])]),
431+
log_entry(nil, '4d0985a7bd8f591dff4b',
432+
'git', 'svn-admin@ruby-lang.org',
433+
'2021-01-07 10:21:34 +0900',
434+
[list(:BULLET, item(nil, para("2021-01-07 [ci skip]")))]))
435+
436+
expected.file = @top_level
437+
438+
assert_equal expected, @top_level.comment
439+
end
440+
401441
def util_parser content = ''
402442
RDoc::Parser::ChangeLog.new \
403443
@top_level, @tempfile.path, content, @options, @stats

0 commit comments

Comments
 (0)