-1

我正在尝试使用 ruby​​ 的 SVN 绑定来获取文件的提交日期。下面的代码有效。但是,我不满足于我需要使用一个块来从 status 方法中获取结果。有没有更好的办法 ?

ctx = Svn::Client::Context.new()
ctx.add_simple_prompt_provider(2) do |cred, realm, user_name, may_save|
  cred.username = "sorin"
  cred.password = "realyniftypassword"
end

svndate = nil
ctx.status(path, "HEAD", true, true) do |path, status| 
    break if status.entry.nil?
    svndate = status.entry.cmt_date
end 

next if svndate.nil?

我正在寻找类似的东西:

svndate = ctx.status(path, "HEAD", true, true)[0].entry.cmt_date

但 ctx.status 返回一个整数。

有没有更合适的方法?

我使用 Ubuntu deb 包 libsvn-ruby1.8,除了网上的一些示例外,我找不到任何文档。

4

1 回答 1

1

为了将来参考,有一个 Ruby gem 可能会有所帮助。

http://rubygems.org/gems/svn_wc
https://github.com/dvwright/svn_wc/

require 'svn_wc'
conf = {
  "svn_repo_master"       => "svn+ssh://sorin@192.168.10.1/opt/repo",
  "svn_user"              => "sorin",
  "svn_pass"              => "realyniftypassword",
  "svn_repo_working_copy" => "/tmp/local_working_repo/root",
  #"svn_repo_config_path"  => "/tmp/my_config"
}

svn = SvnWc::RepoAccess.new YAML::dump(conf)
repo_wc = conf['svn_repo_working_copy']
svn.list_entries(repo_wc, nil, verbose=true).each do |info|
  puts "#{info[:entry_name]} #{info[:cmt_date]}"
end
于 2012-06-26T20:56:28.247 回答