On Tue, Aug 18, 2020 at 12:20:47PM +0800, Li Ping wrote:
On Tue, Aug 18, 2020 at 10:02:45AM +0800, Wu Fengguang wrote:
CC Shaofei.
I have already CC All.
On Mon, Aug 17, 2020 at 07:32:45PM +0800, Li Ping wrote:
Previously, the tag_prefix was the first matched tag_prefix in git_tag. It is easy to make errors
So, I get ten matched tag_prefix in git_tag and choose the one that appears the most
archlinux/parse-git_tag.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/archlinux/parse-git_tag.rb b/archlinux/parse-git_tag.rb index 85ab41e..22054ea 100755 --- a/archlinux/parse-git_tag.rb +++ b/archlinux/parse-git_tag.rb @@ -35,15 +35,24 @@ rescue StandardError end
def write_config(config)
- git_tags = {}
- git_tags.default = ["", 0]
- i = 0 config['git_tag'].each do |tag| next unless tag.to_s =~ /^([-_.a-zA-Z]*)\d+([._]?)/
- config['tag_prefix'] = ("^#{Regexp.last_match(1)}" if Regexp.last_match(1))
- config['separator'] = Regexp.last_match(2)
- File.open(file, 'w') do |f|
f.write(config.to_yaml)
swap the below 2 lines, to
- git_tags["^#{Regexp.last_match(1)}"][0] = Regexp.last_match(2)
- git_tags["^#{Regexp.last_match(1)}"][1] += 1
Move i += 1 here, like this
Thank you for your reminder
- i += 1
- break if i > 9
- end
- git_tags.each do |t, n|
- if n[1] > git_tags[config['tag_prefix']][1]
config['tag_prefix'] may be nil
OK, I will add a code: config['tag_prefix'] = "^#{Regexp.last_match(1)}"
Thanks, Ping
这个语句能够确保 config['tag_prefix'] 不为空么
config['tag_prefix'] = t
endconfig['separator'] = git_tags[t][0]
- break
- end
- File.open(file, 'w') do |f|
- f.write(config.to_yaml) end
end
这个想法很好,将 File.open 放到循环外面. 谢谢 jimmy
-- 2.23.0