Mercurial 命令用于识别与文件规范匹配且自上次更新以来已更改的文件

发布于 2024-11-07 11:58:44 字数 941 浏览 0 评论 0原文

理想情况下,我正在寻找一种无状态的方法来执行此操作,因为我使用的是批处理文件。

场景是我在服务器上有一个存储库,用于接收用户的推送。该存储库也是一个工作副本,它是 wiki 页面 (dokuwiki) 的源,这些页面只是存储库中的文本文件,每个页面对应 wiki 中的一个。

由于它位于 Web 服务器上,因此任何人都不会以交互方式使用工作副本。相反,批处理文件会定期运行并发出适当的命令,以使用已推送到存储库的最新更改来更新工作副本。作为实现的旁注,它还接受来自 wiki 对工作副本的更改,并尝试同时合并和提交它们。

批处理文件如下所示:

@echo off
cd \dokuwiki\data\directory
start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"
for /r %%x in (*.jpg *.png *.gif) do copy /y "%%x" ..\..\media\directory

这对于文本文件来说效果很好,但是 dokuwiki 要求将图形等媒体存储在另一个目录中,这就是最后一个 for 语句的用途。

请注意,到目前为止我并不关心脚本的改进。它已被审查为我们在此环境中进行更新的理想方式。

最后复制的问题是它会复制所有图形,无论它们是否已更改。显然,最好只复制已更改的图形。由于自上次更新以来可能有多次推送到此存储库,因此我只想识别并复制自上次更新此工作副本(即上次此脚本运行 hg 时)以来已更改的那些图形更新

我想不出一种直观的方法来立即完成此操作。如果不需要在脚本运行之间手动保留信息,那就最好了,但这也不是不可能的。

Ideally, I'm looking for a stateless way to do this since I'm using a batch file.

The scenario is that I have a repository on a server that receives pushes from users. The repo is also a working copy that is the source for wiki pages (dokuwiki), which are simply the text files that are in the repository, one for each page in the wiki.

Because this is on a web server, the working copy isn't used by anyone interactively. Rather, a batch file runs periodically and issues the appropriate commands to keep the working copy updated with the latest changes that have been pushed to the repo. As a side note to the implementation, it also accepts changes to the working copy from the wiki and tries to merge and commit them at the same stroke.

The batch file looks like this:

@echo off
cd \dokuwiki\data\directory
start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"
for /r %%x in (*.jpg *.png *.gif) do copy /y "%%x" ..\..\media\directory

This works fine for the text files, but dokuwiki requires that media such as graphics be stored in another directory, which is what the last for statement is for.

Note that I'm not concerned with improvements to the script up to that point. It's been vetted as our desired way to do the update in this environment.

The issue with the copy at the end is that it copies all graphics irrespective of whether they've changed or not. Obviously, it would be better to only copy the graphics which have changed. Since there may have been more than one push into this repository since the last update, I want to identify and copy only those graphics which have changed since the last time this working copy was updated, i.e. the last time this script ran hg update.

I can't think of an intuitive way to do this off-hand. It would be best if information didn't need to be persisted manually between script runs, but it's not out of the question.

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

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

发布评论

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

评论(2

韬韬不绝 2024-11-14 11:58:44

我不知道 Windows 批处理文件的语法,但 Mercurial 的 hg status --rev REV 可能就是您正在寻找的:

@echo off
cd \dokuwiki\data\directory

ORIG_REV = hg log --rev . --template="{node}"

start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"

CHANGED_FILES = hg status --no-status --added --modified --rev ORIG_REV -I '*.jpg' -I '*.png' -I '*.gif'

for /r %%x in (CHANGED_FILES) do copy /y "%%x" ..\..\media\directory

I have no idea about the syntax of Windows batch files, but Mercurial's hg status --rev REV is probably what you're looking for:

@echo off
cd \dokuwiki\data\directory

ORIG_REV = hg log --rev . --template="{node}"

start /wait cmd.exe /c hg update
start /wait cmd.exe /c hg resolve -m -a
start /wait cmd.exe /c hg resolve -a
start /wait cmd.exe /c hg commit -A -m "Automated commit"

CHANGED_FILES = hg status --no-status --added --modified --rev ORIG_REV -I '*.jpg' -I '*.png' -I '*.gif'

for /r %%x in (CHANGED_FILES) do copy /y "%%x" ..\..\media\directory
转瞬即逝 2024-11-14 11:58:44

您也许可以使用 xcopy 及其 /D 开关,该开关仅复制比目标中的文件新的源文件。

You may be able to get away with using xcopy and its /D switch, which copies only source files that are newer than files in the destination.

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