/******************************************************************************* 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.Label.cs * * Author : wjb * * Description : Label 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 label in the repository. /// /// Label specification for the new label /// The '-i' flag is required when creating a new label /// The Label object if new label was created, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help label ///
///
label -- Create or edit a label specification ///
///
p4 label [-f -t template] name ///
p4 label -d [-f] name ///
p4 label -o [-t template] name ///
p4 label -i [-f] ///
///
Create or edit a label. The name parameter is required. The ///
specification form is put into a temporary file and the editor ///
(configured by the environment variable $P4EDITOR) is invoked. ///
///
The label specification form contains the following fields: ///
///
Label: The label name (read only.) ///
///
Owner: The user who created this label. Can be changed. ///
///
Update: The date that this specification was last modified. ///
///
Access: The date of the last 'labelsync' or use of '@label' ///
referencing this label. ///
///
Description: A short description of the label (optional). ///
///
Options: Flags to change the label behavior. ///
///
locked Prevents users other than the label owner ///
from changing the specification. Prevents ///
the label from being deleted. Prohibits ///
'p4 labelsync'. ///
///
Revision: An optional revision specification for an automatic ///
label. Enclose in double quotes if it contains the ///
# (form comment) character. ///
///
View: A mapping that selects files from the depot. The ///
default view selects all depot files. Only the left ///
side of the mapping is used for labels. ///
///
A label is a named collection of revisions. A label is either ///
automatic or static. An automatic label refers to the revisions ///
given in the View: and Revision: fields. A static label refers to ///
the revisions that are associated with the label using the 'p4 tag' ///
or 'p4 labelsync' commands. A static label cannot have a Revison: ///
field. See 'p4 help revisions' for information on using labels as ///
revision specifiers. ///
///
Flag -d deletes the specified label. You cannot delete a locked label. ///
The -f flag forces the delete. ///
///
The -o flag writes the label specification to standard output. The ///
user's editor is not invoked. ///
///
The -i flag reads a label specification from standard input. The ///
user's editor is not invoked. ///
///
The -t flag copies the view and options from the template label to ///
the new label. ///
///
The -f flag forces the deletion of a label. By default, locked labels ///
can only be deleted by their owner. The -f flag also permits the ///
Last Modified date to be set. The -f flag requires 'admin' access, ///
which is granted by 'p4 protect'. ///
///
///
public Label CreateLabel(Label label, Options options) { if (label == null) { throw new ArgumentNullException("label"); } P4Command cmd = new P4Command(this, "label", true); cmd.DataSet = label.ToString(); if (options == null) { options = new Options((LabelCmdFlags.Input), null); } if (options.ContainsKey("-i") == false) { options["-i"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success) { return label; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Create a new label in the repository. /// /// Label specification for the new label /// The Label object if new label was created, null if creation failed public Label CreateLabel(Label label) { return CreateLabel(label, null); } /// /// Update the record for a label in the repository /// /// Label specification for the label being updated /// The Label object if new depot was saved, null if creation failed public Label UpdateLabel(Label label) { return CreateLabel(label, null); } /// /// Get the record for an existing label from the repository. /// /// Label name /// Flags used when fetching an existing label /// The Label object if label was found, null if creation failed public Label GetLabel(string label, string template, Options options) { if (label == null) { throw new ArgumentNullException("label"); } P4Command cmd = new P4Command(this, "label", true, label); if (options == null) { options = new Options((LabelCmdFlags.Output), template); } 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; } Label value = new Label(); value.FromLabelCmdTaggedOutput((results.TaggedOutput[0])); return value; } else { P4Exception.Throw(results.ErrorList); } return null; } public Label GetLabel(string label) { return GetLabel(label, null, null); } /// /// Get a list of labels from the repository /// /// A list containing the matching labels /// ///
p4 help labels ///
///
labels -- Display list of defined labels ///
///
p4 labels [-t] [-u user] [[-e|-E] nameFilter -m max] [file[revrange]] ///
///
Lists labels defined in the server. ///
///
If files are specified, 'p4 labels' lists the labels that contain ///
those files. If you include a file specification, automatic lablels ///
are omitted from the list. If the file specification includes a ///
revision range, 'p4 labels' lists labels that contain the specified ///
revisions. See 'p4 help revisions for details about specifying ///
revisions. ///
///
The -t flag displays the time as well as the date. ///
///
The -u user flag lists labels owned by the specified user. ///
///
The -e nameFilter flag lists labels with names that match the ///
the nameFilter pattern, for example: -e 'svr-dev-rel*'. -E makes ///
the matching case-insensitive. ///
///
The -m max flag limits output to the first 'max' number of labels. ///
///
///
public IList