Perforce: submit files with "Version in workspace is not latest version"? - eclipse

(I work with perforce from eclipse by the perforce plugin).
After associating my workspace with a perforce depot, all the files got status "Version in workspace is not latest version" (yellow triangle)....
When a file has this status, submit is disabled for this file.
When I do "Sync with depot" on a project, all those files show the conflict icon (even when there's no conflict...).
Conflict? does it mean I need to resolve?
Here is how to do resolve:
http://www.perforce.com/perforce/doc.current/manuals/p4guide/05_resolve.html
The problem is... by "resolving" perforce overrides all the files in my workspace with the files in the depot. So every change I made to the workspace before associating it to perforce is gone.
What I actually want to achieve is the other way around: submit all the files in my workspace to the depot. i.e. override the depot.
How can I do that?

If perforce says that you cannot submit because "Version in workspace is not latest version", then this means that you have a file open for edit that was already changed and submitted by someone else, i.e. you're working on an old version of the file.
You definitely should not try to force your (old) version on top of the newer one in the depot.
You really need to resolve. Perforce will not "override" all the files your workspace and discard your changes.
For merging (resolving) you can use the eclipse built-in merge tool or the p4merge (from Perforce).

As other answers say, most of the time your best bet is to work with Perforce's workflow and check out the workspace in advance and make your changes there, rather than make changes first and create the workspace later. Sometimes, though, you really do need to break Perforce's workflow and override the changes in the depot. If you're going to do that, you need to be extra careful that you're not reverting something important. (Even on a one-person project you might have forgotten you checked something in, so look carefully at the diffs before submitting.)
The easiest thing to do is, when Perforce tells you that you have a conflict, resolve but keep your changes. In the Perforce documentation link, that's 'resolve, accept yours' rather than accepting what Perforce thinks is the sensible merge. From the command line, that's p4 resolve -ay. It's worded a little differently in the p4v GUI, and may be worded differently still in the Eclipse plugin (which I haven't actually worked with).
The other option, which you might use if you have files checked out from an earlier revision, and you want to update to the tip revision without making any changes, is to tell Perforce to update the metadata, so that it thinks you have a newer version of the file, without actually altering any of your files. From the command line, that's p4 sync -k (whatever you want to sync). This, too, can be dangerous if used inappropriately.

I don't think you can achieve what you want in Perforce. You will need to copy the files you've changed to a safe place and then resolve/revert all of the files to remove the conflict/out of date flag. Once done, copy your changes back and submit. It's a pain, but you should have connected with Perforce before making your changes.

Related

Unexpected overwriting CVS/SVN repository files in Mac Eclipse

I worked with Windows Eclipse CVS and CVS did not allow me to overwrite the latest revisions – I needed to update first. At the same time one developer working on Mac constantly overwrote my files. We looked at this problem and found that his CVS Eclipse plugin allows overwriting the latest revisions without any warning.
Now I work with Mac myself using SVN Eclipse plugin and I accidentally overwrote the latest revisions from my co developer. How to prevent this overwriting? If this overwriting happens what is the graceful way of reverting to the previous revisions and committing them back to the repository?
Wait? Something is not right here...
CVS and Subversion will never let you overwrite someone else's changes. The whole purpose of version control is to allow multiple people to work on the same files at the same time.
There are two ways version control systems do this:
Checkout and Lock: The oldest systems used a checkout and lock system. That is, you checkout the code for changes, and no one else was allowed to checkout and make changes until you checked in your changes. The problem is that someone could checkout files for a week and forget to check them back in, or go on vacation. Then, everyone else is stuck unable to work.
Checkout, and first person who commits wins: In this system, two people can checkout the same file and do their work. However, the first person who finishes their changes and commits wins. The other person must do an update which will incorporate the first person's changes into their working copy before they can commit their changes. This is what Subversion and CVS do.
So, how in the world are you losing your changes? Or, how are you overwriting the other person's changes?
Sometimes this happens if you are sharing your checked out working copy with other people. This is wrong and should never be done. Instead, each user should have their own separate independent copy of the project (Heck, you can even have multiple version if you want). When your partner checks in their changes, it shouldn't affect your files.
What will happen is that when you try to commit your changes, you will be told that your working copy is out of date. You'll have to update your working copy and that will incorporate your partner's changes into your working copy. You should then verify that everything is okay, and then commit your working copy which will now include both your and your partner changes.
Does this answer your question? Are you sharing all sharing the same directory, or do you have your own working copy? Is there something else going on?

Eclipse CVS Commit, ignore certain file types

