来自Svn :: Client :: Context的状态方法可以返回一个数组

时间:2012-05-27 19:23:11

标签: ruby svn

我正在尝试使用ruby的SVN绑定来获取文件的提交日期。以下代码有效。但是,我不满足于我需要使用块来获取状态方法的结果。还有更好的方法吗?

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,除了网上的一些例子外,我找不到任何文档。

1 个答案:

答案 0 :(得分:1)

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

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