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?
The working copy will be located in a directory called trunk on your computer relative to the directory you issued the command in. If you wish to have a different name for your working copy you can add that as a parameter to the end of the command. e.g. This will create a working copy called MyProjectSource .
A Subversion working copy is your own private working area, which looks like any other ordinary directory on your system. It contains a COPY of those files which you will have been editing on the website.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With