简体   繁体   English

svn hook从提交的文件生成文件

[英]svn hook to generate file from committed files

I have an SVN repository that has 我有一个SVN存储库

trunk/file1.txt
trunk/file2.txt
trunk/fileR.txt

On the server, I have a working copy checkout of trunk ( /var/www/trunk ) owned by user www-data . 在服务器上,我有用户www-data拥有的主干( /var/www/trunk )的工作副本签出。

fileR.txt is read only for everyone except the user www-data (access restricted by authz or svnlook author ). 除了用户www-data (访问权限受authzsvnlook author限制)外, fileR.txt仅对所有人有效。 fileR.txt should be generated by concatentating file1.txt and file2.txt : cat file1.txt file2.txt > fileR.txt fileR.txt应由concatentating生成file1.txtfile2.txtcat file1.txt file2.txt > fileR.txt

What I want is that every time there is a commit on either trunk/file1.txt or trunk/file2.txt , a script should be run that updates the working copy on the server, concatenates the files and commits the new fileR.txt to the repository. 我想要的是,每次在trunk/file1.txttrunk/file2.txt上都有一个提交时,应该运行一个脚本来更新服务器上的工作副本,并连接文件并将新的fileR.txt提交到存储库。

What I had in mind was a post-commit hook that does all of the above, but I am not sure if and how SVN can handle a new commit until the previous commit has been finalized. 我想到的是执行上述所有操作的提交后挂钩,但是我不确定在最终提交之前,SVN是否以及如何处理新的提交。

Example: So, commit1 with changes to file1.txt comes in, pre-commit hook runs (if any), transaction is committed to the database and then the post-commit hook runs. 示例:因此,带有对file1.txt更改的commit1进来了,提交前挂接运行(如果有),将事务提交到数据库,然后运行提交后挂接。 The post-commit hook actually creates a commit2 that needs to finalize before the post-commit hook from commit1 will actually finish. 提交后挂钩实际上创建了一个commit2,该提交需要在commit1的提交后挂钩实际完成之前完成。

Is SVN capable of doing this? SVN能够做到这一点吗? If not, what other tools / workflows do you suggest? 如果不是,您还建议其他哪些工具/工作流程?

Thanks 谢谢

Let's say you make a post-commit hook to do what you want... 假设您制作了一个提交后的钩子来执行您想要的操作...

  1. I commit a change in file1.txt. 我对file1.txt进行了更改。
  2. Post-commit hook picks up the change, and creates a new file fileR.txt 提交后挂钩获取更改,并创建一个新文件fileR.txt
  3. Post-commit change commits this change which causes your pre-commit hook to fire. 提交后的更改将提交此更改,从而导致您的提交前钩子触发。
  4. And, you're right back to Step #1 而且,您就回到了步骤1

There's also the issue of creating a working copy on your server where your post commit hook can operate. 还存在在服务器上创建工作副本的问题,您的提交后挂钩可以在其中运行。 When someone does a commit, you'll have to either update or even checkout a working copy on your server, concat the changes, and then do a new commit without firing your commit hook. 当某人进行提交时,您将必须更新或什至在服务器上签出工作副本,并进行更改,然后执行新的提交而无需触发提交钩子。 Remember, people might create branches, so you may have to have multiple working copies. 请记住,人们可能会创建分支,因此您可能必须具有多个工作副本。

And, while your post-commit hook is doing all of this, you users have to wait for the post-commit hook to complete. 而且,在提交后挂钩完成所有这些操作的同时,用户必须等待提交后挂钩完成。

Plus, if I do a commit, my working copy is now out of date. 另外,如果我进行提交,则我的工作副本现在已过期。 I now have to commit, then do an update because the server did a commit. 我现在必须提交,然后执行更新,因为服务器执行了提交。

I hope I've convinced you that this isn't a really good idea. 我希望我已经说服了您,这不是一个好主意。 It is possible, but it certainly isn't advisable. 可能的,但它肯定是不可取的。 In fact, if I saw a build engineer do something like this, I'd fire them. 实际上,如果我看到建筑工程师做这样的事情,我会开除他们。


I suggest you take a look at Jenkins . 我建议你看看詹金斯 Jenkins is a continuous build server. Jenkins是一个连续构建服务器。 What you can do is have Jenkins create your fileR.txt file for you whenever a commit is done. 您可以做的是让Jenkins在完成提交时为您创建fileR.txt文件。 This file can be easily downloaded from the Jenkins server and be made publicly available. 可以从Jenkins服务器轻松下载此文件,并使其公开可用。 You can also maybe take your fileR.txt and create the PDF for people while you're at it. 您也可以使用fileR.txt并为人们创建PDF。

So, your combined file is still available and can be downloaded by your other processes, but it won't cause your post-commit hook to fire another round of hooks. 因此,合并后的文件仍然可用,并且可以由其他进程下载,但不会导致提交后的钩子触发新一轮的钩子。 And, fileR.txt is read only by everyone who has access to that particular Jenkins job. 而且,只有有权访问该特定Jenkins作业的每个人都可以读取fileR.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM