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

ruby-changes:73357

From: Nobuyoshi <ko1@a...>
Date: Thu, 1 Sep 2022 19:39:42 +0900 (JST)
Subject: [ruby-changes:73357] ee09f75a6b (master): Extract `VCS#revision_header`

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

From ee09f75a6ba2c485260f07eb7d9382850def56bf Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 31 Aug 2022 19:51:49 +0900
Subject: Extract `VCS#revision_header`

---
 tool/file2lastrev.rb | 23 +----------------------
 tool/lib/vcs.rb      | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb
index 3d8c69357d..ba65db0f96 100755
--- a/tool/file2lastrev.rb
+++ b/tool/file2lastrev.rb
@@ -76,28 +76,7 @@ exit unless vcs https://github.com/ruby/ruby/blob/trunk/tool/file2lastrev.rb#L76
     }
   when :revision_h
     Proc.new {|last, changed, modified, branch, title|
-      short = vcs.short_revision(last)
-      if /[^\x00-\x7f]/ =~ title and title.respond_to?(:force_encoding)
-        title = title.dup.force_encoding("US-ASCII")
-      end
-      [
-        "#define RUBY_REVISION #{short.inspect}",
-        ("#define RUBY_FULL_REVISION #{last.inspect}" unless short == last),
-        if branch
-          e = '..'
-          limit = @limit
-          name = branch.sub(/\A(.{#{limit-e.size}}).{#{e.size+1},}/o) {$1+e}
-          name = name.dump.sub(/\\#/, '#')
-          "#define RUBY_BRANCH_NAME #{name}"
-        end,
-        if title
-          title = title.dump.sub(/\\#/, '#')
-          "#define RUBY_LAST_COMMIT_TITLE #{title}"
-        end,
-        if modified
-          modified.utc.strftime('#define RUBY_RELEASE_DATETIME "%FT%TZ"')
-        end,
-      ].compact
+      vcs.revision_header(last, changed, modified, branch, title, limit: @limit)
     }
   when :doxygen
     Proc.new {|last, changed|
diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index 29be8db3b4..75a5d65f2f 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -204,6 +204,34 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/lib/vcs.rb#L204
     revision_handler(rev).short_revision(rev)
   end
 
+  def revision_header(last, changed, modified, branch, title, limit: 20)
+    short = short_revision(last)
+    if /[^\x00-\x7f]/ =~ title and title.respond_to?(:force_encoding)
+      title = title.dup.force_encoding("US-ASCII")
+    end
+    code = [
+      "#define RUBY_REVISION #{short.inspect}",
+    ]
+    unless short == last
+      code << "#define RUBY_FULL_REVISION #{last.inspect}"
+    end
+    if branch
+      e = '..'
+      name = branch.sub(/\A(.{#{limit-e.size}}).{#{e.size+1},}/o) {$1+e}
+      name = name.dump.sub(/\\#/, '#')
+      code << "#define RUBY_BRANCH_NAME #{name}"
+    end
+    if title
+      title = title.dump.sub(/\\#/, '#')
+      code << "#define RUBY_LAST_COMMIT_TITLE #{title}"
+    end
+    if modified
+      t = modified.utc
+      code << t.strftime('#define RUBY_RELEASE_DATETIME "%FT%TZ"')
+    end
+    code
+  end
+
   class SVN < self
     register(".svn")
     COMMAND = ENV['SVN'] || 'svn'
-- 
cgit v1.2.1


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

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