这一切都取决于您如何连接到存储库,因为存储库负责将用户名添加到修订版。(它通常会复制连接的凭据,但不必这样做)。
当您使用 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 挂钩时更改修订的作者(请参阅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] 最近的 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);
}
最后一个示例假设直接文件访问存储库,但它绕过存储库挂钩以获得最佳性能。