Perforce : Revert files without losing its modification - perforce

To let you understand my problem, i must give some brief explanation about the way my client application works.
First, we create workspaces with allwrite set, this is because our programming language (PowerBuilder) does not writes directly to txt files, it writes to 'pbl' files, which are binary.
However we dont version pbl files and to be able to version each object inside a pbl we need to run some cmdcommand, which will output the classes within the pbl file to text files (one file per class), these text files is what Perforce must version.
The problem now is that the pbls are being listed as modified files (in fact they are), but we dont want them to be marked as modified.
I could put them in a ignore file, but there are some Pbls in the repository which must be synced.
I know i could specify in the ignore file to ignore Pbls except the Pbls which are in the repository, but then these specific pbls would keep showing up as modified files when i run a reconcile..
What i want is to have the PBL file exactly the way it was before running the reconcile, unopened by perforce but modified.
Its would be ok, if i could revert them without undoing its modifications...
Or if i could run a reconcilefor all the files, except the pbls.
Does anyone knows a way to do that? Thank you.

You can revert files without refreshing their content from the repository by running 'revert -k': http://perforce.com/perforce/doc.current/manuals/cmdref/p4_revert.html

Related

In Perforce, how to get latest version of a binary file (like Excel file) safely, without overriding my local copy?

I use Perforce to manage a project that contains some binary files (Excel, Word and Visio diagram files).
I'd like to know the safe way to update my local version of such files from the latest version available on Perforce, without corrupting/damaging/overriding the local changes. (Local changes are made locally and not submitted to Perforce yet)
Locks don't seem to solve the problem because it helps only in concurrent submission of files.
p4 reconcile to make sure that any local changes are correctly reflected in your pending changelist(s).
p4 sync as normal. Opened files will not be overwritten by a p4 sync.
If you're following the standard Perforce workflow of always opening files for edit before you modify them (i.e. you never override the "read-only" flag on your local files), you can skip step 1 and just sync at any time without fear.
p4 resolve to handle any files that have been modified both locally and in the depot.
Note that Perforce's built-in merge logic will only handle text files, and so resolve will by default offer only a binary yours/theirs choice for binary files (at will overwrite your local changes, and ay will ignore the depot changes). If you have a merge tool that can handle your binary format, you can do:
p4 set P4MERGE=your_merge_tool
p4 resolve -t
m
to invoke your merge tool as part of the resolve process. See the documentation on the P4MERGE variable for more information how this tool will be called (you may need to wrap it in a script if it doesn't follow the base theirs yours merged calling convention): https://www.perforce.com/manuals/v17.1/cmdref/Content/CmdRef/P4MERGE.html

How do you make a specific folder that has subfolders to be uneditable in Sublime Text

How do you make a specific folder that has subfolders to be uneditable in Sublime text? ? I know it's possible but how ? Like i have some old projects that I want to use as a reference to study my old code, but i"m worried that I mistakenly edited some parts of that specific module / file, when I'm mindlessly touring around my code.. How do I do it ? like making a specific folder to be uneditable in sublime text that only modifying it can change it . I mean I tried installing this one package : https://packagecontrol.io/packages/Toggle%20Read-Only
But it still gives me a prompt whenever I want to changed something from a file
Your best bet is to make sure that your source code is covered by some sort of Source Control, such as git or Subversion; this is just always a good idea in general and unrelated to your particular question. Having your code under source control means that when you edit a file (accidentally or on purpose) you can see exactly what you edited or throw those edits away and go back to what you had if you want to. If you also push your code to an external server, such as GitHUb (if you use git) then you also have a cheap and easy off-site backup of your code as well.
That said, if you want to make files uneditable, that's more the job of your file system than the tools that you're using to edit the files (in this case Sublime Text).
All file systems and operating systems should have the concept of a read-only file, which sounds like what you want. A file being marked as read-only stops you from accidentally modifying it; depending on the software that you use, edits are either impossible or will need to be confirmed.
In your case, you can do this in a couple of different ways. If you only want to protect a couple of files, then you would do a Right click and choose Properties; in the bottom of the General tab there is a check box you can check to make that file read-only:
If you have many files, you can do the same thing by editing the properties of the folder that contains the code instead:
When you do this to a folder, the property set works a little differently; since you're modifying the folder as a whole, you need to click the box twice to change it from a square (shown above) to a check mark. When you apply the change, you will be asked if you only want to make files inside of that directory read-only, or all files in that folder as well as all folders under it; choose as appropriate.
Sublime will let you open read-only files and will also let you modify their contents, but when you try to save you will get a warning dialog telling you that the file is write-protected; you need to confirm if you want to actually save changes or not; (other software may not prompt with such a dialog and may just fail):
If you choose to save, you will remove the read-only attribute and make the file normal again.
If you want to make a file completely un-editable so that you can't even accidentally change the file, you can achieve that with a simple plugin in combination with making the file read-only (see this video if you're not sure how to apply a plugin):
import sublime
import sublime_plugin
import os
class ReadOnlyListener(sublime_plugin.EventListener):
def on_load(self, view):
if (os.path.exists(view.file_name())
and not os.access(view.file_name(), os.W_OK)):
view.set_read_only(True)
EDIT: The internal View Package Files command will open package resources from sublime-package files transparently and give them a filename that represents where they would exist on disk if they were not in the package file.
The plugin from the original answer would stop you from being able to use this command by noting that the file is not writable (because it does not exist on disk) and make the view read-only, which stops the file content from being displayed because the view can't be modified.
This is rectified in the edit above by only taking action if the file actually exists on disk (the View Package File command already makes files it loads in this manner read-only if they do not exist on disk).
This makes an event listener that checks every time you open a file to see if the file is writable, and if it's not it makes the view read-only. This distinction is Sublime specific; regardless of the underlying state of the file, you just can't make any changes to such a file at all. That doesn't stop you from saving the file even if you haven't made any changes, which would have the same effect as the above.

