Embedding subversion version information into HTML

Hi,

Say I want to display the subversion release number in the footer of
each page in order to track what version of a site I’m looking at.

I know subversion has a substitution keyword (LastChangedRevision)
that inserts the last known revision in which that file .changed.

So, if I stick $LastChangedRevision$ into
views/layouts/application.rhtml, it’ll show the last time that file
was changed, not the current version of the repository. W hich isn’t
quite what I want. Any ideas?

Thanks,
Joe

I haven’t found a solution other than to modify the keyworded file
every time I commit to svn.

Love to hear another solution, but since svn only commits modified
files, substitution can only happen when this file is changed.

Jodi

Don,

I use svn info inside of the checked out directory and then parse
results.

Here’s a method we use internally:

def svn_version
File.new(".svn/entries").each do |x|
if md = /^[\s]*url=".*tags/REL-([\d.-]+)/.match(x)
return md[1]
elsif md = /^[\s]*url=".*branches/([^/"]+)/.match(x)
return md[1]
elsif md = /^[\s]*revision="([\d]+)/.match(x)
return md[1]
end
end
return ‘(unknown version)’
end

… it does some nice things if you’ve deployed from a tag or a branch,
as well as just returning the raw revision number.

HTH

  • james

Joe Van D. wrote:

Hi,

Say I want to display the subversion release number in the footer of
each page in order to track what version of a site I’m looking at.

I know subversion has a substitution keyword (LastChangedRevision)
that inserts the last known revision in which that file .changed.

So, if I stick $LastChangedRevision$ into
views/layouts/application.rhtml, it’ll show the last time that file
was changed, not the current version of the repository. W hich isn’t
quite what I want. Any ideas?

Thanks,
Joe

You are simply not sing the right keyword, if you want the latest
revision place $Rev$ or $Revision$ somewhere in your code, the result
will be: “$Rev: 552 $”
One thing to keep in mind is that you need to make a change to the file
where you put the “$Rev$” keyword to make it change.

Joe Van D. wrote:

was changed, not the current version of the repository. W hich isn’t
quite what I want. Any ideas?

You could use svnversion to crawl your working copy redirect its output
into a
separate file that is included in all your views or use it in a sed like
command
to change each of your views.

http://svnbook.red-bean.com/en/1.2/svn.ref.svnversion.re.html

Regards,
Blair


Blair Z., Ph.D.
[email protected]ain.invalid
Subversion training, consulting and support
http://www.orcaware.com/svn/

Joe Van D. wrote:

was changed, not the current version of the repository. W hich isn’t

Hi Joe,
you can create dynamically partial template when deploying with
capistrano, for example add this code to deploy.rb

task :after_update_code, :roles => [:web] do
put(revision, “#{release_path}/app/views/layouts/_version.rhtml”)
end

and include it in layout with

Revision: <%= render_partial(’/layouts/version’)%>

hope that helps you,
Bojan M.


Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org

On 7/24/06, Julien S. [email protected] wrote:

views/layouts/application.rhtml, it’ll show the last time that file
where you put the “$Rev$” keyword to make it change.
$Rev$ is shorthand for $LastChangedRevision$.

The problem is that I don’t want to have to update the file in order
to get the repository version.

I think Bojan (thanks!) has the solution.

Joe

Can you use File.open to get at the info from your .svn directory?
If not, you could use open-uri to download the info from a repository.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs