问题描述
我将通过 perforce API 同步 perforce 文件.我期望每个文件操作的输出.类似于我们从 p4 cmd 看到的输出:
I am going to sync perforce files through perforce API. I expect output about each file operation. Something like what we see as output from p4 cmd:
- //depot/file.txt#1 - 正在更新 X:\file.txt
- //depot/file.txt#2 - 删除为 X:\file.txt
- //depot/file.txt#1 - updating X:\file.txt
- //depot/file.txt#2 - deleted as X:\file.txt
这是我用于同步文件的 perforce api 代码:
Here is my perforce api code to sync files:
var repository = new P4.Repository(new P4.Server(new P4.ServerAddress("server:111111")));
repository.Connection.UserName = "me";
repository.Connection.Connect(new P4.Options());
repository.Connection.Login("password");
repository.Connection.Client = repository.GetClient("client");
var syncFlags = new P4.Options(P4.SyncFilesCmdFlags.Force, 100);
var clientPath = new P4.ClientPath(@"X:\File.txt");
IList<P4.FileSpec> results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(1)) });
P4.VersionSpec downloadedVersion = results.First().Version; // This is #1 as expected
results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(2)) });
downloadedVersion = results.First().Version; // This is #2 as expected
results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(0)) });
downloadedVersion = results.First().Version; // File is really deleted and I hoped for #0, but it's #2!
我如何获得文件被删除的信息?我尝试使用 SyncFiles 输出,但对于已删除的文件,该信息不正确.还有其他办法吗?
How can I get information that the file is deleted? I tried to use SyncFiles output for that, but the information is not correct for deleted files. Is there any other way?
推荐答案
这是我找到的解决方案:
Here is solution I found:
repository.Connection.TaggedOutputReceived += Connection_TaggedOutputReceived;
static void Connection_TaggedOutputReceived(uint cmdId, int ObjId, P4.TaggedObject t)
{
string action, oldAction, haveRevStr, depotFile;
t.TryGetValue("action", out action);
t.TryGetValue("oldAction", out oldAction);
t.TryGetValue("haveRev", out haveRevStr);
t.TryGetValue("depotFile", out depotFile);
if (haveRevStr == null || haveRevStr == "none")
haveRevStr = string.Empty;
else
haveRevStr = "#" + haveRevStr;
if (string.IsNullOrEmpty(oldAction))
oldAction = string.Empty;
else
oldAction = oldAction + " ";
if (depotFile != null && action != null)
Console.Out.WriteLine("{0}{1} - {2}{3}", depotFile, haveRevStr, oldAction, action);
}
... repository.Connection 还包含其他有趣的钩子委托:.CommandEcho、.Errorreceived、.InfoResultReceived、.TextResultsReceived
... the repository.Connection contains also other interesting delegates to hook: .CommandEcho, .Errorreceived, .InfoResultReceived, .TextResultsReceived
这篇关于如何显示 Perforce API 执行的文件操作的输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!