[译]SvnRev:从您的源中提取修订号
By robot-v1.0
本文链接 https://www.kyfws.com/applications/svnrev-extract-revision-numbers-from-your-sources-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 29 分钟阅读 - 14287 个词 阅读量 0[译]SvnRev:从您的源中提取修订号
原文地址:https://www.codeproject.com/Articles/10602/SvnRev-Extract-Revision-Numbers-from-Your-Sources
原文作者:Ukkie9
译文由本站 robot-v1.0 翻译
前言
How to get the revision number for your project using Subversion or CVS/RCS
如何使用Subversion或CVS/RCS获取项目的修订号
- 下载源-8.66 KB(Download source - 8.66 KB)
- 下载Win32二进制文件-233.23 KB(Download binary for Win32 - 233.23 KB)
- 下载Linux二进制文件-260.13 KB(Download binary for Linux - 260.13 KB)
SvnRev:用于Subversion和CVS/RCS的实用程序(SvnRev: A Utility for Subversion and CVS/RCS)
SvnRev是一个小程序,它将项目的当前修订号写入C/C ++头文件,Java包文件,C#类文件或Ant属性文件.该修订版号以数字和字符串形式存储在常量中(在C/C ++中为宏).它从源文件中的" RCS关键字"获取修订版本号,或者从"工作副本"数据库获取(对于Subversion的最新版本). SvnRev是专门为Subversion版本控制系统设计的,但也可以与CVS和RCS一起使用.(SvnRev is a little program that writes the current revision number of a project into a C/C++ header file, a Java package file, a C# class file, or an Ant property file. This revision number is stored in constants (macros in the case of C/C++), both as a number and as a string. It gets the revision number from the “RCS keywords” in the source files, or (for recent versions of Subversion) from the “working copy” database. SvnRev is specifically designed for the Subversion version control system, but it can also be used with CVS and RCS.)
SvnRev是一个独立的实用程序,不依赖于特定的IDE. SvnRev是可移植的实用程序,应在可使用兼容C编译器的每个环境上运行.我们的目标是从" makefile"中使用它,并将其附加到版本控制系统,尤其是Subversion系统.(SvnRev is a self-contained utility that does not rely on a particular IDE. SvnRev is a portable utility and should run on every environment on which a conforming C compiler is available. Our aim was to use it from a “makefile” and to attach to a version control system, and specifically to the Subversion system.)
要获得全部功能,必须使用以下命令编译SvnRev(For full functionality, SvnRev must be compiled with) SQLite的(SQLite) . SQLite的源代码必须单独下载.用于Microsoft Windows和Linux的预编译可执行文件是使用SQLite构建的.(. The source code for SQLite must be downloaded separately. The pre-compiled executables, for Microsoft Windows and Linux, are built with SQLite.)
为什么要使用SvnRev?(Why use SvnRev?)
计算机程序具有版本.每个组件(DLL,ActiveX对象,OLE服务器,嵌入式固件等)可能都有自己的版本.如果世界是完美的,则不应存在两个具有相同版本号的不同组件.实际上,“隐形"升级会发生,特别是在beta期间.有很多(Computer programs have versions. Each component (DLL, ActiveX object, OLE server, embedded firmware, etc.) may have its own version. If the world were perfect, there should not exist two different components with the same version number. In practice, “stealth” upgrades happen, especially during the beta period. There are numerous)**不同(different)**释放MSVCRT20.DLL版本2.11.000,CTL3D.DLL版本1.0和COMDLG32.DLL版本4.00. (认为这仅发生在Microsoft上是愚蠢的.)(releases of MSVCRT20.DLL version 2.11.000, CTL3D.DLL version 1.0 and COMDLG32.DLL version 4.00 “out there”. (And it would be foolish to think that this happens only to Microsoft.))
SvnRev成年.在最初开发SvnRev时,可以在许多系统上找到上面引用的三个文件.隐身升级(SvnRev comes of age. At the time SvnRev was first developed, the three files cited above could be found on many systems. Stealth upgrades)**仍然(still)**但是,这些天发生了.(happen these days, though.)区分各个组件所需要的是附加一个”(What is needed to distinguish the various components from each other is to attach a “)**修订号(revision number)**在组件的版本字符串中添加”.“设置了这样的方案(版本号是版本号的一部分)后,开发人员不再会意外地发布具有与先前版本完全相同的版本标记的更新组件.版本号显示在"关于"框中和/或版本资源中,用户可以快速验证(” to the version string of the component. When such a scheme is set up (and the revision number is part of the version number), developers no longer accidentally release an updated component with exactly the same version stamp as the previous release. When the version number is present in the “About” box and/or in the version resource, the user can quickly verify)**究竟(exactly)**他或她拥有什么版本,以及将其传达给开发人员时,错误可能更容易重现.(what version he or she has, and when this is communicated to the developers, bugs might be quite a bit easier to reproduce.)
用更流行的术语:如果您曾经问过客户或同事"该组件的日期是什么?",则应考虑使用SvnRev.日期和时间戳建立了不可靠的声誉.(In more popular terms: if you have ever asked a customer or a colleague “of what date is that component?”, you should consider using SvnRev. Date and time stamps have built a reputation of being unreliable.)
有几个实用程序可以保持自动增加(There are several utilities to maintain an automatically increasing)**建立(build)**每次编译的编号.但是,这样做的缺点是在构建标记和版本控制之间没有直接的链接.要获得这样的链接,您需要将保存当前内部版本号的文件检入版本控制中.在多开发人员团队中,这种由机器生成的,经常更改的文件将成为版本控制系统的麻烦.实际上,您通常会(number for every compile. However, this has the disadvantage that there is no direct link between the build stamp and the version control. To get such a link, you would need to check in the file that holds the current build number into version control. In multi-developer groups, this machine-generated, frequently changing file, will become a nuisance for the version control system. Actually, you do typically)**不(not)**将机器生成的文件放入版本控制中.(put machine-generated files in version control.)
SvnRev使用另一种方法:它从版本控制系统在源文件中维护的关键字中查询内部版本号.更具体地说,SvnRev使用"(SvnRev uses a different approach: it queries the build number from the keywords that a version control system maintains in a source file. More specifically, SvnRev uses the “) $Id:$
“关键字(以及其他两个关键字).Subversion具有便利的属性,它仅对整个项目使用单个修订号,而不是每个文件使用单独的修订号.CVS和RCS并非如此;请参见”(” keyword (and optionally two others). Subversion has the convenient property that it uses only a single revision number for an entire project, instead of a separate revision number per file. This is not the case with CVS and RCS; see the section “) 在CVS和RCS中使用SvnRev(Using SvnRev with CVS & RCS) 有关在CVS/RCS上使用SvnRev的详细信息.(” for details on using SvnRev with CVS/RCS.)
SvnRev(*SvnRev*)**确实(does*)**假设您在将产品/更新发送给某人之前将更改提交到版本控制.如果SvnRev检测到差异,则会添加一个(assume that you commit your changes to version control before you send a product/update to someone. If SvnRev detects a difference, it adds a*) “modified flag”)“修改后的标志”( 到它生成的两个宏/常量.其背后的原因是,如果源代码的本地副本包含尚未在版本控制中的更改,则您发送的应用程序/组件的修订版号将链接到(to two of the macros/constants that it generates. The reasoning behind this is that if your local copy of the source code contains changes that are not yet in version control, the revision number of the application/component that you sent is linked to the)**错误(wrong)**Subversion中的修订版本号.该数字仍然可能与发布的任何早期应用程序/组件不同(除非您严重使用了版本控制,或者太快地发送了更新),但是找回正确的修订可能很困难,甚至不可能.因此:首先提交更改,然后构建将要部署的最终版本.(revision number in Subversion. The number is still likely to be different from any earlier application/component that went out of the door (unless you use version control badly, or send out updates far too quickly), but finding the correct revision back may be hard or even impossible. Therefore: commit your changes first, then build the final release that you will deploy.)
如何使用SvnRev?(How to use SvnRev?)
第一步是确保源文件处于版本控制中:显然,该文件是(The first step is to ensure that the source file is in version control: obviously, a file that is)**不(not)**Subversion或CVS/RCS系统中已知的系统永远不会为该系统分配"修订号".(known in Subversion or CVS/RCS system will never get assigned a “revision numbers” by that system.)
您需要调整makefile或项目(或"解决方案"),以使SvnRev在所有源(和头)文件上运行,这是构建过程的一部分.由于强大的命令外壳以及通用的GNU,这在Unix或Linux上很容易做到(You need to adjust your makefile or project (or “solution”) so that SvnRev runs over all source (and header) files, as part of the build process. This is easy to do in Unix or Linux, because of the powerful command shells and because of the versatile GNU)**使(make)**效用.跑步(utility. Running)**svnrev * .c * .cpp * .h(*svnrev .c .cpp .h)**让外壳扩展通配符并具有(lets the shell expand the wildcards and have) svnrev
运行所有文件.为了在Windows下获得相同的功能,必须将该程序与一个附加的(编译器提供的)目标文件链接.看到(run over all files. To get the same functionality under Windows, you must link the program with an additional (compiler-supplied) object file; see the) 制作说明(build instructions) .(.)
SvnRev具有以下选项(按用途分组):(SvnRev has the following options (grouped by purpose):)
选项(Option) | 描述(Description) |
---|---|
-jpackage | 选项(The option) -j 编写Java包文件而不是C/C ++头文件.软件包的名称必须遵循该选项(默认软件包名称为" com.compuphase").(writes a Java package file instead of a C/C++ header file. The name of the package must follow the option (the default package name is “com.compuphase”).) |
-cnamespace.class | 选项(The option) -c 编写C#类文件而不是C/C ++头文件.名称空间和类的名称必须在选项之后.名称空间和类名称以句点分隔(默认名称空间/类字符串为" compuphase.svnrev").(writes a C# class file instead of a C/C++ header file. The name of the namespace and class must follow the option; namespace and class names are separated by a period (the default namespace/class string is “compuphase.svnrev”).) |
-Oname | 选项(The option) -O 写入Oracle时,此选项将创建Oracle软件包文件而不是C/C ++头文件.软件包名称必须遵循该选项(默认软件包名称为"(writes an Oracle this option creates a Oracle package file instead of a C/C++ header file. The name of the package must follow the option (the default package name is “)svnrev.sql"). |
-P | 选项(The option) -P 为Apache Ant编写一个"属性文件”,而不是C/C ++头文件.名称文件是"(writes a “property file” for Apache Ant instead of a C/C++ header file. The name file is “)svnrev.property”. |
-pfilename | 选项(The option) -p 导致领域(causes the fields) AssemblyVersion and AssemblyFileVersion 要在Assembly Property文件中进行更新(通常是"(to be updated in the Assembly Property file (usually “)AssemblyInfo.cs").("). The) -c 也应该设置.(should be set as well.) |
-ofilename | 选项(The option) -o 允许您指定生成的包含文件的名称.默认名称是”(allows you to specify the name of the generated include file. The default name is “)svnrev.h“对于C/C ++模式,"(” for C/C++ mode, “)SvnRevision.java“对于Java模式和”(” for Java mode and “) SvnRevision.cs “用于C#模式.当您添加”(” for C# mode. When you add “) -omydefs.h “在命令行中(不带引号),实用程序将创建文件”(” to the command line (without the quotes), the utility creates the file “)mydefs.h".当你说(” instead. When you say) -o 而不在选项后面直接粘贴文件名,结果被写入(without gluing a filename directly behind the option, the results get written to) stdout . |
-i | 选项(The option) -i 是为了(is for)incremental运行.此开关使SvnRev扫描”(running. This switch makes SvnRev scan the “)svnrev.h"(除部分(部分)源文件集外),它是从上一次运行生成的.在生成文件中使用SvnRev时,此开关可能很重要,请参见下文.(” generated from a previous run, in addition to the (partial) set of source files. This switch may be important when using SvnRev in a makefile, see below. If you use the) -o 此外(in addition to) -i ,SvnRev将查找使用(, SvnRev will look for the filename specified with the) -o 选项代替(option instead of)svnrev.h,SvnRevision.javaorSvnRevision.cs. |
-fpattern | 选项(The option) -f 向字符串常量中的内部版本号添加前缀或后缀(或两者)(adds a prefix or a suffix (or both) to the build number in the string constant) SVN_REVSTR .的格式(. The format for)pattern是"(is “)prefix#suffix"(不带引号),其中#号被替换为内部版本号,(” (without the quotes) where the # symbol gets replaced by the build number and)prefixandsuffix是任意字符串.(are arbitrary strings.) |
-mname | 选项(The option) -m 更改生成的常量的基本名称(或前缀).默认情况下,所有生成的常量都以(changes the base name (or prefix) of the generated constants. By default all generated constants start with) SVN_REV ,但是可以使用此选项进行更改.(, but this can be changed with this option.) |
-n | 选项(The option) -n 在将工作副本与基本版本进行比较时,使SvnRev忽略行结尾(CR与LF与CR + LF).(makes SvnRev ignore line endings (CR versus LF versus CR+LF) when comparing the working copy to the base version.) |
-v | 选项(The option) -v 使SvnRev列出对stderr的最后一次版本控制提交的文件名(控制台输出).(causes SvnRev to list the names of files that were modified after the last commit to version control on stderr (console output).) |
在生成文件中,您需要添加一个在所有文件上运行的新目标.仅当文件更改时,才需要更新生成的包含文件.最(In a makefile, you need to add a new target that runs over all the files. The generated include file needs to be updated only if a file changes. Most)**使(make)**实用程序提供自动变量"(utilities provide the automatic variable “) $^
“将生成必备源文件(也称为"依赖项”)列表,并用空格字符分隔.(” that results in the list of prerequisite source files (also called “dependencies”), separated by space characters.)
svnrev.h : main.cpp gui.cpp gui.h storage.cpp storage.h
svnrev $^
GNU(The GNU)**使(make)**实用程序和其他几个提供了一个自动变量"(utility and several others provide an automatic variable “) $?
“,其中包含比目标更新的所有先决条件的名称,并在它们之间留有空格.使用此变量,(” that holds the names of all the prerequisites that are newer than the target, with spaces between them. By using this variable,) svnrev
只在(runs only over the)**改性(modified)**文件,当然更快.在这种情况下,您还需要告诉SvnRev运行(files, which is, of course, quicker. In this situation, you will also need to tell SvnRev to run)渐进地(incrementally)(((the) -i
选项).(option).)
svnrev.h : main.cpp gui.cpp gui.h storage.cpp storage.h
svnrev -i $?
接下来,包括(Next, include)**svnrev.h(svnrev.h)在任何C/C ++源文件中和/或(in any C/C++ source file and/or the).RC(.RC)**资源文件,并使用SvnRev生成的宏.对于Java和C#,请使用相应的输出文件(而不是(resource file and use the macros that SvnRev has generated. For Java and C#, use the corresponding output files (instead of)svnrev.h(svnrev.h)).().)
SvnRev创建并更新以下宏/常量:(SvnRev creates and updates the following macros/constants:)
SVN_REV
- 当前版本号.(The number of the current revision.)-SVN_REVSTR
- 与上面相同的数字,但编码为字符串,并可能用前缀和/或后缀设置为(The same number as above, but encoded as a string, and possibly decorated with a prefix and/or suffix set with the)-f
选项(option) .当数字后面出现字母” M"时,一个或多个源文件具有未提交的更改(这意味着内部版本号可能不能很好地表示当前内部版本);也可以看看(. When the letter “M” appears behind the number, one or more of the source files have uncommitted changes (meaning that the build number may not be a good representation of the current build); see also)SVN_REVMODIFIED
,如下.(, below.)-SVN_REVDATE
- 修订日期,编码为字符串,格式为YYYY-MM-DD.(The date of the revision, encoded as a string in the format YYYY-MM-DD.)-SVN_REVSTAMP
- 修订日期,以YYYYMMDD格式编码为整数.当"(The date of the revision, encoded as an integer in the format YYYYMMDD. This format may be convenient when “) 在CVS和RCS中使用SvnRev(using SvnRev with CVS & RCS) “.(”.)-SVN_REVMODIFIED
- 如果所有源文件在版本控制中都是最新的,则设置为零(0);如果一个或多个源文件进行了未提交的更改,则设置为非零值.如果存在未提交的更改,则(Set to zero (0) if all source files are up-to-date in version control, and to a non-zero value if one or more of the source files have uncommitted changes. If there are non-committed changes, the value of the)SVN_REVMODIFIED
每次SvnRev运行时,常量都会增加;它的功能类似于"内部版本号”.一旦所有源都提交给版本控制,该值将重置为零.例如,您可以使用此宏在程序开始时有条件地打印警告消息.要找出哪些文件有未提交的更改,请使用(constant is incremented every time that SvnRev runs; it functions akin to a “build” number. As soon as all sources are committed to version control, the value is reset to zero. You can use this macro to conditionally print a warning message at the start of your program, for example. To find out which files have uncommitted changes, use the)-v
选项(option) .当SvnRev与CVS或RCS一起使用时,该值将始终为零.(. When SvnRev is used with CVS or RCS, this value will always be zero.)如果常量的名称可能不同,(The names of the constants may be different if the)-m
选项(option) 在SvnRev的命令行上使用.例如,带有选项(is used on the command line of SvnRev. For example, with the option)-mAPP
,带有修订日期的常数将是(, the constant with the revision date will be)APPDATE
而不是默认值(instead of the default)SVN_REVDATE
.(.)生成的文件的示例是:(An example of a generated file is:)
/* This file was generated by the "svnrev" utility
* (http://www.compuphase.com/svnrev.htm).
* You should not modify it manually, as it may be re-generated.
*
* $Revision: 4224$
* $Date: 2011-02-22$
*/
#ifndef SVNREV_H
#define SVNREV_H
#define SVN_REV 4224
#define SVN_REVSTR "4224"
#define SVN_REVDATE "2011-02-22"
#define SVN_REVSTAMP 20110222L
#define SVN_REVMODIFIED 0
#endif /* SVNREV_H */
Java软件包文件示例为:(An example Java package file is:)
/* This file was generated by the "svnrev" utility
* (http://www.compuphase.com/svnrev.htm).
* You should not modify it manually, as it may be re-generated.
*
* $Revision: 4224$
* $Date: 2011-02-22$
*/
package com.compuphase;
public interface SvnRevision
{
public final static int SVN_REV = 4224;
public final static String SVN_REVSTR = "4224";
public final static String SVN_REVDATE = "2011-02-22";
public final static long SVN_REVSTAMP = 20110222L;
public final static int SVN_REVMODIFIED = 0;
}
现在,在源文件中,您可以使用这些宏/常量来输入内部版本号或修订号. SvnRev定义了数字宏和字符串宏,以便您可以利用ANSI C预处理器的字符串连接功能(也用于C ++和资源文件).(In your source files, you can now use these macros/constants where you would otherwise type a build or revision number. SvnRev defines both a numeric macro and a string macro so that you can take advantage of the string concatenation feature of the ANSI C preprocessor (also used in C++ and resource files).)
现在,在程序中的某个位置,您将使用一个或多个宏来显示修订号.如果您制作一个简单的控制台程序,则可以例如在使用信息中将其打印出来,例如以下示例(来自SvnRev的源代码):(Somewhere in your program, you will now use one or more of the macros to display the revision number. If you make a simple console program, you could, for example, print it in the usage information, like in the example below (which comes from the source code of SvnRev):)
printf("svnrev 2.0." SVN_REVSTR "\n\n");
RCS关键字(RCS Keywords)
对于由根据Subversion库1.6版或更早版本编译的客户端创建的"工作副本",还有另一个要求:源文件应全部包含" RCS关键字"并具有"(For “working copies” created by clients compiled against the Subversion libraries version 1.6 and earlier, there is another requirement: the source files should all contain “RCS keywords” and have the property “) svn:keywords
对于Subversion 1.7客户端创建的"工作副本”,此步骤是可选的.(". For “working copies” created by Subversion 1.7 clients, this step is optional.)
您如何知道工作副本是" 1.7格式"还是更早的格式?转到本地硬盘上项目的根文件夹.会有一个(How do you know whether a working copy is in the “1.7 format” or an earlier format? Go to the root folder of a project on your local hard disk. There will be a)**.svn(.svn)目录.看里面(directory in it. Look inside the).svn(.svn)**对于一个名为(for a file called)wc.db(wc.db);如果存在,则为" 1.7"格式.有关更改的摘要,请参见(; if it is present, this is the “1.7” format. For a summary of the changes, see the) Subversion 1.7发行说明(Subversion 1.7 Release notes) .(.)RCS关键字应该出现在所有源文件中:头文件以及代码文件.关键字如下:(The RCS keywords should be present in all source files: header files as well the code files. A keyword looks like:)
$Id$
版本控制系统会将其扩展为以下行:(The version control system will expand this to something like the line below:)
$Id: svnrev.c 3116 2005-03-18 16:26:29Z thiadmer $
C/C ++编译器在源代码中不喜欢上面的行,因此通常在注释或字符串中扩展关键字.作为更完整的示例,以下代码来自(A C/C++ compiler does not like lines like the above in the source code, so typically a keyword is expanded in a comment, or in a string. As a more complete example, the code below is from the)**svnrev(svnrev.c)**源文件:(source file:)
/*
* Version: $Id: svnrev.c 3116 2005-03-18 16:26:29Z thiadmer $
*/
SvnRev支持以下关键字.请注意,(The following keywords are supported by SvnRev. Note that the “) $Id:$
“关键字包含所有必需的信息,因此通常是您要在每个源文件顶部的注释中使用的信息.(” keyword contains all the required information, so this is often the one that you will want to use in the comment that you have at the top of each source file.)
$Id:$
- 一个标准标头,其中包含RCS文件名,修订号,日期和时间,作者,状态以及提交修订(或锁定文件)的用户的登录名.(A standard header containing the RCS file name, revision number, date and time, author, status, and the login name of the user who committed the revision (or who has locked the file).)-$Date:$
- 签入修订的日期和时间.(The date and time the revision was checked-in.)-$Rev:$
- 分配给修订的修订号.(The revision number assigned to the revision.)-$Revision:$
- 的别称(Another name for)$Rev:$
.(.)此外,要扩展关键字,每个文件都必须具有”(Furthermore, to expand keywords, each file must have the property “)svn:keywords
“,并且此属性必须具有值(”, and this property must have the value)"Date Id Rev"
(您可以使用"修订"代替"修订”).您可以将它们明确地添加到文件中,或者在客户端上配置Subversion以自动添加它们;见下文.((you may use “Revision” instead of “Rev”). You can add these to the files explicitly, or configure Subversion on your client to add them automatically; see below.)
[### 为自动关键字属性配置Subversion(Configure Subversion for Automatic Keyword Properties)
]() 如前所述,每个源文件必须具有一个名为(As stated before, each source file must have a property called) svn:keywords
. Subversion客户端允许您分别设置每个文件的属性.下面的两个屏幕抓图说明了将该属性设置为适当的值.(. Subversion clients allow you to set the properties of each file individually. The two screen grabs below illustrate setting the property to an appropriate value.)
TortoiseSVN的文件属性对话框(The file properties dialog for TortoiseSVN)
eSvn的文件属性对话框(The file properties dialog for eSvn)除了为添加的每个文件显式设置这些字段外,您还可以让Subversion自动设置它们.必须在Subversion中启用此行为(Apart from setting these fields explicitly for every file that you add, you may have Subversion set them automatically. This behaviour must be enabled in the Subversion “)配置(config)“文件在客户端上.您将在”(” file on the client. You will find this file in the “)颠覆(Subversion)"(” folder below the “)应用数据(Application Data)“文件夹,位于用户的个人资料中.该文件称为”(” folder, in the user’s profile. The file is called “)配置(config)",没有扩展名.如果您使用的是TortoiseSVN,则可以从TortoiseSVN的"设置"对话框中编辑此文件;对于其他客户端,可能需要找到该文件并将其加载到记事本或其他合适的编辑器中.在配置文件中,您可以会寻找(”, without extension. If you are using TortoiseSVN, you can edit this file from TortoiseSVN’s “Settings” dialog; for other clients, you may need to locate the file and load it into Notepad or another suitable editor. In the configuration file, you will be looking for the) enable-auto-props
关键字和(keyword and the) [auto-props]
部分(默认情况下已注释掉).您需要删除注释标记("#“字符)并添加属性(section (which are commented out by default). You need to remove the comment markers (the “#” character) and add the property) svn:keywords=Rev Date Id
到选定的文件扩展名.以下是来自(to selected file extensions. Below is a snippet from a)**配置(config)**调整后的文件.(file after this adjustment.)
[miscellany]
### Set enable-auto-props to 'yes' to enable automatic properties
### for 'svn add' and 'svn import', it defaults to 'no'.
### Automatic properties are defined in the section 'auto-props'.
enable-auto-props = yes
### Section for configuring automatic properties.
### The format of the entries is:
### file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?'). All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
[auto-props]
*.c = svn:eol-style=native;svn:keywords=Author Rev Id Date
*.cpp = svn:eol-style=native;svn:keywords=Author Rev Id Date
*.h = svn:eol-style=native;svn:keywords=Author Rev Id Date
*.dsp = svn:eol-style=CRLF
*.dsw = svn:eol-style=CRLF
*.sh = svn:eol-style=native;svn:executable
*.txt = svn:eol-style=native
*.png = svn:mime-type=image/png
*.jpg = svn:mime-type=image/jpeg
[## 在CVS和RCS中使用SvnRev(Using SvnRev with CVS & RCS)
]() 使用CVS或RCS时,SvnRev也可以从关键字中提取修订号和日期. CVS和RCS系统使用与Subversion相同的关键字,除了它们通常使用$ Revision:$代替$ Rev:$.无需使用CVS/RCS启用关键字扩展(每个文件).与Subversion相比,关键字扩展是(When you use CVS or RCS, SvnRev can extract the revision number and the date from the keywords as well. The CVS and RCS system use the same keywords as Subversion, except that they often use $Revision:$ instead of $Rev:$. There is no need to enable keyword expansion (per file) with CVS/RCS. In contrast to Subversion, keyword expansion is)**总是(always)**在签入(或"提交”)中完成–无需配置文件属性.(done on a check-in (or “commit”) –there is no need to configure file properties.)
Subversion的一个重要功能是它为整个项目使用一个修订版本号. CVS和RCS每个文件都有一个修订号.现在,SvnRev实用程序必须组成一个唯一的数字,该数字代表完整文件集的修订. SvnRev的执行方式与(An important feature of Subversion is that it uses a single revision number for a complete project. CVS and RCS have a revision number per file. The SvnRev utility now has to make up a unique number that represents the revision for the complete set of files. SvnRev does this in the same way as the) cvs2svn.py(cvs2svn.py) 脚本:文件的每次提交都计为项目的新修订版.简而言之,这意味着各个文件的修订号已累积.总数是"项目修订"号.(script: every commit of a file counts as a new revision of a project. In brief, this means that the revision numbers of individual files are accumulated. The total is the “project revision” number.)
不幸的是,该方案不允许简单查找作为特定项目修订的一部分的源文件的所有修订.也就是说,如果客户报告与整个应用程序的修订版" 4351"相关的错误,则此应用程序由多个源文件组成,每个源文件都有其自己的修订版号-但这些文件中没有一个具有修订版" 4351".(Unfortunately, this scheme does not allow a simple lookup of all revisions of the source files that are part of a particular project revision. That is, if a customer reports a bug related to revision “4351” of the complete application, this application consists of several source files that each have their own revision number –but none of these files will have revision “4351”.)
一种选择是检入生成的(One option is to check in the generated)**svnrev.h(svnrev.h)**文件在选定的里程碑.或者,您可以使用修订日期作为检索旧修订的标准.宏(file at selected milestones. Alternatively, you can use the revision date as the criterion for retrieving an older revision. The macro) SVN_REVDATE
以字符串格式保存最近修改的日期;宏(holds the date of the latest modification in a string format; the macro) SVN_REVSTAMP
还以YYYYMMDD格式将日期编码为整数.(also has the date encoded in an integer, in YYYYMMDD format.)
我不是早先写过日期/时间戳不可靠,而我现在建议您依靠它们吗?好吧,是的,但是…在我谈论一个日期的日期/时间戳之前(Did I not write earlier that date/time stamps are unreliable, whereas I am now suggesting that you rely on them? Well, yes, but… before I was talking about the date/time stamp of a)文件(file).这些是不可靠的.中的日期戳(. These are unreliable. The date stamp in the) SVN_REVDATE
是提交的内容,它存储在CVS存储库中并且可以依赖.(is that of the commit, which is stored in the CVS repository and which can be relied upon.) [## 建筑物SvnRev(Building SvnRev)
]() 该源代码是可移植的,并且我已经在Microsoft Windows上使用Borland C ++和OpenWatcom C/C ++以及在Linux下使用GCC成功地对其进行了编译.(The source is build to be portable, and I have successfully compiled it under Microsoft Windows using Borland C++ and OpenWatcom C/C++, and under Linux using GCC.)
对于Subversion 1.7版客户端,SvnRev具有对(For Subversion version 1.7 clients, SvnRev has a dependency on) SQLite的(SQLite) . Subversion的"工作副本"格式在1.7版中已发生了重大变化:工作副本的元数据现在存储在SQLite数据库中,这意味着SvnRev也必须能够读取SQLite数据库.您可以选择构建SvnRev(. The “working copy” format of Subversion has changed significantly in version 1.7: and the meta-data for a working copy is now stored in a SQLite database, which means that SvnRev has to be able to read SQLite databases, too. You can optionally build SvnRev)**没有(without)**SQLite,因此仅支持不超过1.6的Subversion客户端的工作副本.编译(SQLite, thereby supporting only working copies of Subversion clients up to 1.6. To compile)**没有(without)**SQLite,添加定义(SQLite, add the definition) NOSQL
在构建SvnRev时在命令行上.(on the command line when building SvnRev.)
Unix和Linux下的shell将文件名中的通配符扩展为所有匹配文件的列表. Windows的命令行外壳与(The shells under Unix and Linux expand wildcards in filenames to a list of all matching files. The command line shell of Windows is bare-bones when compared with)重击(BASH)(和表兄弟),并且它不提供诸如在命令行上使用通配符扩展文件名的功能.几个Windows编译器提供了一个目标文件,您可以将其与执行自动命令行扩展的程序链接,然后再调用((and cousins), and it does not provide features like expanding the filenames with wildcards on the command line. Several Windows compilers provide an object file that you can link with your program that does the automatic command line expansion before calling your) main()
功能.该目标文件是(function. This object file is)**setargv.obj(setargv.obj)**用于Microsoft Visual C/C ++和(for Microsoft Visual C/C++ and)**wildargs.obj(wildargs.obj)**适用于Borland C ++.其他编译器也可能附带此类文件.(for Borland C++. Other compilers may come with such a file too.)
那么SubWCRev呢?(What about SubWCRev?)
SubWCRev是一种实用工具,其目的和操作与SvnRev相似. SubWCRev的"官方"发行版仅在Microsoft Windows上运行,但是现在存在用于Linux的端口:请参阅(SubWCRev is a utility with a similar goal and operation as SvnRev. The “official” release SubWCRev runs only on Microsoft Windows, but there now exists a port of it for Linux: see) svnwcrev(svnwcrev) .(.)
主要区别在于SubWCRev从项目的"工作副本"获得Subversion的所有版本的修订号. SvnRev仅在Subversion 1.7(及更高版本)中具有此功能. (“工作副本"是一个存储库,其中包含目录中文件的所有版本控制信息).使用工作副本的优点在于,您无需在源文件中添加关键字,还可以查询不包含关键字的二进制文件的修订版号.(The main difference is that SubWCRev gets the revision numbers from the “working copy” of the project, for all versions of Subversion. SvnRev has this capability only for version 1.7 (and later) of Subversion. (The “working copy” is a repository that holds all version-control information on the files in a directory). The advantages for using the working copy are that you do not need to add keywords to the source files and that you can also query the revision numbers of binary files, which do not contain keywords.)
SubWCRev仅返回单个文件或文件的修订号.(SubWCRev only returns the revision number of a single file or of a)目录(directory).第一个选项,返回版本号(. The first option, returning the revision number of)**一(one)**文件,不是很有用.但是,第二个选项返回的是(file, is not very useful. However, the second option, returning the top revision number of a)目录(directory),也有局限性.我们的许多产品可以构建为多种配置,其中每种配置都会添加一些特定的源文件.其中一个特定于配置的源文件的更改不应影响其他配置的内部版本号. SvnRev为您提供传递的确切文件集的(已提交)内部版本号.因此,产品的不同配置各自具有各自的相关修订号.(, has limitations as well. Many of our products can be built in multiple configurations, where each configuration adds a few specific source files. A change in one of the configuration-specific source files should not affect the build numbers of the other configurations. SvnRev gives you the (committed) build number of the exact set of files that you pass in. Therefore, different configurations of a product each have their own relevant revision number.)
另一个区别是SvnRev也可以与(Another difference is that SvnRev also works with) CVS/RCS(CVS/RCS) (有限制).((with limitations).)
svnversion呢?(What about svnversion?)
" svnversion"实用程序是标准Subversion发行版的一部分.像SubWCRev一样,svnversion从工作副本中获取版本信息,因此您无需添加RCS关键字.另外,与SubWCRev不同,svnversion是可移植的.(The “svnversion” utility is part of the standard Subversion distribution. Like SubWCRev, svnversion gets the version information from the working copy, so you do not need to add the RCS keywords. In addition, and unlike SubWCRev, svnversion is portable.)
默认情况下,svnversion返回整个Subversion存储库的版本号,如果您在单个存储库中有多个项目,则不需要此版本号,但是可以告诉您为工作副本提供"已提交"的版本号.该值可与SvnRev给您的结果相媲美.(By default, svnversion returns the version number of the entire Subversion repository, which is not what you want if you have multiple projects in a single repository, but it can be told to give you the “committed” version number of a working copy. This value is comparable to what SvnRev gives you.)
类似于SubWCRev,svnversion仅返回版本号(Similar to SubWCRev, svnversion only returns the version number of a)目录(directory),而不是一组文件.如上文所述,这在可以用多种配置构建的项目中是一个重大缺点,其中每个配置都添加了一些特定的源文件(对一个特定于配置的源文件的更改不应影响另一个配置的源文件配置).同样,SvnRev为您提供传入的确切文件集的(已提交)内部版本号.(, not that of a set of files. As was explained above, this is a significant disadvantage in projects that can be built in multiple configurations, where each configuration adds a few specific source files (a change in one of the configuration-specific source files should not affect the build numbers of the other configurations). Again, SvnRev gives you the (committed) build number of the exact set of files that you pass in.)
在构建环境中使用的便利性是另一个区别:不能告诉svnversion以可以从C/C ++,Java或C#程序立即使用的格式编写版本.如果使用svnversion,则始终需要围绕它编写脚本包装.另一方面,SvnRev旨在集成到"构建链"中.(Convenience of use in a build environment is another difference: svnversion cannot be told to write the version in a format that is immediately usable from a C/C++, Java or C# program. If you use svnversion, you will always need to write a script wrapper around it. SvnRev, on the other hand, is designed to be integrated in the “build chain”.)
参考文献(References)
-
颠覆(Subversion) Subversion版本控制系统的站点,其中包含许多服务器和客户端软件以及书籍的链接. (还有一些工具和脚本可以从RCS/CVS或Visual SourceSafe迁移到Subversion.)(The site for the Subversion version control system, with many links to server and client software, as well as books. (There are also tools and scripts to migrate from RCS/CVS or Visual SourceSafe to Subversion.))
-
乌龟SVN(TortoiseSVN) 与Windows资源管理器集成的Microsoft Windows客户端.(A client for Microsoft Windows that integrates with Windows Explorer.)
-
eSvn(eSvn) 用于Subversion的多平台图形客户端;显然不再维护.(A multi-platform graphical client for Subversion; apparently no longer maintained.)
-
RapidSVN(RapidSVN) 用于Subversion的多平台图形客户端.(A multi-platform graphical client for Subversion.)
历史(History)
- 版本1.0\6(Version 1.0, 6)日(th)2005年6月-初始版本(June 2005 - Initial release)
- 版本1.1\24(Version 1.1, 24)日(th)2005年7月-支持CVS和RCS(July, 2005 - Support for CVS and RCS)
- 版本1.2\9(Version 1.2, 9)日(th)2005年12月-修复了在Makefile中仅使用SvnRev的问题(December, 2005 - Fix the use of SvnRev in a Makefile where only)**部分(part)**项目中所有文件中的所有文件都将重新生成(并因此由SvnRev重新扫描).扩展并更正了Subversion关键字的解释(of all files in the project are re-built (and therefore re-scanned by SvnRev). Expanded and corrected the explanation of Subversion keywords)
- 版本1.3\9(Version 1.3, 9)日(th)2006年8月-对SvnRev和CVS的使用进行了较小的更正(August, 2006 - Minor corrections for using SvnRev with CVS)
- 版本1.4\5(Version 1.4, 5)日(th)2007年3月-对Java软件包文件的支持,由Tom McCann贡献(March, 2007 - Support for Java package files, contributed by Tom McCann)
- 版本1.5\22(Version 1.5, 22)日(th)2007年11月-验证输入文件中的修改(November, 2007 - Verification for modifications in the input files)
- 版本1.6\30(Version 1.6, 30)日(th)2008年12月-选择列出自上次提交以来已修改的文件名的选项(December, 2008 - Option to list the names of files that were modified since last commit)
- 版本1.7\31(Version 1.7, 31)日(th)2009年3月-选择向内部版本号添加前缀和/或后缀(在字符串常量中)(March, 2009 - Option to add a prefix and/or a suffix to the build number (in the string constant))
- 版本1.8\2(Version 1.8, 2)nd(nd)2010年4月-支持C#,并且能够更改生成的宏的名称(April, 2010 - Support for C#, plus the ability to change the names of the generated macros)
- 版本1.9\21(Version 1.9, 21)圣(st)2010年5月-错误修复版本(May, 2010 - Bug fix release)
- 版本1.10\15(Version 1.10, 15)日(th)2010年7月-不变(July, 2010 - The constant)
SVN_REVMODIFIED
现在在每次运行时都会递增,以用作未签入的源代码的内部版本号(now increments on every run, to function as a build number for source code that is not checked in) - 版本1.11\23(Version 1.11, 23)rd(rd)2010年11月-使用新选项时,行尾的差异(Unix/Linux,Microsoft Windows和Apple)不算作"修改”(November, 2010 - Differences in line endings (Unix/Linux versus Microsoft Windows versus Apple) do not count as a “modification” when the new option)
-n
用来(is used) - 版本1.12\30(Version 1.12, 30)日(th)2011年4月-支持Oracle和Apache Ant的输出文件(April, 2011 - Support for output files for Oracle and Apache Ant)
- 版本2.0\30(Version 2.0, 30)日(th)2011年10月-支持Subversion 1.7的新"工作副本";放宽了对源文件中RCS关键字的要求(在Subversion 1.7工作副本上)(October, 2011 - Support for the new “working copy” of Subversion 1.7; relaxed requirement for RCS keywords in source files (on Subversion 1.7 working copies))
- 版本2.0A,15(Version 2.0A, 15)日(th)2011年11月-更好的错误检查; (改写(November, 2011 - Better error checking; (re-)write)**svnrev.h(svnrev.h)****只要(only)**版本号更改时(when version number changes)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ Windows Visual-Studio Dev 新闻 翻译