筛选 P4 .Net 文件列表
本文关键字:列表 文件 Net P4 筛选 | 更新日期: 2023-09-27 18:36:53
>我有一个程序,它填充了一个组合框,其中包含perforce库中选定目录中包含的文件的详细信息。
相关的代码段是这样的:
PerforcePath dir = _ctlProductSelect.SelectedItem as PerforcePath;
_ctlServicePackSelect.Items.Clear();
if (dir != null)
{
foreach (P4.File file in _perforce.GetFiles(null, P4.FileSpec.DepotSpec(dir.Path + "/*.sp")))
{
_ctlServicePackSelect.Items.Add(new PerforcePath(file.DepotPath.Path));
}
}
问题是这还包括标记为已删除的文件。有什么方法可以从GetFiles
方法返回的列表中过滤已删除的文件?我在 P4_dotNet API 文档中找不到任何可能的嫌疑人。
使用 P4API.NET,您可以将 -e
选项添加到 GetFiles
:
IList filesToFind = new List();
FileSpec fileToFind = new FileSpec(new DepotPath("//depot/..."), null, null, VersionSpec.Head);
filesToFind.Add(fileToFind);
Options o = new Options();
o.Add("-e", "");
IList filesFound = pRep.GetFiles(filesToFind, o);
我最终的工作是做这个 inisde foreach 循环:
foreach (P4.File file in _perforce.GetFiles(null, P4.FileSpec.DepotSpec(dir.Path + "/*.sp")))
{
if (_perforce.GetFileMetaData(null, file)[0].HeadAction.ToString() != "MoveDelete")
_ctlServicePackSelect.Items.Add(new PerforcePath(file.DepotPath.Path));
}
基本上在将每个文件添加到组合框之前检查每个文件的元数据。
IList<FileSpec> filesToFind = new List<FileSpec>();
FileSpec fileToFind = new FileSpec(FileSpec.DepotSpec("//depot/...").DepotPath, Revision.Head);
filesToFind.Add(fileToFind);
Options o = new Options();
o.Add("-m", "changelistid");
IList<File> FilesFound = rep.GetFiles(filesToFind, o)