/******************************************************************************* 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 -g -t template] name ///
p4 label -d [-f -g] name ///
p4 label -o [-t template] name ///
p4 label -i [-f -g] ///
///
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 ///
unlocked from changing the specification. Prevents ///
the label from being deleted. Prohibits ///
'p4 labelsync'. For a loaded label, prevents ///
'p4 unload'. ///
///
autoreload For a static label, indicates where label ///
noautoreload revisions are stored. Specify 'noautoreload' ///
to indicate that the revisions should be ///
stored in the db.label table. Specify ///
'autoreload' to indicate that the revisions ///
should be stored in the unload depot. ///
Revision: An optional revision specification for an automatic ///
label. Enclose in double quotes if it contains the ///
# (form comment) character. An automatic label can ///
be treated as a pure alias of a single revision ///
specification (excluding @label) provided that the ///
View mapping is empty. ///
///
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. Leave this ///
field blank when creating an automatic label as ///
a pure alias. ///
///
ServerID: If set, restricts usage to the named server. ///
If unset, usage is allowed on any server. ///
///
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. ///
///
Only the label owner can run 'p4 labelsync', and only if the label ///
is unlocked. A label without an owner can be labelsync'd by any user. ///
///
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'. ///
///
The -g flag should be used on an Edge Server to update a global ///
label. Without -g, the label definition is visible only to users ///
of this Edge Server. Configuring rpl.labels.global=1 reverses this ///
default and causes this flag to have the opposite meaning. ///
///
///
/// /// To create a new label: /// /// /// /// Label l = new Label(); /// l.Id = "newLabel"; /// l.Owner = "admin"; /// l.Description = "created by admin"; /// l.Options = "unlocked"; /// l.ViewMap = new ViewMap(); /// string v0 = "//depot/main/..."; /// string v1 = "//depot/rel1/..."; /// string v2 = "//depot/rel2/..."; /// string v3 = "//depot/dev/..."; /// l.ViewMap.Add(v0); /// l.ViewMap.Add(v1); /// l.ViewMap.Add(v2); /// l.ViewMap.Add(v3); /// Label newLabel = rep.CreateLabel(l, null); /// /// /// /// To create a label using another label as a template: /// /// /// Label newLabel2 = rep.CreateLabel(newLabel, /// new LabelCmdOptions(LabelCmdFlags.None, newLabel.Id)); /// /// 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 /// /// To create a new label: /// /// /// /// Label l = new Label(); /// l.Id = "newLabel"; /// l.Owner = "admin"; /// l.Description = "created by admin"; /// l.Options = "unlocked"; /// l.ViewMap = new ViewMap(); /// string v0 = "//depot/main/..."; /// string v1 = "//depot/rel1/..."; /// string v2 = "//depot/rel2/..."; /// string v3 = "//depot/dev/..."; /// l.ViewMap.Add(v0); /// l.ViewMap.Add(v1); /// l.ViewMap.Add(v2); /// l.ViewMap.Add(v3); /// Label newLabel = rep.CreateLabel(l, null); /// /// /// 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 /// /// /// To lock a label: /// /// /// Label l = rep.GetLabel("admin_label"); /// l.Locked = true; /// rep.UpdateLabel(l); /// /// /// 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 /// /// /// To get the admin_label with the gobal option: /// /// /// /// LabelCmdOptions opts = new LabelCmdOptions(LabelCmdFlags.Global,null); /// Label label = rep.GetLabel("admin_label", null, opts); /// /// /// 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; } /// /// Get the record for an existing label from the repository. /// /// Label name /// The Label object if label was found, null if creation failed /// /// /// To get the admin_label: /// /// /// /// string targetLabel = "admin_label"; /// Label l = rep.GetLabel(targetLabel); /// /// /// 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 ///
///
p4 labels [-t] [-u user] [[-e|-E] nameFilter -m max] [file[revrange]] ///
p4 labels [-t] [-u user] [[-e|-E] nameFilter -m max] [-a|-s serverID] ///
p4 labels -U ///
///
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 labels ///
and labels with the 'autoreload' option set 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. ///
///
The -U flag lists unloaded labels (see 'p4 help unload'). ///
///
The -a and -s flags are useful in a distributed server installation ///
(see 'p4 help distributed') in order to see the names of local labels ///
stored on other Edge Servers. These flags are not allowed if the ///
command includes a file specification. ///
///
The -a flag specifies that all labels should be displayed, not just ///
those that are bound to this server. ///
///
The -s serverID flag specifies that only those labels bound to the ///
specified serverID should be displayed. ///
///
On an Edge Server, if neither -s nor -a is specified, only those ///
local labels bound to this Edge Server are displayed. Labels created ///
on the Commit Server are global, and are also included in the output. ///
///
/// /// /// To get 50 labels on a distributed server installation: /// /// /// /// LabelsCmdOptions opts = new LabelsCmdOptions(LabelsCmdFlags.All, /// null, null, 50, null, null); /// IList<Label> labels = rep.GetLabels(opts); /// /// /// /// To get labels which contain files with the path //depot/Modifiers/...: /// /// /// FileSpec path = new FileSpec(new DepotPath("//depot/Modifiers/..."), null); /// Options ops = new Options(); /// IList<Label> l = rep.GetLabels(ops, path); /// /// /// public IList