1553: patch crash in reviewboard, post-review's difflib_unified_diff() fails to handle missing newline terminated file

hort*****@gmai***** (Google Code) (Is this you? Claim this profile.)
April 4, 2011
What version are you running?
1.0.5.1

What's the URL of the page containing the problem?
1. http://reviewboard2.efi.com/r/[request id]/
2. click "View Diff"

What steps will reproduce the problem?
1. post-review a file whose previous version does not have newline
terminated, and the working copy extends from the previous version from a
clearcase repos
2. http://reviewboard2.efi.com/r/[request id]/
3. click "View Diff"

What is the expected output? What do you see instead?
crash; last function in backtrace is patch()

What operating system are you using? What browser?
post-review from linux, firefox reviewboard from windows

Please provide any additional information below.
The problem is from python's difflib.unified_diff() that fails to 
output "\\ No newline at end of file" in the diff file.

According to post-review source code, post-review tries to remedy this, but
it fails in the case when the copy version extends from the version that is
missing newline.

e.g.
### note missing \n after close curly brace
old_file_content = """
int Foo(const char* path)
{
    int ret = -1;

    return ret;
}"""

new_file_content = """
int Foo(const char* path)
{
    int ret = -1;

    return ret;
}

int Bar(void)
{
    int return = 0;
    return ret;
}
"""

diff -u output:
# diff -u oldold.cpp newnew.cpp

--- oldold.cpp  2010-03-17 15:08:36.600738000 -0700
+++ newnew.cpp  2010-03-17 15:06:19.641658000 -0700
@@ -3,4 +3,10 @@
     int ret = -1;

     return ret;
-}
\ No newline at end of file
+}
+
+int Bar(void)
+{
+    int return = 0;
+    return ret;
+}


post-review (difflib_unified_diff). I slightly modify post-review to get
this output.
Note: "-}+}"

--- /vobs/.../src/oldold.cpp   2002-02-21 23:30:39.942229878 -0800
+++ /vobs/.../src/newnew.cpp   2002-02-21 23:30:50.442260588 -0800
@@ -3,4 +3,10 @@
     int ret = -1;

     return ret;
-}+}
+
+int Bar(void)
+{
+    int return = 0;
+    return ret;
+}


Unix patch command on reviewboard does not like "-}+}" and crash.

I installed python2.6 recently and difflib still have this bug!

My suggested workaround: 
In post-review, add '\n' to the original file if is not
newline terminated. In reviewboard diffutils.py, possibly
convert_line_endings(data), 
add '\n' to data if data[-1] is not '\r' or '\n'

Thank you.
(newline terminated)
#1 hort*****@gmai***** (Google Code) (Is this you? Claim this profile.)
My suggested workaround relies on peeking the diff file by diff.startswith("---
/vobs") to determine that the diff is from clearcase and add an extra '\n' to the
original file. But it breaks if I post-review from windows, as the diff file starts
with  "--- X:\\foo\\bar\\..." or "--- M:\\someview\\foo\\bar\\...". Is there a call
that returns the diff is from a clearcase repo?

I also found bugs on reviewboard if I post-review on a clearcase file from windows.
I'll post it on different thread with my proposed fix.
david
#2 david
  • +Component-RBTools
david
#3 david
Fixed in reviewboard 7553ec1 and rbtools 47fb2ce. Thanks!
  • +Fixed