I am trying to write a method which takes a file path and a revision number as its arguments and returns the date the revision is associated with. The code I have works (although pretty slowely) however, when I put a revision number greater than 51 in, the output gets messed up.. Here is the API.
Input
String [] filePaths= {"//file/x/y/strings/somefile.csv"};
p4Client.getDateAssociatedWithFileRevision(filePaths, 52);
Output – This should just be one line…
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;
}
GetIFileSpecList
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;
}
Edit
Just figured out that the output is getting messed up after an integration, just need to find a way to handle them now..
I managed to return only the date I want by adding an if statement (marked below). I don’t know how elegant this solution is… any comments are welcome.
getDateAssociatedWithFileRevision