我正在使用使用SWIG构建的Ruby SVN绑定。 Here's一个小教程。
当我这样做时
@repository = Svn::Repos.open('/path/to/repository')
我可以很好地访问存储库。但是当我这样做时
@repository = Svn::Repos.open('svn://localhost/some/path')
失败了
/SourceCache/subversion/subversion-35/subversion/subversion/libsvn_subr/io.c:2710: 2: Can't open file 'svn://localhost/format': No such file or directory
当我从命令行执行此操作时,我会得到输出
svn ls svn://localhost/some/path
为什么我不能使用svn://协议?
的任何想法修改的
这是我最终做的事情,并且有效。
require 'svn/ra'
class SvnWrapper
def initialize(repository_uri, repository_username, repository_password)
# Remove any trailing slashes from the path, as the SVN library will choke
# if it finds any.
@repository_uri = repository_uri.gsub(/[\/]+$/, '')
# Initialize repository session.
@context = Svn::Client::Context.new
@context.add_simple_prompt_provider(0) do |cred, realm, username, may_save|
cred.username = repository_username
cred.password = repository_password
cred.may_save = true
end
config = {}
callbacks = Svn::Ra::Callbacks.new(@context.auth_baton)
@session = Svn::Ra::Session.open(@repository_uri, config, callbacks)
end
def ls(relative_path, revision = nil)
relative_path = relative_path.gsub(/^[\/]+/, '').gsub(/[\/]+$/, '')
entries, properties = @session.dir(relative_path, revision)
return entries.keys.sort
end
def info(relative_path, revision = nil)
path = File.join(@repository_uri, relative_path)
data = {}
@context.info(path, revision) do |dummy, infoStruct|
# These values are enumerated at http://svn.collab.net/svn-doxygen/structsvn__info__t.html.
data['url'] = infoStruct.URL
data['revision'] = infoStruct.rev
data['kind'] = infoStruct.kind
data['repository_root_url'] = infoStruct.repos_root_url
data['repository_uuid'] = infoStruct.repos_UUID
data['last_changed_revision'] = infoStruct.last_changed_rev
data['last_changed_date'] = infoStruct.last_changed_date
data['last_changed_author'] = infoStruct.last_changed_author
data['lock'] = infoStruct.lock
end
return data
end
end
享受。
答案 0 :(得分:1)
svn
命令是客户端。它使用多个协议(http(s)://,svn://和file:///)与Subversion 服务器进行通信。
Repos.open
是一个存储库函数(就像svnadmin一样)。它直接在数据库上运行,不使用客户端协议与服务器通信。