P4 changes on a specific folder/file - perforce

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>

Related

Perforce :Not able to create new changeList with Description

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.

How to find the local perforce depot path?

I am trying to write a maven compile command and want it to work on my colleagues' machines as well, and since they have a different perforce depot path than mine, I need a unified way to find it.
I have tried p4 where but it didn't help.
When you run the p4 where command make sure that you're using the correct client workspace.
E.g.:
p4 set P4CLIENT=my_client_name
p4 where //depot/...
or:
p4 -c my_client_name where //depot/...
The example you describe of p4 where returning the wrong path indicates that it's giving the answer in terms of a different client workspace.

Perforce - Specify target directory path for sync

Is it possible to specify the folder name where depot needs to be synced ?
I tried syncing the depot to my specified path using following command but it does not work.
p4sync -d "c:\my\path" sync //depot//branch/file
Note : My aim is just to copy the file from depot to my specified location.
Looks like sync is not the command I should be using. Is there any other command or way I can do this ?
sync - gets files from depot to your workspace, which must be already customized. To get files without workspace you need to make some hack with command "print":
p4 print -o filename //path/on/depot/filename
This command (above) gets filename and store it in "filename". Also, you can make some another workaround to get all files from some directory, probably with "p4 -x - command" ( -x stands for xargs in unix-world)

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.

Get the changelist number of current workspace directory

Each time we do a build, we have to record the changelist number of source files for tracking. We have different projects (under different directories) and they are synced at different changelist number. May you please show me how can we get the changelist number of a specific directory?
Also, there's p4 changes -m1 //path/to/your/project/...#have which, if run in the client workspace that synced the files for building, will give you the highest changelist number of the files in the workspace.
You can also use the short version p4 changes -m1 #have if you don't want to specify the directory.
If you are using a shell for which "#" is a comment character like bash, remember to escape it as follows: p4 changes -m1 \#have
p4 cstat //path/to/your/project...#have |grep -B1 have|tail -n2
#thegeko, this does not require high max_scanrows perforce limits
If your build system always syncs to head on the directory before building, you can use p4 changes -m 1 //path/to/your/project/... to get the head changelist number for that directory.
If you go with this method, I would suggest running the changes command before syncing, and then explicitly syncing to that changelist. That should eliminate the chance of someone checking in between the changes command and the sync command.
I use the "lazy manual way" (aka I don't know better) within the P4V client:
Use this in the "Submitted" tab filters: //yourproject/...#>have
And it will show you which CLs you haven't synched, note the oldest one.
Remove the #>have filter and see what's the CL that came before the one you just noted.
From within the directory:
p4 changes -m1 //...#have
Using just the workspace path, p4 changes -m1 /path/to/your/workspace/...#have (or cd /path/to/your/workspace; p4 changes -m1 $(pwd)/...#have) gives you the highest changelist number of the files in the workspace. This is similar to the accepted answer above from user1054341 p4 changes -m1 //your-client-name...#have, but you don't have to remember the client name.
A path to a subdirectory in the client gives you the latest changelist in that subdirectory and its children, e.g. p4 changes -m1 /path/to/your/workspace/src/module1/...#have. This can be run from any directory within the workspace.
Omitting #have shows the latest changelist checked in to the depot.
These commands must be run from a directory in the workspace.
In my case, I just want to know what changelist number is opened (not syned to) in a specific directory. For that, I do:
p4 opened -s | cut -d' ' -f5 | uniq

Resources