How to clone a workspace in perforce - perforce

How to clone my co-worker's workspace in perforce? I have the name of the workspace to clone from, how can I do it? I have tried doing it via command line with
'p4 client -t coworker_workspace_name', but I get this error 'Client '?coworker_workspace_name' doesn't exit.
Thank you.

You can do this via the P4V GUI client. I would post a screenshot, but I need at least 10 reputation :'(
Go to the Workspaces tab.
If you don't see it, you can show it via "View -> Workspaces"
Untick the filtering options, such as "Show only workspaces available or use on this computer" (see figure). You should see your co-worker's workspace (assuming it's on the same Perforce server you're connected to).
Right-click it and select "Create/Update Workspace from '...'"
Select the "Create Workspace" radio button to create a new workspace.

Using linux/bash command line:
p4 client -o -t source_client target_client_name | sed 's,Root.*,Root:\tdesired path,' | p4 client -i
p4 client -o -t source_client target_client_name
Copies source_client and changes any reference to its name to "target_client_name".
E.g. All references of "clientA" become "clientB"
sed 's,Root.\*,Root\:\tDesired_Root_Path,'
Replace "Desired_Root_Path" with wherever you'd like your Root directory. I like to group my workspaces into "/workarea/allmyworkspaces/" so that's what I'd supply.
The commas are the separators for the sed command.
p4 client -i
Reads a client spec from standard input, so this pipes all the output from the previous commands into a spec creation.
To test that your values will be correct, leave this portion off the command and everything will print to stdout and you can inspect.

Related

automatic selection of workspace when launching p4v

In the shell, when I am in a directory located as part of a p4 workspace, I can run p4 commands in the shell and it knows what workspace I am in.
However, when I launch p4v, I have to manually find the workspace that I want to load. Since, the context of p4 commands to run is already known in the shell, how I can I pass that to p4v, so it will launch in the same workspace. There's no reason why I should have to select a workspace when I launch the tool, since the p4 toolchain already can self-determine the context.
I should only have to select the workspace if I am wanting to select some other workspace that I am not currently operating under.
As you've found, P4V has its own settings file and ignores the shell's environment. Per this blog post:
https://www.perforce.com/blog/100114/p4v-secrets-calling-p4v-command-line
the way I'd handle this would be to write a script/alias that wraps P4V and passes the current environment to it. Something along these lines:
$_ = `p4 -Ztag -F "%serverAddress%#%clientName%#%userName%" info`;
#env = split /\#/;
exec "p4v -p $env[0] -c $env[1] -u $env[2]";

Perforce: How can I delete a changelist that p4v refuses to delete?

After a while of working with perforce I was left with a lot of still open change lists.
To clean up I want to get rid of a subset of them.
So here is what makes this complicate:
For a subset of the changes the host of the client has changed.
Some changes contain shelved files.
Files from the change list may be deleted or moved.
When one or more of above points are true for a change list, p4v (the visual client) will not allow you to delete the change list.
So what is an effective way of deleting these change lists?
First of all, perforce refuses to work on any change lists if the host differs in their workspace. So step one is to change the host of the workspace to the current one. This can easily be done with the visual client p4v. Open the properties of a workspace, choose edit and change the host.
Then you can use the command line to get rid of the pesky change list(s):
# to delete a changelist
CLIENT="name_of_your_client"
CHANGE="number_of_the_changelist_to_delete"
p4 -c $CLIENT shelve -c $CHANGE -d //... # Delete all shelved files from it.
p4 -c $CLIENT revert -k -c $CHANGE //... # Revert all files from changelist (only metadata).
p4 -c $CLIENT change -d $CHANGE # Finally delete the changelist.
After the last command the change list will be gone forever.
Fixing the hostname can be done from the command line like this:
client_hostname="$(p4 client -o ${CLIENT} | grep "^Host" | awk '{print $2}')"
p4 client -o ${CLIENT} | sed "/^Host:/ s=${client_hostname}=${HOSTNAME}=" | p4 client -i
Had the same problem some time ago and wrote a script (p4-delete-changelist) that overcomes all of these problems (and another one - deleting p4 fixes).
Note that the script depends on another file in the repository.

