You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by Nathan Haigh <n....@sheffield.ac.uk> on 2006/06/21 09:36:57 UTC

Get latest revision number for web app

I am using svn to track changes/version of a web application. I would 
like to be able to dynamically embed the revision number of the checkout 
code into the applications homepage using php. Does anyone know if this 
is possible or how this could be done.

What i have in mind is, that the code is checkout into a web directory 
and i want the apps homepage to display that revision number. In the 
mean time, i will continue updates on a working copy, making commits 
until i make another release of the app and check it out to the web 
directory again. I suppose i could just manually edit the file in web 
directory to display the checkout revision number, but this seems quite 
hacky.

Thanks
Nathan

RE: Get latest revision number for web app

Posted by "Nathan S. Haigh" <n....@sheffield.ac.uk>.
Excellent! This works perfectly. Thanks!

Nathan

> -----Original Message-----
> From: Ryan Schmidt [mailto:subversion-2006q2@ryandesign.com]
> Sent: 21 June 2006 11:04
> To: n.haigh@sheffield.ac.uk
> Cc: users@subversion.tigris.org
> Subject: Re: Get latest revision number for web app
> 
> On Jun 21, 2006, at 11:36, Nathan Haigh wrote:
> 
> > I am using svn to track changes/version of a web application. I
> > would like to be able to dynamically embed the revision number of
> > the checkout code into the applications homepage using php. Does
> > anyone know if this is possible or how this could be done.
> >
> > What i have in mind is, that the code is checkout into a web
> > directory and i want the apps homepage to display that revision
> > number. In the mean time, i will continue updates on a working
> > copy, making commits until i make another release of the app and
> > check it out to the web directory again. I suppose i could just
> > manually edit the file in web directory to display the checkout
> > revision number, but this seems quite hacky.
> 
> There is this FAQ entry:
> 
> http://subversion.tigris.org/faq.html#version-value-in-source
> 
> It's written for C programmers, but the idea is the same for any
> language: when you're ready to build or deploy your project, you run
> the "svnversion" command over the working copy, and put its output
> into a file. You can then read that file from within your application.
> 
> Thisolution is ideal for compiled languages like C because such
> programmers are already used to having to run a script (the makefile)
> to turn their code into something they can run, so this is a great
> place to incorporate a call to svnversion. In interpreted languages
> like PHP, we don't have to compile, so this may seem a bit unusual to
> PHP programmers like us.
> 
> In our deployed web sites, we essentially have a working copy on the
> production server which we can run "svn up" on when we want to pull
> down more-current code from the development server. Instead of
> calling "svn up" directly, consider writing a script "svnup.sh" (or
> "svnup.php" if you like) which does two things: first, it runs "svn
> up" as usual, and second, it runs "svnversion" and puts the result
> into a file "revision.txt" in a known location, which your PHP
> homepage can read in. Now you just need to train yourself to use your
> "svnup.sh" script instead of calling "svn up" yourself.
> 
> In case you're thinking of trying to skip the wrapper script by
> calling "svnversion" from within the code for your homepage, I'd
> advise against that, since that would be much slower than simply
> reading in a text file.
> 
> In fact, we've cheated a bit in our setup. It's a bit more
> complicated than I wrote above. We actually have a working copy of
> the last deployed tag of the project, and when we want to pull down a
> new release, we switch that working copy to the new tag. Then we
> export the working copy to a new directory named just like the tag.
> We have a script that automates all this. The trick is that when we
> make a new tag, we put the revision number into the tag name -- for
> example "1.4-7845". The web site then runs from a directory named
> "1.4-7845" and the page that wants to display the revision can simply
> extract it from its pathname. I'm not saying this is the best
> solution, or even a good one; it's just the compromise I was able to
> reach with the other programmers.

---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0625-4, 21/06/2006
Tested on: 21/06/2006 17:21:47
avast! - copyright (c) 1988-2006 ALWIL Software.
http://www.avast.com




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

Re: Get latest revision number for web app

Posted by Ryan Schmidt <su...@ryandesign.com>.
On Jun 21, 2006, at 11:36, Nathan Haigh wrote:

