Subversion keywords and unicode
I'm editing some text files, and I like to use subversion to do this. It helps with managing my own different revisions of the files, and can mark them automatically with metadata.
(Subversion is a version control system--you create a repository, work on a local copy, then commit changes to the repository when you're satisfied with them. Programmers use version control systems to keep track of giant code bases, so you can prepare new versions of software while at the same time release bug fixes for previous versions. But there's no reason why the files managed need to be an executable piece of software--it can be a website or a single text file. And there's no reason why you need more than one developer to have a version control system in place.)
Anyway, subversion allows you mark keywords in your file to keep track of some metadata. For instance, I like to note the date when a file was last committed (had changes saved to the repository). To do this, you use the string "$Date$" in the file. Then you declare that you want this keyword substituted. On the command-line, assuming you're in a checked-out working copy of the version-controlled directory, you type
$ svn propadd svn:keyword Date foo.txt
When you next check the status, you will find that the file's metadata has been changed:
$ svn status M foo.txt
The "M" appearing in the second column rather than the first indicates a modification to metadata rather than actual file content. Commit the changes, then the next time you commit or update the file, you will see the string "$Date$" has been changed to "$Date: <actual date committed>$"
Pretty cool, except I'm having trouble getting this to work on unicode files. I don't always need unicode but I feel cutting-edge when I use it. Even after setting the property and committing changes the keyword stayed unsubstituted. I finally got it to work by writing the property value "in unicode." My workaround is extremely inelegant, the epitome of muddling through, but it does do the job.
- Create a file with the property value in it. In this case, the property value is just the word "Date". I'm using Aquamacs, an emacs build for Mac OS X. There is a set of keystrokes in emacs to change the text encoding for a file, but I keep forgetting it. Instead, I use a local variable and save the file. One way to do this is to declare at the end of the file:
Local variables: coding: utf-8
(Eight bits is all the unicode I need, which is lucky because that's all subversion supports.) Save the file, and a little "u" appears in the emacs status line, letting you know the change of encoding. Save the file to some descriptive name like "svn-keywords-utf8.txt"
- Set the property value. Subversion allows you to set property values from a file, not just on the command line.
$ svn propset svn:keyword -F svn-keywords-utf8.txt foo.txt
- Commit as before.