`
zhang_ly520
  • 浏览: 162001 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

svn keywords

阅读更多

Keyword Substitution

原文地址:http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html

Subversion has the ability to substitute keywords—pieces of useful, dynamic information about a versioned file—into the contents of the file itself. Keywords generally provide information about the last modification made to the file. Because this information changes each time the file changes, and more importantly, just after the file changes, it is a hassle for any process except the version control system to keep the data completely up to date. Left to human authors, the information would inevitably grow stale.

For example, say you have a document in which you would like to display the last date on which it was modified. You could burden every author of that document to, just before committing their changes, also tweak the part of the document that describes when it was last changed. But sooner or later, someone would forget to do that. Instead, simply ask Subversion to perform keyword substitution on the LastChangedDate keyword. You control where the keyword is inserted into your document by placing a keyword anchor at the desired location in the file. This anchor is just a string of text formatted as $KeywordName$.

All keywords are case-sensitive where they appear as anchors in files: you must use the correct capitalization for the keyword to be expanded. You should consider the value of the svn:keywords property to be case-sensitive, too—certain keyword names will be recognized regardless of case, but this behavior is deprecated.

Subversion defines the list of keywords available for substitution. That list contains the following five keywords, some of which have aliases that you can also use:

Date

This keyword describes the last time the file was known to have been changed in the repository, and is of the form $Date: 2006-07-22 21:42:37 -0700 (Sat, 22 Jul 2006) $. It may also be specified as LastChangedDate. Unlike the Id keyword, which uses UTC, the Date keyword displays dates using the local time zone.

Revision

This keyword describes the last known revision in which this file changed in the repository, and looks something like$Revision: 144 $. It may also be specified as LastChangedRevision or Rev.

Author

This keyword describes the last known user to change this file in the repository, and looks something like $Author: harry $. It may also be specified as LastChangedBy.

HeadURL

This keyword describes the full URL to the latest version of the file in the repository, and looks something like$HeadURL: http://svn.collab.net/repos/trunk/README $. It may be abbreviated as URL.

Id

This keyword is a compressed combination of the other keywords. Its substitution looks something like $Id: calc.c 148 2006-07-28 21:30:43Z sally $, and is interpreted to mean that the file calc.c was last changed in revision 148 on the evening of July 28, 2006 by the user sally. The date displayed by this keyword is in UTC, unlike that of the Date keyword (which uses the local time zone).

Several of the preceding descriptions use the phrase “last known” or similar wording. Keep in mind that keyword expansion is a client-side operation, and your client “knows” only about changes that have occurred in the repository when you update your working copy to include those changes. If you never update your working copy, your keywords will never expand to different values even if those versioned files are being changed regularly in the repository.

Simply adding keyword anchor text to your file does nothing special. Subversion will never attempt to perform textual substitutions on your file contents unless explicitly asked to do so. After all, you might be writing a document [13] about how to use keywords, and you don't want Subversion to substitute your beautiful examples of unsubstituted keyword anchors!

To tell Subversion whether to substitute keywords on a particular file, we again turn to the property-related subcommands. The svn:keywords property, when set on a versioned file, controls which keywords will be substituted on that file. The value is a space-delimited list of keyword names or aliases.

For example, say you have a versioned file named weather.txt that looks like this:

Here is the latest report from the front lines.
$LastChangedDate$
$Rev$
Cumulus clouds are appearing more frequently as summer approaches.

With no svn:keywords property set on that file, Subversion will do nothing special. Now, let's enable substitution of theLastChangedDate keyword.

$ svn propset svn:keywords "Date Author" weather.txt
property 'svn:keywords' set on 'weather.txt'
$

Now you have made a local property modification on the weather.txt file. You will see no changes to the file's contents (unless you made some of your own prior to setting the property). Notice that the file contained a keyword anchor for the Revkeyword, yet we did not include that keyword in the property value we set. Subversion will happily ignore requests to substitute keywords that are not present in the file and will not substitute keywords that are not present in the svn:keywordsproperty value.

Immediately after you commit this property change, Subversion will update your working file with the new substitute text. Instead of seeing your keyword anchor $LastChangedDate$, you'll see its substituted result. That result also contains the name of the keyword and continues to be delimited by the dollar sign ($) characters. And as we predicted, the Rev keyword was not substituted because we didn't ask for it to be.

Note also that we set the svn:keywords property to Date Author, yet the keyword anchor used the alias $LastChangedDate$ and still expanded correctly:

Here is the latest report from the front lines.
$LastChangedDate: 2006-07-22 21:42:37 -0700 (Sat, 22 Jul 2006) $
$Rev$
Cumulus clouds are appearing more frequently as summer approaches.

If someone else now commits a change to weather.txt, your copy of that file will continue to display the same substituted keyword value as before—until you update your working copy. At that time, the keywords in your weather.txt file will be resubstituted with information that reflects the most recent known commit to that file.

Subversion 1.2 introduced a new variant of the keyword syntax, which brought additional, useful—though perhaps atypical—functionality. You can now tell Subversion to maintain a fixed length (in terms of the number of bytes consumed) for the substituted keyword. By using a double colon (::) after the keyword name, followed by a number of space characters, you define that fixed width. When Subversion goes to substitute your keyword for the keyword and its value, it will essentially replace only those space characters, leaving the overall width of the keyword field unchanged. If the substituted value is shorter than the defined field width, there will be extra padding characters (spaces) at the end of the substituted field; if it is too long, it is truncated with a special hash (#) character just before the final dollar sign terminator.

For example, say you have a document in which you have some section of tabular data reflecting the document's Subversion keywords. Using the original Subversion keyword substitution syntax, your file might look something like:

$Rev$:     Revision of last commit
$Author$:  Author of last commit
$Date$:    Date of last commit

Now, that looks nice and tabular at the start of things. But when you then commit that file (with keyword substitution enabled, of course), you see:

$Rev: 12 $:     Revision of last commit
$Author: harry $:  Author of last commit
$Date: 2006-03-15 02:33:03 -0500 (Wed, 15 Mar 2006) $:    Date of last commit

The result is not so beautiful. And you might be tempted to then adjust the file after the substitution so that it again looks tabular. But that holds only as long as the keyword values are the same width. If the last committed revision rolls into a new place value (say, from 99 to 100), or if another person with a longer username commits the file, stuff gets all crooked again. However, if you are using Subversion 1.2 or later, you can use the new fixed-length keyword syntax and define some field widths that seem sane, so your file might look like this:

$Rev::               $:  Revision of last commit
$Author::            $:  Author of last commit
$Date::              $:  Date of last commit

You commit this change to your file. This time, Subversion notices the new fixed-length keyword syntax and maintains the width of the fields as defined by the padding you placed between the double colon and the trailing dollar sign. After substitution, the width of the fields is completely unchanged—the short values for Rev and Author are padded with spaces, and the long Date field is truncated by a hash character:

$Rev:: 13            $:  Revision of last commit
$Author:: harry      $:  Author of last commit
$Date:: 2006-03-15 0#$:  Date of last commit

The use of fixed-length keywords is especially handy when performing substitutions into complex file formats that themselves use fixed-length fields for data, or for which the stored size of a given data field is overbearingly difficult to modify from outside the format's native application (such as for Microsoft Office documents).

 

 

 

        Be aware that because the width of a keyword field is measured in bytes, the potential for corruption of multibyte values exists. For example, a username that contains some multibyte UTF-8 characters might suffer truncation in the middle of the string of bytes that make up one of those characters. The result will be a mere truncation when viewed at the byte level, but will likely appear as a string with an incorrect or garbled final character when viewed as UTF-8 text. It is conceivable that certain applications, when asked to load the file, would notice the broken UTF-8 text and deem the entire file corrupt, refusing to operate on the file altogether. So, when limiting keywords to a fixed size, choose a size that allows for this type of byte-wise expansion.

 

 

分享到:
评论

相关推荐

    SVN使用手册中文版快速入门

    svn:keywords svn:eol-style svn:externals svn:special 自动属性设置 Peg和实施修订版本 外部定义 卖主分支 常规的卖主分支管理过程 svn_load_dirs.pl 本地化 理解地区 Subversion对地区的支持 Subversion版本库URL...

    SVN使用手册中文版.chm

    svn:keywords svn:eol-style svn:externals svn:special 自动属性设置 Peg和实施修订版本 外部定义 卖主分支 常规的卖主分支管理过程 svn_load_dirs.pl 本地化 理解地区 Subversion对地区的支持 Subversion版本库URL...

    SVN基本指令

    ### SVN基本指令详解 #### 目录架构与用途解析 ... svn propset svn:keywords "Id" filename ``` 以上是对SVN基本指令及部分进阶操作的详细解析,掌握了这些,你就可以有效地管理和协作代码库了。

    SVN操作手册中文版网页格式

    svn:keywords 4.17.1.2. 增加和编辑属性 4.17.1.3. Exporting and Importing Properties 4.17.1.4. 二进制属性 4.17.1.5. 自动属性设置 4.17.2. TortoiseSVN 项目属性 4.18. External Items 4.18.1. ...

    【每日一步】Java代码中如何加入SVN版本控制.pdf

    在Java代码中,通过设置特定的关键词(Keywords),如`Id`、`LastChangedDate`、`LastChangedBy`、`LastChangedRevision`和`HeadURL`,SVN可以在每次提交时自动更新这些信息。例如,`Id`关键字会被替换为文件的完整...

    SVN安装文件及使用帮助文档

    - 属性设置:可以为文件或目录设置特定的SVN属性,如`svn:keywords`用于插入版本信息。 4. **冲突解决**: - 当多个人对同一文件的同一部分进行修改并提交时,会出现冲突。SVN会在冲突文件中标识出冲突区域,需要...

    svn使用手册

    svn在高级主题部分介绍了修订规格符(Revision Specifiers)、修订关键词(Revision Keywords)和修订日期(Revision Dates)。此外,还讨论了属性(Properties)的概念和作用,属性是版本控制之外的元数据信息,...

    svn-book.pdf

    - **修订关键字(Revision Keywords)**:在文件中自动插入版本信息的特殊字符串。 - **修订日期(Revision Dates)**:与版本相关的日期信息。 - **定位修订(Peg and Operative Revisions)**:允许指定特定版本下的操作...

    TortoiseSVN和TortoiseMerge的中文帮助文档(chm格式)

    4.34. svn:keywords 属性页 4.35. svn:eol-style 属性页 4.36. tsvn:bugtraq 属性页 4.37. 日志信息属性页的大小 4.38. 语言属性页 4.39. svn:mime-type 属性页 4.40. svn:needs-lock 属性页 4.41. svn:executable ...

    如何个性化地生成Javadoc文档

    会从语言、编码、链接、自定义标记、设置版本的自动增加(并引申Eclipse下如何设置SVN中的svn:keywords属性)几个方面来个性你的Javadoc文档。 本人博客:http://www.blogjava.net/lishunli/,希望大家支持

    Python库 | hgsubversion-1.4.tar.gz

    此外,`hgsubversion`还支持一些高级特性,例如处理Subversion的属性(svn:keywords、svn:eol-style等),以及处理Subversion的分支和标签。 在Python开发中,选择合适的库可以极大地提高开发效率和项目质量。`...

    Version Control with Subversion For Subversion 1.3

    - **修订关键词(Revision Keywords)**:特定的关键词可以自动替换为修订版本的信息。 - **修订日期(Revision Dates)**:每条修订都有一个对应的日期时间戳。 - **初始化检出(Initial Checkout)**:首次从...

    Version Control with Subversion

    - **修订关键字(Revision Keywords)**:在文件中嵌入版本信息的特殊标记,例如$Rev$表示当前文件的版本号。 - **属性(Properties)**:附加在文件或目录上的元数据,可用于记录作者信息、版权声明等内容。 #### ...

    robotframework-ride-1.5.2.1

    其核心概念包括测试套件(Test Suite)、测试用例(Test Case)和步骤(Steps),这些步骤通常由关键字(Keywords)组成。关键词可以是自定义的或者预定义的,它们封装了具体的测试逻辑。 3. **RIDE 界面组件** - ...

    UE(官方下载)

    How to enable and disable autocorrect keywords with syntax highlighting Insert Menu Commands UltraEdit includes several special insert functions under the Insert menu. You can use these functions to ...

    登录页面源码

    charset=UTF-8"><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><title>ReadMe.io : Crowdsource Your Developer Hub</title><meta name="keywords" content="readme,...

    APKTool批处理版l

    3.在同时出现多个重复的关键字时,请谨慎修改,有些可能是定义函数的, 具体参考http://code.google.com/p/smali/source/browse/#svn/dalvik-docs/opcodes 4.保存时的文本编码要设置为ANSI格式,具体操作在菜单栏的...

Global site tag (gtag.js) - Google Analytics