Roni
Roni

Reputation: 403

How to set default view for 'p4 client'

I'm new in Perforce and I not understand how to configure the p4 client command.

If typing p4 set command I get this:

C:\Program Files\Perforce>p4 set
P4CLIENT=aronTest (set)
P4EDITOR=C:\Windows\SysWOW64\notepad.ex
P4PORT=******:1666 (set)
P4USER=aron (set)
P4_*******:1666_CHARSET=none (set)

1) If I type p4 client the result as below:

Client: aronTest

....
....
View:
    //Depot_1/... //aronTest/Depot_1/...
    -//depot/... //aronTest/depot/...
    "//Depot_1/ ARCS II/Test Code/*" "//aronTest/Depot_1/ ARCS II/Test Code/*"
    "-//Depot_1/Book Store NET/..." "//aronTest/Depot_1/Book Store NET/..."

2) If I type - p4 client cli the result as below:

Client: cli
...
...

View:
    //Depot_1/... //cli/Depot_1/...
    //depot/... //cli/depot/...

I want that every client I'll create will get the view of the current P4CLIENT, but with the second command I've got the view of all depots (Depot1 & depot).

How to configure it, means every creation of client\workspace I'll get the same view of the current environment variable P4CLIENT (in other words I want the view like aronTest for every p4 client <client_name>)?

Thanks!

Upvotes: 2

Views: 5459

Answers (2)

Samwise
Samwise

Reputation: 71479

Add an alias that uses your current client (P4CLIENT) as a template when you create a new client using the "p4 client CLIENT" command:

echo client $(arg) = client -t $(P4CLIENT) $(arg) > %USERPROFILE%\p4aliases.txt

Note that you need a 2016.1 p4.exe for this to work.

Upvotes: 1

Bryan Pendleton
Bryan Pendleton

Reputation: 16359

Unfortunately, there isn't a trivial way to configure the default client view; all the ways I know of take a certain amount of work.

One widely-used technique is to use what is called a template client; this is a workspace that already exists, and has the appropriate client view, client options, etc. In your case, the aronTest client could be used as a template for the creation of new workspaces. To use aronTest as a template for the new client cli, you'd simply type p4 client -t aronTest cli instead of p4 client cli.

If your Perforce server is running release 2014.1 or later, you can set the 'template.client' configurable on the server to specify a default template client to be used when the -t argument is omitted.

You can use any client as a template for the creation of another client, but if you always have a specific template client that you want to use, the template.client configurable might do the trick for you.

If you have a 2016.1 or higher version of the p4 command line tool, you can also define a command line alias (or even several command line aliases) to specify the -t argument to the p4 client command. This could be useful if your server is older than 2014.1 and can't make use of the template.client configurable.

A second widely-used technique is to write a form-out trigger for the client spec. The form-out trigger is invoked at the time that the server is preparing the initial default client spec, and you can modify that automatically-generated spec in your trigger.

Here's an example of using the form-out trigger to control the client view: https://www.perforce.com/perforce/doc.current/manuals/p4sag/chapter.scripting.html#scripting.triggers.forms.out

You have to write (and debug) that trigger, but once it's developed and deployed, the flow is trouble-free, with no extra arguments for your developers to remember.

Yet a third approach is to adopt the 'streams' development process, in which you define your stream mappings using the p4 stream command, and switch between streams using the p4 switch command. Streams are very powerful; one particular aspect of streams which is relevant here is that client workspaces no longer have to worry about the View: section of the client spec because the server takes over the task of maintaining the client view entirely. (That is, the server generates the client's view automatically, based on the definition of the stream in use for that client.)

Here's a nice, if somewhat advanced, discussion of the power of stream definitions to simplify client spec issues: https://www.perforce.com/blog/160122/pro-tip-use-ignored-paths-slim-down-workspaces

I hope some of these ideas help; let us know what approach you choose!

Upvotes: 1

Related Questions