I have a rather large project made up of lots of...projects, each with their own Debug and Release folders along with a bunch of other files that I don't really want to commit like .rc and .user.
At the moment I right click the top folder, click commit and eclipse asks how i would like to store all these "new files" it has detected, how do i tell it I don't want to commit any of them.
So far i have read that i need a .cvsignore file but that doesn't seem to make a difference. I tried doing a "clean" of the project but there was still plenty of files i don't want.
Does anyone have any advice on how to make this at the very least less painful? I have even tried doing a search on the project for certain . files I don't want and deleting them but some of them re-create themselves....
Note: I usually just commit the files I want by selecting them individually but this time it is about 600+ files...
UPDATE
Sorry for taking so long. Thank you to everyone for their answers, they are all technically correct, none actually worked for me, but i will mark Burhan as the best answer
I have tried the cvs ignore route before and it never seemed to work, unfortunately it still didn't work for me.
The per directory approach does seem to work but its quite a painful process in this case. But khmarbaise is correct this is the documented method, and is actually correct.
The Global method Burhan mentioned seemed ideal but didn't seem to work, Perhaps i have mis-understood where CVSROOT is, i always assumed it was the "CVS" folder located in the top most directory, it includes files like "Tag", "Root" etc. is this wrong?
#thkala, the "Team->Add to .cvsignore" was always greyed out for me and therefore could not be used but again is another valid route when it does work.
However I think i have finally realized why I have so many problems with CVS and eclipse and i would like to post what finally worked for me and what may actually be the missing link for the .cvsignore route.
I always checked the project out this way: CVS Repositoris -> Right click the branch -> check out as -> check out as project in the workspace.
However the reason i was having so many problems with cvs and indexing what i should have done is:
*CVS Repositoris -> Right click the branch -> check out as -> check out as ...New Project Wizard. -> retype branch -> Makefile Project with Existing code * (as a side note does anyone know how to specify the directory for the new project?)
Anyone who didn't do this and doesn't want to re-checkout can remove the project and re-add it using "new project"
At this point "Add to CVS ignore" was no longer greyed out. So you can now use that route if you want.
At this point however i tried something else i hadnt used before Team->synchronize with repo. This Seemed to bring up only the Changes i had made and therefore did not have any of the "new files" which was all the files i didn't want to commit. I was therefore able to simply double check the folders and then do a blanket commit on all those files in the sync view. It is really important to note that I actually had some build generated .h and .c files, so if i had succeeded in ignoring certain files, i would have still checked in these unwanted files (silver lining i suppose).
Perhaps i should rephrase the question to "large commit" to be more helpful to future cvs + eclipse newbies? anyone agree?
You can add a .cvsignore file on a per-directory basis containing the files in the directory that you want cvs to ignore. Note that if you want this to persist, you will have to commit that file too. #khmarbaise pointed to some documentation that talks about what kind of thing you can put in this file.
If you want to ignore certain file types on a global basis, then you should check out the CVSROOT module and make additions to the cvsignore file in that module (note that lack of a "dot" at the start of the name). Don't forget to commit this change for it to take effect.
Both .cvsignore and cvsignore files can contain the same types of information.
You can create a file which is call cvsignore which contains certan file types. I can't remember if it's called ".cvsignore" or "cvsignore". Check the documentation.

Undo mark as merged

I am using Eclipse Indigo and subeclipse as the svn plugin for eclipse. Now here is the situation. I was synchronizing my project with the remote repository. There were conflicts present and I mistakenly clicked on "mark as merged" for one of the files without merging it. I tried restarting eclipse and some other stupid hacks. But nothing works out. So is there a way to undo "mark as merged" action?
Mark as Merged means that the local version of the file contains the content you want, after having compared the files and manually resolving issues. Subclipse still has to update the local file so that SVN's metadata is happy, so it saves the current content of the file, runs svn update, and then replaces the file.
So you can now run Team > Revert if you want the file to match what was in the repository, or Compare with > Base Revision if you just want to examine the differences again and possibly make more changes.
Neither of Marks suggestions worked for me. The class did revert back to the original (pre-merged) state, but trying to Merge again just gave me a 'no differences detected' message.
What did end up working for me was to Compare With > Local History. I was able to pick a version that was right before I hit Mark As Merged, and that got me back to the Compare Editor view that I had during the original Merge (which showed all the conflicts). I was then able to change the code correctly, and Mark As Merged again.
Delete the local project and re-import it, and this has the effect of undoing an accidental 'Mark as Merged' action. Just make sure that the deletion won't result in loss of uncommitted work.

Should I submit unchanged files to Perforce?

