/******************************************************************************* 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.Client.cs * * Author : dbb * * Description : Class used to abstract a client in Perforce. * ******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Perforce.P4 { public partial class Repository { /// /// Create a new client in the repository. /// /// Client specification for the new user /// The '-i' flags is required when creating a new user /// The Client object if new user was created, null if creation failed /// The '-i' flag is added if not specified by the caller ///
///
p4 help client ///
///
client -- Create or edit a client workspace specification and its view ///
workspace -- Synonym for 'client' ///
///
p4 client [-f -t template] [name] ///
p4 client -d [-f] name ///
p4 client -o [-t template] [name] ///
p4 client -S stream [[-c change] -o] [name] ///
p4 client -s [-f] -S stream [name] ///
p4 client -s [-f] -t template [name] ///
p4 client -i [-f] ///
///
Creates a new client specification ('spec') or edits an existing ///
spec. A client spec is a named mapping of depot files to workspace ///
files. ///
///
The 'p4 client' command puts the client spec into a temporary file ///
and invokes the editor configured by the environment variable ///
$P4EDITOR. For new workspaces, the client name defaults to the ///
$P4CLIENT environment variable, if set, or to the current host name. ///
Saving the file creates or modifies the client spec. ///
///
The client spec contains the following fields: ///
///
Client: The client name. ///
///
Host: If set, restricts access to the named host. ///
If unset, access is allowed from any host. ///
///
Owner: The user who created this client. ///
///
Update: The date that this spec was last modified. ///
///
Access: The date that this client was last used in any way. ///
///
Description: A short description of the workspace. ///
///
Root: The root directory of the workspace (specified in local ///
file system syntax), under which all versioned files ///
will be placed. If you change this setting, you must ///
physically relocate any files that currently reside ///
there. On Windows client machines, you can specify the ///
root as "null" to enable you to map files to multiple ///
drives. ///
///
AltRoots: Up to two optional alternate client workspace roots. ///
The first of the main and alternate roots to match the ///
client program's current working directory is used. If ///
none match, the main root is used. 'p4 info' displays ///
the root that is being used. ///
///
Options: Flags to configure the client behavior. Defaults ///
are marked with *. ///
///
allwrite Leaves all files writable on the client; ///
noallwrite * by default, only files opened by 'p4 edit' ///
are writable. If set, files might be clobbered ///
as a result of ignoring the clobber option ///
(see below). ///
///
clobber Permits 'p4 sync' to overwrite writable ///
noclobber * files on the client. noclobber is ignored if ///
allwrite is set. ///
///
compress Compresses data sent between the client ///
nocompress * and server to speed up slow connections. ///
///
locked Allows only the client owner to use or change ///
unlocked * the client spec. Prevents the client spec from ///
being deleted. ///
///
modtime Causes 'p4 sync' and 'p4 submit' to preserve ///
nomodtime * file modification time, as with files with the ///
+m type modifier. (See 'p4 help filetypes'.) ///
With nomodtime, file timestamps are updated by ///
sync and submit operations. ///
///
rmdir Makes 'p4 sync' attempt to delete a workspace ///
normdir * directory when all files in it are removed. ///
///
SubmitOptions: Flags to change submit behaviour. ///
///
submitunchanged All open files are submitted (default). ///
///
revertunchanged Files that have content or type changes ///
are submitted. Unchanged files are ///
reverted. ///
///
leaveunchanged Files that have content or type changes ///
are submitted. Unchanged files are moved ///
to the default changelist. ///
///
+reopen Can be appended to the submit option flag ///
to cause submitted files to be reopened in ///
the default changelist. ///
Example: submitunchanged+reopen ///
///
LineEnd: Set line-ending character(s) for client text files. ///
///
local mode that is native to the client (default). ///
unix linefeed: UNIX style. ///
mac carriage return: Macintosh style. ///
win carriage return-linefeed: Windows style. ///
share hybrid: writes UNIX style but reads UNIX, ///
Mac or Windows style. ///
///
View: Maps files in the depot to files in your client ///
workspace. Defines the files that you want in your ///
client workspace and specifies where you want them ///
to reside. The default view maps all depot files ///
onto the client. See 'p4 help views' for view syntax. ///
A new view takes effect on the next 'p4 sync'. ///
///
Stream: The stream to which this client's view will be dedicated. ///
(Files in stream paths can be submitted only by dedicated ///
stream clients.) When this optional field is set, the ///
View field will be automatically replaced by a stream ///
view as the client spec is saved. ///
///
Note: changing the client root does not actually move the client ///
files; you must relocate them manually. Similarly, changing ///
the 'LineEnd' option does not actually update the client files; ///
you can refresh them with 'p4 sync -f'. ///
///
The -d flag deletes the specified spec, as long as the client ///
workspace has no opened files or pending changes. (See 'p4 help ///
opened'.) The -f flag forces the delete. ///
///
The -o flag writes the named client spec to the standard output. ///
The user's editor is not invoked. ///
///
The -i flag reads a client spec from the standard input. The ///
user's editor is not invoked. ///
///
The -t template flag, where 'template' is the name of another client ///
spec, causes the View and Options fields to be replaced by those of ///
the template. ///
///
The -f flag can force the updating of locked clients; normally ///
locked clients can only be modified by their owner. -f also allows ///
the last modified date to be set. The -f flag requires 'admin' ///
access granted by 'p4 protect'. ///
///
The -s flag is used to switch an existing client spec's view without ///
invoking the editor. It can be used with -S to switch to a stream ///
view, or with -t to switch to a view defined in another client spec. ///
Switching views is not allowed in a client that has opened files. ///
The -f flag can be used with -s to force switching with opened files. ///
View switching has no effect on files in a client workspace until ///
'p4 sync' is run. ///
///
Without -s, the '-S stream' flag can be used to create a new client ///
spec dedicated to a stream. If the client spec already exists, and ///
-S is used without -s, it is ignored. ///
///
The '-S stream' flag can be used with '-o -c change' to inspect an ///
old stream client view. It yields the client spec that would have ///
been created for the stream at the moment the change was recorded. ///
///
///
///
public Client CreateClient(Client client, Options options) { if (client == null) { throw new ArgumentNullException("client"); } P4Command cmd = new P4Command(this, "client", true); cmd.DataSet = client.ToString(); if (options == null) { options = new Options(); } options["-i"] = null; P4CommandResult results = cmd.Run(options); if (results.Success) { return client; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Create a new client in the repository. /// /// Client specification for the new client /// The Client object if new client was created, null if creation failed public Client CreateClient(Client client) { return CreateClient(client, null); } /// /// Update the record for a client in the repository /// /// Client specification for the client being updated /// The Client object if new client was saved, null if creation failed public Client UpdateClient(Client client) { return CreateClient(client, null); } /// /// Get the record for an existing client from the repository. /// /// Client name /// There are no valid flags to use when fetching an existing client /// The Client object if new client was found, null if creation failed public Client GetClient(string client, Options options) { if (client == null) { throw new ArgumentNullException("client"); } P4Command cmd = new P4Command(this, "client", true, client); if (options == null) { options = new Options(); } options["-o"] = null; P4CommandResult results = cmd.Run(options); if (results.Success) { if ((results.TaggedOutput == null) || (results.TaggedOutput.Count <= 0)) { return null; } Client value = new Client(); value.FromClientCmdTaggedOutput((results.TaggedOutput[0])); return value; } else { P4Exception.Throw(results.ErrorList); } return null; } public Client GetClient(string client) { return GetClient(client, null); } /// /// Get a list of clients from the repository /// /// options for the clients command /// A list containing the matching clients /// ///
p4 help clients ///
///
clients -- Display list of clients ///
workspaces -- synonym for 'clients' ///
///
p4 clients [-t] [-u user] [[-e|-E] nameFilter -m max] [-S stream] ///
///
Lists all client workspaces currently defined in the server. ///
///
The -t flag displays the time as well as the date. ///
///
The -u user flag lists client workspaces that are owned by the ///
specified user. ///
///
The -e nameFilter flag lists workspaces with a name that matches ///
the nameFilter pattern, for example: -e 'svr-dev-rel*'. -E makes ///
the matching case-insensitive. ///
///
The -m max flag limits output to the specified number of workspaces. ///
///
The -S stream flag limits output to the client workspaces dedicated ///
to the stream. ///
///
///
///
public IList GetClients(Options options) { P4Command cmd = new P4Command(this, "clients", 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) { Client client = new Client(); client.FromClientsCmdTaggedOutput(obj); value.Add(client); } return value; } else { P4Exception.Throw(results.ErrorList); } return null; } /// /// Delete a client from the repository /// /// The client to be deleted /// Only the '-f' flag is valid when deleting an existing client public void DeleteClient(Client client, Options options) { if (client == null) { throw new ArgumentNullException("client"); } P4Command cmd = new P4Command(this, "client", true, client.Name); if (options == null) { options = new Options(); } options["-d"] = null; P4CommandResult results = cmd.Run(options); if (results.Success == false) { P4Exception.Throw(results.ErrorList); } } } }