Substituting client path on P4 sync

I have an XML file that refers to some other files. I can use neither relative paths nor variables in this file.
Is it possible to somehow add to the P4 repository a template and some script that will generate that file on the sync? E.g. I can use something trivial like sed to update paths depending on where the P4 client root is.
I really would like to make this transparent so I know that this file is always of proper version and contains actual info.
If you mean you want dynamic root, try putting "null" (no quotes) in the root path of your workspace, and the root of your workspace will be whatever directory you are in.
If you are trying to create a dynamic workspace, you can create a text file of your workspace (p4 client -o > template_worksapce.txt) and use sed on that to create a workspace, then read it in via p4 client -i
Is that what you were looking for?
Try:
p4 info | grep 'Client root'
or:
p4 -ztag client -o | grep Root

How to view Shelved P4 Changes?

One of our team member (located in different region) has shelved changes in P4 with changelist 1234.
Now, if I want to see what files are modified snf what are the changes, how can I do this?
What is the P4 command that I should use to see the changes made by our team member?
p4 describe -S 1234 should to the trick, see the documentation on describe.
To see the file content you would unshelve the files into your workspace (assuming you have a workspace for the same project your colleague is working on).
Create a new (empty) changelist with p4 change (results in e.g. 2345), then use p4 unshelve (docu) to get the modified files to your workspace:
p4 unshelve -s 1234 -c 2345
If you don't want the modified files in your workspace any longer, you can p4 revert -c 2345 them.
Using the GUI, go to Pending and remove all filters except by user, where you will put the other developer's ID. From there you should be able to see her Changelists, including the ones having shelved files. Right click on the Shelved Files icon and select Unshelve. You will have to have a workspace active that includes the files that you are trying to unshelve.
Using UI client, press Ctrl+G. Dialog window is appears. Select Changelist in combobox and input number of changelist.
Let's assume that changelist 123456 is the shelved changelist in question. As a previous answer mentioned, the way to list the files are associated with that changelist is via the p4 describe -s <changelist> command. Like so:
$ p4 describe -s 123456
Change 123456 by john.doe#JohnsBranch on 2013/10/24 15:38:10 *pending*
[Shelving my changes for Jane.]
Fix memory corruption caused by uninitialized pointer.
Affected files ...
... //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 edit
Once you know the file(s) in question, there are a couple of ways to diff the files without a corresponding workspace. Method #1 is to use p4 print:
$ p4 print -q //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 > /tmp/old
$ p4 print -q //depot/branches/JohnsBranch/kernel/vm/pageutils.c#=123456 > /tmp/new
$ diff /tmp/old /tmp/new # Or use kdiff3, tkdiff, etc.
...
<diff output here>
The other method is to use p4 diff2:
$ p4 diff2 //depot/branches/JohnsBranch/kernel/vm/pageutils.c#1 //depot/branches/JohnsBranch/kernel/vm/pageutils.c#=123456
...
<diff output here based on Perforce server's diff algorithm>
Both methods can be easily incorporated into the scripting language of choice.
jhwist's solution is good if you want to see the files' diffs.
If you want to see just the shelved files, use p4 describe -sS 1234.
The lower case s restricts the output from including file diffs.
If you wanted to see the actual content of the files, you could use:
p4 print <file>#=<shelved_change>
The #= means to look at the shelved change, where as # means to look at the change.
If you want to see only the list of files inside a ChangeList (whether it's a shelve, pending or submitted CL), without extra data, grep the result:
p4 describe -S 12345 | grep -oP '(?=//).*(?=#)'
In P4V UI, select
Search - > Go To
then choose type of changelist (in your case 'Pending changelist'), enter changelist number and click "OK".
You may try
p4 -ztag describe <changeno>
The description contains a string called '... shelved' if it is shelved.

How to perform p4 submit operation without passing description inside the p4 submit form

I have a p4 client workspace on Linux machine.
I added/edited few files in my client space and then tried to submit those changes to perforce server.
I followed the steps below but could not succeed:
p4 submit -d "test" (the same command works on a Windows machine)
when I tried it with just p4 submit then it opened a p4 submit form and then I replaced [enter description here] token with the proper description and then it works.
But I don't want to edit the p4 submit form for every p4 submit task.
How can I pass this info in from the command prompt?
Answer
-d flag support for p4 submit command was not introduced in
perforce 2006 version. so here is the workaround for this problem:
To modify the description field on pre-2006.2 release Perforce Servers, try
piping the change form in/out of a stream editor. This will create a numbered
changelist, which should then be submitted.
For example, something like:
p4 change -o | sed -e "s/<enter description here>/my desc/" | p4 change -i
Which gives the output, similar to:
Change 102 created with 3 open file(s).
This change (number 102 in this case) can then be submitted, as follows:
p4 submit -c 102
It's not just the description you need to enter, you also can edit the changelist specification which allows you to exclude files from the commit.
If you can do it on windows then perhaps there is a newer client on windows than what you're using on Linux?
From http://www.perforce.com/perforce/downloads/platform.html download the appropriate version of p4 command-line client. Then:
Replace the existing p4 executable with the new one.
Or put the new p4 exe in a directory earlier in your $PATH
Make the chmod 755 <new p4>
hash -r
p4 -V to verify you are running perforce 2009.1 client
p4 help submit
We can md5sum the p4 binary
p4 info and verify the perforce server is 2006.2 or more recent.
Step 5 should produce:
$ p4 -V
Perforce - The Fast Software Configuration Management System.
Copyright 1995-2009 Perforce Software. All rights reserved.
Rev. P4/LINUX26X86/2009.1/205670 (2009/06/29).
Step 6 should produce:
$ p4 help submit
submit -- Submit open files to the depot
p4 submit [ -r -s -f option ]
p4 submit [ -r -s -f option ] files
p4 submit [ -r -f option ] -d description
p4 submit [ -r -f option ] -d description files
p4 submit [ -r -f option ] -c changelist#
p4 submit -i [ -r -s -f option ]
'p4 submit' commits a pending changelist and its files to the depot.
With no argument 'p4 submit' attempts to submit all files in the
'default' changelist. Submit provides the user with a dialog
similar to 'p4 change' so the user can compose a changelist
description. In this dialog the user is presented with the list
of files open in changelist 'default'. Files may be deleted from
this list but they cannot be added. (Use an open command (edit,
add, delete) to add additional files to a changelist.)
If a (single) file pattern is given, only those files in
the 'default' changelist that match the pattern will be submitted.
The -c flag submits the numbered pending changelist that has been
previously created with 'p4 change' or a failed 'p4 submit'.
The -d flag allows a description to be passed into submit rather
than using a numbered changelist or engaging in a change description
dialog. This option is useful when scripting but does not allow for
jobs to be added or the default changelist to be modified.
The -f flag allows a submit option to be passed into submit which
will override the one that is set in the client. See 'p4 help client'
for valid submit options.
The -i flag causes a changelist specification (including files to be
submitted) to be read from the standard input. The user's editor
is not invoked.
The -r flag allows submitted files to remain open (on the client's
default changelist) after the submit has completed.
The -s flag extends the list of jobs to include the fix status
for each job, which becomes the job's status when the changelist
is committed. See 'p4 help change' for more notes on this option.
Before committing a changelist submit locks all associated files not
already locked. If any file cannot be locked, or if the submit
fails for any other reason the files are left open in a newly
created pending changelist.
Submit is guaranteed to be atomic. Either all files will be
updated in the depot as a unit or none will be.
Of which the important bit is:
The -d flag allows a description to be passed into submit rather
than using a numbered changelist or engaging in a change description
dialog. This option is useful when scripting but does not allow for
jobs to be added or the default changelist to be modified.
Step 7:
$ md5sum $(which p4)
bef01f66b8d3964c74a2d8992c0c900c /opt/perforce/bin/p4
Step 8:
The feature was introduced in perforce 2006.2, and it's possible that it requires a sufficiently recent server to support the operation:
#106450 (Bug #258) **
'p4 submit' now sports a '-d description' option. This allows
the user to submit files without the need for a changelist
dialog. See 'p4 help submit'.

Resources