Track changes missed by not using "check out and open" a file in perforce

I have a few files that have been edited by an external IDE, I forgot to Check Out the files before making the changes however when I look at the files through P4V the files have changed but the indicator for the file itself shows as nothing has changed. How can I ensure my changes are committed without loosing what I have done?
One way I was thinking was to making a copy of the file, revert, check out, copy content or replace file.
That is OK with a few files but what happens when you have done so with hundreds of files?
The "check out" command doesn't modify the local file, so you can just do that on its own without having to make a backup copy of the file first. (What you want to avoid doing is "get latest", although if the local files are writable, Perforce will automatically balk at updating them by default because of this exact situation.)
If you have lots of files that might or might not have been modified in different ways, use Actions > Reconcile Offline Work, or "p4 reconcile" from the command line. This will find the locally modified files and open them for the appropriate action.
The P4V way to do this is called "Reconcile Offline Work": http://www.perforce.com/perforce/doc.current/manuals/p4v/Offline.html
Or, at the command line, you can use 'p4 reconcile': http://www.perforce.com/perforce/doc.current/manuals/cmdref/p4_reconcile.html

Perforce Change List too Big

In Perforce, I have created a change list that has over 200,000 files (by doing a rename on a directory). This change list is now too big to submit or revert. When I try, I get an error saying that the operation took too long.
I am now stuck with this change list that has my original directory in marked for delete state and a new directory that hasn't been submitted. Is there a way undo this change list?
You can revert the files a few at a time. As a test, you could run p4 revert //path/to/some/file and verify that it's able to revert that file.
Once you know that's working, you just need a way to automate the process.
You could script something up that starts in the root directory and runs through all directories breadth-first, running p4 revert //path/to/folder/* at each folder (I think you could also use client paths).
You can revert via the command line using the p4 tool. I do not think you can revert the files from the UI. The associated documentation shows various examples of how revert all or specific files (see the Examples section):
http://www.perforce.com/perforce/r12.1/manuals/cmdref/revert.html

In Perforce, can you rename a folder to the same name but cased differently?

Can I rename a folder in Perforce from //depot/FooBar/ to //depot/Foobar/?
I've tried this by renaming from //depot/FooBar/ to //depot/Temp/ to //Depot/Foobar/ but the end result ends up the same as //depot/FooBar/.
Once it is in Perforce, the case remains set. As mentioned by Johan you can obliterate, set the name up correctly, and add it in again. However, there is a slight gotcha....
If anyone else (running Windows) has already synced the wrong-cased version, then when they sync again the right one, it will not change the case on their PC. This is a peculiarity of the Windows file system acknowledging case but still being fundamentally case-independent.
If a number of users have synced, and it is not convenient to get them to remove-from-client too (and blasting the folders from their machines), then you can resort to a dark and dirty Perforce technique called "Checkpoint surgery". It's not for the fainthearted, but you do this:
Stop your server, take a checkpoint.
Using your favourite text editor that can handle multi-megabyte files, search & replace all occurances of the old case name with the new. You could of course use a script too.
Replay your checkpoint file to recreate the Perforce database meta data.
Restart your server.
This will affect all user client specs transparently, and so when they sync they will get the right case as if by magic.
It sounds hairy, but I've had to do it before and as long as you take care, backup, do a trial run etc, then all should be OK.
Maybe not needed anymore, but here's the official Perforce HowTo about changing file cases on Windows and Unix: http://answers.perforce.com/articles/KB/3448/?q=change+file+case
I'm not sure about directories, but we've had this problem with files. To fix it, we have to delete the file, submit that change, then p4 add the file with the correct case and submit the second change. Once that's done, unix users who have sync'ed the incorrect-case file have to p4 sync, then physically delete the file (because p4 won't update the case) and then p4 sync -f the file.
Our server is on Windows, so that might make a difference.
I guess it treats files and folders the same.
For files:
It depends (on whether you have a Windows or Unix server). We have this problem with our Windows perforce server (which versions our Java code), where very occasionally someone will check in a file with a case problem (this then causes compile errors because it's Java). The only way to fix this is to obliterate the file and resubmit it with the correct case.
I think you should remove the Perforce Cache, so that your modification can be shown.
You can rename with ABC rename to abc_TMP, then abc_TMP rename to abc, then clear cache.
Setps to clear cache:
Open windows user home folder (on windows7 ==> C:\Users\)
Locate the folder called ".p4qt"
Rename the folder to "old.p4qt"
Launch Perforce, now everything works!
NOTE: these steps will rest your default setting.
The question is over 3 years old, but I ran into an issue like this while doing a Subversion import into Perforce and figured the info I got could be useful to some. It's similar to the obliterate method, but helps you retain history. You use the duplicate command that may not have been available back then to retain the history. The process basically being:
Duplicate to temporary location.
Obliterate the location you just duplicated.
Duplicate from the temporary location to the renamed case location.
Obliterate the temporary location.
Through this you retain the history of file changes, but get them all in the new path as well. Unfortunately there will be no history of the path case change, but that seems to be unavoidable. Similar to other methods mentioned here, users will need to either manually rename the directories in their workspace or delete and re-sync to get the new path name.
Also, P4V caches the paths it shows in the tree so after doing this it may still show up as the old name. a p4 dirs command however will show the new case.

Resources