0

I have a script who creates new tags in a SVN, and add some files. I want to automate this task so I would like to find some way to do automatically the incrementation for the tags name, from 1.0 to X.0.

I thought about a conf file who would contains "1.0" as a first version number and who would be overwrite at each call to the script. But not sure I can get the "1.0" value from the file and then do an incrementation on it in my script.

Any help would be really appreciate.

Thanks in advance

Greezer
  • 231
  • 1
  • 5
  • 19

3 Answers3

2

Take a look at keywords in Subversion using autoprops.

First, setup subversion to honor keyword expansion

enable-auto-props = yes

[auto-props]
version.txt = svn:keywords=Revision

Then, setup a simple file, let's call it version.txt with the $revision$ keyword and some random content.

$revision$
Random content

Then, in your batch file, recreate the version.txt file with new random content

echo $revision$ >version.txt
echo %random% %date% %time% >>version.txt

and check in this new file every time your batch file is run, so it will become

$revision 32 $
4214 Mon 21/01/2013 15:53:27,62 

This way, subversion will keep an accurate version number of all the runs of the batch file, even in multiple clients and simultaneosly.

You might then extract and use the revision number from version.txt with code similar to

for /f "tokens=1,2" %%a in (version.txt) do (
   if %%a==$revision (
     echo Revision number is %%b
     echo do something with %%b, create %%b tag or whatever
   )
)
PA.
  • 28,486
  • 9
  • 71
  • 95
  • +1, Though a random number could generate a consecutive duplicate. Why not include `%date%` and `%time%` in addition to %random% in the version file? As long as multiple runs are at least 0.01 seconds apart it will then be guaranteed to be unique. – dbenham Jan 21 '13 at 14:18
2

Don't create a seed configuration file. Instead, let the batch script default to 1.0 if file does not exist.

@echo off
setlocal
set "conf=version.conf"
if not exist "%conf%" (set version=1.0) else (
  for /f "usebackq delims=." %%N in ("%conf%") do set /a version=%%N+1
)
set "version=%version%.0"
(echo %version%)>"%conf%"

I'm assuming you will never run this process multiple times in parallel - it can fail if you do run in parallel. Modifications can be made to lock the conf file so you can run in parallel if need be. See the accepted answer to how to check in command line if given file or directory is locked, that it is used by a process? for more info.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
1

Since you don't say what language you want to use only general remarks can be given:

It certainly is possible to maintain a small 'version' file holding the 'dottet version number', something like 0.2.6 maybe. That files content can be read by any process. You should implement a little collection of methods to split that content into its numerical tokens (major and minor version and the like). Those numerical values can be processed by any mathematical function you like to use. For example you can increment them. Another method would be some 'implode' function that takes the numerical tokens and creates again a 'dottet version number' (now maybe 0.2.7...) and finally you can write that information back into the file. It certainly makes sense to allow an argument that controls which part of the version should be incremented.

Such scheme is not really efficient, but often sufficient.

Note, that such approach will only work if you can guarantee that it is always only a single process to access that version file. Otherwise multiple processes might overwrite each others results which certainly is a cause of problems.

As an alternative, maybe a more elegant alternative, you might consider treating the subversion repository itself as seed storage for your version number: instead of reading a special files content (what if that file is deleted or something else happens?) make a request to the tags folder inside subversion. It should contain all previously tagged versions. So that is precisely the information you want. Take all version numbers, sort them, take the highest one and process it as above.

arkascha
  • 41,620
  • 7
  • 58
  • 90