> I am using svn to track changes/version of a web application. I  
> would like to be able to dynamically embed the revision number of  
> the checkout code into the applications homepage using php. Does  
> anyone know if this is possible or how this could be done.
>
> What i have in mind is, that the code is checkout into a web  
> directory and i want the apps homepage to display that revision  
> number. In the mean time, i will continue updates on a working  
> copy, making commits until i make another release of the app and  
> check it out to the web directory again. I suppose i could just  
> manually edit the file in web directory to display the checkout  
> revision number, but this seems quite hacky.

There is this FAQ entry:

http://subversion.tigris.org/faq.html#version-value-in-source

It's written for C programmers, but the idea is the same for any  
language: when you're ready to build or deploy your project, you run  
the "svnversion" command over the working copy, and put its output  
into a file. You can then read that file from within your application.

Thisolution is ideal for compiled languages like C because such  
programmers are already used to having to run a script (the makefile)  
to turn their code into something they can run, so this is a great  
place to incorporate a call to svnversion. In interpreted languages  
like PHP, we don't have to compile, so this may seem a bit unusual to  
PHP programmers like us.

In our deployed web sites, we essentially have a working copy on the  
production server which we can run "svn up" on when we want to pull  
down more-current code from the development server. Instead of  
calling "svn up" directly, consider writing a script "svnup.sh" (or  
"svnup.php" if you like) which does two things: first, it runs "svn  
up" as usual, and second, it runs "svnversion" and puts the result  
into a file "revision.txt" in a known location, which your PHP  
homepage can read in. Now you just need to train yourself to use your  
"svnup.sh" script instead of calling "svn up" yourself.

In case you're thinking of trying to skip the wrapper script by  
calling "svnversion" from within the code for your homepage, I'd  
advise against that, since that would be much slower than simply  
reading in a text file.

In fact, we've cheated a bit in our setup. It's a bit more  
complicated than I wrote above. We actually have a working copy of  
the last deployed tag of the project, and when we want to pull down a  
new release, we switch that working copy to the new tag. Then we  
export the working copy to a new directory named just like the tag.  
We have a script that automates all this. The trick is that when we  
make a new tag, we put the revision number into the tag name -- for  
example "1.4-7845". The web site then runs from a directory named  
"1.4-7845" and the page that wants to display the revision can simply  
extract it from its pathname. I'm not saying this is the best  
solution, or even a good one; it's just the compromise I was able to  
reach with the other programmers.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org

RE: Re: Get latest revision number for web app

Posted by Arthur Penn <AP...@quilogy.com>.
Hello,

Is there no way to get the keyword substitution to only provide the revision number without the $Revision: xx$ text? I'd like to use the output in a build script to set a portion of the version number but the way the output is produced I have to parse it.

Cheers.

Arthur


-----Original Message-----
From: Andres Freund [mailto:andres@anarazel.de] 
Sent: Wednesday, June 21, 2006 6:11 AM
To: users@subversion.tigris.org; n.haigh@sheffield.ac.uk
Subject: Re: Get latest revision number for web app

Hi,


On Wednesday 21 June 2006 11:36, Nathan Haigh wrote:
> I am using svn to track changes/version of a web application. I would
> like to be able to dynamically embed the revision number of the checkout
> code into the applications homepage using php. Does anyone know if this
> is possible or how this could be done.
Look for svn:keywords in the svnbook:
http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.keywords
I dont see where you need to do something dynamically though, so perhaps i did 
misunderstand you.

Greetings,

Andres

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org


Re: Get latest revision number for web app

Posted by Andres Freund <an...@anarazel.de>.
Hi,


On Wednesday 21 June 2006 11:36, Nathan Haigh wrote:
> I am using svn to track changes/version of a web application. I would
> like to be able to dynamically embed the revision number of the checkout
> code into the applications homepage using php. Does anyone know if this
> is possible or how this could be done.
Look for svn:keywords in the svnbook:
http://svnbook.red-bean.com/nightly/en/svn.advanced.props.html#svn.advanced.props.special.keywords
I dont see where you need to do something dynamically though, so perhaps i did 
misunderstand you.

Greetings,

Andres

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org