自动创建 Subversion 修订文件

发布于 2024-08-17 19:17:23 字数 375 浏览 6 评论 0原文

我有一个项目,Subversion 中的结构如下,

branch
tags
trunk
-- Library
---- Library Code
-- Website
---- Website Code

Library 文件夹包含大部分项目代码,是一个类库。 Website 文件夹是一个使用该库的网站项目。该网站是部署到实时站点的内容。

我想在网站目录的根目录中自动创建一个文件,用于存储 trunk 目录的最新修订号。这可能吗?如果可以的话我该怎么做?

Subversion 服务器是 Windows 上的 VisualSVN,使用 TortoiseSVN 和 VisualSVN 作为客户端。

I have a project who's structure in Subversion goes as follows,

branch
tags
trunk
-- Library
---- Library Code
-- Website
---- Website Code

The Library folder contains most of the project code and is a class library. The Website folder is a website project which uses the library. The website is what gets deployed to the live site.

I would like to automatically create a file in the root of the website directory that stores the latest revision number of the trunk directory. Is this possible and if so how would I go about it?

The subversion server is VisualSVN on Windows using TortoiseSVN with VisualSVN for the client.

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

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

发布评论

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

评论(4

み青杉依旧 2024-08-24 19:17:23

由于您使用的是 TortoiseSVN,我建议使用 SubWCRev 来完成此任务而不是 svnversion。

Since you're using TortoiseSVN, I suggest using SubWCRev for this task instead of svnversion.

贱贱哒 2024-08-24 19:17:23

那么,包含修订号的常用方法是将其放入

$Revision$

源文件中的某个位置,该文​​件在提交时会扩展,前提是 svn:keywords 属性包含 Revision

不过,这只会为您提供上次提交该文件时的修订号,而不是当前的 HEAD 修订号。

在过去的项目中,我使用了一个调用命令行 subversion 程序的小脚本来提取当前的修订号。您可以调用 svn info 并获取各种信息,包括工作副本的修订号。当您对目录或其父目录之一执行更新时,该目录的该信息会更新;而文件的信息则在实际更新时更新,因此可能不完全准确。然而,当时这对我来说已经足够了,因为我只更新了顶级文件夹:

>svn info trunk | findstr /r /c:"^Revision"
Revision: 14466

Well, the usual way of including a revision number is to put

$Revision$

somewhere into the source file which gets expanded on commit, provided the property svn:keywords property contains Revision.

That will only give you the revision number when that file was last committed, though, not the current HEAD revision number.

In a past project I used a little script that called the command line subversion program to extract the current revision number. You can call svn info and get all kinds of information back, including the revision number of the working copy. This gets updated for a directory when you perform an update on that directory or one of its parents and for files when they are actually updated so it might not be fully accurate. However it was enough for me at that time as I only ever updated the top-level folder anyway:

>svn info trunk | findstr /r /c:"^Revision"
Revision: 14466
生来就爱笑 2024-08-24 19:17:23

有一个名为 svnversion 的命令行工具,可以用于生成您需要的价值。但是,您仍然需要手动执行它。还有一个额外的问题:

  1. 如果您想将结果存储到存储库中,则必须在提交之前执行它,并且存储的值将始终过时。

  2. 如果您想保持结果不受版本控制,则必须在提交后执行。但这样它就不会被导出。

所以这个问题没有简单的答案。建议:

  1. 拥有一个 version.txt 文件或任何带有 $Revision$ 关键字
  2. 编写预提交挂钩脚本 如果 version.txt 尚未修改,则拒绝提交
  3. 可选地,编写 TortoiseSVN 客户端挂钩脚本 在提交之前自动修改文件。

There's a command line tool called svnversion that can be used to generate the value you need. However, you still need to execute it manually. And there's an additional issue:

  1. If you want to store the result into the repository, you'll have to execute it before you commit and the stored value will always be outdated.

  2. If you want to keep the result unversioned, you'll have to execute after you commit. But then it won't get exported.

So there's no simple answer to the question. A proposal:

  1. Have a version.txt file or whatever with the $Revision$ keyword.
  2. Write a pre-commit hook script that rejects the commit if version.txt has not been modified
  3. Optionally, write a TortoiseSVN client-side hook script to modify the file automatically on before commit.
半透明的墙 2024-08-24 19:17:23

看看 svn 信息命令。在项目中将其作为构建前/构建后事件运行将为您提供所需的信息(以及一些附加信息)。然后,您需要将修订号写入文件。 (如果你这样做,请确保你的 SVN 忽略这个文件,否则它将进入文件更改、你检查它、文件更改等的无限循环......

Have a look at the svn info command. Running this as a pre/post build event in your project will get you the information you need (and some additional information). You then need to write the revision number to a file. (If you do this, make sure you SVN ignore this file otherwise it will enter an endless loop of the file changing, you checking it it, the file changing, etc...)

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