Showing a change in a shelved perforce file - perforce

If a colleague has a file shelved in perforce, and I'd like to diff the file in the shelved changelist against the source version of that file what is the perforce command needed to do this?
For example if the file a.txt is shelved in changelist 156222 how do I view the changes to a.txt that are in the shelved changelist vs. the current review of a.txt

If you know the revision of the shelved file (e.g. #4) and the head revision (#3 in this case) you can use
p4 diff2 //path/to/depot/file#3 //path/to/depot/file#=<changenumber>
or - even easier - you can use p4 describe (see manual):
p4 describe -S <changenumber>
Find the changenumber with:
p4 changes -u <user> -s shelved

If you are using P4V, you can go to your Pending tab and select the "User" and "Workspace" of your colleague (with the help of the drop-down "Browse..." option).
Then you will see his/her Pending lists, being it composed of shelved files or not. From there, the normal "Diff Against" will work for the "a.txt" file.

Related

Get a folder's changelist

If I select from Perforce a folder from my workspace->right-click->Folder History, in the new view that appears, there is a label: Changhelist: 1234. Is there a command line that can retrieve this information(e.g. p4 changelist d:/my_path)?
Yes, it's p4 changes. See: https://www.perforce.com/perforce/r14.2/manuals/cmdref/p4_changes.html
So: p4 changes -m 1 d:/my_path/... will show you the most recent changelist that affected files in d:/my_path/.
p4 changelists is the same as p4 changes, so you were very close with your guess, but there is no p4 changelist, just p4 changelists and p4 changes.
Try p4 help to see all the available commands.

Perforce - Get files from a shelved changelist into default changelist , work on those files and again shelve them to a same changelist

I have created a changelist for review by shelving some files. Now I want to implement the review comments. For that I tried unshelving the files but p4 opened still shows that the files are in the shelved changelist and not in the default changelist. I want to work on these files and again shelve the modified files in the same changelist. How to do this using p4 commands.
If you intend to update the same shelved changelist, it's actually best if the unshelved open files are open in the same changelist number, and not in the default changelist.
The overall process for updating one of your existing shelves (number NNN) is:
Make sure your workspace is empty of any work in progress: p4 opened should say "file(s) not opened on this client".
p4 unshelve -s NNN -c NNN
work on your files using your text editor, etc. If you open any new files, make sure you do: p4 edit -c NNN so that the new files, too, are in the same changelist number. You can also discard a file from this changelist number by doing p4 revert if that need should arise.
When you are ready to update your shelved changelist, do: p4 shelve -r -c NNN. This replaces all the files in the shelved changelist with the files that you have open in your workspace at that changelist number. If there is only one (or a couple) of files that you wish to replace in the shelved changelist, you can alternatively do: p4 shelve -f -c NNN //path/to/file to replace just that one file in the shelved changelist
p4 revert -w -c NNN //... to clean all those modified files out of your workspace and leave the changed versions only in the shelved changelist
You can repeat this sequence over and over to revise your shelved changelist through multiple code review cycles.
Note that this is not the only workflow that you can use with shelves. For example, it's also perfectly fine, and quite common, for developers to prefer to create multiple shelves, where each shelved changelist represents a point in time through the evolution of your work as you respond to review comments, etc.
But updating a shelved changelist in place is also a good workflow, and I use it regularly.
Watch out for one particular "gotcha", though, which is why the p4 revert -w is so important: files opened for add. If you have a file opened for add in your shelved changelist, and if you do a simple p4 revert, rather than a p4 revert -w, Perforce will leave the added file's data in your workspace on your laptop, whereas the -w flag tells Perforce to delete that file from your laptop entirely. When you do the p4 unshelve -s NNN -c NNN, if the shelved changelist contains a file opened for add, and if a file by that name is already present on your laptop, Perforce won't unshelve that file (because it doesn't want to clobber the data that's already present on your laptop), and so it won't re-open that file for add in your workspace. It will give you a "can't clobber writable file" message when it does so, but if you absent-mindedly overlook that message, then you'll not have the file open for add anymore, and when you do the p4 shelve -r -c NNN, Perforce will remove that file from the shelf, and you'll have accidentally deleted that file from your shelf. It's easy to avoid this problem if you always reliably use p4 revert -w (so put 'revert => revert -w' in your P4ALIASES file).

How to unshelve a shelved changelist to another branch prior to Perforce 2013?

Using Perforce Server 2012.2/538478, how can I unshelve files from the trunk to another branch?
When trying to do it, I get:
//filename... (not mapped to your workspace view)
In Perforce 2013, I found this unshelve command to really be helpful:
p4 unshelve -s <changlist#-with-shelved-files> -S //depot/streamname
But with the version I'm using currently, I found nothing to help me with that issue.
Any suggestions?
The other answers didn't work for me, this is what I did using perforce 2014:
Edit your current workplace so that both //depot/product/B1/... and //depot/product/B2/... are mapped in it (not to each other, to your workspace like normal mappings)
In P4V, go to "Branch Mappings" (View menu->Branch Mappings )
Ctrl+N to start a new mapping (or right click the list and choose "New Branch Mapping..." )
Under "Branch Mapping" provide a name like B1_TO_B2
Replace the mappings under View to be for example
//depot/product/B1/... //depot/product/B2/...
OK
Create an empty Changelist where your unshelved files will be placed (otherwise they will go to "default" changelist). The number of this new changelist will be < TARGET_CL > in the command below.
In the command line, run
p4 unshelve -s <SOURCE_CL> -c <TARGET_CL> -b B1_to_B2
If it doesn't work, make sure the correct workspace is set in .p4config
Now all you have to do is resolve the files in < TARGET_CL >
You're looking at the right command, but possibly not the right parameters. This is how I use it:
p4 unshelve -s 77655 -b MY_BRANCH_SPEC
which unshelves changelist 77655, using the specified branch specification to map the files to the new branch.
Critically, you need to make sure that both the specified branch mapping and your current workspace mapping contain both the source and destination files, otherwise you will get the "file not mapped" error.
Unfortunately, without upgrading to 2013.1 and getting the improved unshelve operation, you're going to need to manually copy the data by:
unshelving in trunk, noting the specific files that have changed
p4 edit the files in your other stream/branch
manually copy the unshelved files to the other stream/branch (you can't use p4 copy or p4 integrate for this because they aren't committed on the trunk
test and commit on the other branch
After spending sometime searching and reading, I have not come across a concrete example for unshelving a shelved changelist to another branch. finally I put together a concrete example.
Assuming you have a shelved changelist 324426 in Branch B1 and want to unshelve it to Branch B2.
I was able to create branch spec, then unshelve changelist to another branch.
here is exactly what I did:
1. Create a text file named branchSpec.txt, with the content below: set you own Branch name and View.
Branch: B1_to_B2
View:
//depot/dev/main/B1/... //depot/release/B2/...
2. p4 branch -i < branchSpec.txt (in target directory)
3. p4 unshelve -s 324426 -b B1_to_B2 (in target directory)
Viola, shelved files in changelist 324426 in B1 now is unshelved to B2 and ready to be submitted.
A way how to get around this is in P4 2012:
Manually copy and overwrite the branch with the trunk
Right click the branch in P4 client and click 'Reconcile Offline Work...'
This will allow you to select the new and changed files and add them to the changeset.
You can use P4 unshelve for this, but you have to create a branch mapping namely A_to_B.
1] p4 unshelve -s CL_NUM -b A_to_B
2] p4 add (files opened for add)
3] p4 resolve
Note: Please do not forget step 2. P4 do not open them by default in your destination branch. You can confirm that with "p4 opened"
This what helped me to unshelve a change list from one branch to another.
Let's say you have a shelved change list #112233 in a source branch: "//depot/release1/main/" that you want to unshelve to a destination branch: "//depot/release2/main/" .
Create a branch spec in a text editor:
nano branch-spec.txt
Branch: R1_to_R2
View:
//depot/release1/main/... //depot/release2/main/...
Create a branch
p4 branch -i < branch-spec.txt
Unshelve Changes
p4 unshelve -s 112233 -b R1_to_R2
Resolve
p4 resolve
I think what you really need is "p4 move -f". It's explained in detail here: p4 move -f: What It's For

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.

p4 diff does not show newly added files

I need some help.
How do I get diff using p4 diff so that my patch contains
information about newly added files too ?
p4 add foo.cc
p4 diff > my.patch
my.patch should contain foo.cc
p4 diff compares files on your client with what's in the depot on the server. If you haven't submitted your changelist containing the new file to add, then the file isn't on the server, so there's nothing to compare.
To use p4 diff...
Mark the file for add, as above ('p4 add //myworkspace/myfile')
Submit the changelist to add the file to the P4 server ('p4 submit')
Checkout the new file locally with 'p4 edit //myworkspace/myfile'
run 'p4 diff //myworkspace/myfile'
If you haven't edited the file since step 3, it shouldn't show any differences. If you edit the file after checking it out (and save your changes locally), step 4 will show diffs.

Resources