c# - Perforce P4API.NET Repository.GetDepotFiles() 返回已删除的文件

标签 c# .net file-io perforce p4api.net

我使用了 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/

相关文章:

c# - Entity Framework 和面向服务的架构如何入手?

.net - 反射,有IsClass但没有IsStruct?

Android:如何使用 ndk 从 C++ 代码中读取游戏 Assets 文件

java - Java 中的 FileOutputStream 问题

C# null 合并运算符返回 null

c# 在自定义属性中执行代码

c# - Java(我的世界)不是从 C# 开始的

c# - 如何将 javascript 添加到 WebBrowser.NavigateToString()?

c# - 检测它是否是应用程序的最后一个实例 c#

c# - 如何从解决方案项目中添加的 .txt 文件中读取