Perforce Api - 如何命令“获取修订版 [更改列表编号]"; [英] Perforce Api - How to command "get revision [changelist number]"

查看:134
本文介绍了Perforce Api - 如何命令“获取修订版 [更改列表编号]";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Perforce .NET API (C#) 实现 Perforce 命令获取修订版 [更改列表编号]".我目前有可以获取最新修订版"的代码,但我需要对其进行修改以获取特定的更改列表.

I would like to implement the Perforce command "Get Revision [Changelist Number]" using the Perforce .NET API (C#). I currently have code that will "Get Latest Revision", but I need to modify it to get a specific changelist.

要将数据与更改列表编号同步,我该怎么做?

To sync the data with a changelist number, what should I do?

来源

// --------Connenct----------------
Perforce.P4.Server server = new Perforce.P4.Server(
    new Perforce.P4.ServerAddress("127.0.0.1:9999"));
Perforce.P4.Repository rep = new Perforce.P4.Repository(server);
Perforce.P4.Connection con = rep.Connection;

con.UserName = m_P4ID;
string password = m_P4PASS;

Perforce.P4.Options opconnect = new Perforce.P4.Options();
opconnect.Add("-p", password);
con.Connect(opconnect);

if (con.Credential == null)
    con.Login(password);

//----------Download----------
string clientPath = @"C:\P4V\";
string ws_client = clientPath;
Perforce.P4.Client client = new Perforce.P4.Client();
client.Name = ws_client;
client.Initialize(con);

con.CommandTimeout = new TimeSpan(0);
IList<Perforce.P4.FileSpec> fileList = client.SyncFiles(new Perforce.P4.Options());

//----------Disconnect------------
con.Disconnect();
con.Dispose();

尝试 1

Perforce.P4.DepotPath depot = new Perforce.P4.DepotPath("//P4V//");
Perforce.P4.LocalPath local = new Perforce.P4.LocalPath(ws_client);
Perforce.P4.FileSpec fs = new Perforce.P4.FileSpec(depot, null, local,
    Perforce.P4.VersionSpec.Head);

IList<Perforce.P4.FileSpec> listFiles = new List<Perforce.P4.FileSpec>();
listFiles.Add(fs);
IList<Perforce.P4.FileSpec> foundFiles = rep.GetDepotFiles(listFiles,
    new Perforce.P4.Options(1234)); // 1234 = Changelist number

client.SyncFiles(foundFiles, null);

错误信息

用法:files/print [-o localFile -q] files...无效选项:-c.

Usage: files/print [-o localFile -q] files...Invalid option: -c.

我不知道任何争论的问题.

I do not know the problem of any argument.

或者不会有与此参考源相关的内容?

Or there will not be related to this reference source?

编辑 2

我试图解决这个问题.然而,它还没有解决问题.

I tried to solve this problem. However, it does not solve the problem yet.

Perforce.P4.Changelist changelist = rep.GetChangelist(1234);
IList<Perforce.P4.FileMetaData> fileMeta = changelist.Files;

在这种情况下,我只能获取更改列表中的文件.我想在changelist 1234时刻同步客户端的所有文件.

In this case, I could get only the files in the changelist. I would like to synchronize all files of the client at the moment of changelist 1234.

推荐答案

SyncFiles 采用可选的 FileSpec 参数.您可以使用该 FileSpec arg 指定文件路径和修订说明符.以下是相关文档:

SyncFiles takes an optional FileSpec arg. You can specify a file path and a revision specifier with that FileSpec arg. Here are the relevant docs:

FileSpec 对象文档

SyncFiles 方法文档

您不需要运行 GetDepotFiles() 来获取 FileSpec 对象;您可以直接创建一个,如 FileSpec 对象文档中所示.您使用 GetDepotFiles() 遇到的错误是因为它希望将更改编号指定为作为 GetDepotFiles() 的第一个参数传入的 FileSpec 对象的一部分.

You don't need to run GetDepotFiles() to get the FileSpec object; you can just create one directly as shown in the FileSpec object docs. The error you are getting with GetDepotFiles() is because it expects the change number to be specified as part of the FileSpec object passed into as the first argument to GetDepotFiles().

为了进一步扩展,GetDepotFiles() 在与 Perforce 对话时调用p4 文件"命令.new Perforce.P4.Options(1234) 生成-c 1234"选项,p4 文件"不接受该选项.这就是为什么错误消息是用法:文件/打印 [-o localFile -q] 文件...无效选项:-c."

To expand further, GetDepotFiles() calls the 'p4 files' command when it talks to Perforce. new Perforce.P4.Options(1234) generates an option of '-c 1234' which 'p4 files' doesn't accept. That's why the error message is 'Usage: files/print [-o localFile -q] files...Invalid option: -c.'

这篇关于Perforce Api - 如何命令“获取修订版 [更改列表编号]";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