首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于分支文件,P4Api client.GetFileMappings不返回前导减号/破折号

对于分支文件,P4Api client.GetFileMappings不返回前导减号/破折号
EN

Stack Overflow用户
提问于 2019-12-19 14:31:54
回答 2查看 126关注 0票数 2

我在P4服务器上的多个分支下有文件,例如

代码语言:javascript
复制
//depot/branch1/file.txt
//depot/branch2/file.txt
//depot/branch3/file.txt

假设file.txt是同一个文件但不同的分支

当我使用命令行

代码语言:javascript
复制
p4 -c testWorkspace where somepath\file.txt

我得到了以下结果

代码语言:javascript
复制
-//depot/branch1/file.txt {client path depot path}
-//depot/branch2/file.txt {client path depot path}
//depot/branch3/file.txt {client path depot path}

由此我可以看出,客户端testWorkspace中的file.txt应该通过branch3进行访问(因此,从该仓库路径中,我将获得FileSpec、元数据、编辑等

但是当我尝试通过P4api.net做同样的事情,并使用

代码语言:javascript
复制
Client.GetClientFileMappings("somepath\file.txt")

代码语言:javascript
复制
P4Command cmd3 = new P4Command(con, "where", true, "somepath\file.txt");
P4CommandResult result3 = cmd3.Run();

我得到了类似的结果,但没有前导减号(破折号)

代码语言:javascript
复制
//depot/branch1/file.txt {client path depot path}
//depot/branch2/file.txt {client path depot path}
//depot/branch3/file.txt {client path depot path}

我不知道我到底做错了什么。

我需要的是获得给定工作空间的当前文件属于哪个分支的信息,或者更好地获得其正确的FileSpec,以便我可以使用MoveFile、Add等。但我只能获得所有分支的路径,并且可以识别它在当前工作空间中属于哪个分支

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-07 14:54:00

所以我和P4团队成员讨论了这个问题,他们确认GetClientFileMappings真的不会返回有关排除的信息。

他们给了我一个“变通办法”

代码语言:javascript
复制
P4Command cmd3 = new P4Command(con, "where", true, "somepath\file.txt");
P4CommandResult result3 = cmd3.Run();
if (result3.TaggedOutput!=null)
    {
        List<string> depotFiles = new List<string>();
        foreach(TaggedObject taggedObject in results3.TaggedOutput)
        {
            if (taggedObject.ContainsKey("unmap"))
            {
                continue;
            }
            else
            {
                string path = "";
                taggedObject.TryGetValue("depotFile", out path);
                depotFiles.Add(path);
            }
        }
    }

这对我很有效。在原始问题中,我提到这不会返回前导'-‘,这是真的。但taggedObject包含的关键字"unmap“足以确定信息。

我第一次没有注意到这一点,因为我以错误的方式传递了参数。"file1.txt file2.txt“作为简单字符串,而不是字符串数组。

我还想出了另一个更难看的“变通办法”(使用p4命令行、process.Start()和解析字符串结果)

代码语言:javascript
复制
string commandText = $"/C p4 -u {UserName} -c {Client.Name} where {string.Join(" ", filePaths)}";

var process = new Process()
{
    StartInfo = new ProcessStartInfo()
    {
        UseShellExecute = false,
        CreateNoWindow = true,
        WindowStyle = ProcessWindowStyle.Hidden,
        FileName = "cmd.exe",
        Arguments = commandText,
        RedirectStandardError = true,
        RedirectStandardOutput = true

    }
};

process.Start();

string processTextResult = process.StandardOutput.ReadToEnd();

var exitCode = process.ExitCode;
var errorMsg = process.StandardError.ReadToEnd();


process.Dispose();
if (exitCode == 0)
{
    var resultLines = processTextResult.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

    List<FileSpec> fileSpecResults = new List<FileSpec>();

    foreach (var resultLine in resultLines)
    {
        var splitedLine = resultLine.Split(' ');

        if (!splitedLine.First().StartsWith("-"))
        {
            fileSpecResults.Add(new FileSpec(new DepotPath(splitedLine[0]), new ClientPath(splitedLine[1]), new LocalPath(splitedLine[2]), null));
        }
    }

    return fileSpecResults;
}
else
{
    Logger.TraceError("P4 error - get file spec :" + errorMsg);
    return new List<FileSpec>();
}
票数 0
EN

Stack Overflow用户

发布于 2019-12-20 00:22:01

查看GetClientFileMappings的接口:

https://www.perforce.com/manuals/v15.1/p4api.net/p4api.net_reference/html/M_Perforce_P4_Client_GetClientFileMappings.htm

它看起来并不像是真正返回一个映射;它返回一个FileSpec对象列表,没有关于映射类型的信息(例如-+&)。在C++应用编程接口中,这由MapType枚举表示:

https://swarm.workshop.perforce.com/projects/perforce_software-p4/files/2018-2/support/mapapi.h#6

在.NET应用程序接口中有一个类似的枚举:

https://www.perforce.com/manuals/v15.1/p4api.net/p4api.net_reference/html/T_Perforce_P4_MapType.htm

它是MapEntry类型的一部分:

https://www.perforce.com/manuals/v15.1/p4api.net/p4api.net_reference/html/M_Perforce_P4_MapEntry__ctor.htm

如果你能找到任何能返回MapEntry列表的东西,那就是你想要的东西,但是我找不到任何能返回的东西。GetClientFileMappings似乎就是这样,特别是因为名称中有“映射”,但是...

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59404338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档