/******************************************************************************* 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.Stream.cs * * Author : wjb * * Description : Stream operations for the Reposity. * ******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Perforce.P4 { public partial class Repository { /// /// Create a new stream in the repository. /// /// Stream specification for the new stream /// The '-i' flag is required when creating a new stream /// The Stream object if new stream was created, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help stream ///
///
stream -- Create, delete, or modify a stream specification ///
///
p4 stream [-P parent] -t type name ///
p4 stream [-f] [-d] [-o [-v]] [-P parent] -t type name ///
p4 stream -i [-f] ///
///
A stream specification ('spec') names a path in a stream depot to be ///
treated as a stream. (See 'p4 help streamintro'.) The spec also ///
defines the stream's lineage, its view, and its expected flow of ///
change. ///
///
The 'p4 stream' command puts the stream spec into a temporary file and ///
invokes the editor configured by the environment variable $P4EDITOR. ///
When creating a stream, the type of the stream must be specified with ///
the '-t' flag. Saving the file creates or modifies the stream spec. ///
///
Creating a stream spec does not branch a new stream. To branch a ///
stream, use 'p4 copy -r -S stream', where 'stream' is the name of a ///
stream spec. ///
///
The stream spec contains the following fields: ///
///
Stream: The stream's path in a stream depot, of the form ///
//depotname/streamname. This is both the name of the stream ///
spec and the permanent, unique identifier of the stream. ///
///
Update: The date this stream spec was last changed. ///
///
Access: The date of the last command used with this spec. ///
///
Owner: The stream's owner. Can be changed. ///
///
Name: An alternate name of the stream, for use in display outputs. ///
Defaults to the 'streamname' portion of the stream path. ///
Can be changed. ///
///
Parent: The parent of this stream. Can be 'none' if the stream type ///
is 'mainline', otherwise must be set to an existing stream ///
identfier, of the form //depotname/streamname. ///
Can be changed. ///
///
Type: 'mainline', 'development', or 'release'. Default is ///
'development'. Defines the expected flow of change between ///
a stream and its parent: A development stream expects to ///
merge from the parent and copy to the parent; a release ///
stream expects to copy from the parent and merge to the ///
parent. Can be changed ///
///
Description: An optional description of the stream. ///
///
Options: Flags to configure stream behavior. Defaults are marked *: ///
///
unlocked * Indicates whether the stream spec is locked ///
locked against modifications. If locked, the spec ///
may not be deleted, and only its owner may ///
modify it. ///
///
allsubmit * Indicates whether all users or only the ///
ownersubmit of the stream may submit changes to the ///
stream path. ///
///
toparent * Indicates whether integration from the ///
notoparent stream to its parent is expected to occur. ///
///
fromparent * Indicates whether integration to the stream ///
nofromparent from its parent is expected to occur. ///
///
Paths: One or more lines that define file paths in the stream view. ///
Each line is of the form: ///
///
<path_type> <view_path> [<depot_path>] ///
///
where <path_type> is a single keyword, <view_path> is a file ///
path with no leading slashes, and the optional <depot_path> ///
is a file path beginning with '//'. Both <view_path> and ///
<depot_path> may contain trailing wildcards, but no leading ///
or embedded wildcards. Lines in the Paths field may appear ///
in any order. A duplicated <view_path> overrides its ///
preceding entry. ///
///
For example: ///
///
share src/... ///
import lib/abc/... //over/there/abc/... ///
isolate bin/* ///
///
Default is: ///
///
share ... ///
///
The <path_type> keyword must be one of: ///
///
share: <view_path> will be included in client views and ///
in branch views. Files in this path are accessible ///
to workspaces, can be submitted to the stream, and ///
can be integrated with the parent stream. ///
///
isolate: <view_path> will be included in client views but ///
not in branch views. Files in this path are ///
accessible to workspaces, can be submitted to the ///
stream, but are not integratable with the parent ///
stream. ///
///
import: <view_path> will be included in client views but ///
not in branch views. Files in this path are mapped ///
as in the parent stream's view (the default) or to ///
<depot_path> (optional); they are accessible to ///
workspaces, but can not be submitted or integrated ///
to the stream. ///
///
exclude: <view_path> will be excluded from client views ///
and branch views. Files in this path are not ///
accessible to workspaces, and can't be submitted ///
or integrated to the stream. ///
///
Paths are inherited by child stream views. A child stream's ///
paths can downgrade the inherited view, but not upgrade it. ///
(For instance, a child stream can downgrade a shared path to ///
an isolated path, but it can't upgrade an isolated path to a ///
shared path.) Note that <depot_path> is relevant only when ///
<path_type> is 'import'. ///
///
Remapped: Optional; one or more lines that define how stream view paths ///
are to be remapped in client views. Each line is of the form: ///
///
<view_path_1> <view_path_2> ///
///
where <view_path_1> and <view_path_2> are Perforce view paths ///
with no leading slashes and no leading or embedded wildcards. ///
For example: ///
///
... x/... ///
y/* y/z/* ///
///
Line ordering in the Remapped field is significant; if more ///
than one line remaps the same files, the later line has ///
precedence. Remapping is inherited by child stream client ///
views. ///
///
Ignored: Optional; a list of file or directory names to be ignored in ///
client views. For example: ///
///
/tmp # ignores files named 'tmp' ///
/tmp/... # ignores dirs named 'tmp' ///
.tmp # ignores file names ending in '.tmp' ///
///
Lines in the Ignored field may appear in any order. Ignored ///
names are inherited by child stream client views. ///
///
The -d flag causes the stream spec to be deleted. A stream spec may ///
not be deleted if it is referenced by child streams or stream clients. ///
Deleting a stream spec does not remove stream files, but it does mean ///
changes can no longer be submitted to the stream's path. ///
///
The -o flag causes the stream spec to be written to the standard ///
output. The user's editor is not invoked. -v may be used with -o to ///
expose the automatically generated client view for this stream. ///
('p4 help branch' describes how to expose the branch view.) ///
///
The -P flag can be used to insert a value into the Parent field of a ///
new stream spec. It has no effect on an existing spec. ///
///
The -t flag is used to insert a value into the type field of a ///
new stream spec and to adjust the default fromparent option ///
for a new 'release' -type stream. The flag has no effect on an ///
existing spec. ///
///
The -i flag causes a stream spec to be read from the standard input. ///
The user's editor is not invoked. ///
///
The -f flag allows a user other than the owner to modify or delete a ///
locked stream. It requires 'admin' access granted by 'p4 protect'. ///
///
///
public Stream CreateStream(Stream stream, Options options) { if (stream == null) { throw new ArgumentNullException("stream"); } P4Command cmd = new P4Command(this, "stream", true); cmd.DataSet = stream.ToString(); if (options == null) { options = new Options((StreamCmdFlags.Input), null, null); } if (options.ContainsKey("-i") == false) { options["-i"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success) { return stream; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Create a new stream in the repository. /// /// Stream specification for the new stream /// The Stream object if new stream was created, null if creation failed public Stream CreateStream(Stream stream) { return CreateStream(stream, null); } /// /// Update the record for a stream in the repository /// /// Stream specification for the stream being updated /// The Stream object if new stream was saved, null if creation failed public Stream UpdateStream(Stream stream) { return CreateStream(stream, null); } /// /// Get the record for an existing stream from the repository. /// /// Stream name /// There are no valid flags to use when fetching an existing stream /// The Stream object if new stream was found, null if creation failed public Stream GetStream(string stream, string parent, Options options) { if (stream == null) { throw new ArgumentNullException("stream"); } P4Command cmd = new P4Command(this, "stream", true, stream); if (options == null) { options = new Options((StreamCmdFlags.Output), parent, null); } 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; } Stream value = new Stream(); value.FromStreamCmdTaggedOutput((results.TaggedOutput[0])); return value; } else { P4Exception.Throw(results.ErrorList); } return null; } public Stream GetStream(string stream) { return GetStream(stream, null, null); } /// /// Get a list of streams from the repository /// /// options for the streams command /// A list containing the matching streams /// ///
p4 help streams ///
///
streams -- Display list of streams ///
///
p4 streams [-F filter -T fields -m max] [streamPath ...] ///
///
Reports the list of all streams currently known to the system. If ///
a 'streamPath' argument is specified, the list of streams is limited ///
to those matching the supplied path. ///
///
For each stream, a single line of output lists the stream depot path, ///
the type, the parent stream depot path, and the stream name. ///
///
The -F filter flag limits the output to files satisfying the expression ///
given as 'filter'. This filter expression is similar to the one used ///
by 'jobs -e jobview', except that fields must match those above and ///
are case sensitive. ///
///
e.g. -F "Parent=//Ace/MAIN & Type=development" ///
///
Note: the filtering takes place post-compute phase; there are no ///
indexes to optimize performance. ///
///
The -T fields flag (used with tagged output) limits the fields output ///
to those specified by a list given as 'fields'. These field names can ///
be separated by a space or a comma. ///
///
e.g. -T "Stream, Owner" ///
///
The -m max flag limits output to the first 'max' number of streams. ///
///
///
public IList GetStreams(Options options, params FileSpec[] files) { P4Command cmd = null; if ((files != null) && (files.Length > 0)) { cmd = new P4Command(this, "streams", true, FileSpec.ToStrings(files)); } else { cmd = new P4Command(this, "streams", true); } P4CommandResult results = cmd.Run(options); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } List value = new List(); foreach (TaggedObject obj in results.TaggedOutput) { Stream stream = new Stream(); stream.FromStreamCmdTaggedOutput(obj); value.Add(stream); } return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Delete a stream from the repository /// /// The stream to be deleted /// Only the '-f' flag is valid when deleting an existing stream public void DeleteStream(Stream stream, Options options) { if (stream == null) { throw new ArgumentNullException("stream"); } P4Command cmd = new P4Command(this, "stream", true, stream.Id); if (options == null) { options = new Options((StreamCmdFlags.Delete | StreamCmdFlags.Force), null, null); } if (options.ContainsKey("-d") == false) { options["-d"] = null; } if (options.ContainsKey("-f") == false) { options["-f"] = null; } P4CommandResult results = cmd.Run(options); if (results.Success == false) { P4Exception.Throw(results.ErrorList); } } } }