Category Archives: TurtoiseSVN

TurtoiseSVNのコマンドでSubVersionのRevisionをexeファイルに埋め込む方法

TurtoiseSVNに標準で含まれているSubWCRev.exeを使ってレビジョン番号を表示、ファイル出力が可能です。

コマンドの例として以下のコマンドでテンプレートファイル(Version_Tempalte.h)内のキーワードを書き換えて、Version.hファイルに出力します。

"c:\Program Files\TortoiseSVN\bin\SubWCRev.exe" . Version_Template.h Version.h -nmdfe

すでにVersion.hファイルが存在すると、エラーになるのでVersion.batファイルを使ってファイルを削除するコマンドを追加します。Version.batファイルの内容は以下の通り。

cd %~dp0
IF EXIST Version.h del Version.h
"c:\Program Files\TortoiseSVN\bin\SubWCRev.exe" . Version_Template.h Version.h -nmdfe

cd %~dp0 は、カレントディレクトリを現在のフォルダに移動するコマンドです。Version.hファイルをソリューションフォルダに置いた場合、プロジェクトのビルドはプロジェクトフォルダがカレントになるので、ソリューションフォルダに移動するようにします。

プロジェクト側の設定は、.rc ファイルにVersion.hをインクルードして、変数を下記のように書きます。

Version.batコマンドをプロジェクトのPREBUILDイベントコマンドに追加してプロジェクトをリビルドして.exeファイルのファイルの詳細を確認して完了です。

#include "..\Version.h"
.....
FILEVERSION FILE_VERSION
PRODUCTVERSION PRODUCT_VERSION
"c:\Program Files\TortoiseSVN\bin\SubWCRev.exe"
SubWCRev 1.8.11, Build 26392 - 64 Bit

Usage: SubWCRev WorkingCopyPath [SrcVersionFile DstVersionFile] [-nmdf]

Params:
WorkingCopyPath    :   path to a Subversion working copy.
SrcVersionFile     :   path to a template file containing keywords.
DstVersionFile     :   path to save the resulting parsed file.
-n                 :   if given, then SubWCRev will error if the working
                       copy contains local modifications.
-N                 :   if given, then SubWCRev will error if the working
                       copy contains unversioned items.
-m                 :   if given, then SubWCRev will error if the working
                       copy contains mixed revisions.
-d                 :   if given, then SubWCRev will only do its job if
                       DstVersionFile does not exist.
-q                 :   if given, then SubWCRev will perform keyword
                       substitution but will not show status on stdout.

-f                 :   if given, then SubWCRev will include the
                       last-committed revision of folders. Default is
                       to use only files to get the revision numbers.
                       this only affects $WCREV$ and $WCDATE$.
-e                 :   if given, also include dirs which are included
                       with svn:externals, but only if they're from the
                       same repository.
-E                 :   if given, same as -e, but it ignores the externals
                       with explicit revisions, when the revision range
                       inside of them is only the given explicit revision
                       in the properties. So it doesn't lead to mixed
                       revisions

-x                 :   if given, then SubWCRev will write the revisions
                       numbers in HEX instead of decimal
-X                 :   if given, then SubWCRev will write the revisions
                       numbers in HEX with '0x' before them

Switches must be given in a single argument, e.g. '-nm' not '-n -m'.

SubWCRev reads the Subversion status of all files in a working copy
excluding externals. If SrcVersionFile is specified, it is scanned
for special placeholders of the form "$WCxxx$".
SrcVersionFile is then copied to DstVersionFile but the placeholders
are replaced with information about the working copy as follows:

$WCREV$         Highest committed revision number
$WCREV&$        Highest committed revision number ANDed with the number
                after the &
$WCREV+$        Highest committed revision number added with the number
                after the &
$WCREV-$        Highest committed revision number subtracted with the
                number after the &
$WCDATE$        Date of highest committed revision
$WCDATE=$       Like $WCDATE$ with an added strftime format after the =
$WCRANGE$       Update revision range
$WCURL$         Repository URL of the working copy
$WCNOW$         Current system date & time
$WCNOW=$        Like $WCNOW$ with an added strftime format after the =
$WCLOCKDATE$    Lock date for this item
$WCLOCKDATE=$   Like $WCLOCKDATE$ with an added strftime format after the =
$WCLOCKOWNER$   Lock owner for this item
$WCLOCKCOMMENT$ Lock comment for this item


The strftime format strings for $WCxxx=$ must not be longer than 1024
characters, and must not produce output greater than 1024 characters.

Placeholders of the form "$WCxxx?TrueText:FalseText$" are replaced with
TrueText if the tested condition is true, and FalseText if false.

$WCMODS$        True if local modifications found
$WCMIXED$       True if mixed update revisions found
$WCEXTALLFIXED$ True if all externals are fixed to an explicit revision
$WCISTAGGED$    True if the repository URL contains the tags classification patt
ern
$WCINSVN$       True if the item is versioned
$WCNEEDSLOCK$   True if the svn:needs-lock property is set
$WCISLOCKED$    True if the item is locked