Script to write or update latest subversion revision

Discuss and share scripts and script files...
Post Reply
avsfan
Posts: 554
Joined: 29 Jun 2006 09:00
Location: Fort Collins, Colorado

Script to write or update latest subversion revision

Post 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):

Code: Select all

#define mybuild "0049"
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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script to write or update latest subversion revision

Post 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.

avsfan
Posts: 554
Joined: 29 Jun 2006 09:00
Location: Fort Collins, Colorado

Re: Script to write or update latest subversion revision

Post 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

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Script to write or update latest subversion revision

Post by TheQwerty »

I think you'd be better off using a post-commit hook within Subversion than using XY for this.

avsfan
Posts: 554
Joined: 29 Jun 2006 09:00
Location: Fort Collins, Colorado

Re: Script to write or update latest subversion revision

Post by avsfan »

TheQwerty wrote:I think you'd be better off using a post-commit hook within Subversion than using XY for this.
AHA! :idea: 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

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Script to write or update latest subversion revision

Post 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? :D

avsfan
Posts: 554
Joined: 29 Jun 2006 09:00
Location: Fort Collins, Colorado

Re: Script to write or update latest subversion revision

Post 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! :idea: 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

carmenm

Re: Script to write or update latest subversion revision

Post 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/

Post Reply