[前][次][番号順一覧][スレッド一覧]

ruby-changes:65031

From: Nobuyoshi <ko1@a...>
Date: Sun, 24 Jan 2021 16:53:53 +0900 (JST)
Subject: [ruby-changes:65031] 52ebaf718e (master): [ruby/rdoc] Skip non-date logs by git-log

https://git.ruby-lang.org/ruby.git/commit/?id=52ebaf718e

From 52ebaf718e6a78297ceb0dff49815eeed28eae45 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 23 Jan 2021 17:28:59 +0900
Subject: [ruby/rdoc] Skip non-date logs by git-log

`RDoc::Parser::ChangeLog` mis-parses ChangeLog generated by
git-log, because of too heuristic `Time.parse`.

For instance, "commit 8187228de0142d3ac7950b7d977c2849e934c637"
results in "8187-08-16", that is, day 228 in the year 8187.

https://github.com/ruby/rdoc/commit/9711e6f6d9
---
 lib/rdoc/parser/changelog.rb            | 36 ++++++++++++++++++++-------------
 test/rdoc/test_rdoc_parser_changelog.rb |  2 ++
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb
index dcc8464..9ef7678 100644
--- a/lib/rdoc/parser/changelog.rb
+++ b/lib/rdoc/parser/changelog.rb
@@ -1,5 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L1
 # frozen_string_literal: true
-require 'time'
 
 ##
 # A ChangeLog file parser.
@@ -106,15 +105,33 @@ class RDoc::Parser::ChangeLog < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L105
     entries.group_by do |title, _|
       begin
         time = @time_cache[title]
-        (time || Time.parse(title)).strftime '%Y-%m-%d'
+        (time || parse_date(title)).strftime '%Y-%m-%d'
       rescue NoMethodError, ArgumentError
         time, = title.split '  ', 2
-        Time.parse(time).strftime '%Y-%m-%d'
+        parse_date(time).strftime '%Y-%m-%d'
       end
     end
   end
 
   ##
+  # Parse date in ISO-8601, RFC-2822, or default of Git
+
+  def parse_date(date)
+    case date
+    when /\A\s*(\d+)-(\d+)-(\d+)(?: (\d+):(\d+):(\d+) *([-+]\d\d)(\d\d))?\b/
+      Time.new($1, $2, $3, $4, $5, $6, ("#{$7}:#{$8}" if $7))
+    when /\A\s*\w{3}, +(\d+) (\w{3}) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d)(\d\d))\b/
+      Time.new($3, $2, $1, $4, $5, $6, ("#{$7}:#{$8}" if $7))
+    when /\A\s*\w{3} (\w{3}) +(\d+) (\d+) (\d+):(\d+):(\d+) *(?:([-+]\d\d)(\d\d))\b/
+      Time.new($3, $1, $2, $4, $5, $6, ("#{$7}:#{$8}" if $7))
+    when /\A\s*\w{3} (\w{3}) +(\d+) (\d+):(\d+):(\d+) (\d+)\b/
+      Time.new($6, $1, $2, $3, $4, $5)
+    else
+      raise ArgumentError, "bad date: #{date}"
+    end
+  end
+
+  ##
   # Parses the entries in the ChangeLog.
   #
   # Returns an Array of each ChangeLog entry in order of parsing.
@@ -152,19 +169,10 @@ class RDoc::Parser::ChangeLog < RDoc::Parser https://github.com/ruby/ruby/blob/trunk/lib/rdoc/parser/changelog.rb#L169
         entry_name = $&
 
         begin
-          time = Time.parse entry_name
+          time = parse_date entry_name
           @time_cache[entry_name] = time
-          # HACK Ruby 1.8 does not raise ArgumentError for Time.parse "Other"
-          entry_name = nil unless entry_name =~ /#{time.year}/
-        rescue NoMethodError
-          # HACK Ruby 2.1.2 and earlier raises NoMethodError if time part is absent
-          entry_name.split '  ', 2
         rescue ArgumentError
-          if /out of range/ =~ $!.message
-            Time.parse(entry_name.split('  ', 2)[0]) rescue entry_name = nil
-          else
-            entry_name = nil
-          end
+          entry_name = nil
         end
 
         entry_body = []
diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb
index 6a14b61..eb1b5d4 100644
--- a/test/rdoc/test_rdoc_parser_changelog.rb
+++ b/test/rdoc/test_rdoc_parser_changelog.rb
@@ -212,6 +212,8 @@ Mon Dec  3 20:28:02 2012  Koichi Sasada  <ko1@a...> https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_parser_changelog.rb#L212
 	  change condition of using `opt_send_simple'.
 	  More method invocations can be simple.
 
+commit\ 8187228de0142d3ac7950b7d977c2849e934c637
+
 Other note that will be ignored
 
     ChangeLog
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]