[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

svn pre-commit hook

Bil Kleb

3/10/2006 9:24:00 PM

OK, I give up.

Can someone (Kou?) please sketch out how to intercept
a Subversion transaction with a pre-commit hook and
throw each file matching, say, /\.rb$/ to some StyleChecker?

Based on Kou's svnlook,

https://svn.collab.net/repos/svn/trunk/tools/examples/...

and the bindings,

http://svn.collab.net/repos/svn/trunk/subversion/bindings/swig...

it seems that Svn:Fs might be the answer, but I'm having
trouble figuring out SVN transactions -- the manual says
very little about these creatures.

Thanks,
--
Bil
http://fun3d.lar...
4 Answers

Justin Collins

3/10/2006 9:44:00 PM

0

Bil Kleb wrote:
> OK, I give up.
>
> Can someone (Kou?) please sketch out how to intercept
> a Subversion transaction with a pre-commit hook and
> throw each file matching, say, /\.rb$/ to some StyleChecker?
>
> Based on Kou's svnlook,
>
> https://svn.collab.net/repos/svn/trunk/tools/examples/...
>
> and the bindings,
>
> http://svn.collab.net/repos/svn/trunk/subversion/bindings/swig...
>
> it seems that Svn:Fs might be the answer, but I'm having
> trouble figuring out SVN transactions -- the manual says
> very little about these creatures.
>
> Thanks,
> --
> Bil
> http://fun3d.lar...
>

I don't know about pre-commit hooks, but here's a post-commit hook I
wrote the other day. Not fancy or anything, but will maybe give you an idea?
I just used the normal 'svnlook'.

> #!/usr/bin/env ruby
> require 'net/smtp'
>
> if ARGV.length != 2
> puts "Usage: post-commit [repos] [revision]"
> end
>
> def parse_changed(change_list)
> added = Array.new
> modified = Array.new
> deleted = Array.new
> other = Array.new
> change_list = change_list.split("\n")
>
> change_list.each { |changed|
>
> #changed file/dir is preceded by U/D/A
> mod = changed[0, 1]
>
> case mod
> when 'U'
> modified << changed[1..-1]
> when 'A'
> added << changed[1..-1]
> when 'D'
> deleted << changed[1..-1]
> else
> other << changed
> end
> }
>
> change_string = String.new
>
> if not added.empty?
> change_string << "Added:\n" << added.join("\n") << "\n"
> end
>
> if not modified.empty?
> change_string << "Modified:\n" << modified.join("\n") << "\n"
> end
>
> if not deleted.empty?
> change_string << "Deleted:\n" << deleted.join("\n") << "\n"
> end
>
> if not other.empty?
> change_string << "Other:\n" << other.join("\n") << "\n"
> end
>
> return change_string
> end
>
> recipients = ['fake@fake.com']
>
> repository = ARGV[0]
> revision = ARGV[1]
>
> author = `svnlook author #{repository} --revision #{revision}`.chomp.capitalize
> date = `svnlook date #{repository} --revision #{revision}`.chomp
> changed = parse_changed(`svnlook changed #{repository} --revision #{revision}`.chomp)
> diff = `svnlook diff #{repository} --revision #{revision} --no-diff-deleted`
> log = `svnlook log #{repository} --revision #{revision}`
>
> message = <<END_OF_MESSAGE
> To: #{recipients.join(',')}
> From: SVN <svn@host.net>
> Subject: SVN Commit: Revision #{revision} by #{author}
>
> Author: #{author}
> Date: #{date}
> Revision: #{revision}
>
> #{changed}
>
> Log Message:
> #{log}
>
> #{diff}
>
> END_OF_MESSAGE
>
> if $DEBUG
> puts message
> exit
> end
>
> Net::SMTP.start('smtp.host.net', 25, 'host.net', 'fake@fake.net', 'password') { |smtp|
>
> smtp.send_message(message, 'fake@fake.net', recipients)
>
> }
>

-Justin


Bil Kleb

3/10/2006 10:03:00 PM

0

Justin Collins wrote:
>
> I don't know about pre-commit hooks, but here's a post-commit hook I
> wrote the other day. Not fancy or anything, but will maybe give you an
> idea?

Thanks.

> I just used the normal 'svnlook'.

If you have the SVN Ruby bindings compiled, you could use Kouhei's
commit-email.rb for post-hook mailings (and RSS feed):

https://svn.collab.net/repos/svn/trunk/tools/hook-scripts/commi...

If you want HTML output also, see

https://svn.collab.net/repos/svn/trunk/tools/examples/svnl...

Regards,
--
Bil
http://fun3d.lar...

Kouhei Sutou

3/13/2006 2:58:00 PM

0


Content-Type: Multipart/Mixed;
boundary="--Next_Part(Mon_Mar_13_23_58_08_2006_761)--"

Bil Kleb

3/13/2006 3:14:00 PM

0

Kouhei Sutou wrote:
> Hi,

Hello.

> What about attached script?

Excellent, Thanks!

This is the nugget I most craved:

> def changed_paths(base_rev=nil)
> base_rev ||= @txn.base_revision
> base_root = @fs.root(base_rev)
> editor = Svn::Delta::ChangedEditor.new(@root, base_root)
> base_root.dir_delta('', '', @root, '', editor)
> (editor.added_files + editor.updated_files).uniq.sort
> end

Thanks again,
--
Bil
http://fun3d.lar...