📜 ⬆️ ⬇️

Automatically add keywords to files in TortoiseSVN under Windows

Subversion has the functionality of automatic substitution of embedded keywords. This feature allows you to add to the file, for example, such information as the last user who edited the file, revision and modification date.
At the moment, this functionality is very limited, but nevertheless it can be very useful. One of the main limitations is the need to add keyword processing for each new file. The same applies to renamed and moved files (SVN treats them as new).

Substituted Keywords [1]


According to the manual, there are the following auto substitutions:
  Date 
last modified date. $ Date $ is replaced by something like
  $ Date: 2006-07-22 21:42:37 -0700 (Sat, 22 Jul 2006) $ 
  Revision 
last revision with modification
  Author 
recent change author
  HeadURL 
repository path to the latest file version
  Id 
a combination of the previous information is obtained in a format like:
  $ Id: calc.c 148 2006-07-28 21: 30: 43Z sally $ 
where calc.c is the file name, 158 is the revision, after the date and time, and then the author

In one of the current projects in which I am participating, it was decided to use these auto-lookups in the SQL script headers. In particular, this will give the opportunity to version files and view the installed versions on the production server.
Initially adding keywords to the files was very simple. In TortoiseSVN 1.7, this process has become even simpler than in previous ones [2] . After a problem appeared - the developers did not always add versions to new files. Similarly, it happened after changing the project structure, when most of the files were organized by functionality.

Restrictions


The security policies of the company limited the developers' access to the server side of the repository, so there was no possibility to use server hooks.
Some developers have a limited set of software, which they do not intend to expand without a weighty argument. For example, some do not want to switch from TSVN 1.6.

Decision


As the most painless solution, it was decided to use an automatic script that will add these words to new and modified files.
Since not everyone has installed PowerShell, we will use BAT. And to get information about the repository and add keywords - Subversion Command-line Client (for example, installed with TSVN).
The result is the following script:
@echo off title Update tags rem %CD% - current directory :start rem for %%i in (*.tmp) do del %%i del *.tmp > nul svn status "%CD%\Sql" > svn_chg.tmp set CNT=0 :repeat set line="" for /f "eol= tokens=2 delims= " %%i in (svn_chg.tmp) do set line=%%i if "%line%"=="" goto ender if "%line%"=="""" goto ender SET /A CNT=%CNT%+1 echo %CNT%: %line% svn propset svn:keywords "Author Date Revision" "%line%">nul type svn_chg.tmp| find /v "%line%"> svn_chg1.tmp copy /Y svn_chg1.tmp svn_chg.tmp >nul goto repeat :ender del *.tmp > nul echo Press <Enter> to exit... pause 

Used functionality:


%CD%current directory
for %%i in (*.tmp) do del %%ideleting * .tmp files in a loop
svn status "%CD%\Sql" > svn_chg.tmpreading the list of modified / new files in the Sql directory in the svn_chg.tmp file
for /f "eol= tokens=2 delims= " %%i in (svn_chg.tmp) do set line=%%igetting the substring from the file path (take the last line)

Thus, developers have the opportunity to gradually add keyword support to their own files.
')

Alternative solutions


This script can be used in the client hook on Pre-Commit. Also for the hook, you can modify this script so that there is no “svn status” [3] .
As an extension of keywords, SubWCRev exists [4] . The solution using this utility was not originally envisaged, since the use of scripts was not supposed, they wanted everything “out of the box”. Perhaps there will be a migration later.
You can also customize your scripts on the build server (we have TeamCity), which, among other things, can add changes to the repository.
  1. svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html
  2. tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-propertypage.html#id597790
  3. tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-settings.html#tsvn-dug-settings-hooks
  4. tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html

Source: https://habr.com/ru/post/138941/


All Articles