using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Perforce.P4
{
///
/// Represents a Perforce server and connection.
///
public partial class Repository : IDisposable
{
///
/// Create a repository on the specified server.
///
/// The repository server.
public Repository (Server server)
{
Server = server;
}
///
/// Represents a specific Perforce server.
///
public Server Server {get; private set;}
private Connection _connection;
///
/// Represents the logical connection between a specific Perforce Server
/// instance and a specific client application.
///
public Connection Connection
{
get
{
if (_connection == null)
{
_connection = new Connection(Server);
}
return _connection;
}
}
///
/// Return a list of FileSpecs of files in the depot that correspond
/// to the passed-in FileSpecs.
///
///
///
///
///
/// p4 help files
///
/// files -- List files in the depot
///
/// p4 files [ -a ] [ -A ] [ -e ] [ -m max ] file[revRange] ...
/// p4 files -U unloadfile ...
///
/// List details about specified files: depot file name, revision,
/// file, type, change action and changelist number of the current
/// head revision. If client syntax is used to specify the file
/// argument, the client view mapping is used to determine the
/// corresponding depot files.
///
/// By default, the head revision is listed. If the file argument
/// specifies a revision, then all files at that revision are listed.
/// If the file argument specifies a revision range, the highest revision
/// in the range is used for each file. For details about specifying
/// revisions, see 'p4 help revisions'.
///
/// The -a flag displays all revisions within the specific range, rather
/// than just the highest revision in the range.
///
/// The -A flag displays files in archive depots.
///
/// The -e flag displays files with an action of anything other than
/// deleted, purged or archived. Typically this revision is always
/// available to sync or integrate from.
///
/// The -m flag limits files to the first 'max' number of files.
///
/// The -U option displays files in the unload depot (see 'p4 help
/// unload' for more information about the unload depot).
///
///
///
/// To get a maximum of 10 files from the repository:
///
///
/// GetDepotFilesCmdOptions opts =
/// new GetDepotFilesCmdOptions(GetDepotFilesCmdFlags.None, 10);
/// FileSpec fs = new FileSpec(new DepotPath("//depot/..."), null);
/// List<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
/// IList<FileSpec> files = Repository.GetDepotFiles(lfs, opts);
///
///
///
///
public IList GetDepotFiles(IList filespecs, Options options)
{
P4.P4Command filesCmd = new P4Command(this, "files", true, FileSpec.ToStrings(filespecs));
P4.P4CommandResult r = filesCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
if ((r.TaggedOutput == null) || (r.TaggedOutput.Count <= 0))
{
return null;
}
List value = new List();
foreach (P4.TaggedObject obj in r.TaggedOutput)
{
string path = obj["depotFile"];
PathSpec ps = new DepotPath(path);
int rev = 0;
int.TryParse(obj["rev"], out rev);
FileSpec fs = new FileSpec(ps, new Revision(rev));
value.Add(fs);
}
return value;
}
///
/// Return a list of Files opened by users / clients.
///
///
///
///
///
/// p4 help opened
///
/// opened -- List open files and display file status
///
/// p4 opened [-a -c changelist# -C client -u user -m max -s] [file ...]
/// p4 opened [-a -x -m max ] [file ...]
///
/// Lists files currently opened in pending changelists, or, for
/// specified files, show whether they are currently opened or locked.
/// If the file specification is omitted, all files open in the current
/// client workspace are listed.
///
/// Files in shelved changelists are not displayed by this command. To
/// display shelved changelists, see 'p4 changes -s shelved'; to display
/// the files in those shelved changelists, see 'p4 describe -s -S'.
///
/// The -a flag lists opened files in all clients. By default, only
/// files opened by the current client are listed.
///
/// The -c changelist# flag lists files opened in the specified
/// changelist#.
///
/// The -C client flag lists files open in the specified client workspace.
///
/// The -u user flag lists files opened by the specified user.
///
/// The -m max flag limits output to the first 'max' number of files.
///
/// The -s option produces 'short' and optimized output when used with
/// the -a (all clients) option. For large repositories '-a' can take
/// a long time when compared to '-as'.
///
/// The -x option lists files that are opened 'exclusive'. This option
/// only applies to a distributed installation where global tracking of
/// these file types is necessary across servers. The -x option implies
/// the -a option.
///
///
///
/// To get a maximum of 10 opened files from the repository, opened by
/// user fred, opened with any client:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
///
/// List<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// // null for changelist and client options
/// GetOpenedFilesOptions opts =
/// new GetOpenedFilesOptions(GetOpenedFilesCmdFlags.AllClients,
/// null, null, "fred", 10);
///
/// IList<File> target = Repository.GetOpenedFiles(lfs, opts);
///
///
///
public IList GetOpenedFiles(IList filespecs, Options options)
{
P4.P4Command openedCmd = new P4Command(this, "opened", true, FileSpec.ToStrings(filespecs));
P4.P4CommandResult r = openedCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
if ((r.TaggedOutput == null) || (r.TaggedOutput.Count <= 0))
{
return null;
}
List value = new List();
DepotPath dps = null;
ClientPath cps = null;
int revision = 0;
Revision rev = new Revision(0);
Revision haveRev = new Revision(0);
StringEnum action = null;
int change = -1;
FileType type = null;
DateTime submittime = DateTime.MinValue;
string user = string.Empty;
string client = string.Empty;
foreach (P4.TaggedObject obj in r.TaggedOutput)
{
if (obj.ContainsKey("depotFile"))
{
dps = new DepotPath(obj["depotFile"]);
}
if (obj.ContainsKey("clientFile"))
{
cps = new ClientPath(obj["clientFile"]);
}
if (obj.ContainsKey("rev"))
{
int.TryParse(obj["rev"], out revision);
rev = new Revision(revision);
}
if (obj.ContainsKey("haveRev"))
{
int.TryParse(obj["haveRev"], out revision);
haveRev = new Revision(revision);
}
if (obj.ContainsKey("action"))
{
action = obj["action"];
}
if (obj.ContainsKey("change"))
{
int.TryParse(obj["change"], out change);
}
if (obj.ContainsKey("type"))
{
type = new FileType(obj["type"]);
}
if (obj.ContainsKey("user"))
{
user = obj["user"];
}
if (obj.ContainsKey("client"))
{
client = obj["client"];
}
File f = new File(dps, cps, rev, haveRev, change, action, type, submittime, user, client);
value.Add(f);
}
return value;
}
///
/// Use the p4 fstat command to get the file metadata for the files
/// matching the FileSpec.
///
///
///
///
///
/// p4 help fstat
///
/// fstat -- Dump file info
///
/// p4 fstat [-F filter -L -T fields -m max -r] [-c | -e changelist#]
/// [-Ox -Rx -Sx] file[rev] ...
///
/// Fstat lists information about files, one line per file. Fstat is
/// intended for use in Perforce API applications, where the output can
/// be accessed as variables, but its output is also suitable for parsing
/// from the client command output in scripts.
///
/// The fields that fstat displays are:
///
/// attr-<name> -- attribute value for <name>
/// attrProp-<name> -- set if attribute <name> is propagating
/// clientFile -- local path (host or Perforce syntax)
/// depotFile -- name in depot
/// movedFile -- name in depot of moved to/from file
/// path -- local path (host syntax)
/// isMapped -- set if mapped client file is synced
/// shelved -- set if file is shelved
/// headAction -- action at head rev, if in depot
/// headChange -- head rev changelist#, if in depot
/// headRev -- head rev #, if in depot
/// headType -- head rev type, if in depot
/// headCharset -- head charset, for unicode type
/// headTime -- head rev changelist time, if in depot
/// headModTime -- head rev mod time, if in depot
/// movedRev -- head rev # of moved file
/// haveRev -- rev had on client, if on client
/// desc -- change description
/// digest -- MD5 digest (fingerprint)
/// fileSize -- file size
/// action -- open action, if opened
/// type -- open type, if opened
/// charset -- open charset, for unicode type
/// actionOwner -- user who opened file, if opened
/// change -- open changelist#, if opened
/// resolved -- resolved integration records
/// unresolved -- unresolved integration records
/// reresolvable -- reresolvable integration records
/// otherOpen -- set if someone else has it open
/// otherOpen# -- list of user@client with file opened
/// otherLock -- set if someone else has it locked
/// otherLock# -- user@client with file locked
/// otherAction# -- open action, if opened by someone else
/// otherChange# -- changelist, if opened by someone else
/// openattr-<name> -- attribute value for <name>
/// openattrProp-<name> -- set if attribute <name> is propagating
/// ourLock -- set if this user/client has it locked
/// resolveAction# -- pending integration record action
/// resolveBaseFile# -- pending integration base file
/// resolveBaseRev# -- pending integration base rev
/// resolveFromFile# -- pending integration from file
/// resolveStartFromRev# -- pending integration from start rev
/// resolveEndFromRev# -- pending integration from end rev
/// totalFileCount -- total no. of files, if sorted
///
/// The -A <pattern> flag restricts displayed attributes to those
/// that match 'pattern'.
///
/// The -F flag lists only files satisfying the filter expression. This
/// filter syntax is similar to the one used for 'jobs -e jobview' and is
/// used to evaluate the contents of the fields in the preceding list.
/// Filtering is case-sensitive.
///
/// Example: -Ol -F "fileSize > 1000000 & headType=text"
///
/// Note: filtering is not optimized with indexes for performance.
///
/// The -L flag can be used with multiple file arguments that are in
/// full depot syntax and include a valid revision number. When this
/// flag is used the arguments are processed together by building an
/// internal table similar to a label. This file list processing is
/// significantly faster than having to call the internal query engine
/// for each individual file argument. However, the file argument syntax
/// is strict and the command will not run if an error is encountered.
///
/// The -T fields flag returns only the specified fields. The field names
/// can be specified using a comma- or space-delimited list.
///
/// Example: -Ol -T "depotFile, fileSize"
///
/// The -m max flag limits output to the specified number of files.
///
/// The -r flag sorts the output in reverse order.
///
/// The -c changelist# flag displays files modified after the specified
/// changelist was submitted. This operation is much faster than using
/// a revision range on the affected files.
///
/// The -e changelist# flag lists files modified by the specified
/// changelist. When used with the -Ro flag, only pending changes are
/// considered, to ensure that files opened for add are included. This
/// option also displays the change description.
///
/// The -O options modify the output as follows:
///
/// -Oa output attributes set by 'p4 attribute'.
///
/// -Od output the digest of the attribute.
///
/// -Oe output attribute values encoded as hex
///
/// -Of output all revisions for the given files (this
/// option suppresses other* and resolve* fields)
///
/// -Ol output a fileSize and digest field for each revision
/// (this may be expensive to compute)
///
/// -Op output the local file path in both Perforce syntax
/// (//client/) as 'clientFile' and host form as 'path'
///
/// -Or output pending integration record information for
/// files opened on the current client, or if used with
/// '-e <change> -Rs', on the shelved change
///
/// -Os exclude client-related data from output
///
/// The -R option limits output to specific files:
///
/// -Rc files mapped in the client view
/// -Rh files synced to the client workspace
/// -Rn files opened not at the head revision
/// -Ro files opened
/// -Rr files opened that have been resolved
/// -Rs files shelved (requires -e)
/// -Ru files opened that need resolving
///
/// The -S option changes the order of output:
///
/// -St sort by filetype
/// -Sd sort by date
/// -Sr sort by head revision
/// -Sh sort by have revision
/// -Ss sort by filesize
///
/// The -U flag displays information about unload files in the unload
/// depot (see 'p4 help unload').
///
/// For compatibility, the following flags are also supported:
/// -C (-Rc) -H (-Rh) -W (-Ro) -P (-Op) -l (-Ol) -s (-Os).
///
///
///
///
/// To get FileMetaData for //depot/ReadMe.txt:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//depot/MyCode/ReadMe.txt"), null);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None,
/// null, null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(opts, fs);
///
/// To get FileMetaData for files in the depot that need resolving:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.NeedsResolve,
/// null, null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(opts, fs);
///
/// To get FileMetaData for files in the depot that are over a specific file
/// size and of file type, text:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None,
/// "fileSize > 1000000 & headType=text", null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(opts, fs);
///
/// To get FileMetaData for files in the depot that have been modified at or
/// after changelist 20345 and are mapped to the client view:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.ClientMapped,
/// null, null, 20345, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(opts, fs);
///
/// To get FileMetaData for files in the depot including attributes which match
/// the pattern "tested":
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.Attributes,
/// null, null, 0, null, null, "tested");
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(opts, fs);
///
///
///
public IList GetFileMetaData(Options options, params FileSpec[] filespecs)
{
string[] paths = FileSpec.ToEscapedStrings(filespecs);
P4.P4Command fstatCmd = new P4Command(this, "fstat", true, paths);
P4.P4CommandResult r = fstatCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
if ((r.TaggedOutput == null) || (r.TaggedOutput.Count <= 0))
{
return null;
}
List value = new List();
foreach (P4.TaggedObject obj in r.TaggedOutput)
{
if ((obj.Count <=2) && (obj.ContainsKey("desc")))
{
// hack, but this not really a file, it's just a
// the description of the change if -e option is
// specified, so skip it
continue;
}
FileMetaData fmd = new FileMetaData();
fmd.FromFstatCmdTaggedData(obj);
value.Add(fmd);
}
return value;
}
///
/// Use the p4 fstat command to get the file metadata for the files
/// matching the FileSpec.
///
///
///
///
///
/// p4 help fstat
///
/// fstat -- Dump file info
///
/// p4 fstat [-F filter -L -T fields -m max -r] [-c | -e changelist#]
/// [-Ox -Rx -Sx] file[rev] ...
///
/// Fstat lists information about files, one line per file. Fstat is
/// intended for use in Perforce API applications, where the output can
/// be accessed as variables, but its output is also suitable for parsing
/// from the client command output in scripts.
///
/// The fields that fstat displays are:
///
/// attr-<name> -- attribute value for <name>
/// attrProp-<name> -- set if attribute <name> is propagating
/// clientFile -- local path (host or Perforce syntax)
/// depotFile -- name in depot
/// movedFile -- name in depot of moved to/from file
/// path -- local path (host syntax)
/// isMapped -- set if mapped client file is synced
/// shelved -- set if file is shelved
/// headAction -- action at head rev, if in depot
/// headChange -- head rev changelist#, if in depot
/// headRev -- head rev #, if in depot
/// headType -- head rev type, if in depot
/// headCharset -- head charset, for unicode type
/// headTime -- head rev changelist time, if in depot
/// headModTime -- head rev mod time, if in depot
/// movedRev -- head rev # of moved file
/// haveRev -- rev had on client, if on client
/// desc -- change description
/// digest -- MD5 digest (fingerprint)
/// fileSize -- file size
/// action -- open action, if opened
/// type -- open type, if opened
/// charset -- open charset, for unicode type
/// actionOwner -- user who opened file, if opened
/// change -- open changelist#, if opened
/// resolved -- resolved integration records
/// unresolved -- unresolved integration records
/// reresolvable -- reresolvable integration records
/// otherOpen -- set if someone else has it open
/// otherOpen# -- list of user@client with file opened
/// otherLock -- set if someone else has it locked
/// otherLock# -- user@client with file locked
/// otherAction# -- open action, if opened by someone else
/// otherChange# -- changelist, if opened by someone else
/// openattr-<name> -- attribute value for <name>
/// openattrProp-<name> -- set if attribute <name> is propagating
/// ourLock -- set if this user/client has it locked
/// resolveAction# -- pending integration record action
/// resolveBaseFile# -- pending integration base file
/// resolveBaseRev# -- pending integration base rev
/// resolveFromFile# -- pending integration from file
/// resolveStartFromRev# -- pending integration from start rev
/// resolveEndFromRev# -- pending integration from end rev
/// totalFileCount -- total no. of files, if sorted
///
/// The -A <pattern> flag restricts displayed attributes to those
/// that match 'pattern'.
///
/// The -F flag lists only files satisfying the filter expression. This
/// filter syntax is similar to the one used for 'jobs -e jobview' and is
/// used to evaluate the contents of the fields in the preceding list.
/// Filtering is case-sensitive.
///
/// Example: -Ol -F "fileSize > 1000000 & headType=text"
///
/// Note: filtering is not optimized with indexes for performance.
///
/// The -L flag can be used with multiple file arguments that are in
/// full depot syntax and include a valid revision number. When this
/// flag is used the arguments are processed together by building an
/// internal table similar to a label. This file list processing is
/// significantly faster than having to call the internal query engine
/// for each individual file argument. However, the file argument syntax
/// is strict and the command will not run if an error is encountered.
///
/// The -T fields flag returns only the specified fields. The field names
/// can be specified using a comma- or space-delimited list.
///
/// Example: -Ol -T "depotFile, fileSize"
///
/// The -m max flag limits output to the specified number of files.
///
/// The -r flag sorts the output in reverse order.
///
/// The -c changelist# flag displays files modified after the specified
/// changelist was submitted. This operation is much faster than using
/// a revision range on the affected files.
///
/// The -e changelist# flag lists files modified by the specified
/// changelist. When used with the -Ro flag, only pending changes are
/// considered, to ensure that files opened for add are included. This
/// option also displays the change description.
///
/// The -O options modify the output as follows:
///
/// -Oa output attributes set by 'p4 attribute'.
///
/// -Od output the digest of the attribute.
///
/// -Oe output attribute values encoded as hex
///
/// -Of output all revisions for the given files (this
/// option suppresses other* and resolve* fields)
///
/// -Ol output a fileSize and digest field for each revision
/// (this may be expensive to compute)
///
/// -Op output the local file path in both Perforce syntax
/// (//client/) as 'clientFile' and host form as 'path'
///
/// -Or output pending integration record information for
/// files opened on the current client, or if used with
/// '-e <change> -Rs', on the shelved change
///
/// -Os exclude client-related data from output
///
/// The -R option limits output to specific files:
///
/// -Rc files mapped in the client view
/// -Rh files synced to the client workspace
/// -Rn files opened not at the head revision
/// -Ro files opened
/// -Rr files opened that have been resolved
/// -Rs files shelved (requires -e)
/// -Ru files opened that need resolving
///
/// The -S option changes the order of output:
///
/// -St sort by filetype
/// -Sd sort by date
/// -Sr sort by head revision
/// -Sh sort by have revision
/// -Ss sort by filesize
///
/// The -U flag displays information about unload files in the unload
/// depot (see 'p4 help unload').
///
/// For compatibility, the following flags are also supported:
/// -C (-Rc) -H (-Rh) -W (-Ro) -P (-Op) -l (-Ol) -s (-Os).
///
///
///
///
/// To get FileMetaData for //depot/ReadMe.txt:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//depot/MyCode/ReadMe.txt"), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None,
/// null, null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(lfs, opts);
///
/// To get FileMetaData for files in the depot that need resolving:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.NeedsResolve,
/// null, null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(lfs, opts);
///
/// To get FileMetaData for files in the depot that are over a specific file
/// size and of file type, text:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.None,
/// "fileSize > 1000000 & headType=text", null, 0, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(lfs, opts);
///
/// To get FileMetaData for files in the depot that have been modified at or
/// after changelist 20345 and are mapped to the client view:
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.ClientMapped,
/// null, null, 20345, null, null, null);
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(lfs, opts);
///
/// To get FileMetaData for files in the depot including attributes which match
/// the pattern "tested":
///
///
/// FileSpec fs = new FileSpec(new DepotPath("//..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetFileMetaDataCmdOptions opts =
/// new GetFileMetaDataCmdOptions(GetFileMetadataCmdFlags.Attributes,
/// null, null, 0, null, null, "tested");
///
/// IList<FileMetaData> target = Repository.GetFileMetaData(lfs, opts);
///
///
///
public IList GetFileMetaData(IList filespecs, Options options)
{
return GetFileMetaData(options, filespecs.ToArray());
}
///
/// Return a list of Files in the depot that correspond to the passed-in
/// FileSpecs.
///
///
/// p4 help files
///
/// files -- List files in the depot
///
/// p4 files [ -a ] [ -A ] [ -e ] [ -m max ] file[revRange] ...
/// p4 files -U unloadfile ...
///
/// List details about specified files: depot file name, revision,
/// file, type, change action and changelist number of the current
/// head revision. If client syntax is used to specify the file
/// argument, the client view mapping is used to determine the
/// corresponding depot files.
///
/// By default, the head revision is listed. If the file argument
/// specifies a revision, then all files at that revision are listed.
/// If the file argument specifies a revision range, the highest revision
/// in the range is used for each file. For details about specifying
/// revisions, see 'p4 help revisions'.
///
/// The -a flag displays all revisions within the specific range, rather
/// than just the highest revision in the range.
///
/// The -A flag displays files in archive depots.
///
/// The -e flag displays files with an action of anything other than
/// deleted, purged or archived. Typically this revision is always
/// available to sync or integrate from.
///
/// The -m flag limits files to the first 'max' number of files.
///
/// The -U option displays files in the unload depot (see 'p4 help unload'
/// for more information about the unload depot).
///
///
///
///
/// To get Files in local depot //depot/...:
///
/// GetDepotFilesCmdOptions opts =
/// new GetDepotFilesCmdOptions(GetDepotFilesCmdFlags.None, 0);
///
/// FileSpec fs = new FileSpec(new DepotPath("//depot/..."), null);
///
/// IList<File> target = Repository.GetFiles(opts, fs);
///
/// To get Files in unload depot //Unloaded/...:
///
/// GetDepotFilesCmdOptions opts =
/// new GetDepotFilesCmdOptions(GetDepotFilesCmdFlags.InUnloadDepot, 0);
///
/// FileSpec fs = new FileSpec(new DepotPath("//Unloaded/..."), null);
///
/// IList<File> target = Repository.GetFiles(opts, fs);
///
///
///
public IList GetFiles(Options options, params FileSpec[] filespecs)
{
P4.P4Command fstatCmd = new P4Command(this, "files", true, FileSpec.ToStrings(filespecs));
P4.P4CommandResult r = fstatCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
if ((r.TaggedOutput == null) || (r.TaggedOutput.Count <= 0))
{
return null;
}
List value = new List();
foreach (P4.TaggedObject obj in r.TaggedOutput)
{
File val = new File();
val.ParseFilesCmdTaggedData(obj);
value.Add(val);
}
return value;
}
///
/// Return a list of Files in the depot that correspond to the passed-in
/// FileSpecs.
///
///
/// p4 help files
///
/// files -- List files in the depot
///
/// p4 files [ -a ] [ -A ] [ -e ] [ -m max ] file[revRange] ...
/// p4 files -U unloadfile ...
///
/// List details about specified files: depot file name, revision,
/// file, type, change action and changelist number of the current
/// head revision. If client syntax is used to specify the file
/// argument, the client view mapping is used to determine the
/// corresponding depot files.
///
/// By default, the head revision is listed. If the file argument
/// specifies a revision, then all files at that revision are listed.
/// If the file argument specifies a revision range, the highest revision
/// in the range is used for each file. For details about specifying
/// revisions, see 'p4 help revisions'.
///
/// The -a flag displays all revisions within the specific range, rather
/// than just the highest revision in the range.
///
/// The -A flag displays files in archive depots.
///
/// The -e flag displays files with an action of anything other than
/// deleted, purged or archived. Typically this revision is always
/// available to sync or integrate from.
///
/// The -m flag limits files to the first 'max' number of files.
///
/// The -U option displays files in the unload depot (see 'p4 help unload'
/// for more information about the unload depot).
///
///
///
///
/// To get Files in local depot //depot/...:
///
/// FileSpec fs = new FileSpec(new DepotPath("//depot/..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetDepotFilesCmdOptions opts =
/// new GetDepotFilesCmdOptions(GetDepotFilesCmdFlags.None, 0);
///
/// IList<File> target = Repository.GetFiles(lfs, opts);
///
/// To get Files in unload depot //Unloaded/...:
///
/// FileSpec fs = new FileSpec(new DepotPath("//Unloaded/..."), null);
/// IList<FileSpec> lfs = new List<FileSpec>();
/// lfs.Add(fs);
///
/// GetDepotFilesCmdOptions opts =
/// new GetDepotFilesCmdOptions(GetDepotFilesCmdFlags.InUnloadDepot, 0);
///
/// IList<File> target = Repository.GetFiles(lfs, opts);
///
///
///
public IList GetFiles(IList filespecs, Options options)
{
return GetFiles(options, filespecs.ToArray());
}
///
/// List selected directory paths in the repository.
///
///
///
///
///
/// p4 help dirs
///
/// dirs -- List depot subdirectories
///
/// p4 dirs [-C -D -H] [-S stream] dir[revRange] ...
///
/// List directories that match the specified file pattern (dir).
/// This command does not support the recursive wildcard (...).
/// Use the * wildcard instead.
///
/// Perforce does not track directories individually. A path is treated
/// as a directory if there are any undeleted files with that path as a
/// prefix.
///
/// By default, all directories containing files are listed. If the dir
/// argument includes a revision range, only directories containing files
/// in the range are listed. For details about specifying file revisions,
/// see 'p4 help revisions'.
///
/// The -C flag lists only directories that fall within the current
/// client view.
///
/// The -D flag includes directories containing only deleted files.
///
/// The -H flag lists directories containing files synced to the current
/// client workspace.
///
/// The -S flag limits output to depot directories mapped in a stream's
/// client view.
///
///
///
///
/// To get dirs on the server that fall within the current client view:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.CurrentClientOnly, null);
///
/// IList<String> target = Repository.GetDepotDirs(opts, "//* );
///
/// To get dirs on the server that contain files synced to the current
/// client workspace:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.SyncedDirs, null);
///
/// IList<String> target = Repository.GetDepotDirs(opts, "//* );
///
/// To get dirs on the server that fall under the path //depot/main/:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.None, null);
///
/// IList<String> target = Repository.GetDepotDirs(opts, "//depot/main/* );
///
///
///
public IList GetDepotDirs(Options options, params string[] dirs)
{
P4.P4Command dirsCmd = new P4Command(this, "dirs", false, dirs);
P4.P4CommandResult r = dirsCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
List value = new List();
foreach (P4.P4ClientInfoMessage l in r.InfoOutput)
{
value.Add(l.Message);
}
return value;
}
///
/// List selected directory paths in the repository.
///
///
///
///
///
/// p4 help dirs
///
/// dirs -- List depot subdirectories
///
/// p4 dirs [-C -D -H] [-S stream] dir[revRange] ...
///
/// List directories that match the specified file pattern (dir).
/// This command does not support the recursive wildcard (...).
/// Use the * wildcard instead.
///
/// Perforce does not track directories individually. A path is treated
/// as a directory if there are any undeleted files with that path as a
/// prefix.
///
/// By default, all directories containing files are listed. If the dir
/// argument includes a revision range, only directories containing files
/// in the range are listed. For details about specifying file revisions,
/// see 'p4 help revisions'.
///
/// The -C flag lists only directories that fall within the current
/// client view.
///
/// The -D flag includes directories containing only deleted files.
///
/// The -H flag lists directories containing files synced to the current
/// client workspace.
///
/// The -S flag limits output to depot directories mapped in a stream's
/// client view.
///
///
///
///
/// To get dirs on the server that fall within the current client view:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.CurrentClientOnly, null);
///
/// IList<String> dirs = new List<String>()
/// dirs.Add("//*");
///
/// IList<String> target = Repository.GetDepotDirs(dirs, opts);
///
/// To get dirs on the server that contain files synced to the current
/// client workspace:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.SyncedDirs, null);
///
/// IList<String> dirs = new List<String>()
/// dirs.Add("//*");
///
/// IList<String> target = Repository.GetDepotDirs(dirs, opts);
///
/// To get dirs on the server that fall under the path //depot/main/:
///
/// GetDepotDirsCmdOptions opts =
/// new GetDepotDirsCmdOptions(GetDepotDirsCmdFlags.None, null);
///
/// IList<String> dirs = new List<String>()
/// dirs.Add("//depot/main/*");
///
/// IList<String> target = Repository.GetDepotDirs(dirs, opts);
///
///
///
public IList GetDepotDirs(IList dirs, Options options)
{
return GetDepotDirs(options, dirs.ToArray());
}
///
/// Return the contents of the files identified by the passed-in file specs.
///
///
///
///
/// GetFileContents
///
/// p4 help print
///
/// print -- Write a depot file to standard output
///
/// p4 print [-a -o localFile -q] file[revRange] ...
///
/// Retrieve the contents of a depot file to the client's standard output.
/// The file is not synced. If file is specified using client syntax,
/// Perforce uses the client view to determine the corresponding depot
/// file.
///
/// By default, the head revision is printed. If the file argument
/// includes a revision, the specified revision is printed. If the
/// file argument has a revision range, then only files selected by
/// that revision range are printed, and the highest revision in the
/// range is printed. For details about revision specifiers, see 'p4
/// help revisions'.
///
/// The -a flag prints all revisions within the specified range, rather
/// than just the highest revision in the range.
///
/// The -o localFile flag redirects the output to the specified file on
/// the client filesystem.
///
/// The -q flag suppresses the initial line that displays the file name
/// and revision.
///
///
///
///
/// To get the contents of the file //depot/MyCode/README.txt:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.None, null);
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
///
/// IList<String> target = Repository.GetFileContents(opts, filespec);
///
/// To get the contents of the file //depot/MyCode/README.txt redirecting the
/// contents to local file C:\Doc\README.txt and supressing the file name
/// and revision line:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress,
/// "C:\\Doc\\README.txt");
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
///
/// IList<String> target = Repository.GetFileContents(opts, filespec);
///
///
///
public IList GetFileContents(Options options, params FileSpec[] filespecs)
{
P4.P4Command printCmd = new P4Command(this, "print", true, FileSpec.ToEscapedStrings(filespecs));
P4.P4CommandResult r = printCmd.Run(options);
if (r.Success != true)
{
P4Exception.Throw(r.ErrorList);
return null;
}
IList value = new List();
if (r.TaggedOutput != null)
{
if ((options == null) ||
(options.ContainsKey("-q") == false))
{
foreach (P4.TaggedObject obj in r.TaggedOutput)
{
string path = string.Empty;
string rev = string.Empty;
if (obj.ContainsKey("depotFile"))
{
value.Add(obj["depotFile"]);
}
}
}
}
value.Add(r.TextOutput);
return value;
}
///
/// Return the contents of the files identified by the passed-in file specs.
///
///
///
///
/// GetFileContents
///
/// p4 help print
///
/// print -- Write a depot file to standard output
///
/// p4 print [-a -o localFile -q] file[revRange] ...
///
/// Retrieve the contents of a depot file to the client's standard output.
/// The file is not synced. If file is specified using client syntax,
/// Perforce uses the client view to determine the corresponding depot
/// file.
///
/// By default, the head revision is printed. If the file argument
/// includes a revision, the specified revision is printed. If the
/// file argument has a revision range, then only files selected by
/// that revision range are printed, and the highest revision in the
/// range is printed. For details about revision specifiers, see 'p4
/// help revisions'.
///
/// The -a flag prints all revisions within the specified range, rather
/// than just the highest revision in the range.
///
/// The -o localFile flag redirects the output to the specified file on
/// the client filesystem.
///
/// The -q flag suppresses the initial line that displays the file name
/// and revision.
///
///
///
///
/// To get the contents of the file //depot/MyCode/README.txt:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.None, null);
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
/// IList<FileSpec> filespecs = new List<FileSpec>();
/// filespecs.Add(filespec);
///
/// IList<String> target = Repository.GetFileContents(filespecs, opts);
///
/// To get the contents of the file //depot/MyCode/README.txt redirecting the
/// contents to local file C:\Doc\README.txt and supressing the file name
/// and revision line:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress,
/// "C:\\Doc\\README.txt");
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
/// IList<FileSpec> filespecs = new List<FileSpec>();
/// filespecs.Add(filespec);
///
/// IList<String> target = Repository.GetFileContents(filespecs, opts);
///
///
///
public IList GetFileContents(IList filespecs, Options options)
{
return GetFileContents(options, filespecs.ToArray());
}
///
/// Return the contents of the files identified by the passed-in file specs.
///
///
///
///
/// GetFileContentsEx
///
/// p4 help print
///
/// print -- Write a depot file to standard output
///
/// p4 print [-a -o localFile -q] file[revRange] ...
///
/// Retrieve the contents of a depot file to the client's standard output.
/// The file is not synced. If file is specified using client syntax,
/// Perforce uses the client view to determine the corresponding depot
/// file.
///
/// By default, the head revision is printed. If the file argument
/// includes a revision, the specified revision is printed. If the
/// file argument has a revision range, then only files selected by
/// that revision range are printed, and the highest revision in the
/// range is printed. For details about revision specifiers, see 'p4
/// help revisions'.
///
/// The -a flag prints all revisions within the specified range, rather
/// than just the highest revision in the range.
///
/// The -o localFile flag redirects the output to the specified file on
/// the client filesystem.
///
/// The -q flag suppresses the initial line that displays the file name
/// and revision.
///
///
///
///
/// To get the contents of the file //depot/MyCode/README.txt:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.None, null);
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
///
/// IList<String> target = Repository.GetFileContents(opts, filespec);
///
/// To get the contents of the file //depot/MyCode/README.txt redirecting the
/// contents to local file C:\Doc\README.txt and supressing the file name
/// and revision line:
///
/// GetFileContentsCmdOptions opts =
/// new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress,
/// "C:\\Doc\\README.txt");
///
/// FileSpec filespec =
/// new FileSpec(new DepotPath("//depot/MyCode/README.txt"), null);
///
/// IList<String> target = Repository.GetFileContents(opts, filespec);
///
///
///
public IList