[cvsspam-devel] CVSSPAM and SVN

Jerry Talton jot3 at cs.stanford.edu
Mon Sep 17 02:43:31 UTC 2007


I finally hacked together the following to fix my problem.  Perhaps
someone could clean it up and include it in the next release?  It was
pretty simple to prevent the system from crashing by detecting binary
files in the diff, but since you don't get version numbers from SVN
(that I can tell) the output could certainly be better.

--- svn_post_commit_hook.rb.old 2007-09-16 19:38:22.810211671 -0700
+++ svn_post_commit_hook.rb.new 2007-09-16 19:38:29.748493645 -0700
@@ -152,16 +152,25 @@
   def assert_next(re=nil)
     raise "unexpected end of text" unless next_line
     unless re.nil?
-      raise "unexpected #{lines.current.inspect}" unless @line =~ re
+      raise "unexpected #{lines.current.inspect}" unless @line =~ re
|| @line =~ /^\(Binary.*$/
     end
     $~
   end
+
+  def catch_binary
+    @line =~ /^\(Binary.*$/ ? true : false
+  end
 end


 def read_modified_diff(out, lines, path)
   lines.assert_next(/^=+$/)
   m = lines.assert_next(/^---.*\(rev (\d+)\)$/)
+  if lines.catch_binary
+    out.puts "#V NA,NA"
+    out.puts "#M #{path}"
+    return
+  end
   prev_rev = m[1].to_i
   diff1 = lines.current
   m = lines.assert_next(/^\+\+\+.*\(rev (\d+)\)$/)
@@ -179,6 +188,11 @@
 def read_added_diff(out, lines, path)
   lines.assert_next(/^=+$/)
   m = lines.assert_next(/^---.*\(rev (\d+)\)$/)
+  if lines.catch_binary
+    out.puts "#V NA,NA"
+    out.puts "#A #{path}"
+    return
+  end
   prev_rev = m[1].to_i
   diff1 = lines.current
   m = lines.assert_next(/^\+\+\+.*\(rev (\d+)\)$/)
@@ -196,6 +210,11 @@
 def read_deleted_diff(out, lines, path)
   lines.assert_next(/^=+$/)
   m = lines.assert_next(/^---.*\(rev (\d+)\)$/)
+  if lines.catch_binary
+    out.puts "#V NA,NA"
+    out.puts "#R #{path}"
+    return
+  end
   prev_rev = m[1].to_i
   diff1 = lines.current
   m = lines.assert_next(/^\+\+\+.*\(rev (\d+)\)$/)

On 9/13/07, Jerry Talton <jot3 at cs.stanford.edu> wrote:
> I recently installed CVSSPAM in a subversion repository that I'm
> helping maintain, with the usual post-commit script to call
> svn_post_commit_hook.rb.  For the most part, it works great, but any
> time I add or change a binary file I get the following:
>
> Warning: 'post-commit' hook failed with error output:
> /web/svn/elysium/hooks/svn_post_commit_hook.rb:155:in `assert_next':
> undefined local variable or method `lines' for
> #<LineReader:0xb7fa7974> (NameError)
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:164:in
> `read_modified_diff'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:278:in
> `process_svnlook_diff'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:274:in `svnlook'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:94:in `safer_popen'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:45:in `popen'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:45:in `safer_popen'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:94:in `svnlook'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:274:in
> `process_svnlook_diff'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:299:in
> `process_commit'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:297:in `open'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:297:in
> `process_commit'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:307:in `main'
>        from /web/svn/elysium/hooks/svn_post_commit_hook.rb:313
>
> I am really only a novice Ruby programmer: can someone suggest a
> workaround?  It seems as if it shouldn't try to read_modified_diff on
> binary files, right?
>
> Any help would be *much* appreciated!!
>

-- 
Jerry Talton
jtalton at cs.stanford.edu
http://www.stanford.edu/~jtalton



More information about the cvsspam-devel mailing list