首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用p4复制p4java回购协议?

如何利用p4复制p4java回购协议?
EN

Stack Overflow用户
提问于 2017-07-31 08:23:38
回答 2查看 558关注 0票数 1

我试图在Java程序中克隆P4存储库,同样使用P4java。

如何一次复制整个P4存储库,而不是一次读取一个文件(如下面所示)?

代码语言:javascript
复制
fileList = server.getDepotFiles(FileSpecBuilder.makeFileSpecList(new String[] {"//depot/dir/apps/..."}), false);
for (IFileSpec fileSpec : fileList){
    if (fileSpec != null){
            BufferedReader br = new BufferedReader(new InputStreamReader(fileSpec.getContents(true)));
    // create new file locally and write content
    }
}

任何帮助都是非常感谢的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-07 11:47:46

我找到了的解决方案,运转良好。(多亏了博客)。基本上,它创建一个新的临时客户端,并使用filespec (depot文件名)和p4同步命令克隆repo。编辑后的代码如下:

代码语言:javascript
复制
{
    InputStream input = new FileInputStream(getPerforceDetails);
    Properties prop = new Properties();
    prop.load(input);

    url = prop.getProperty("url"); //ex: perforce.xxx.xxxxxxx.com:port#
    repo = prop.getProperty("repo"); //ex: //depot/xxx/xxxx/apps/...
    username = prop.getProperty("username");
    password = prop.getProperty("password"));

    final String url = IServerAddress.Protocol.P4JAVA.toString() + "://" + serverUri;

    server = ServerFactory.getServer(url, null);
    server.connect();
    server.setUserName(username);       
    server.login(password);

    IServerInfo info = server.getServerInfo();
    System.out.println( "Server Info \n" + info);
    fileList = server.getDepotFiles(FileSpecBuilder.makeFileSpecList(new String[] {prop.getProperty("repo")}), false);
    //comment above line if you have only few files to clones and refer blog mentioned.

    // Creating new temporary client
    IClient tempClient = new Client();          
    tempClient.setName("tempClient" + UUID.randomUUID().toString().replace("-", ""));
    tempClient.setRoot("c:/tempP4"); 
    tempClient.setServer(server);

    // Setting the client as the current one for the server
    server.setCurrentClient(tempClient);

    // Creating Client View entry
    ClientViewMapping tempMappingEntry = new ClientViewMapping();

    // Setting up the mapping properties
    tempMappingEntry.setLeft("//depot/gxxxx/hxxxxxx/ixxxx/...");
    tempMappingEntry.setRight("//" + tempClient.getName() + "/...");
    tempMappingEntry.setType(EntryType.INCLUDE);     
    // Creating Client view
    ClientView tempClientView = new ClientView();
    // Attaching client view entry to client view
    tempClientView.addEntry(tempMappingEntry);
    tempClient.setClientView(tempClientView);
    // Registering the new client on the server
    System.out.println(server.createClient(tempClient));
    fileList = server.getDepotFiles(FileSpecBuilder.makeFileSpecList(new String[] {prop.getProperty("repo")}), false);
    try{
    // Forming the FileSpec collection to be synced-up
          List<IFileSpec> fileSpecsSet =     FileSpecBuilder.makeFileSpecList(pathsUnderDepot);
          // Syncing up the client
          //tempClient.sync(FileSpecBuilder.getValidFileSpecs(fileSpecsSet), true, false, false, false);
          //uncomment above line, n comment below if you are cloning only few files                 
          tempClient.sync(fileList, true, false, false, false);
    }finally{
        // Removing the temporary client from the server
          System.out.println(server.deleteClient(tempClient.getName(), false));
   }
 }

谢谢萨姆·斯塔福德给了我正确的方向。

票数 0
EN

Stack Overflow用户

发布于 2017-07-31 17:56:18

您的示例程序正在做什么(获取每个文件的头rev并编写一个本地副本)正是sync命令所做的。我建议您只使用sync

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

https://stackoverflow.com/questions/45410731

复制
相关文章

相似问题

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