summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-31 19:51:49 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-09-01 18:01:40 +0900
commitee09f75a6ba2c485260f07eb7d9382850def56bf (patch)
tree4b536e0ba7206a5052cd9ebe231119443447529e /tool
parent762fca9b12b9cfb0159404c95ee4275100169c17 (diff)
Extract `VCS#revision_header`
Diffstat (limited to 'tool')
-rwxr-xr-xtool/file2lastrev.rb23
-rw-r--r--tool/lib/vcs.rb28
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
}
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
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'