Adding SVN Information to File Headers Revisited

 

You may already be familiar with my previous post on Adding SVN Information to File Headers. After further review, I have decided to update the content to be more explicit. I want to better define how to establish the keywords and their usage in subversion repositories.

If you want to apply a standardized header to the files you are committing to your svn repository, you must first define the keyword list that you want to use. For this explanation and ease of use, I will use the same set of keywords I used in the previous post. Here is the sample header you can add to the top of your file. I use this specifically with php.

 


It’s important to note two things. First, the keyword is case sensitive. Second, the keyword is enclosed by to dollar signs. This tells svn that it is in fact the keyword it is looking for to replace.

There are two ways to establish the keyword list with svn. I will first describe the simplest method for establishing the svn keyword set. It is to set the keyword properties in your ~/.subversion/config file. To do that, follow these steps:

  1. Open a terminal screen and make sure you are in your home directory: cd ~/
  2. Open the .subversion/config file for editing: vi ~/.subversion/config
  3. Find the [miscellany] section of the file by using the command: /[misc and hit Enter
  4. Down arrow to enable-auto-props and make sure it is set as: enable-auto-props = yes
  5. Next, find the [auto-props] section of the file by using the command:/[auto and hit Enter
  6. Scroll to the bottom of the section (most likely the end of the file) and add:*.php = svn:keywords:Date Author Id Copyright Revision License URL

The keywords for subversion have been established on your machine for your user. This is not a global setting that is applied to the repository itself, only to your box and the user name you are running the updates from. Also, if you prefer to set the keywords specifically for only certain files, you can do so from withing the checkedout repository by running:

svn propset svn:keywords “list of keywords here” name_of_file.ext

The name_of_file.ext is the file within the repository you want to establish the list of keywords for.

Now that we have the keywords established, we need to understand that svn only recognizes some of the keywords by default. You can find the list at thesubversion site. The list is as follows:

  • Date (may also be specified as LastChangeDate)
  • Revision (may also be specified as LastChangedRevision or Rev)
  • Author (may also be specified as LastChangedBy)
  • HeadURL (may be abbreviated as URL)
  • ID

The other 4 keywords for use with svn will need to be set differently. Since the className and subClass name will not change for the given file, you can just manually add that once and it will stay in the actual file. There is no need to update it.

The other two keywords need to be defined using the propset command on the subversion command line. This will define the values for the keywords for all files within your checked out version. Test set the keyword value for copyright, run the following command from the root directory of your checked out repository:

svn propset Copyright “(c)2009 My Company Name. All Rights Reserved” ./*

I want to bring your attention to two things. First, you will need to change the information between the quotes to make sure the copyright reads the way you want it to. Second, I want you to notice the ./* on the end. This basically tells subversion that this will apply to all of the svn specific files for the repository you are in.

The next keyword is set in a similar fashion. The only difference is, you define the license by pointing to a specific file within the repository. So if your license file is in the main subversion directory, you will run the following command:

svn propset License -F ./path/to/license ./*

Again, make sure the ./path/to/license is an actual path and file name from within the repository. Also note the same usage of the directory application setting of ./* to which this keyword will be applied.

A word of warning. The keyword fields are measured in bytes, so there is some risk of corruption if using multi-byte characters. Be sure to read up on the subversion docs if you have any concerns as this is outside the scope of this topic.

That should do it. You now have what it takes to set the headers in all of your repository files. If you use this, please feel free to post your comments and/or feedback.

 

Ref: http://blogchuck.com/2009/09/adding-svn-headers-revisited/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值