วันพุธ, กันยายน 12, 2550

การใช้คีย์เวิร์ดอัตโนมัติใน Subversion (keywords (tag) substitutions in Subversion)

ต่อจากบทความเก่า http://xoguy.blogspot.com/2007/05/tag-subversion.html ที่เคยแปะค้างๆไว้
ได้ลองใช้พวก tag (จริงๆในคู่มือเค้าเรียกว่า keyword) ต่างๆ ของ Subversion ดูแล้วเลยมาเมโม่เก็บไว้

ref: http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html

คีย์เวิร์ด
คีย์เวิร์ดที่ใช้มี 5 อันคือ
  1. Date (alias = LastChangedDate)
  2. Revision (alias = LastChangedRevision, Rev)
  3. Author (alias = LastChangedBy)
  4. Id (no alias)
  5. HeadURL (alias = URL)

วิธีการใช้
1. เพิ่มคีย์เวิร์ดเหล่านี้ไว้ในไฟล์ อย่างเช่นในคอมเม้นท์ตรงหัวไฟล์
/* foo.txt initiated 2007/05/05
* $Revision$ last committed rev
* $Author$ last committed author
* $Date$ last committed date
* $Id$ last committed Id
* $URL$ head URL
*/
2.
เซต property svn:keywords ของไฟล์ foo.txt เพื่อเซตให้คีย์เวิร์ดเหล่านั้นถูกแทนค่าตอนคอมมิต, Subversion จะไม่แทนค่าคีย์เวิร์ดเหล่านี้ถ้าหากเราไม่เซต การเซตให้ LastChangedDate กับ Author ถูกแทนค่าทำได้โดย
$ svn propset svn:keywords "Date Author" foo.txt
property 'svn:keywords' set on 'foo.txt'
3. คอมมิตซะ! คีย์เวิร์ดเหล่านี้ก็จะถูกแทนค่าโดยอัตโนมัติตอนคอมมิต


นอกจากนี้แล้วการแสดงผลแบบกำหนดความกว้างตายตัวเพื่อความสวยงามสามารถทำได้โดยเพิ่มโคล่อนสองอันไว้หลังคีย์เวิร์ดซะ ใช้รูปแบบ อย่างนี้
$Rev::               $:  Revision of last commit
$Author:: $: Author of last commit
$Date:: $: Date of last commit

--
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.

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.

ไม่มีความคิดเห็น: