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:

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.


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

Anonymous said...

Thank you for this tip.. Exactly what I needed.

The value of the keywords properties is in the eye of the beholder. It is there for a single reason: it is useful for a large group of users.

Some developers love to type commands to find information that can be just read by looking at the top of the file, and it requires no effort to be updated.

Brett Randall said...

I run this in a single find. For example, the following finds Java files which do not have svn:eol-style=native:


find . -name "*.java" -print |
(while read javaFile
eolStyle=`svn propget svn:eol-style $javaFile`
if [ "$eolStyle" != "native" ]; then
echo $javaFile ":" $eolStyle

Cara Menyembuhkan otitis Media (Radang Telinga Tengah) Secara Alami said...

Never gonna give up
Cara Menyembuhkan otitis Media (Radang Telinga Tengah) Secara Alami

Obat Herbal Gula Darah Tinggi Terbaik said...

Great article on our site. Keep up the good writing.
Obat Herbal Gula Darah Tinggi Terbaik

dewi suherman said...

Obat Benjolan Di Bibir Vagina

Cara Mengobati Luka Bakar

bela said...

Obat Menghilangkan flek hitam ekas jerawat
Obat Mengatasi Telat Datang Haid
Obat perut keras dan kembung
Obat Menghilangkan Benjolan Lipoma
Obat prurigo secara alami

bela said...

Obat farry liver
Obat impetigo pada anak
Obat penyakit liver

bela said...

Obat Asam Lambung Naik

bela said...

Obat Gatal di Sekitar Kemaluan

bela said...

bela said...

cara mengobati telinga berair

bela said...

Obat Cantegan Bodo Isi

bela said...
This comment has been removed by the author.
bela said...

Obat Cacingan