【问题标题】:Perforce P4API.NET Repository.GetDepotFiles() returns deleted filesPerforce P4API.NET Repository.GetDepotFiles() 返回已删除的文件
【发布时间】:2012-10-31 00:16:31
【问题描述】:

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

【问题讨论】:

  • 我找到了文档。像 google 和 microsoft(sd) 这样的大公司使用 perforce。 filehost.perforce.com/perforce/r11.1/doc/manuals/p4api.net/…
  • 我会假设您在文件规范中指定的头版本应​​该排除删除?有一个包装字典的选项类,但我没有看到 GetDepotFiles 的构造函数,选项的 GetFiles 构造函数只需要一个 int 来表示最大项。如果可能的话,也许可以使用 ILSpy 或其他东西,看看他们是否正在阅读 Options 字典的任何选项? filehost.perforce.com/perforce/r11.1/doc/manuals/p4api.net/…
  • 我认为您需要迭代 filesFound 列表,并且对于每个条目,您需要检查 FileAction.DELETE 是真还是假。这就是我们在 p4-java api 中的做法。我认为它与 p4api.net 相同。
  • .NET 具有 FileAction 枚举类,但 FileSpec 在其构造中没有文件属性,我可以检查 FileAction.deleted。您如何构造语法来检查 FileSpec for Java 中的每个文件?
  • 您可以查看ivyp4 中的方法list。除此之外,perforce java api manual 中应该还有一些内容。

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


【解决方案1】:

使用命令行 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。

【讨论】:

    猜你喜欢
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2020-09-04
    • 2012-03-20
    相关资源
    最近更新 更多