如何编写批处理文件来更新服务器上已提交的文件

发布于 2024-11-15 03:12:21 字数 605 浏览 1 评论 0原文

我是web开发人员。我在自己的机器上编辑本地svn工作副本中的文件,我们的开发服务器是通过samba共享的磁盘,并且服务器的根目录也是工作副本,我想做的是使用客户端 svn 提交后挂钩,每当开发人员提交一些代码时,它都会自动更新服务器上的工作副本。我发现两个批处理文件可以正确执行此操作,一个正在使用 subversion 命令,其他正在使用 Tortoise SVN命令,但问题都是批处理文件更新除更改的文件之外的整个工作副本,这是非常慢的,通常需要一两分钟。所以我认为如果我只能更新更改的文件可能会更快。或者 mybe 是否最好将批处理文件制作为 ssh 到服务器并直接更新而不是通过 samba?以及如何做到这一点?

抱歉我的英语不好,任何帮助将不胜感激。

I am web developer.I edit files in a local svn working copy on my own machine,our development server is a shared disk through samba,and the root directory of the server is also a working copy,what I want to do is to use a client-side svn post-commit hook to automatically update the working copy on the server whenever a developer commit some code.I've found two batch file can do this properly,one is using the subversion command,the other is using Tortoise SVN command,but the problem is both batch file update the whole working copy other than the changed files,which is very slow,often takes one or two minutes.So I think it may be faster if I can only update the changed files. Or mybe is it better to make the batch file to ssh to the server and update directly other than through samba?and how to do that?

Sorry for my poor English,any assistance would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-11-22 03:12:21

您可以执行以下步骤:
1. 使用 svnlook 命令找出发生更改的文件

svnlook changed REPOSITORY NAME  
  1. 将命令的输出获取到文件中。
  2. 动态读取此文件并将其提取到 SVN 更新命令中。

我可以告诉你如何在 Linux 中执行此操作,但不清楚批处理文件。

You can do the following steps:
1. Use svnlook command to find out the files which were changed

svnlook changed REPOSITORY NAME  
  1. Get the output of the command into a file.
  2. Read this file dynamically and fetch it into SVN Update Command.

I can tell you how to do this in Linux, but not clear on batch files.

花想c 2024-11-22 03:12:21

我也遇到了类似的问题,但使用的是托管 SVN 的 Linux 服务器。也许您可以从这里获取一些线索并更改它以匹配您的 Windows 系统。

POST_COMMIT

#!/bin/sh
wget http://localhost/update_svn.php

update_svn.php

<?php
$output = shell_exec('/media/disk3/velsvn/projects/hooks/svn_update_step1.sh');
echo "<pre>$output</pre>";
?>

svn_update_step1.sh

    ssh -i /media/d/mykey/id_rsa velsvnuser@localhost /media/disk3/velsvn/projects/hooks/svn_update_step2.sh

    svn_update_step2.sh

#!/bin/sh
cd /media/disk3/velsvn/projects/hooks
rm -f filelist
rm -f log
whoami >> log

    svnlook dirs-changed /media/disk3/velsvn/projects/  | sed "s/^..//" | awk '{ print substr( $0, 9 ) }' >> /media/disk3/velsvn/projects/hooks/filelist; sed -i -e 's#^#/media/disk2/www/htdocs#' filelist; cat /media/disk3/velsvn/projects/hooks/filelist | xargs /usr/bin/svn up -N >> /media/disk3/velsvn/projects/hooks/log

注意:
1. /media/d/mykey/id_rsa 是为 SSH 访问生成的密钥。这确保系统不会等待用户提供密码来连接到 SVN 以及执行 shell 脚本。
2. POST-COMMIT 文件和 shell 文件 sh1 和 sh2 被赋予 +x mod 以便它们可以被执行。

请随时对这篇文章发表评论并提供更好的解决方案。我现在所知道的是,这个解决方案有效:)

I had a similar problem but with Linux Server hosting SVN. May be you can take some clue from here and change it to match your Windows system.

POST_COMMIT

#!/bin/sh
wget http://localhost/update_svn.php

update_svn.php

<?php
$output = shell_exec('/media/disk3/velsvn/projects/hooks/svn_update_step1.sh');
echo "<pre>$output</pre>";
?>

svn_update_step1.sh

    ssh -i /media/d/mykey/id_rsa velsvnuser@localhost /media/disk3/velsvn/projects/hooks/svn_update_step2.sh

    svn_update_step2.sh

#!/bin/sh
cd /media/disk3/velsvn/projects/hooks
rm -f filelist
rm -f log
whoami >> log

    svnlook dirs-changed /media/disk3/velsvn/projects/  | sed "s/^..//" | awk '{ print substr( $0, 9 ) }' >> /media/disk3/velsvn/projects/hooks/filelist; sed -i -e 's#^#/media/disk2/www/htdocs#' filelist; cat /media/disk3/velsvn/projects/hooks/filelist | xargs /usr/bin/svn up -N >> /media/disk3/velsvn/projects/hooks/log

Note:
1. /media/d/mykey/id_rsa is the key which was generated for SSH access. This ensures that the system does not waits for the user to provide password to connect to SVN as well as execute shell scripts.
2. POST-COMMIT file and the shell files sh1 and sh2 were given +x mod so that they can be executed.

Please feel free to comment on this post and provide a better looking solution. All I know right now is, this solution works :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文