Wednesday, November 17, 2010

Bookmark and Share
At my day job we are using the SVN property "svn:keywords" to let SVN replace the string "$Id$" with author name, revision number etc. within each Java source file.

One can add this property automatically when creating new files with the help of SVN's auto props feature. But from time to time someone, e.g. a new developer not knowing about auto props, checks in files without having the "svn:keywords" property set.

So I wondered how to identify such files in the repository. SVN doesn't provide a command answering that question, you only can retrieve all files having a certain property set.

But no problem, some shell magic to the rescue:

1
comm -23 <(sort <(sed 's/\.\///g' <(find . -name "*.java"))) <(sort <(sed 's/ - Id//g' <(svn propget svn:keywords * -R)))

So what's happening here? The basic idea is to list those files with the svn:keywords property set (svn propget) and compare this to a list with all files (find).

The outputs of both commands are brought into the same format using sed, sorted and then passed as parameters to the comm command, which compares two input files to each other. The -23 parameter causes only those lines to be put out which are only contained in file1 but not in file2, which are exactly the names of those files lacking the "svn:keywords" property.

I tested the command successfully on Mac OS X, but I think it should work pretty much the same way on other Unix systems, too.

4 comments:

Anonymous said...

Exactly what I needed. Thanks.

Gunnar Morling said...

Great that I could be of help. Thanks for your feedback, Gunnar

Anonymous said...

Nice, exactly what i was looking for.

Since i do not use the Id Tag, I use this more generic variant (.* instead of Id):
comm -23 <(sort <(sed 's/\.\///g' <(find . -name "*.java"))) <(sort <(sed 's/ - .*//g' <(svn propget svn:keywords * -R)))

Anonymous said...

> from time to time someone, e.g. a new developer not knowing about auto props, checks in files without having the "svn:keywords" property set.

Or, you know, an experienced developer who realizes that version control information belongs in the version control system and not in the source code...

Found this blog post helpful while looking for information on how to nuke these useless keywords from my code:

svn propdel svn:keywords . --recursive