为什么我必须使用本地路径而不是“svn://”与 SVN 绑定?

发布于 2024-08-25 00:59:39 字数 2455 浏览 9 评论 0原文

我正在使用使用 SWIG 构建的 Ruby SVN 绑定。 这里一点教程。

当我这样做时,

@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

享受。

I'm using the Ruby SVN bindings built with SWIG. Here's a little tutorial.

When I do this

@repository = Svn::Repos.open('/path/to/repository')

I can access the repository fine. But when I do this

@repository = Svn::Repos.open('svn://localhost/some/path')

It fails with

/SourceCache/subversion/subversion-35/subversion/subversion/libsvn_subr/io.c:2710: 2: Can't open file 'svn://localhost/format': No such file or directory

When I do this from the command line, I do get output

svn ls svn://localhost/some/path

Any ideas why I can't use the svn:// protocol?

EDIT

Here's what I ended up doing, and it works.

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

Enjoy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2024-09-01 00:59:40

svn 命令是一个客户端。它使用多种协议(http(s)://、svn:// 和 file:///)与 Subversion 服务器通信。

Repos.open 是一个存储库函数(例如,很像 svnadmin)。它直接对数据库进行操作,不使用客户端协议与服务器进行通信。

The svn command is a client. It communicates with the Subversion server using several protocols (http(s)://, svn:// and file:///).

Repos.open is a repository function (much like svnadmin for instance). It operates directly on the database, and doesn't use a client protocol to communicate with the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文