2065: patch fails when trying to view patch

kand****@gmai***** (Google Code) (Is this you? Claim this profile.)
Aug. 8, 2013
> What version are you running?

1.5.4

> What's the URL of the page containing the problem?

/r/<id>/diff/

> What steps will reproduce the problem?

1. Put console.py into a sub directory. (eg. /repo/review/)
2. Upload console.patch for review. 
3. Try to view the patch.

> What is the expected output? What do you see instead?

Instead of difference, a Python traceback is shown:

Traceback (most recent call last):
...
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/diffutils.py", line 378, in get_patched_file
    return patch(filediff.diff, buffer, filediff.dest_file)

(Full traceback attached.)

patch() method executes this command, imho this is wrong:

  patch -o /tmp/reviewboard.Tvwttz/tmpP37ele-new /tmp/reviewboard.Tvwttz/tmpP37ele < /tmp/reviewboard.Tvwttz/console.py.diff

patch command fails:
  "invalid output file name: /tmp/reviewboard.Tvwttz/tmpP37ele"

Changing working directory and running patch works fine:
  cd /tmp/reviewboard.Tvwttz/
  patch -o tmpP37ele-new tmpP37ele < console.py.diff

IMHO, an os.chdir() will fix this.
Index: console.py
===================================================================
--- console.py	(revision 2093)
+++ console.py	(working copy)
@@ -16,6 +16,12 @@
     """
         Main loop
     """
+
+    args = sys.argv[1:]
+    if len(args) < 2:
+        print "Usage: %s <from> <to>" % sys.argv[0]
+        return FAILURE
+
     return SUCCESS
 
 if __name__ == '__main__':
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/views.py", line 153, in view_diff
    interdiffset, highlighting, True)
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/diffutils.py", line 1067, in get_diff_files
    large_data=True)
  File "/usr/lib/python2.7/site-packages/Djblets-0.6.7-py2.7.egg/djblets/util/misc.py", line 166, in cache_memoize
    data = lookup_callable()
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/diffutils.py", line 1066, in <lambda>
    enable_syntax_highlighting)),
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/diffutils.py", line 553, in get_chunks
    new = get_patched_file(old, filediff)
  File "/usr/lib/python2.7/site-packages/ReviewBoard-1.5.4-py2.7.egg/reviewboard/diffviewer/diffutils.py", line 378, in get_patched_file
    return patch(filediff.
#1 kand****@gmai***** (Google Code) (Is this you? Claim this profile.)
Sorry, wrong file was attached.
  • +
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    """
        Example console application
    """
    # Standard modules
    import sys
    # Exit codes
    SUCCESS, FAILURE = range(0, 2)
    # Main
    def main():
        """
            Main loop
        """
        return SUCCESS
    if __name__ == '__main__':
        sys.exit(main())
david
#2 david
  • +Component-DiffViewer
david
#3 david
Setting the cwd shouldn't be necessary, but maybe it's something in your version of `patch`

I've pushed a fix for this to master (1db33ee). It will be available in 1.8.0
  • +Fixed