Reputation: 6335
How can I find out the working copy version (SVN 1.7 vs. 1.8) by taking a look at files inside .svn
without using any SVN tool?
Upvotes: 35
Views: 37142
Reputation: 10510
I was wondering about this myself for a while and couldn't find an answer anywhere, not even by looking at the SQLite database. So I ended up looking into the Subversion source code, where I found that the version is indeed stored in the database, I just wasn't looking in the right place. Here's the relevant snippet from subversion/libsvn_subr/sqlite.c
:
svn_error_t *
svn_sqlite__read_schema_version(int *version,
svn_sqlite__db_t *db,
apr_pool_t *scratch_pool)
{
(...)
SVN_ERR(prepare_statement(&stmt, db, "PRAGMA user_version;", scratch_pool));
(...)
}
I wasn't even aware of the PRAGMA
statement, which, according to the SQLite documentation is...
...an SQL extension specific to SQLite and used to modify the operation of the SQLite library or to query the SQLite library for internal (non-table) data.
Thus, assuming a reasonably up-to-date version of SQLite on the PATH
you can do...
sqlite3 .svn/wc.db "PRAGMA user_version"
...in the root of your working copy, which will then yield e.g. 29
for Subversion 1.7.13 and 31
for Subversion 1.8.0. Unfortunately there seems to be no list correlating user_version
to the Subversion version, but if you're interested in what the format changes actually consist of, you can find them described in the sources in subversion/libsvn_wc/wc-metadata.sql
for format 20 onwards.
Update 1: Addressing the question of how to retrieve the value of user_version
without an SQLite executable: You need to read a DWORD
at offset 60
in the database file, as specified in the SQLite file format specification (see "1.2 The Database Header").
Update 2: To clarify further how to view it in a text/binary file viewer: Since the current version numbers are still pretty low and fit in a single byte (i.e. they're smaller than 255
) and a DWORD
is four bytes long, it's sufficient at the moment to look at the least significant byte - which is byte number 64
. Below is a screenshot of how it looks like in a Subversion 1.8.0 working copy's SQLite database file, which carries 31
for user_version
- as already mentioned above.
Update 3: I was always looking for a way to do such "binary queries" with a command-line tool, to avoid throwing perl or such at the problem. Turns out there's a *nix utility for that called od
(and I even got it in my collection of win32 ports, yay!). od
can get the least significant byte of user_version
like this:
od -An -j63 -N1 -t dC .svn/wc.db
This will again output 31
for Subversion 1.8.0 and so on.
Upvotes: 49
Reputation: 2069
If .svn/format exists, then read the number in it:
Version 7 is SVN 1.3
Version 8 is SVN 1.4
Version 9 is SVN 1.5
If .svn/format doesn't exist then the version number is on the first line in .svn/entries:
Version 10 is SVN 1.6
Version 12 is SVN 1.7
Upvotes: 19
Reputation: 30662
Can't find documentation on this so far, however the short answer is -- you can. Peek into \.svn\format
file. For example, number 12
there means that the working copy is of SVN 1.8 format. I assume that if it's of SVN 1.7, then you'll see 11
there.
Upvotes: -4