getting svn version info from inside rails application

hi,

who has an example of how to retrieve svn-version information from inside a rails application.

i'd like to display this information to the user, so that he can report a bug relating to the version number.

retrieving should be quick as it is displayed on every view.

many thanks in advance, siegi

You could parse the results of `svn info` then store it in a cached class variable in your ApplicationHelper. In production mode, `svn info` would only be called once.

  def svn_revision     (@@svn_revision rescue false) or       @@svn_revision = `svn info`.scan(/Revision: (\d+)/)[0][0]   end

Hacky, but...

If you're deploying with capistrano and have a revisions.log, you can use something like this:

Layout:      <div id='footer'>        <div id='revision'><%= application_revision %></div>        <div id='time'><%= Time.now %></div>      </div>

Helper:    def application_revision      " ver. #{RevisionNumber.from_log}" rescue ''    end

From lib/revision_number.rb: Note that this uses the file-tail gem to simplify getting the last line of the log file:

# revision_number.rb

You might use a metadata file, accessible to the app, which includes
the svn revision, and then have that revision managed by svn's
'Revision' keyword substitution:

http://svnbook.red-bean.com/nightly/en/ svn.advanced.props.special.keywords.html

-faisal

Hope you still need this, I'm a few days behind on reading the forums.

Here's what I use, assuming you have svnversion in your path:

class ApplicationController < ActionController::Base    def svn_revision      @svn_revision ||= `svnversion .`.gsub(/^.*\:/, '').gsub(/[MS]/, '').to_i    end    helper_method :svn_revision end

That caches the revision number for the life of the Ruby process, so it should be fast.

Brad

A variation:

In environment.rb

If you're deploying with capistrano and have a revisions.log, you can

revisions.log is phased out in Capistrano 2.x see:     http://www.capify.org/upgrade

Alain