3

My overall goal is to be able to sync, check out, and check in files within a workspace. This is the main part I am confused about:

IList<FileSpec> files = new List<FileSpec>();
FileSpec file = new FileSpec(testpath, null, locpath, VersionSpec.Head);
files.Add(file);
IList<FileSpec> foundFiles = rep.GetDepotFiles(files, null);

con.Client.SyncFiles(foundFiles, null);

Changelist cl = new Changelist();
cl.Description = "newest change";
cl.ClientId = ws_client;
Changelist changelist = rep.CreateChangelist(cl);

//Added the line below
con.Client.EditFiles(new Options(EditFilesCmdFlags.None, changelist.Id, null), file);

I first create the list of depot files (foundFiles) that I get from the repository, which works fine. I then try to sync these files to the client. I then create a Changelist, but I do not know how to go about editing files and submitting the changes. I am aware of the Client.EditFiles and Changelist.Submit methods, but I am not sure how to utilize them in this situation since I do not fully understand the linkage between a client/workspace and a changelist. In short, I would like to be able to access, edit, and submit files. One main problem is that my Changelist has no files in it and I am predicting that knowing how to add files is the first step. Any help or sample code is greatly appreciated!

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
JuiceZBox
  • 111
  • 1
  • 8

2 Answers2

2

I know the question is 2 years old, but the p4api.net documentation is still poor, so any answer might help future users. I believe your remaining problem is that you use versioned file spec. Your problem should be solved by following last line:

        //Added the line below            
        con.Client.EditFiles(new P4.Options(P4.EditFilesCmdFlags.None, changelist.Id, null), P4.FileSpec.UnversionedSpecList(foundFiles).ToArray());
jing
  • 1,919
  • 2
  • 20
  • 39
0

I don't have a lot of experience with P4API.NET, but I think what you need to do is call Client.EditFiles, and use the options parameter to specify the changelist. Not sure if you'd use a reference to the changelist object, or just the changelist number.

Mike O'Connor
  • 3,813
  • 24
  • 27
  • Okay, so I added the Client.EditFiles to my code as shown above and am now getting an error: "A revision specification (# or @) cannot be used here." Any ideas? – JuiceZBox Jun 26 '13 at 15:47
  • A good deal of my files have the # sign in them, which may be the problem. I do not have the jurisdiction to change these and so am looking for a way around it if anyone has ideas. – JuiceZBox Jun 26 '13 at 16:07
  • Yes, I believe so. The variable "testpath" used above is a DepotPath and the path it references is within my perforce depot. – JuiceZBox Jun 27 '13 at 15:44
  • Although, when I go into perforce and look at the file whose path is referenced by "testpath", it says the file is "not mapped to workspace view" when I scroll over it. – JuiceZBox Jun 27 '13 at 16:22
  • You need to convert # to %23 in your path. See the bottom of http://www.perforce.com/perforce/doc.current/manuals/cmdref/o.fspecs.html. – Mike O'Connor Jun 27 '13 at 16:58
  • The thing is that when I am referencing the path, I am usually not directly referencing a file but rather a folder name. Even if I am referencing a specific file, it does not have a # in the name until I turn it into a FileSpec, which requires a VersionSpec as an argument. The VersionSpec always adds a # followed by version number. How would I convert the # to %23 if I am not directly typing in the file name? And thanks for the help so far! – JuiceZBox Jun 27 '13 at 17:46
  • I am now using the other EditFiles overload method for personal purposes. When I pass "file" above to the EditFiles method, that is where I get the error. Unfortunately, I cannot alter the string name of "file" because it is a FileSpec and not a string... – JuiceZBox Jun 27 '13 at 18:49