2016-09-06

Extract subversion metadata directly from checkout, without subversion tools

Hello readers!

By now, you suspect that I am an avid subversion user, or at least a professional programmer, so yes. I might as well admit it.

The following trick is not for the showroom. I had to work with incompatible subversion versions. It usually is a pain to work with different versions of subversion. Checkouts are incompatible.

Anyway, I had to find the author and revision number of the last commit in a given checkout, without having the proper subversion command line tool at hand. It can be done, because subversion metadata resides in a sqlite3 database in the .svn directory.

This is the magic incantation:

sqlite3 .svn/wc.db "select changed_author,changed_revision from NODES order by changed_revision desc limit 1;"

There are many other interesting items to be found in .svn/wc.db and the database schema seems to be fairly stable since subversion 1.6 or so.

2016-09-02

following code through history, in subversion and git

Both, git and subversion, have the famous "blame" command, which allows me to see, line by line, who changed this line of code last.

Sometimes it is not the latest modifier of a line who is its true author. For example when a programmer added or removed whitespace for better readability, she will then be "blame"d as it's author, even though she is not.

In this case, it is possible to give the blame command an additional agrument, saying "look at the file in this revision, and tell me who brought it up to that state, line by line".

in subversion:

$svn blame filename
   649     joe  today's code
$svn blame filename -r648
  171     jim previous code
$svn blame filename -r170
 svn: Unable to find repository location for 'filename' in revision 170

in git:

$ git blame filename
3c9fb2a17 (Joe 2016-09-01 16:43:11 +0200 1) today's code
$ git blame filename 3c9fb2a17^
 98bcec40b (Jack 2016-06-23 18:04:55 +0200 1) previous code
$ git blame filename 98bcec40b^
fatal: no such path filename in 98bcec40b^

Note the caret (^) you have to add to the end of the git hash. It means "the previous commit from that designated by the hash". In subversion, where everything is nicely ordered, you simply subtract one in order to get the same effect.

One day I might write a script that traces the history of a single line of code back to its creation. Please tell me if this has already been done.