I'm trying to do some customizations for P4V using P4JsApi and I can not figure out how to read workspace file content, any suggestions ?
(P4JsApi supports "p4 print" command but it seems to be only for depot files; "p4 print" + "p4 diff" is a way to get workspace file content, but it is complex and seems not suitable for new(add) file)
There is no direct way to do this now with P4JsApi, but the pending P4V release may contain a command to print workspace file content just as "p4 print".
Related
Server version: P4D/LINUX26X86_64/2018.2/1975995 (2020/06/25)
Proxy version: P4P/LINUX26X86_64/2018.2/1975995 (2020/06/25)
Broker version: P4BROKER/LINUX26X86_64/2010.2/279478
After I sync a perforce workarea to head, I 'p4 edit' a file, then manually edit the file in my workarea using my favorite text editor. Over time, other users submit changes, so I am no longer synched to the head. And I may save and re-edit the file in my workarea. Now, I want to compare my edited version of the file to the version that I synched to (which is no longer head).
I'm OK with doing a 'p4 print' of the file (with, I'm assuming, a version specifier) in the P4 depot, then comparing my edited file with that outside of p4 commands. Using one of the p4 diff commands isn't really what I want to do because the file is an xml file for which I wrote a perl script which will compare content in an order agnostic way.
I think the missing piece here is getting a handle on the P4 version of the file that my WA is synched to so that I can p4 print it out and then compare. Not sure how to do that. I'm also open to other suggestions, but remember the comparison will eventually be done by my perl script which does simple file open commands.
Set P4DIFF to point to your perl script (which needs to take the two local files as arguments) and run p4 diff. The p4 diff command does all the work of "printing" the depot file to a local temp file, invoking the diff tool (specified by P4DIFF), and cleaning up the temp file.
How do I find if a file is managed by perforce?
I tried
p4 status myfile
but I am getting
myfile - reconcile to add //repo/myfile
Another way to read the message you're getting is "this file is not managed by Perforce; run reconcile to add it". So you're running the right command; just interpret "reconcile to add" as "this file has not yet been added".
Another option is "p4 files myfile", which will return "no such file" if the file is not in Perforce, and will return information about the depot file if it is. Almost any Perforce command that reports file information can be used to determine whether a specific file is managed by Perforce, since they will all return something along those lines if it is not.
I deleted a file from Perforce in the last month. Is there a way to retrieve it from P4?
If so, what command can I use?
Note: I'm not the admin for p4. And I don't want the file back in P4 but I just want it in my local workspace.
Also, I don't know the exact timeframe when I deleted it in last month...What command can I run?
I'm running P4 on windows. I'll appreciate if someone can provide equivalent command for windows
Thanks!
When you delete a file in Perforce, it creates a "deleted" revision, but the archive file is still there.
In the Perforce P4V GUI in the depot veiw, there is a filter symbol on top of the explore pane .
Click on this and select "Show Deleted Depot Files".
Find the file you want to restore and right-click on it. Select "Rollback..." and revert it to the previous revision of that file (before it was deleted.)
By default it will create a new changelist, be sure to select the one you want if you already have one.
On the command line:
p4 sync //depot/folder/subfolder/filename#changelist
You can use either the command line or the GUI, from the command line p4 sync -f forces the files to be resynchronized. For more information see the Perforce Knowledge Base.
If you haven't committed the change list of deleted files to the repository, right click on the folder containing the deleted files in p4v and choose Get Revision. Be sure to check Force Operation and then Click Get Revision. Then the deleted files will be restored from p4 server.
ref: https://forums.perforce.com/index.php?/topic/1479-how-to-restore-files-deleted-in-p4c-workspace/#entry4726
Sometimes I "Mark for Add" and add files to Perforce which I actually didn't want Perforce to worry about.
Is there a way to revert it so it just goes back to showing in P4V as an "untracked" item?
See my example:
I've added mil.ico and mil3.ico by mistake. I just want them to go back to looking like test.ico, ie. ignored by Perforce:
Even if I save a copy of the files, then delete, then put them back (all of which is a serious bore), P4V still knows they have a history and marks them as shown:
I just want Perforce to leave a file alone when I tell it to.
If you want to remove the last traces of the files from perforce, your only chance is through p4 obliterate. This will irreversibly remove file revisions or even file's complete history from perforce and will only work with administrator privileges. I don't know if obliterate is available through p4v, on the command line you would issue:
cd directory_of_accident
p4 obliterate accidentally_submitted_file
and if it looks like you and perforce agree on the file to forget
p4 obliterate -y accidentally_submitted_file
to seal the issue.
You can delete the items from the Perforce depot. Keep in mind Perforce will want to delete your local copy of that file so you should save it off in a different location, delete the file in Perforce and move the local version back.
Are you looking at your file structure through the Depot tab or the Workspace tab? It looks like it may be your Depot tab.
Try going to your Workspace tab then click on the Filter icon (looks more like a funnel) and ensure that "Show Files Not in Depot" is selected.
Hopefully looking through the Workspace tab, as opposed to Depot, will hide the deleted files, and selecting the appropriate filters will show your non-Perforce files.
Suppose you open a file for branch to another place (without submitting), and then reopen it for add and make some edits. I would like to diff this edited version against its branch source in a script.
p4 diff2 is no good because one of the versions is in the client.
p4 diff is no good because it can only diff against the "corresponding" version of the file in the depot, which a branched unsubmitted file doesn't have yet.
Is there a way, or is the only option to just grab the two files and diff them using a third-party tool?
Sadly, you're on the money here, you'd need to use a third party diff tool to do this because, as you rightly pointed out, until you've submitted the initial integration to the depot, it doesn't have a copy against which to diff. If you go down this route you'd obviously not be able to access files directly in the depot though, you'd need to have both files on the client PC and specify their paths explicity.
ninesided is correct that you need to have both files on the client PC.
But there are shortcuts:
If you're using P4V, choose "Diff Against..." from the context or Tools menu. For 1st Path, choose the old location and select "Latest Revision'. For 2nd path, choose the new location and select "Workspace revision on local disk".
The work of selecting the paths can be made easier if you can get both files to appear in the same pane and Ctrl-click to multi-select. e.g. use the Workspace tree pane or open the source file for edit temporarily in order to get it listed in the Pending files pane.
P4V accomplishes this by running 'p4 print -o' on the depot file to create a temporary file on the client PC, then passing that temporary file to the diff application. If you need a textual diff, you can either configure P4V to run a textual diffing application, or run p4 print -o and diff yourself.