Perforce :Not able to create new changeList with Description - perforce

Not able to create new changeList for a file/files with Description
p4 --field Files=E:\MyFolder\run.py --field Description=Test change -o | p4 change -i
Shows error
Error in change specification.
Can't include file(s) not already opened.
Open new files with p4 add, p4 edit, etc.
Cant do it in single command, wanted automate.

Like the error says, you can't include files that aren't already open. To create an empty changelist, do:
p4 --field Description=Test change -o | p4 change -i
If you want to open the file for edit and submit it, you don't need to create a changelist explicitly. Just do:
p4 edit E:\MyFolder\run.py
(make changes?)
p4 submit -d Test
If you want to create a changelist that contains that file, you can take advantage of the fact that a newly created changelist will by default take ownership of files in the default changelist:
p4 edit E:\MyFolder\run.py
p4 --field Description=Test change -o | p4 change -i
If you have an empty changelist and files open in another changelist, you can move them over with the "reopen" command:
p4 reopen -c CHANGE E:\MyFolder\run.py
Note that this requires you to know the actual change number (CHANGE).
Finally, IFF the file is already open in the default changelist and you want to make a new changelist that contains that file and only that file, you can do this by specifying the file's depot path in the Files field of the changelist:
p4 --field Description=Test --field Files=//depot/run.py change -o | p4 change -i
A changelist description's Files field must contain the fully qualified depot path of each file, and it's only valid to include files there that are already open.
If you don't know the depot path of the open file, you can get it by running a command like p4 opened, which will list all open files by their depot paths.

Related

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).

Add a file to existing changelist

I edited few files in my workspace and did p4 change. Then I remembered that I have to make some more edits to additional files(not in the changelist). I opened those files with p4 edit but how to add these files to existing changelist. Is there a way to do it?
In general you can use:
p4 reopen -c CLN FILE ...
to move open files into the specified changelist (regardless of whether they were open for edit, add, etc.).
CLN may be default to dissociate the specified files from any numbered changelist.
You can say:
p4 edit -c changelist# file ...
where changelist# refers to the pending changelist.
p4 edit -c changelist file
same works for sd
file not open
p4 edit -c [changelist] [file]
file open already
p4 reopen -c [changelist] [file]
be lazy
p4 edit [file] && p4 reopen -c [changelist] [file]

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 changes on a specific folder/file

I am trying to get the last checkin on a particular folder structure on perforce, I know "p4 changes -m1 'filepath" does the job, but the problem is the filepath has to be the depot file-path. What I have on the other hand is the local filepath something like "C:\Android\Version10.2\MyApp\" and not "//depot/Andoid/Version10.2/MyApp".
I tried using commands like "p4 fstat", "p4 where" and "p4 files", but for all of them it works fine with the depot file path, if I give the local file path, it keeps complaining file(s) not on client/no such file(s).
The other issue is I dont have rights to change the p4client on the machine. How do I get this to work?
Basic question then to sum up is being able to get the last change on a folder/file for which I have the local filepath.
Regards
If you're going to run any commands on files those files have to be in the workspace. The problem is probably that p4 on Windows defaults to the machine name as the workspace name if you don't supply one.
So you either have to run set P4CLIENT=<clientname> then run p4 changes -m1 <filename>,
or p4 -c <clientname> changes -m1 <filepath> where <filepath> can be the file on your local file system, so C:\Android\Version10.2\MyApp\ would be acceptable.
Does p4 filelog -m 1 <filename> give you what you want? You can add the -l (lowercase L, not one) switch to get more information.
If you have a local file (as opposed to the depot-path), then you also should have a client-spec. You need to specify this with the -c option:
p4 -c <name-of-client-spec> changes -m1 <filepath>

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