Jump to content


How to create changelist, revert all files/unchanged files in a changelist, copy files, submit perl command in p4.net api

p4.net api

  • Please log in to reply
2 replies to this topic

#1 PerfQuery

PerfQuery

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 25 January 2015 - 04:43 AM

I am trying to create changelist,  revert all files present at local work space location as well as revert unchanged files at same local location, copy files from src to dest and running perl command using p4.net api. Could someone help in this in achieving this?

Basically i am trying to do this in my .net project. I want to do everything using p4.net API. Below is batch file implemented

SO basically am looking below implementation in p4.net api
-first sync files at local directory
-create new changelist
-Revert all files if anything is opened for edit in above changelist
-then actually open it above changelist for fresh edit
-copy files recursively from source location to destination of particular format  of files like format*.*
-Then reverting all unchanged files in above changelist at local workspace location where all files are copied
-After that submit perl command using above changelist which has changes

Batch file:

SET P4CLIENT=deep_abc
SET P4PORT=p4ww:2012
SET SRC="\\serverpath\resources"
SET CPATH=C:
SET AS2="C:\as2\as2\beta_0.4\bin"
SET DEST="localpath\resources"
SET DPATH=D:

%DPATH%
cd %DEST%
pause
p4 revert -c 19264444 file ...
pause
p4 edit -c 19264444 GP100*.*
pause
robocopy %SRC% %DEST% *.rom
pause
p4 revert -a 19264444 file ...
pause
%CPATH%
cd %AS2%
pause
perl as2.pl -c %p4client% submit -t -c 19264444
pause

#2 P4Shimada

P4Shimada

    Advanced Member

  • Members
  • PipPipPip
  • 831 posts

Posted 28 January 2015 - 01:18 AM

Hi Deepak,

Do you have a test server to try out API calls for yourself on your test platform? If not, it would be helpful.  For an example using the API to revert all files, see the following post:

    http://forums.perfor...age__hl__revert

To specify the changelist option with the "-c" flag, you could do something like:

Options opts = new Options();
opts["-c"] = _changelistToRevert.ToString();

Then pass those options to the 'Client.RevertFiles' method.  Here is the doc link for the Client.RevertFiles method:

http://www.perforce....RevertFiles.htm

#3 PerfQuery

PerfQuery

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 28 January 2015 - 03:59 PM

Thanks. Yeah i have test environment to test api calls but am facing server.cs not found while trying to get server address

I created below functions. Could you please check?

// to create a new changelist
    public Changelist CreateChangeList(String description)
    {
    var rep = Connect();
    var cl = new Changelist();
    cl = rep.CreateChangelist(cl, null);
    cl.Description = description;
    return cl;
    }

    // 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
    public IList<FileSpec> RevertChangeList(string clNumber, string fileFormat, string destinationPath)
    {
    try
    {
    var rep = Connect();
    var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
    opts["-a"] = clNumber;
    //  var fs = new FileSpec(new DepotPath(destinationPath + "/..." + fileFormat));
    IList<FileSpec> revertedFiles = rep.Connection.Client.RevertFiles(null, opts);
    return revertedFiles;
    }
    catch (Exception exc)
    {
    Logger.LogError(exc.Message);
    throw;
    }
    }

    // to merge files from source to client workspace location
    public IList<FileSpec> MergeFiles(string clNumber, string fileFormat, string sourcePath, string destinationPath)
    {
    try
    {
    var rep = Connect();
    var opts = new Options(ChangeCmdFlags.None, ChangeListType.None);
    var destinationfs = new FileSpec(new DepotPath(destinationPath));
    var sourcefs = new FileSpec(new DepotPath(sourcePath + "/..." + fileFormat));
    IList<FileSpec> mergedFiles = rep.Connection.Client.MergeFiles(sourcefs,
    new List<FileSpec> {destinationfs}, opts);
    return mergedFiles;
    }
    catch (Exception exc)
    {
    Logger.LogError(exc.Message);
    throw;
    }
    }





Also tagged with one or more of these keywords: p4.net api

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users