如何在 C# 中使用 SharpSVN 库设置 SVN 提交的作者

发布于 2024-07-19 03:04:29 字数 435 浏览 9 评论 0原文

我使用来自 CollabNET 的 SharpSvn 库。 我想在提交时设置修订作者,但我总是以我的 Windows 用户名进行提交。

这对我不起作用:

System.Net.NetworkCredential oCred = new
    System.Net.NetworkCredential("user"​, "pass");
client.Authentication.DefaultCredentials = oCred;

我也尝试过:

client.SetProperty("", "svn:author", "user");

但我收到一个错误,目标(第一个参数)不好。

那么你能告诉我如何在 c# 中设置提交到 subversion 存储库的用户(作者)吗?

I use SharpSvn library from CollabNET. I would like to set revision author while commiting, but I always end up with a commit with my Windows user name.

This does not work for me:

System.Net.NetworkCredential oCred = new
    System.Net.NetworkCredential("user"​, "pass");
client.Authentication.DefaultCredentials = oCred;

I've tried also:

client.SetProperty("", "svn:author", "user");

But I get an error that target (first argument) is bad.

So could you please tell me how to set user (author) of commit to subversion repository in c#?

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

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

发布评论

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

评论(1

内心激荡 2024-07-26 03:04:30

这一切都取决于您如何连接到存储库,因为存储库负责向修订添加用户名。 (它通常会复制连接的凭据,但并非必须这样做)。

当您使用 file:/// 存储库时(通常不推荐 - 请参阅The Subversion Book)您可以直接在提交上解决此问题。

using (SvnClient client = new SvnClient())
{
    client.Authentication.Clear(); // Clear predefined handlers

    // Install a custom username handler
    client.Authentication.UserNameHandlers +=
        delegate(object sender, SvnUserNameEventArgs e)
        {
            e.UserName = "MyName";
        };

    SvnCommitArgs ca = new SvnCommitArgs { LogMessage = "Hello" }
    client.Commit(dir, ca);
}

如果连接到远程存储库,则可以在存储库中安装 pre-revprop-change 挂钩时更改修订的作者(请参阅 颠覆书)

using (SvnClient client = new SvnClient())
{
    client.SetRevisionProperty(new Uri("http://my/repository"), 12345,
                              SvnPropertyNames.SvnAuthor,
                              "MyName");

    // Older SharpSvn releases allowed only the now obsolete syntax
    client.SetRevisionProperty(
        new SvnUriTarget(new Uri("http://my/repository"), 12345),
        SvnPropertyNames.SvnAuthor,
        "MyName");

}

[2009-08-14]
最新的 SharpSvn 版本也允许这样做:

using (SvnRepositoryClient rc = new SvnRepositoryClient())
{
   SvnSetRevisionPropertyRepositoryArgs ra;
   ra.CallPreRevPropChangeHook = false;
   ra.CallPostRevPropChangeHook = false;
   rc.SetRevisionProperty(@"C:\Path\To\Repository", 12345,
                         SvnPropertyNames.SvnAuthor, "MyName", ra);
}

最后一个示例假设直接文件访问存储库,但它绕过存储库挂钩以获得最佳性能。

This all depends on how you connect to your repository, as the repository is responsible for adding a username to the revision. (It usually copies the credentials for the connections but it doesn't have to do that).

When you use a file:/// repository (which is usually not recommended - See The Subversion Book) you can work around this directly on the commit.

using (SvnClient client = new SvnClient())
{
    client.Authentication.Clear(); // Clear predefined handlers

    // Install a custom username handler
    client.Authentication.UserNameHandlers +=
        delegate(object sender, SvnUserNameEventArgs e)
        {
            e.UserName = "MyName";
        };

    SvnCommitArgs ca = new SvnCommitArgs { LogMessage = "Hello" }
    client.Commit(dir, ca);
}

If you connect to a remote repository you can change the author of a revision when a pre-revprop-change hook is installed in the repository (See The Subversion Book)

using (SvnClient client = new SvnClient())
{
    client.SetRevisionProperty(new Uri("http://my/repository"), 12345,
                              SvnPropertyNames.SvnAuthor,
                              "MyName");

    // Older SharpSvn releases allowed only the now obsolete syntax
    client.SetRevisionProperty(
        new SvnUriTarget(new Uri("http://my/repository"), 12345),
        SvnPropertyNames.SvnAuthor,
        "MyName");

}

[2009-08-14]
More recent SharpSvn releases also allow this:

using (SvnRepositoryClient rc = new SvnRepositoryClient())
{
   SvnSetRevisionPropertyRepositoryArgs ra;
   ra.CallPreRevPropChangeHook = false;
   ra.CallPostRevPropChangeHook = false;
   rc.SetRevisionProperty(@"C:\Path\To\Repository", 12345,
                         SvnPropertyNames.SvnAuthor, "MyName", ra);
}

This last example assumes direct file access to the repository, but it bypasses repository hooks for optimal performance.

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