我使用了 Perforce Repository.GetDepotFiles() 并注意到该函数返回与搜索模式匹配的文件,但也返回已在 Perforce Depot 中删除的文件。如何过滤搜索以排除已删除的文件?
我在 Depot 中进行文件搜索的代码:
IList<FileSpec> filesToFind = new List<FileSpec>();
FileSpec fileToFind = new FileSpec(new DepotPath("//depot/....cpp"), null, null, VersionSpec.Head);
filesToFind.Add(fileToFind);
IList<FileSpec> filesFound = pRep.GetDepotFiles(filesToFind, null);
最佳答案
使用命令行 p4.exe,您可以获得如下所示的未删除文件列表:
p4 files -e //depot/....cpp
命令 p4 files
支持几个不同的标志,例如“-a”和“-A”。这些由 p4api.net.dll 支持:
Options options = new FilesCmdOptions(FilesCmdFlags.AllRevisions, maxItems: 10);
IList<FileSpec> filesFound = rep.GetDepotFiles(filesToFind, options);
FilesCmdFlags.AllRevisions
对应于“-a”标志(而 FilesCmdFlags.IncludeArchives
是“-A”)。不幸的是,p4api.net.dll 似乎不支持“-e”。
但是有一个使用 P4Command 的解决方法:
var cmd = new P4Command(rep, "files", true);
StringList args = new StringList(new[] { "-e", "//depot/....cpp" });
P4CommandResult result = cmd.Run(args);
IEnumerable<FileSpec> foundFiles =
result.TaggedOutput.Select(o =>
new FileSpec(new DepotPath(o["depotFile"]),
null,
null,
VersionSpec.None));
foreach (FileSpec file in foundFiles)
Console.WriteLine("Found {0}", file.DepotPath);
我使用的是 p4net.api.dll 版本 2013.3.78.1524。
关于c# - Perforce P4API.NET Repository.GetDepotFiles() 返回已删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13149481/