2

我正在尝试编写一个方法,该方法将文件路径和修订号作为其参数并返回与修订关联的日期。我的代码可以工作(虽然速度很慢)但是,当我输入大于 51 的修订号时,输出会变得混乱。这是 API。

输入

String [] filePaths= {"//file/x/y/strings/somefile.csv"};
p4Client.getDateAssociatedWithFileRevision(filePaths, 52);

输出 - 这应该只是一行......

Rev number: 2 :: Revision Date: Wed Aug 24 23:48:42 BST 2005

Rev number: 52 :: Revision Date: Wed Aug 24 23:52:53 BST 2005

Rev number: 51 :: Revision Date: Sat Aug 20 02:01:59 BST 2005

getDateAssociatedWithFileRevision

public Date getDateAssociatedWithFileRevision(String [] filePath, int revisionNumber) {

        List<IFileSpec> fileList = null;
        Map<IFileSpec,List<IFileRevisionData>> fileRevisionData = null;
        String currentFile = null;
        Date revisionDate = null;

        try 
        {
            String file = filePath[0] + "#" + revisionNumber;
            currentFile = file;
            fileList = getIFileSpecList(file);  //Get list of file(s) in path

            for(IFileSpec fileSpec: fileList)
            {
                if(file.toString() == null)
                {
                    System.out.println("\"" + currentFile +"\"" + " does not exist...");
                    break;
                }
                fileRevisionData = fileSpec.getRevisionHistory(0, true,false,true,false);
                int i = 0;
                for(List<IFileRevisionData> revisionData : fileRevisionData.values()) {
                    revisionDate = revisionData.get(0).getDate();
                    int revision = revisionData.get(0).getRevision();
                    System.out.println("Rev number: " +revision +" :: " + "Revision Date: " + revisionDate);
                    System.out.println(i);
                    i++;
                }

            }
        }
        catch(Exception e){e.printStackTrace();}
        return revisionDate;  
     }

获取IFileSpecList

public List<IFileSpec> getIFileSpecList(String file) {
        List<IFileSpec> fileList = null;
        try {
            fileList = iServer.getDepotFiles(
                        FileSpecBuilder.makeFileSpecList(new String[] {file}), false);  //Get list of file(s) in path
        }
        catch(Exception e){e.printStackTrace();}
        return fileList;
     }

编辑

刚刚发现集成后输出变得混乱,现在只需要找到一种方法来处理它们..

4

2 回答 2

2

太多的工作。采用这个命令行理念(“p4 文件会为您提供经过解析的信息”)并让 Perforce 为您连接数据。然后对其进行 Java 化。

% p4 -Ztag files //guest/jeff_bowles/scripts/0228devbranch.html
... depotFile //guest/jeff_bowles/scripts/0228devbranch.html
... rev 2
... change 4421
... action edit
... type ktext
... time 1093044566

% p4 -Ztag files //guest/jeff_bowles/scripts/0228devbranch.html#1
... depotFile //guest/jeff_bowles/scripts/0228devbranch.html
... rev 1
... change 4420
... action add
... type ktext
... time 1093042787
于 2012-07-12T14:28:50.493 回答
1

我设法通过添加 if 语句(标记如下)仅返回我想要的日期。我不知道这个解决方案有多优雅......欢迎任何评论。

getDateAssociatedWithFileRevision

public Date getDateAssociatedWithFileRevision(String [] filePath, int revisionNumber) {

        List<IFileSpec> fileList = null;
        Map<IFileSpec,List<IFileRevisionData>> fileRevisionData = null;
        String currentFile = null;
        Date revisionDate = null;

        try 
        {
            String file = filePath[0] + "#" + revisionNumber;
            currentFile = file;
            fileList = getIFileSpecList(file);  //Get list of file(s) in path

            for(IFileSpec fileSpec: fileList)
            {
                if(file.toString() == null)
                {
                    System.out.println("\"" + currentFile +"\"" + " does not exist...");
                    break;
                }
                fileRevisionData = fileSpec.getRevisionHistory(0, true,false,true,false);
                for(List<IFileRevisionData> revisionData : fileRevisionData.values()) {
                    int revision = revisionData.get(0).getRevision();
     -------------> if(revision.equals(revisionNumber))
                    {
                        revisionDate = revisionData.get(0).getDate();

                        System.out.println("Rev number: " +revision +" :: " + "Revision Date: " + revisionDate);
                        break;

                    }
                }

            }
        }
        catch(Exception e){e.printStackTrace();}
        return revisionDate;  
     }
于 2012-07-10T16:24:28.013 回答