34

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?

Thomas S.
  • 5,804
  • 5
  • 37
  • 72
  • 1
    possible duplicate of [How do I Determine SVN Working Copy Layout Version?](http://stackoverflow.com/questions/1364618/how-do-i-determine-svn-working-copy-layout-version) – William Leara Jun 15 '14 at 23:01
  • 1
    A more general answer to this question already exists: http://stackoverflow.com/questions/1364618/how-do-i-determine-svn-working-copy-layout-version – William Leara Jun 15 '14 at 23:02
  • Possible duplicate of *[How do I determine the SVN working copy layout version?](http://stackoverflow.com/questions/1364618)*. – Peter Mortensen Nov 01 '15 at 20:26
  • 1
    This is not a duplicate, as the question linked above (thrice) does not cover 1.7 vs 1.8 - except for an answer that backlinks to this question. – zb226 Jan 07 '16 at 11:45

3 Answers3

48

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.

Subversion 1.8.0 SQLite database in Text viewer

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.

zb226
  • 9,586
  • 6
  • 49
  • 79
17

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
Shafeeque
  • 2,039
  • 2
  • 13
  • 28
-4

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.

bahrep
  • 29,961
  • 12
  • 103
  • 150
  • 3
    -1 Nope that's not it - just tried it with Subversion 1.7.13 vs 1.8.0 and they both output `12` in the `format` file. – zb226 Oct 09 '13 at 12:35
  • 1
    OK, but that still doesn't help distinguishing a 1.7 from a 1.8 WC - which is what the question was about. You cannot operate on a 1.7 WC with 1.8 and vice versa. – zb226 Oct 09 '13 at 12:58