3

I used the Perforce Repository.GetDepotFiles() and noticed that the function returns files that match the search pattern but also returns files that have been deleted in the Perforce Depot. How do I filter out the search to exclude deleted files?

My code to do file search in Depot:

IList<FileSpec> filesToFind = new List<FileSpec>();
FileSpec fileToFind = new FileSpec(new DepotPath("//depot/....cpp"), null, null, VersionSpec.Head);
filesToFind.Add(fileToFind);
IList<FileSpec> filesFound = pRep.GetDepotFiles(filesToFind, null);
tshepang
  • 12,111
  • 21
  • 91
  • 136
Kevin
  • 515
  • 4
  • 11
  • 22
  • I found documentation. Big companies like google and microsoft(sd) use perforce. http://filehost.perforce.com/perforce/r11.1/doc/manuals/p4api.net/p4api.net_reference/html/M_Perforce_P4_Repository_GetDepotFiles.htm – AbdElRaheim Oct 31 '12 at 03:19
  • I would assume the head version you are specifing in the filespec should exclude deletes? There is this options class that wraps a dictionary but I dont see a constructor for GetDepotFiles, the GetFiles constructor for options just takes an int for max items. If possible maybe use ILSpy or something and see if they are reading any options for the Options dictionary? http://filehost.perforce.com/perforce/r11.1/doc/manuals/p4api.net/p4api.net_reference/html/AllMembers_T_Perforce_P4_Options.htm – AbdElRaheim Oct 31 '12 at 03:26
  • 1
    I think you need to iterate the filesFound list and for each entry you need to check if FileAction.DELETE is true or false. That's the way we do it in the p4-java api. I assume it's the same with p4api.net. – pitseeker Oct 31 '12 at 07:42
  • .NET has the FileAction enum class but the FileSpec doesn't have a file attribute in its construct that I can check for FileAction.deleted. How do you construct the syntax to check each file in FileSpec for Java? – Kevin Oct 31 '12 at 18:20
  • You could have a look at method `list` in [ivyp4](https://github.com/fdrueke/ivyp4/blob/master/src/com/orga/ivy/plugins/p4resolver/P4Repository.java). Apart from that there should be something in [perforce java api manual](http://www.perforce.com/perforce/doc.current/manuals/p4java/index.html). – pitseeker Nov 02 '12 at 08:15

1 Answers1

0

Using the command-line p4.exe you can get a list of non-deleted files like this:

  p4 files -e //depot/....cpp

The command p4 files supports a couple of different flags, like '-a' and '-A'. These are supported by p4api.net.dll:

  Options options = new FilesCmdOptions(FilesCmdFlags.AllRevisions, maxItems: 10);
  IList<FileSpec> filesFound = rep.GetDepotFiles(filesToFind, options);

FilesCmdFlags.AllRevisions corresponds to the '-a' flag (and FilesCmdFlags.IncludeArchives is '-A'). Unfortunately it seems that '-e' is not supported by p4api.net.dll.

There is however a workaround using P4Command:

  var cmd = new P4Command(rep, "files", true);
  StringList args = new StringList(new[] { "-e", "//depot/....cpp" });
  P4CommandResult result = cmd.Run(args);

  IEnumerable<FileSpec> foundFiles =
    result.TaggedOutput.Select(o => 
      new FileSpec(new DepotPath(o["depotFile"]),
                   null,
                   null,
                   VersionSpec.None));

  foreach (FileSpec file in foundFiles)
    Console.WriteLine("Found {0}", file.DepotPath);

I'm using p4net.api.dll version 2013.3.78.1524.

Daniel Brixen
  • 1,633
  • 13
  • 20