mf69/svnspam

Undefined local variable

Opened this issue · 9 comments

What steps will reproduce the problem?
1. Commit changes using svn

What is the expected output? What do you see instead?
I expect svnspam to send an email, but when the commit is done I get a
post-commit hook failed error.

What version of the product are you using? On what operating system?
0.1, on CentOS

Please provide any additional information below.

Here is the error from the logfile:

/opt/svnspam/svn_post_commit_hook.rb:154:in `assert_next': undefined local
variable or method `lines' for #<LineReader:0xb7f6f088> (NameError)
        from /opt/svnspam/svn_post_commit_hook.rb:163:in `read_modified_diff'
        from /opt/svnspam/svn_post_commit_hook.rb:278:in `process_svnlook_diff'
        from /opt/svnspam/svn_post_commit_hook.rb:94:in `svnlook'
        from /opt/svnspam/svn_post_commit_hook.rb:50:in `safer_popen'
        from /opt/svnspam/svn_post_commit_hook.rb:46:in `popen'
        from /opt/svnspam/svn_post_commit_hook.rb:46:in `safer_popen'
        from /opt/svnspam/svn_post_commit_hook.rb:93:in `svnlook'
        from /opt/svnspam/svn_post_commit_hook.rb:274:in `process_svnlook_diff'
        from /opt/svnspam/svn_post_commit_hook.rb:318:in `process_commit'
        from /opt/svnspam/svn_post_commit_hook.rb:316:in `open'
        from /opt/svnspam/svn_post_commit_hook.rb:316:in `process_commit'
        from /opt/svnspam/svn_post_commit_hook.rb:326:in `main'
        from /opt/svnspam/svn_post_commit_hook.rb:332


Original issue reported on code.google.com by bbay...@gmail.com on 24 Apr 2009 at 2:40

Could you verify that you are setting an email address in svnspam.conf or 
setting it
on the command line (in post-commit) ?

For example...
addRecipient "commits@example.com"

Original comment by m...@foster.cc on 28 Apr 2009 at 12:30

The email address is set in svnspam.conf.

I should have added that this does not occur every commit. It seems very random.
Sometimes it happens 3 times in a row, sometimes every 50th commit. I have not 
been
able to reproduce this error with testing or find a certain scenario that 
triggers it.

Original comment by bbay...@gmail.com on 28 Apr 2009 at 2:13

Does this happen when a commit message is not supplied? Take note of the 
revision
this occurs on and try the troubleshooting steps (see the wiki)

Original comment by m...@foster.cc on 2 Jul 2009 at 4:50

I am getting this as error, as well. I have my recipient in the configuration 
file,
and my svnlook command passes on the repository.

The only item that has changed, is I've moved the repository to another server, 
and
am now using svn+ssh to check out the repository.

0.1, FreeBSD

Original comment by jason.he...@gmail.com on 26 Aug 2009 at 6:54

The error was not clear to me, however after installing ruby and fixing the rb 
script
path, the utility started working again.

Original comment by jason.he...@gmail.com on 29 Dec 2009 at 8:27

I keep on getting this error once in a while, consequently missing important 
checkins


/home/quintin/svn/svnspam/svn_post_commit_hook.rb:155:in `assert_next': 
undefined local variable or method `lines' for #<LineReader:0x75e7101a11f8> 
(NameError)
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:181:in `read_added_diff'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:280:in `process_svnlook_diff'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:95:in `svnlook'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:49:in `safer_popen'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:45:in `popen'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:45:in `safer_popen'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:94:in `svnlook'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:274:in `process_svnlook_diff'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:302:in `process_commit'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:300:in `open'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:300:in `process_commit'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:310:in `main'
    from /home/quintin/svn/svnspam/svn_post_commit_hook.rb:316

Original comment by quintin...@gmail.com on 12 Sep 2010 at 6:42

I'm pretty certain this error occurs when committing a binary file in the 
revision. That's why it's showing periodically. Here's the content of an email 
posted to the developer mailing list:

----------

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

Original comment by dmul...@gmail.com on 20 Oct 2010 at 5:43

is the above patch working with binary files commit?

Regards
Vamsi

Original comment by vkpolise...@gmail.com on 29 Oct 2010 at 5:04

I use that patch on my installation of SVNspam and it works fine. It's awesome 
that all commit emails finally work.

The only issue I see is that ViewSVN/WebSVN links are generated for the 
versions even though it says NA. These links of course fail since NA isn't a 
valid version. I'm sure the svnspam.rb file must also be changed to detect the 
NA and skip the linkify step.

Original comment by dmul...@gmail.com on 11 Dec 2010 at 12:39