Page 1 of 1
Script to write or update latest subversion revision
Posted: 24 Feb 2010 23:50
by avsfan
Hi scripting gurus,
I currently use Subversion, and it's working well for me. I'm trying to figure out the best way to get the latest revision number from Subversion into my build code. (It seems it must be simple, but my brain has locked up when it comes to this!)
The command "svnlook youngest c:/myrepositorypath" will return a single number of the latest revision number (for example, 49). I'd like to be able to write this number, surrounded by double quotes, to 2 different files, using 4 decimal places (leading zeros to make a 4-digit string). I can either modify an existing file or write a new file each time, as the two files needed can each be a single line.
For example, after calling my script, the data in the first file would look like this (assuming a current revision number of 49):
The two files names will not change, so that part can be hardcoded as well.
I know this shouldn't be hard to do, but I'm just not thinking about it correctly!
Thanks in advance!
andy
Re: Script to write or update latest subversion revision
Posted: 25 Feb 2010 19:51
by Stefan
Hi andy.
How did this works:
avsfan wrote:The command "svnlook youngest c:/myrepositorypath"
will return a single number of the latest revision number (for example, 49).
?
Is this an dos command line?
Please show what you do to get the '49' and where you see this number incl. the complete surrounding output.
Re: Script to write or update latest subversion revision
Posted: 25 Feb 2010 19:57
by avsfan
Stefan wrote:avsfan wrote:The command "svnlook youngest c:/myrepositorypath"
will return a single number of the latest revision number (for example, 49).
Is this an dos command line?
Please show what you do to get the '49' and where you see this number incl. the complete surrounding output.
Yup, sorry -- dos command line.
Code: Select all
C:\temp>svnlook youngest c:/myreposdir
49
So the command just writes the number to stdout, so I can just redirect to a file (or capture it directly) as needed...
I hope that helps to clarify things...
thanks!
andy
Re: Script to write or update latest subversion revision
Posted: 25 Feb 2010 20:40
by TheQwerty
I think you'd be better off using a post-commit hook within Subversion than using XY for this.
Re: Script to write or update latest subversion revision
Posted: 25 Feb 2010 21:01
by avsfan
TheQwerty wrote:I think you'd be better off using a post-commit hook within Subversion than using XY for this.
AHA!

I had never heard of post-commit hooks, but at first glance they look like they might be just what I need!
I'll give it a look!
Thanks!
andy
Re: Script to write or update latest subversion revision
Posted: 25 Feb 2010 21:13
by Stefan
C:\temp>svnlook youngest c:/myreposdir > C:\Temp\svnlookyoungest.txt
Code: Select all
//Run "cmd /k ""C:\temp>svnlook youngest c:/myreposdir "" > C:\Temp\svnlookyoungest.txt";
//wait 1000; // maybe you may need to wait more then one second?
$youngest = readfile("C:\Temp\svnlookyoungest.txt");
while(strlen($youngest)<4){
$youngest = 0$youngest;}
msg quote($youngest);
/*
writefile(filename, data, [on_exist], [mode])
on_exist
o: [default] create new file/if existing: overwrite
a: create new file/if existing: append
n: create new file/if existing: do nothing
writefile("C:\Temp\svnyoungest.txt", quote($youngest), 0);
*/
I don't know if have have wrote/quote the run command right.
HTH?

Re: Script to write or update latest subversion revision
Posted: 26 Feb 2010 23:43
by avsfan
avsfan wrote:TheQwerty wrote:I think you'd be better off using a post-commit hook within Subversion than using XY for this.
AHA!

I had never heard of post-commit hooks, but at first glance they look like they might be just what I need!
Update: the post-commit hook seems to be perfect! I just create a new file each time with the latest commit version, and then read it as needed -- SWEET!
Thanks, TheQwerty!
andy
Re: Script to write or update latest subversion revision
Posted: 27 Feb 2010 21:41
by carmenm
That s one way to do it. Actually there are a lot cleaner and powerful solutions.
In my company we use CMake to do that kind of thing. cmake is kind of a make alternative. You can use it with any compiler(we use mingw, vs2005, vs2008, darwin) and it helps generate automated files that you can use during you build.
For example when necessary during a build, cmake will update a .h file with svn latest commit revision, date. It will also generate a similar rc file to be used while generating exe files. And you get dependency!!!!
And it s only such a small part of what cmake can do!
It s also very simple to deploy even for a small project.
You should have a look at it
http://www.cmake.org/