I'm using Perforce to integrate two codelines. In the resulting changelist, there are files which are marked as opened for integration, but have not actually changed.
Should I submit these unchanged files or should I revert them?
I want to revert them because I don't want these unchanged files to pollute the changelist.
But, if I submit them, I have a feeling that Perforce might have a use of this "fact" (that the files have been integrated) for future integration.
There is no need to submit unchanged files. I can't even understand why the option exists. Perforce only needs to know about changes you make to files. The fact that you checked a file out, but did nothing to it, is irrelevant. Revert unchanged files. As you said, don't pollute the revision history.
Yes, you should submit them. This will create the integration record to record that the changes have been "integrated" (which may not mean actual changes occurred on the target).
I always reverted unchanged files in my changelists. I can't remember any wrong consequences.
(Fortunately, now we switched to git.)

Can I safely edit a renamed file in perforce

I have a file I need to move that's already under perforce. Once moved it needs some editing - update the package, etc - appropriate to its new location. Should I submit the move changespec and then reopen it for edit, or can I do this in one go? If so, what is the appropriate sequence of events?
I have done this before in one go, but depending on your build process, I recommend against it. What I generally do is this:
Move the file.
If the move needs a change in order to compile, open it for edit and make those changes.
Submit the changes, telling perforce to reopen the files for editing.
Make the changes for path, etc., that don't cause compile errors but should be updated.
Submit those changes with an appropriate description.
If you want to, however, you could just do all your changes in step (2) above. Perforce might change the flag for the new file from integrate to add, but it still remembers the source path for the file.
Edit: Better method
I realized that I often use a different method, but the idea of "moving" the file distracted me. So, I would recommend these steps instead:
Integrate the file into the new path/name, leaving the previous file there. I am assuming that this won't break your build process.
Submit the new file, checking it out again for edit after submission.
Make the required changes to the new file, and to the project so that you are using the new file.
Submit the edits for the new file.
[Optional] You might need to check through branch specs to see if you need to map the old file into the new one in any branches.
Create a changelist for deleting the old file, and submit it sometime later.
This method allows the edits to be cleanly separated from the rename/move, while never leaving the project in a state that won't compile.
Also, why wait for step 6? Sometimes, especially on bigger projects, you might want to move a file that another person is editing. Perforce will helpfully tell you this. By waiting to delete the file, you allow your coworker(s) to finish the edits and submit without needing to move their work manually. After the edits are submitted, they can be integrated into the new file, and then the old one can be safely deleted.
Submit the move change and then reopen for edit (you could use the reopen option too).
This is much more readable to the user in the change history.
Also, recent versions of Perforce do perform checks for changes to files after resolution. So, there may be complaints editing files after some resolve operations have been completed.
I would say always submit first then edit. It is much cleaner and makes it more obvious whats happening in your repository. Then simply checkout the file in the new location and make whatever changes. This also makes it much more obvious that the changes were made in the new location and to all it to work after renaming.
Yes you can. Simply reopen for edit the branched file (i.e. the new one). In P4Win, there is a context menu for this ("re-open for edit").
"Safely" is probably an important point here. Once you rename or move the file it'll get a revision number of "1" which looks like a new file to your Perforce client. Of course, admins will be able to get its prior history, but if the editing/version history of the file is important to you it's a little harder to get the older revision.
Update: Thanks to Commodore Jaeger and Greg Whitfield for enlightening comments.
This wasn't easy to track down regarding what the One True Answer is, even from Perforce support, so I figured I'd update everyone on what we found:
Perforce stores all versions of every document in its database.
If it's saving your file as type <text> or <ktext> then it stores the diffs of one file version to another and not the entire file.
If you check out a file, make no changes to it, and then re-submit, it will save as a new version with 0 diffs. This is configurable and P4 can be set up to ignore changelist items without any actual diffs. You can force this behavior by selecting "Revert unchanged files..." before you submit a changelist.
Use "Rename/Move..." to move files in P4 so it can track them. Don't copy them using Windows Explorer and then re-add them in P4.
If you use the "Rename/Move..." function from the context menu, the "new" file will show a revision number of "1" as though it were a new file.
However, since P4 saves every function performed on a file, you can actually get to any previous revision (and even recover "deleted" files) with the CLI command p4 filelog -i
If you want to get to the revision history of a moved or renamed file and you're not an admin, you can right-click and select its "Revision Graph" which shows every version of a file even when moved between branches.
According to Perforce support, easier tracking of revision history through branch or folder moves is an oft-requested feature and is in their current roadmap.
Perforce's answer: At the moment, there isn't a way to move/rename/integrate files and still maintain the exact file history.
However, if you were to choose "Integrate..." by right-clicking on the folder that you want to share, the versions of the files of the newly branched folder and underlying files will start from revision #1, but the integration history between the branched folder and underlying files and the original folder and underlying files will remain through which you can trace the revision history of the files.