[英]P4Api client.GetFileMappings not returns leading minus/dash sign for branched files
我在多個分支下的 P4 服務器上有文件,例如
//depot/branch1/file.txt
//depot/branch2/file.txt
//depot/branch3/file.txt
假設 file.txt 是同一個文件但不同的分支
當我使用命令行時
p4 -c testWorkspace where somepath\file.txt
我得到以下結果
-//depot/branch1/file.txt {client path depot path}
-//depot/branch2/file.txt {client path depot path}
//depot/branch3/file.txt {client path depot path}
從中我可以知道應該通過 branch3 訪問客戶端 testWorkspace 中的 file.txt(因此從這個倉庫路徑我將獲得 FileSpec、Metadata、edit 等
但是當我嘗試通過 P4api.net 做同樣的事情並使用
Client.GetClientFileMappings("somepath\file.txt")
或者
P4Command cmd3 = new P4Command(con, "where", true, "somepath\file.txt");
P4CommandResult result3 = cmd3.Run();
我得到了類似的結果,但沒有前導減號(破折號 -)
//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 等。 但我只獲得所有分支的路徑,並且可以識別它屬於當前工作區的哪個分支
查看 GetClientFileMappings 的接口:
看起來它實際上並沒有返回映射; 它返回一個 FileSpec 對象列表,沒有關於映射類型的信息(例如-
、 +
或&
)。 在 C++ API 中,這由MapType
枚舉表示:
https://swarm.workshop.perforce.com/projects/perforce_software-p4/files/2018-2/support/mapapi.h#6
在 .NET API 中有一個類似的枚舉:
https://www.perforce.com/manuals/v15.1/p4api.net/p4api.net_reference/html/T_Perforce_P4_MapType.htm
這是MapEntry
類型的一部分:
如果你能找到任何返回MapEntry
列表的東西,那就是你想要的東西,但我找不到任何東西。 GetClientFileMappings
似乎是問題,尤其是因為名稱中包含“映射”,但是......
所以我與 P4 團隊成員討論了這個問題,他們確認 GetClientFileMappings 確實不返回有關排除的信息。
他們給了我一個“解決方法”
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() 和解析字符串結果)
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>();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.