0

Trying to revert files in a changelist using -a option in p4api.net method. It used to work for me but now am getting exception with below message.

Also p4 edit and p4 revert with -c option works fine but p4 revert with -a option throws below exception. I don't know why its picking below test project location in p4 workspace location.

Exception:

Path 'd:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug\19402547' is not under client's root 'D:\p4'.

// to open files for edit in a given changelist at certain loc with particular file format 
          public IList<FileSpec> EditChangeList(string clNumber, string fileFormat, string destinationPath)
    {
        try
        {
            var rep = Connect();
            var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
            opts["-c"] = clNumber;
            var fs = new FileSpec(new DepotPath(destinationPath + "/..." + fileFormat));
            IList<FileSpec> editedFileSpec = rep.Connection.Client.EditFiles(new List<FileSpec> {fs}, opts);
            return editedFileSpec;
        }
        catch (Exception exc)
        {
            Logger.LogError(exc.Message);
            throw;
        }
    }

    // to revert files in a changelist that are unchanged using -a option
           public IList<FileSpec> RevertChangeList(string clNumber, string destinationPath)
    {
        try
        {
            var rep = Connect();
            var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
            opts["-a"] = clNumber;
            var fs = new FileSpec(new DepotPath(destinationPath + "/..."));
            IList<FileSpec> revertedFiles = rep.Connection.Client.RevertFiles(new List<FileSpec> {fs}, opts);
            return revertedFiles;
        }
        catch (Exception exc)
        {
            Logger.LogError(exc.Message);
            throw;
        }
    }
test
  • 91
  • 11
  • What is the value of "destinationPath"? Is it 'd:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug\19402547'? – Bryan Pendleton Mar 14 '15 at 17:56
  • @Bryan Nope, the value of destination path is the perforce workspace location i.e. "D:\\p4\\sw\\dev\\gpu_drv\\chips_a\\diag\\mods\\sim\\resources" It gives exception at revertedFiles line i.e. Path 'd:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug\19402547' is not under client's root 'D:\p4'. d:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug -> this is test project location from where i started unit test to test end to end flow. Wondering why its appending changelist number in test project location and ideally it should append in perforce workspace location. – test Mar 15 '15 at 04:03

1 Answers1

0

The revert command takes several different types of flags and arguments:

  • flags like -a, -n, and -w, which don't have any value, but are just the flag
  • the -c flag, which takes the changelist number as a value for the flag
  • the files to be reverted, which are specified as arguments after all the flags (you can specify multiple file arguments)

In your command, you ran:

p4 revert -a 19402547 d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

Since the -a flag doesn't take a value, the revert command saw this as:

  • the -a flag
  • a file argument: 19402547
  • a file argument: d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

Since the file argument 19402547 did not have a directory name in front of it, the revert command interpreted it as a relative file name, relative to your current directory, and looked for a file named 'd:\cftt\Dev\source\BRF\BRF.Business.Test\bin\Debug\19402547' , which indeed is not under your client's Root directory, and so isn't a file that Perforce is capable of reverting.

The right approach here is either to omit the changelist number entirely, or to specify it as the value of the -c flag, depending on whether you wish to revert all open files in the sim\resources directory, or whether you only wish to revert those open files in that directory which are open in changelist 19402547.

That is, both:

p4 revert -a d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

and

p4 revert -a -c 19402547 d:\p4\sw\dev\gpu_drv\chips_a\diag\mods\sim\resources/...

are reasonable commands, and the right one to pick depends on precisely which behavior you want.

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
  • I want to revert only those files which are still unchanged at sim/resources directory in a given changelist. That's why i used -a flag and it worked for me say 15-20 days back with same function. Reason being to use -a is that i need to send/use that changelist with only files which are actually updated and discard "open for edit files" which remained unchanged in that changelist. – test Mar 15 '15 at 17:06
  • In that case, specify *both* -a and -c, and provide the changelist number as the value of the -c flag, not as the value of the -a flag (the -a flag does not have an associated value, as I explained above). – Bryan Pendleton Mar 15 '15 at 19:22
  • Thanks very much, Bryan. Awesome, it worked. opts["-a"] = ""; var fs = new FileSpec(new DepotPath(destinationPath + "/...")); IList revertedFiles = rep.Connection.Client.RevertFiles(new List {fs}, opts); – test Mar 16 '15 at 06:06
  • Also, i have noticed that there is an update in p4api.net dll in my project and earlier version of p4api.net works fine with opts["-a"] = clNumber whereas it didn't work with latest version of p4api.net (opts["-a"] = clNumber;). so, as per your suggestion, with latest version of p4api.net, i had to try with opts["-a"] = ""; with no value with flag -a and it worked. why there is change in behavior? is this intentionally done from p4api.net or a bug? – test Mar 16 '15 at 06:11
  • Sorry, I don't know why there was a change in behavior. – Bryan Pendleton Mar 16 '15 at 13:46