推广 热搜: page  考试  小红  红书  数据  论文  数据分析  关键词  哪些  搜索 

Keyword Substitution

   日期:2025-01-02     移动:https://sicmodule.kub2b.com/mobile/quote/18129.html

Subversion has the ability to substitute —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 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 keyword. You control where the keyword is inserted into your document by placing a at the desired location in the file. This anchor is just a string of text formatted as .

Adding keyword anchor text alone 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 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 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 that looks like this:

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

Now you have made a local property modification on the 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 keyword, 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 property 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 , 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 keyword was not substituted because we didn't ask for it to be.

Note also that we set the property to , yet the keyword anchor used the alias and still expanded correctly:

If someone else now commits a change to , 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 file will be resubstituted with information that reflects the most recent known commit to that file.

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 property to be case-sensitive, too—for the sake of backward compatibility, 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 keywords, some of which have aliases that you can also use:

Several of the preceding descriptions use the phrase or similar wording. Keep in mind that keyword expansion is a client-side operation, and your client 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.

In addition to previous set of stock keyword definitions and aliases, Subversion 1.8 allows you the freedom to define and use custom keywords. To define a custom keyword, add a token to the value of the property which is of the form , where is the keyword name (which you'll use in the keyword anchor) and is a format string into which information will be substituted when your keyword is expanded inside your file.

The format string syntax used for custom keywords supports the following format codes:

As you can see, many of the individual format codes serve as placeholders for the same information available through the stock keywords. But of course, the custom keyword format allows you to more flexibly string together multiple bits of information. For example, you might wish to have a single keyword in your files which reports the repository relative path of the file and last-changed revision, formatted in a pleasant, human-readable way. To do so, you'd first define your custom keyword:

Next, you'd edit the file's contents to add the keyword anchor for your custom keyword, which in this case is . After committing these changes, an examination of your file's contents will show that your custom keyword was substituted as you would expect—where previously the file contained , it now reads .

You can also instruct 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:

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:

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:

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 and are padded with spaces, and the long field is truncated by a hash character:

本文地址:https://sicmodule.kub2b.com/quote/18129.html     企库往 https://sicmodule.kub2b.com/ , 查看更多

特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


0相关评论
相关最新动态
推荐最新动态
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号