/******************************************************************************* Copyright (c) 2011, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /******************************************************************************* * Name : Repository.Depot.cs * * Author : wjb * * Description : Depot operations for the Repository. * ******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Perforce.P4 { public partial class Repository { /// /// Create a new depot in the repository. /// /// Depot specification for the new depot /// The '-i' flag is required when creating a new depot /// The Depot object if new depot was created, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To create a streams depot named MobileApp: /// /// Depot d = new Depot(); /// /// d.Id = "MobileApp"; /// d.Description = "Stream depot for mobile app project"; /// d.Owner = "admin"; /// d.Type = DepotType.Stream; /// d.Map = "MobileApp/..."; /// /// Depot MobileApp = Repository.CreateDepot(d, null); /// /// /// public Depot CreateDepot(Depot depot, Options options) { if (depot == null) { throw new ArgumentNullException("depot"); } P4Command cmd = new P4Command(this, "depot", true); cmd.DataSet = depot.ToString(); if (options == null) { options = new Options(DepotCmdFlags.Input); } if (options.ContainsKey("-i") == false) { options["-i"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success) { return depot; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Create a new depot in the repository. /// /// Depot specification for the new depot /// The Depot object if new depot was created, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To create a streams depot named MobileApp: /// /// Depot d = new Depot(); /// /// d.Id = "MobileApp"; /// d.Description = "Stream depot for mobile app project"; /// d.Owner = "admin"; /// d.Type = DepotType.Stream; /// d.Map = "MobileApp/..."; /// /// Depot MobileApp = Repository.CreateDepot(d); /// /// public Depot CreateDepot(Depot depot) { return CreateDepot(depot, null); } /// /// Update the record for a depot in the repository /// /// Depot specification for the depot being updated /// The Depot object if new depot was saved, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To update the streams depot named MobileApp: /// /// Depot d = Repository.GetDepot("MobileApp"); /// /// // change description /// d.Description = "Stream depot for Win8 phone apps"; /// /// Depot MobileApp = Repository.UpdateDepot(d); /// /// public Depot UpdateDepot(Depot depot) { return CreateDepot(depot, null); } /// /// Get the record for an existing depot from the repository. /// /// Depot name /// There are no valid flags to use when fetching an existing depot /// The Depot object if depot was found, null if not /// ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To get the spec for a streams depot named MobileApp: /// /// Depot MobileApp = Repository.GetDepot("MobileApp", null); /// /// /// public Depot GetDepot(string depot, Options options) { if (depot == null) { throw new ArgumentNullException("depot"); } P4Command cmd = new P4Command(this, "depot", true, depot); if (options == null) { options = new Options(DepotCmdFlags.Output); } if (options.ContainsKey("-o") == false) { options["-o"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } Depot value = new Depot(); value.FromDepotCmdTaggedOutput(results.TaggedOutput[0]); return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Get the record for an existing depot from the repository. /// /// Depot name /// The Depot object if depot was found, null if not /// ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To get the spec for a streams depot named MobileApp: /// /// Depot MobileApp = Repository.GetDepot("MobileApp"); /// /// /// public Depot GetDepot(string depot) { return GetDepot(depot, null); } /// /// Get a list of depots from the repository /// /// A list containing the matching depots /// ///
p4 help depots ///
///
depots -- Lists defined depots ///
///
p4 depots ///
///
Lists all depots defined in the server. ///
Depots takes no arguments. ///
///
///
/// /// To list the depots on the server: /// /// IList<Depot> depots = Repository.GetDepots(); /// /// public IList GetDepots() { P4Command cmd = new P4Command(this, "depots", true); P4CommandResult results = cmd.Run(); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } bool dst_mismatch = false; string offset = string.Empty; if (Server != null && Server.Metadata != null) { offset = Server.Metadata.DateTimeOffset; dst_mismatch = FormBase.DSTMismatch(Server.Metadata); } List value = new List(); foreach (TaggedObject obj in results.TaggedOutput) { Depot depot = new Depot(); depot.FromDepotsCmdTaggedOutput(obj,offset,dst_mismatch); value.Add(depot); } return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Delete a depot from the repository /// /// The depot to be deleted /// Only the '-d' flag is valid when deleting an existing depot /// ///
///
p4 help depot ///
///
depot -- Create or edit a depot specification ///
///
p4 depot name ///
p4 depot -d [-f] name ///
p4 depot -o name ///
p4 depot -i ///
///
Create a new depot specification or edit an existing depot ///
specification. The specification form is put into a temporary file ///
and the editor (configured by the environment variable $P4EDITOR) ///
is invoked. ///
///
The depot specification contains the following fields: ///
///
Depot: The name of the depot. This name cannot be the same as ///
any branch, client, or label name. ///
///
Owner: The user who created this depot. ///
///
Date: The date that this specification was last modified. ///
///
Description: A short description of the depot (optional). ///
///
Type: One of the types: 'local', 'stream', 'remote', 'spec', ///
'archive', or 'unload'. ///
///
A 'local' depot (the default) is managed directly by ///
the server and its files reside in the server's root ///
directory. ///
///
A 'stream' depot is a local depot dedicated to the ///
storage of files in a stream. ///
///
A 'remote' depot refers to files in another Perforce ///
server. ///
///
A 'spec' depot automatically archives all edited forms ///
(branch, change, client, depot, group, job, jobspec, ///
protect, triggers, typemap, and user) in special, ///
read-only files. The files are named: ///
//depotname/formtype/name[suffix]. Updates to jobs made ///
by the 'p4 change', 'p4 fix', and 'p4 submit' commands ///
are also saved, but other automatic updates such as ///
as access times or opened files (for changes) are not. ///
A server can contain only one 'spec' depot. ///
///
A 'archive' depot defines a storage location to which ///
obsolete revisions may be relocated. ///
///
An 'unload' depot defines a storage location to which ///
database records may be unloaded and from which they ///
may be reloaded. ///
///
Address: For remote depots, the $P4PORT (connection address) ///
of the remote server. ///
///
Suffix: For spec depots, the optional suffix to be used ///
for generated paths. The default is '.p4s'. ///
///
Map: Path translation information, in the form of a file ///
pattern with a single ... in it. For local depots, ///
this path is relative to the server's root directory ///
or to server.depot.root if it has been configured ///
(Example: depot/...). For remote depots, this path ///
refers to the remote server's namespace ///
(Example: //depot/...). ///
///
SpecMap: For spec depots, the optional description of which ///
specs should be saved, as one or more patterns. ///
///
The -d flag deletes the specified depot. If any files reside in the ///
depot, they must be removed with 'p4 obliterate' before deleting the ///
depot. If any archive files remain in the depot directory, they may ///
be referenced by lazy copies in other depots; use 'p4 snap' to break ///
those linkages. Snap lazy copies prior to obliterating the old depot ///
files to allow the obliterate command to remove any unreferenced ///
archives from the depot directory. If the depot directory is not ///
empty, you must specify the -f flag to delete the depot. ///
///
The -o flag writes the depot specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a depot specification from standard input. The ///
user's editor is not invoked. ///
///
///
/// /// To delete a streams depot named MobileApp: /// /// Depot d = Repository.GetDepot("MobileApp"); /// /// Repository.DeleteDepot(d, null); /// /// /// public void DeleteDepot(Depot depot, Options options) { if (depot == null) { throw new ArgumentNullException("depot"); } P4Command cmd = new P4Command(this, "depot", true, depot.Id); if (options == null) { options = new Options(DepotCmdFlags.Delete); } if (options.ContainsKey("-d") == false) { options["-d"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success == false) { P4Exception.Throw(results.ErrorList); } } } }