<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LlamaLabs &#187; subversion</title>
	<atom:link href="http://llamalabs.com/category/subversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://llamalabs.com</link>
	<description>Wisdom of the llama</description>
	<lastBuildDate>Sun, 06 Sep 2009 07:29:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Keyword Substitution in Subversion</title>
		<link>http://llamalabs.com/2009/07/21/using-keyword-substitution-in-subversion/</link>
		<comments>http://llamalabs.com/2009/07/21/using-keyword-substitution-in-subversion/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 07:45:02 +0000</pubDate>
		<dc:creator>kanske</dc:creator>
				<category><![CDATA[subversion]]></category>
		<category><![CDATA[version control]]></category>

		<guid isPermaLink="false">http://llamalabs.com/?p=38</guid>
		<description><![CDATA[Many times I&#8217;ve been looking at a configuration file on a server, wondering who made the last change to this file? What did they change? Whatever they did, it broke something.
When there&#8217;s more than one person making changes to system configuration, I like to keep that system configuration under version control. It makes it easier [...]]]></description>
			<content:encoded><![CDATA[<p>Many times I&#8217;ve been looking at a configuration file on a server, wondering who made the last change to this file? What did they change? Whatever they did, it broke something.</p>
<p>When there&#8217;s more than one person making changes to system configuration, I like to keep that system configuration under version control. It makes it easier to track who is making configuration changes, it provides a history of the changes, and you can set up a post-commit hook to notify team members about the changes that are being committed.</p>
<p>One nice feature in Subversion is <a href="http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html">Keyword Substitution</a>. Keyword substitution allows you to embed keyword anchors into your file that get expanded to show useful information about the file such as the revision, revision date, URL.</p>
<p>I like to embed the Id and the Url near the top of configuration files in a comment block. The Id contains filename, revision, revision time, and user and the Url describes the full URL to the latest version of the file in the repository.</p>
<p>Whenever I encounter a configuration file in a system that has these substitutions in place, I can immediately tell where I need to go in order to check out and commit changes to the file.</p>
<p>Below is an example of how to use Subversion&#8217;s keyword substitution. I&#8217;ll set up a local subversion repository, add a file and do the keyword substitution. I&#8217;m going to do this on my macbook.</p>
<p>First, create an empty repository called &#8217;system&#8217;:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook ~ $ sudo mkdir /usr/local/svn
macbook ~ $ sudo chown $USER /usr/local/svn
macbook ~ $ sudo chgrp $USER /usr/local/svn
macbook ~ $ svnadmin create /usr/local/svn/system
macbook ~ $</pre></div></div>

<p>Next, check out the repository and change directory into the checked out copy. Note, I&#8217;m skipping the normal repository structure (trunk, tags, branches) to keep things simple.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook ~ $ svn co file:///usr/local/svn/system system
Checked out revision 0.
macbook ~ $ cd system/
macbook ~ $</pre></div></div>

<p>Make a sample configuration file full of comments:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ cat &gt;sample.cfg&lt;&lt;EOD
&gt; # this is a sample configuration file
&gt; #
&gt; # \$Id\$
&gt; # \$URL\$
&gt; #
&gt; EOD
macbook system $</pre></div></div>

<p>Add the file to the repository:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ svn add sample.cfg 
A         sample.cfg
macbook system $ svn ci -m 'adding sample config file to demonstrate keyword substitution'
Adding         sample.cfg
Transmitting file data .
Committed revision 1.
macbook system $</pre></div></div>

<p>Notice how the keyword anchors are in the file, not the substitutions.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ cat sample.cfg 
# this is a sample configuration file
#
# $Id$
# $URL$
#
macbook system $</pre></div></div>

<p>We&#8217;ll need to enable the keyword substitution for sample.cfg using &#8217;svn propset svn:keywords&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ svn propset svn:keywords &quot;Id URL&quot; sample.cfg
property 'svn:keywords' set on 'sample.cfg'
macbook system $ svn st
 M     sample.cfg
macbook system $ svn ci -m 'enabling keyword substitution for Id and URL on sample.cfg'
Sending        sample.cfg
&nbsp;
Committed revision 2.
macbook system $</pre></div></div>

<p>Now let&#8217;s look at our configuration file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ cat sample.cfg 
# this is a sample configuration file
#
# $Id: sample.cfg 2 2009-07-22 06:46:35Z dustin $
# $URL: file:///usr/local/svn/system/sample.cfg $
#
macbook system $</pre></div></div>

<p>There&#8217;s our Id and URL. Note, if you checked out an existing repository over HTTP(S) or SSH, the URL would reflect that URL. So for a team accessing the SVN repository through Apache+WebDAV the example may look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">macbook system $ cat sample.cfg 
# this is a sample configuration file
#
# $Id: sample.cfg 2 2009-07-22 06:46:35Z dustin $
# $URL: https://svn.example.com/svn/system/sample.cfg $
#
macbook system $</pre></div></div>

<p>Make sure to read through the docs at <a href="http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html">Keyword Substitution</a> for more examples and additional details.</p>
]]></content:encoded>
			<wfw:commentRss>http://llamalabs.com/2009/07/21/using-keyword-substitution-in-subversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
