Updating files with a Perforce trigger before submit

邮差的信 提交于 2019-12-24 12:25:17

问题


I understand that this question has, in essence, already been asked, but that question did not have an unequivocal answer, so please bear with me.

Background: In my company, we use Perforce submission numbers as part of our versioning. Regardless of whether this is a correct method or not, that is how things are. Currently, many developers do separate submissions for code and documentation: first the code and then the documentation to update the client-facing docs with what the new version numbers should be. I would like to streamline this process.

My thoughts are as follows: create a Perforce trigger (which runs on the server side) which scans the submitted documentation files (such as .txt) for a unique term (such as #####PERFORCE##CHANGELIST##NUMBER###ROFL###LOL###WHATEVER#####) and then replaces it with the value of what the change list would be when submitted. I already know how to determine this value. What I cannot figure out, is how or where to update the files.

I have already determined that using the change-content trigger (whether possible or not), which

"fire[s] after changelist creation and file transfer, but prior to committing the submit to the database",

is the way to go. At this point the files need to exist somewhere on the server. How do I determine the (temporary?) location of these files from within, say, a Python script so that I can update or sed to replace the placeholder value with the intended value? The online documentation for Perforce which I have found so far have not been very explicit on whether this is possible or how the mechanics of a submission at this stage would work.

EDIT

Basically what I am looking for is RCS-like functionality, but without the unsightly special character sequences which accompany it. After more digging, what I am asking is the same as this question. However I believe that this must be possible, because the trigger is running on the server side and the files had already been transferred to the server. They must therefore be accessible by the script.

EXAMPLE

Consider the following snippet from a release notes document:

[#####PERFORCE##CHANGELIST##NUMBER###ROFL###LOL###WHATEVER#####] Added a cool new feature.  Early retirement is in sight.
[52702] Fixed a really annoying bug.  Many lives saved.
[52686] Fixed an annoying bug.

This is what the user submits. I then want the trigger to intercept this file during the submission process (as mentioned, at the change-content stage) and alter it so that what is eventually stored within Perforce looks like this:

[52738] Added a cool new feature.  Early retirement is in sight.
[52702] Fixed a really annoying bug.  Many lives saved.
[52686] Fixed an annoying bug.

Where 52738 is the final change list number of what the user submitted. (As mentioned, I can already determine this number, so please do dwell on this point.) I.e., what the user sees on the Perforce client console is.

Changelist 52733 renamed 52738.
Submitted change 52738.

回答1:


  • Are you trying to replace the content of pending changelist files that were edited on a different client workspace (and different user)?

  • What type of information are you trying to replace in the documentation files? For example, is it a date, username like with RCS keyword expansion? http://www.perforce.com/perforce/doc.current/manuals/p4guide/appendix.filetypes.html#DB5-18921

I want to get better clarification on what you are trying to accomplish in case there is another way to do what you want.

Depending on what you are trying to do, you may want to consider shelving ( http://www.perforce.com/perforce/doc.current/manuals/p4guide/chapter.files.html#d0e5537 )

Also, there is an existing Perforce enhancement request I can add your information to, regarding client side triggers to modify files on the client side prior to submit. If it becomes implemented, you will be notified by email.




回答2:


99w,

I have also added you to an existing enhancement request for Customizable RCS keywords, along with the example you provided.

Short of using a post-command trigger to edit the archive content directly and then update the checksum in the database, there is currently not a way to update the file content with the custom-edited final changelist number.




回答3:


One of the things I learned very early on in programming was to keep out of interrupt level as much as possible, and especially don't do stuff in interrupt that requires resources that can hang the system. I totally get that you want to resolve the internal labeling in sequence, but a better way to do it may be to just set up the edit during the trigger so that a post trigger tool can perform the file modification.

Correct me if I'm looking at this wrong, but there seems a bit of irony, or perhaps recursion, if you are trying to make a file change during the course of submitting a file change. It might be better to have a second change list that is reserved for the log. You always know where that file is, in your local file space. That said, ktext files and $ fields may be able to help.



来源:https://stackoverflow.com/questions/24150792/updating-files-with-a-perforce-trigger-before-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!