Detect a workspace switch from p4v - perforce

If I have a workspace open in P4V and I switch workspaces is there a way to notify or detect that the switch has happened externally?
The workspace contains an editor and needs to checkout files to modify them. I'm worried that a switch via P4V would leave the editor unaware that the files are now from a different stream.
I would rather have a way to detect this in the editor rather than having to notify from P4V if possible.
Thanks,
Alex

Are you saying your editor checks out the files automatically? That's common, so you're not on your own. What editor is it, if I may ask?
Do you know how your editor talks to Perforce? Am I right thinking that it issues p4.exe (the cmdline tool) commands, e.g. p4 edit? (The other way would be using one of the P4 APIs, e.g. p4java or p4python.) If so, the p4 edit commands already do not respect the P4V workspace setting. The p4.exe cmdline tool will work with the p4 workspace specified in one of six ways. To always use the right client,
have a P4CONFIG file specifying P4CLIENT=[client name] in the root of each of your workspaces
change the p4 integration of your editor in such a way that the p4 edit command will always be run effectively from within the given workspace (in the sense of CWD); you can use the -d switch for this, e.g. when checking out C:\workspaces\wksp1\foo\bar\baz.c you would call p4 -d C:\workspaces\wksp1\foo\bar edit C:\workspaces\wksp1\foo\bar\baz.c.

If the user is using a new workspace, they will also be working with a different set of files, so there's hopefully not much chance for confusion there. (Unless they've made multiple workspaces with the same Root, in which case they're doing their very best to shoot off their own kneecaps.)
If they've switched streams within the current workspace, you can detect this with a command like "p4 info", "p4 client -o", or "p4 stream -o".

Related

See all changed and new files in p4v

Is there a way to see all changed files in p4v without out having to trawl through the directory tree in the workspace view?
I am much more familiar with git and I am essentially looking for git status at the top level of a repository. I want to be able to see this in p4v rather than the p4 command line tool which most search results seem to turn up.
If you're using Perforce's standard "check out" workflow, all the changed files are always in your pending changelist(s) in the right hand pane.
If you're modifying files without checking them out (note that this negates many of Perforce's benefits relative to git), use the "Reconcile offline work" feature to do a git status-like scan of the local tree. https://www.perforce.com/manuals/p4v/Content/P4V/using.offline.html

P4V Get Latest does nothing

I do not want to go "Get Revision" > "Force". Because half of my stuff is already downloaded. I don't want to overwrite what I already have. P4V Can clearly see that what is in the depot and what is local is completely different. How can I get Perforce to retrieve the files I do not have, and ignore the ones I already do?
Select your workspace root, go to File > Open Command Window Here, and run:
p4 clean
This will scan your workspace and force-sync everything that's different or missing, as well as deleting unadded files. Note that if you have local work that isn't in a changelist, this will irrevocably erase it. If you only want to "clean" files that are edited/present but out of date (and disregard added/deleted files), do p4 clean -e instead. If you want to preview the operation before doing it for real, do p4 clean -n.
I think you can do the equivalent via the "Reconcile Offline Work" tool in P4V, but it may require additional manual steps.
To make working with Perforce easier, try to avoid modifying files in your workspace that are read-only -- if you want to remove a file from your workspace, use "remove from workspace" in P4V rather than manually deleting it, etc. Perforce is able to make file operations very fast by virtue of knowing what's in your workspace and not having to re-check it each time, but you eliminate that benefit when you mess with your workspace manually.
Instead of p4 clean, you could do:
reconcile offline work on root of workspace then a pop-up saying that you deleted some files and it is going to delete them from Depot of the server as well make sure you added to default or new changelist or whatever. Accept.
Go to changelist and right-click press revert files to bring back the deleted/missing files.

Can I disable the ability for simultaneous checkout in Perforce

I am using perforce with Siemens TIA software. I would like to disable the ability for a file to be checked out by more than one person at a time since the files being used are binary and therefore the merge tools don't work all too well for multiple updates.
In perforce lingo you want to the make the file exclusive, or +l. If you are using the visual application p4v, you can check out the file, right click and then go "Change Filetype...". You can do the same thing on the command line:
p4 edit -t binary+l //somepath/somefile
which can include wild cards if you want to modify a bunch of files. The deeper solution is to use the p4 typemap command so you can tell perforce to understand your extension as always being binary and exclusive.
There are some workflow challenges with making a file exclusive. Imagine user A checks out the file exclusive but then goes home and is sick the next day? User B can't check out the file to do the work while user A is a away and you need an administrator to either unlock user A's computer or to revert the check out. User B can edit the file in "non-exclusive mode" by using the command line:
p4 edit -t binary //somepath/somefile_someone_else_has_exclusive
And then check it in, but now user A is going to have a mess on their hands when they do get back in and they want to check in.
See the "Locking files" section of the p4 resolve documentation - and note what you'll be losing if you do this.

How do I make the perforce command line view the same as the P4Win view

I've written some python tools which work with the p4 command line to work on files I have opened in P4Win. However it seems like the p4 view can become different to the P4Win view. I'm not quite sure how to make them the same.
Maybe by 'view' you mean client workspace? In which case the workspace selected by P4Win and p4 command-line are independent.
You need to use p4 set to select the same workspace for command-line as you've selected for P4Win.

In Perforce command line, how to diff a file reopened for add?

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.

Resources