Find out SVN working copy version (1.7 or 1.8)

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?

  • How do you stop SVN Checkout from bringing back files that were deleted from the project?
  • SVN to Git tags in weird location
  • How to merge my local project with a github project?
  • checkout svn+ssh with loginname
  • Can different git-svn clones of the same svn repository expect to be able to share changes then git svn dcommit?
  • Integrating SVN with kwallet
  • Tracking upstream svn changes with git-svn and github?
  • All-in-1 decentralized project management git+tickets+wiki
  • 3 Solutions collect form web for “Find out SVN working copy version (1.7 or 1.8)”

    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.

    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
    

    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.

    Git Baby is a git and github fan, let's start git clone.