$Revision$ keyword expansion with git-svn

I just ended up needing to do subversion keyword expansion on a bunch of files in a subversion repository I track with git, but git-svn doesn't do that kind of thing. So I hacked up a tiny shell script I called git-svn-keyword-expand, which looks like this:
#! /bin/zsh
typeset -A revs
for n in {1..$#files} ; do
h=$(git log -n 1 --pretty=format:%H -- $f)
revs[$h]=${revs[$h]-$(git svn find-rev $h)}
perl -pi -e 's/\$Revision[ :\d]*\$/\$Revision: '${revs[$h]}' \$/gp' $f

Just feed it a list of files, and it'll update them in place to whatever current revision they are at. It's a rather dumb tool, which doesn't cross reference the file list with which of those files actually have an svn:keywords property including Revision in it, and it doesn't do any other keywords, but people that want that kind of thing might at least grab this as a starting point. Cheers!
blog comments powered by Disqus