mindsifter

sifting through the thoughts in my mind
Copyright Michael D'Auria © 2008

Categories

Bookmarks

Add hg revision number to page titles for QA December 16th, 2007

Recently after my article about Bazaar I switched to Mercurial. Bazaar is just WAY too slow for remote repositories, which is what I use so my partner can pull changes, whereas Mercural is very fast. Now let me show you how to go from the SVN code to Mercurial this time.


Here is the snippet of Brian's original code:


  def revision
    @revision ||= if svn_info_from_working_copy 
      svn_info_from_working_copy["Revision"].value
    else
      last_revision_in_log
    end
  rescue
    @revision = "UNKNOWN"
  end
  
  def svn_info_from_working_copy
    @svn_info ||= YAML.parse(`svn info #{RAILS_ROOT}`)
  end
  
  def last_revision_in_log
    File.readlines(RAILS_ROOT + "/../../revisions.log").last.split[3]
  end
  

And here is my modified:


  def revision
    @revision ||= if hg_log_from_working_copy 
      hg_log_from_working_copy['changeset'].value.split(':').first
    else
      last_revision
    end
  rescue
    @revision = "UNKNOWN"
  end
  
  def bzr_revno_from_working_copy
    @hg_log ||= YAML.parse(`hg log #{RAILS_ROOT}`)
  end
  
  def last_revision
    File.read(RAILS_ROOT + "/REVISION").strip
  end
  

Bazaar made this easier, but the remote repository performance is just too subpar for my use. So there you have it, enjoy.

Sorry, comments are closed for this article.