0

尝试使用 p4api.net 方法中的 -a 选项还原更改列表中的文件。它曾经对我有用,但现在出现以下消息异常。

p4 edit 和 p4 revert with -c 选项也可以正常工作,但 p4 revert with -a 选项会引发以下异常。我不知道为什么它在 p4 工作区位置的测试项目位置下方选择。

例外:

路径 'd:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug\19402547' 不在客户端的根目录 'D:\p4' 下。

// to open files for edit in a given changelist at certain loc with particular file format 
          public IList<FileSpec> EditChangeList(string clNumber, string fileFormat, string destinationPath)
    {
        try
        {
            var rep = Connect();
            var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
            opts["-c"] = clNumber;
            var fs = new FileSpec(new DepotPath(destinationPath + "/..." + fileFormat));
            IList<FileSpec> editedFileSpec = rep.Connection.Client.EditFiles(new List<FileSpec> {fs}, opts);
            return editedFileSpec;
        }
        catch (Exception exc)
        {
            Logger.LogError(exc.Message);
            throw;
        }
    }

    // to revert files in a changelist that are unchanged using -a option
           public IList<FileSpec> RevertChangeList(string clNumber, string destinationPath)
    {
        try
        {
            var rep = Connect();
            var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
            opts["-a"] = clNumber;
            var fs = new FileSpec(new DepotPath(destinationPath + "/..."));
            IList<FileSpec> revertedFiles = rep.Connection.Client.RevertFiles(new List<FileSpec> {fs}, opts);
            return revertedFiles;
        }
        catch (Exception exc)
        {
            Logger.LogError(exc.Message);
            throw;
        }
    }
4

1 回答 1

0

revert 命令采用几种不同类型的标志和参数:

  • 像 -a、-n 和 -w 这样的标志,它们没有任何值,而只是标志
  • -c 标志,它将更改列表编号作为标志的值
  • 要恢复的文件,在所有标志之后指定为参数(您可以指定多个文件参数)

在您的命令中,您运行了:

p4 revert -a 19402547 d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

由于 -a 标志不带值,因此 revert 命令将其视为:

  • -a 标志
  • 文件参数:19402547
  • 文件参数:d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

由于文件参数 19402547 前面没有目录名,revert 命令将其解释为相对文件名,相对于当前目录,并查找名为 'd:\cftt\Dev\source\BRF \BRF.Business.Test\bin\Debug\19402547' ,它确实不在您客户端的 Root 目录下,因此不是 Perforce 能够还原的文件。

此处正确的方法是完全省略更改列表编号,或者将其指定为 -c 标志的值,具体取决于您是否希望还原 sim\resources 目录中的所有打开文件,或者您是否只想还原该目录中打开的文件在更改列表 19402547 中打开。

也就是说,两者:

p4 revert -a d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

p4 revert -a -c 19402547 d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

是合理的命令,正确的选择取决于您想要的行为。

于 2015-03-15T15:55:50.703 回答