找出 SVN 工作副本版本(1.7 或 1.8) [英] Find out SVN working copy version (1.7 or 1.8)
问题描述
如何在不使用任何 SVN 工具的情况下通过查看 .svn
中的文件来找出工作副本版本(SVN 1.7 与 1.8)?
我自己也想过这个问题,但在任何地方都找不到答案,甚至通过查看 SQLite 数据库也找不到.所以我最终查看了 Subversion 源代码,在那里我发现版本确实存储在数据库中,只是我没有找对地方.这是来自 (我什至在我的 win32 端口集合中得到了它,是的!).od
可以像这样获取 user_version
的最低有效字节:
od -An -j63 -N1 -t dC .svn/wc.db
这将再次为 Subversion 1.8.0 等输出 31
.
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?
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.
这篇关于找出 SVN 工作副本版本(1.7 或 1.8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!