Trying to hack subversion.rb by adding an update_changeset function
Added by Steven Risner over 15 years ago
Our organization often a needs to update svn:properties and I need a way to run a command similar to fetch_changesets via svn post-revprop-change hook.
The function I'd like to define and execute is
def update_changeset(scm_revision)
scm_info = scm.info
if scm_info
- latest revision found in database
db_revision = latest_changeset ? latest_changeset.revision.to_i : 0
if db_revision < scm_revision
logger.debug "Changesets for repository #{url} \
out-of-sych use fetch_changesets first" if logger && logger.debug?
else- Get scm revision to update
revision = scm.revisions('', scm_revision, scm_revision, :with_paths => true)
Changeset.update(:repository => self,
:revision => revision.identifier,
:committer => revision.author,
:committed_on => revision.time,
:comments => revision.message)
end
end
end
I'm not a ruby programmer so I sorta winged it by example and assumed the Changeset.update exist (I know update_all does base on other ruby scripts). I'm not sure if this would be all I need, but it seemed resonable.
My first attempt on this was a hard coded scm_revision and update_changeset def with no parameter.
When I tried to execute this using
/usr/bin/ruby runner "Repository.update_changeset" -e production
I got the following ouptut.
/srv/www/redmine/vendor/rails/railties/lib/commands/runner.rb:47: undefined method `update_changeset' for
#<Class:0xb6fa7aec> (NoMethodError)
from (eval):1
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `eval'
from /srv/www/redmine/vendor/rails/railties/lib/commands/runner.rb:47
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from runner:3
How can I make the runner.rb aware of this new sunversion.rb method? Once I can get a non-parameter version working how do I pass a parameter using the following.
/usr/bin/ruby runner "Repository.update_changeset" -e production
Replies (2)
RE: Trying to hack subversion.rb by adding an update_changeset function - Added by Steven Risner over 15 years ago
Hmm sorry some wiki syntax was rendered. ( Wish I could had edited my own post! Why can't I? )
def update_changeset scm_revision = 10102 scm_info = scm.info if scm_info # latest revision found in database db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 if db_revision < scm_revision logger.debug "Changesets for repository #{url} out-of-sych (use fetch_changesets)" if logger && logger.debug? else # Get scm revision to update revision = scm.revisions('', scm_revision, scm_revision, :with_paths => true) Changeset.update(:repository => self, :revision => revision.identifier, :committer => revision.author, :committed_on => revision.time, :comments => revision.message) end end end
RE: Trying to hack subversion.rb by adding an update_changeset function - Added by Steven Risner over 15 years ago
The following works
Again I'm not a ruby programmer so it could be done easer
In repository.rb
def self.update_changeset(path,rev) find(:all).each do |repos| repos.update_changeset(path,rev) end end
in subversion.rb
def update_changeset(repos, rev) scm_info = scm.info scm_url = scm.root_url if scm_info if scm_url == repos # latest revision found in database db_revision = latest_changeset ? latest_changeset.revision.to_i : 0 scm_revision = rev.to_i if db_revision < scm_revision logger.debug "Changesets for repository #{url} out-of-sych (use fetch_changesets)" if logger && logger.debug? else # Get scm revision to update scm.revisions('', scm_revision, scm_revision, :with_paths => true).each do |revision| changesets.find(:all, :conditions => ["revision = ?", rev]).each do |changeset| changeset.update_attribute :comments, revision.message changeset.update_attribute :committer, revision.author end end end end end end
Run ruby runner "Repository.update_changeset(\"REPOS\",\"REV\")" -e production in a post-revprop=change hook script if the svn repository is local. Otherwise an svn is needed to connect to the Redmine DB directly to perform the above similar task.
Perhaps this is good enough to be included in the next version.