2437: "View Diff" cause "patch didn't apply cleanly" error when ReviewBoard is used with Git repository

hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
Dec. 24, 2012
What version are you running?
ReviewBoard-1.6

What's the URL of the page containing the problem?
http://gerrit.am.freescale.net/r/49/diff/#index_header

What steps will reproduce the problem?
1. Send diff using rbtools

$post-review --guess-description --guess-summary
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 66648cc..6a98051 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -65,6 +65,7 @@
 #include <asm/kexec.h>
 #include <asm/mmu_context.h>
 #include <asm/code-patching.h>
+#include <asm/hugetlb.h>

 #include "setup.h"


2. Visit URL which generated review diff https://reviewboard.instance/r/49/diff/#index_header
3. when I click "View Diff" button on the review page, I get the following stack trace: 

The patch to 'arch/powerpc/kernel/setup_64.c' didn't apply cleanly. The temporary files have been left in '/tmp/reviewboard.4NIpTN' for debugging purposes. `patch` returned: patching file /tmp/reviewboard.4NIpTN/tmpf8d2eE Hunk #1 FAILED at 65. 1 out of 1 hunk FAILED -- saving rejects to file /tmp/reviewboard.4NIpTN/tmpf8d2eE-new.rej

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/views.py", line 151, in view_diff
    interdiffset, highlighting, True)
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/diffutils.py", line 1071, in get_diff_files
    large_data=True)
  File "/usr/local/lib/python2.6/dist-packages/Djblets-0.6.10-py2.6.egg/djblets/util/misc.py", line 155, in cache_memoize
    data = lookup_callable()
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/diffutils.py", line 1070, in <lambda>
    enable_syntax_highlighting)),
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/diffutils.py", line 552, in get_chunks
    new = get_patched_file(old, filediff)
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/diffutils.py", line 374, in get_patched_file
    return patch(filediff.diff, buffer, filediff.dest_file)
  File "/usr/local/lib/python2.6/dist-packages/ReviewBoard-1.6-py2.6.egg/reviewboard/diffviewer/diffutils.py", line 242, in patch
    (filename, tempdir, patch_output))
Exception: The patch to 'arch/powerpc/kernel/setup_64.c' didn't apply cleanly. The temporary files have been left in '/tmp/reviewboard.4NIpTN' for debugging purposes.
`patch` returned: patching file /tmp/reviewboard.4NIpTN/tmpf8d2eE
Hunk #1 FAILED at 65.
1 out of 1 hunk FAILED -- saving rejects to file /tmp/reviewboard.4NIpTN/tmpf8d2eE-new.rej


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


What operating system are you using? What browser?
ReviewBoard Server - Ubuntu 10.04.2 LTS
FireFox browser 3.6.24 - Windows
#1 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
/tmp/reviewboard.4NIpT/setup_64.c.diff

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 66648ccdba49bf63cc112f40cd35b50d9240273f..6a98051bf803ed7cb3d2a1de1be22684be420ae0 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -65,6 +65,7 @@
 #include <asm/kexec.h>
 #include <asm/mmu_context.h>
 #include <asm/code-patching.h>
+#include <asm/hugetlb.h>

 #include "setup.h"

--
1.5.4.3

#2 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
/tmp/reviewboard.4NIpTN/tmpf8d2eE_

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>linux.git - linux
</title>
<meta name='generator' content='cgit v0.9.0.2-39-g756e'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/gitolite/cgit.css'/>
<link rel='shortcut icon' href='/gitolite/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='http://git.am.freescale.net/gitolite/gitweb.cgi/sdk/linux.git/atom/?h=master' type='application/atom+xml'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/gitolite/gitweb.cgi/'><img src='/gitolite/cgit-fsl.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/gitolite/gitweb.cgi/'>index</a> : <a title='linux.git' href='/gitolite/gitweb.cgi/sdk/linux.git/'>linux.git</a></td><td class='form'><form method='get' action=''>
<input type='hidden' name='id' value='66648ccdba49bf63cc112f40cd35b50d9240273f'/><select name='h' onchange='this.form.submit();'>
<option value='dpaa-v1.0.x'>dpaa-v1.0.x</option>
<option value='dpaa-v1.1.x'>dpaa-v1.1.x</option>
<option value='master' selected='selected'>master</option>
<option value='qman'>qman</option>
<option value='qoriq-v1.0.x'>qoriq-v1.0.x</option>
</select> <input type='submit' name='' value='switch'/></form></td></tr>
<tr><td class='sub'>linux
</td><td class='sub right'>Kumar Gala</td></tr></table>
<table class='tabs'><tr><td>
<a href='/gitolite/gitweb.cgi/sdk/linux.git/'>summary</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/refs/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>refs</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/log/'>log</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/tree/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>tree</a><a class='active' href='/gitolite/gitweb.cgi/sdk/linux.git/commit/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>commit</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/diff/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>diff</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/stats/'>stats</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/about/'>about</a></td><td class='form'><form class='right' method='get' action='/gitolite/gitweb.cgi/sdk/linux.git/log/'>
<input type='hidden' name='id' value='66648ccdba49bf63cc112f40cd35b50d9240273f'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='text' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='content'><div class='error'>Bad commit reference: 66648ccdba49bf63cc112f40cd35b50d9240273f</div>
</div> <!-- class=content -->
<div class='footer'>generated  by cgit v0.9.0.2-39-g756e at 2012-01-05 07:41:25 (GMT)</div>
</div> <!-- id=cgit -->
</body>
</html>
#3 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
/tmp/reviewboard.4NIpTN/tmpf8d2eE_-new

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>linux.git - linux
</title>
<meta name='generator' content='cgit v0.9.0.2-39-g756e'/>
<meta name='robots' content='index, nofollow'/>
<link rel='stylesheet' type='text/css' href='/gitolite/cgit.css'/>
<link rel='shortcut icon' href='/gitolite/favicon.ico'/>
<link rel='alternate' title='Atom feed' href='http://git.am.freescale.net/gitolite/gitweb.cgi/sdk/linux.git/atom/?h=master' type='application/atom+xml'/>
</head>
<body>
<div id='cgit'><table id='header'>
<tr>
<td class='logo' rowspan='2'><a href='/gitolite/gitweb.cgi/'><img src='/gitolite/cgit-fsl.png' alt='cgit logo'/></a></td>
<td class='main'><a href='/gitolite/gitweb.cgi/'>index</a> : <a title='linux.git' href='/gitolite/gitweb.cgi/sdk/linux.git/'>linux.git</a></td><td class='form'><form method='get' action=''>
<input type='hidden' name='id' value='66648ccdba49bf63cc112f40cd35b50d9240273f'/><select name='h' onchange='this.form.submit();'>
<option value='dpaa-v1.0.x'>dpaa-v1.0.x</option>
<option value='dpaa-v1.1.x'>dpaa-v1.1.x</option>
<option value='master' selected='selected'>master</option>
<option value='qman'>qman</option>
<option value='qoriq-v1.0.x'>qoriq-v1.0.x</option>
</select> <input type='submit' name='' value='switch'/></form></td></tr>
<tr><td class='sub'>linux
</td><td class='sub right'>Kumar Gala</td></tr></table>
<table class='tabs'><tr><td>
<a href='/gitolite/gitweb.cgi/sdk/linux.git/'>summary</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/refs/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>refs</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/log/'>log</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/tree/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>tree</a><a class='active' href='/gitolite/gitweb.cgi/sdk/linux.git/commit/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>commit</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/diff/?id=66648ccdba49bf63cc112f40cd35b50d9240273f'>diff</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/stats/'>stats</a><a href='/gitolite/gitweb.cgi/sdk/linux.git/about/'>about</a></td><td class='form'><form class='right' method='get' action='/gitolite/gitweb.cgi/sdk/linux.git/log/'>
<input type='hidden' name='id' value='66648ccdba49bf63cc112f40cd35b50d9240273f'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='text' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='content'><div class='error'>Bad commit reference: 66648ccdba49bf63cc112f40cd35b50d9240273f</div>
</div> <!-- class=content -->
<div class='footer'>generated  by cgit v0.9.0.2-39-g756e at 2012-01-05 07:41:25 (GMT)</div>
</div> <!-- id=cgit -->
</body>
</html>
#4 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
/tmp/reviewboard.4NIpTN/tmpf8d2eE_-new.rej

--- setup_64.c
+++ setup_64.c
@@ -65,6 +65,7 @@
 #include <asm/kexec.h>
 #include <asm/mmu_context.h>
 #include <asm/code-patching.h>
+#include <asm/hugetlb.h>

 #include "setup.h"

#5 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
refer to the log file, we can find that some diff file failed to view because cache miss for the key.
2012-01-09 17:26:56,306 - DEBUG - Generating diff viewer page for filediff id 58
2012-01-09 17:26:56,308 - DEBUG - Begin: Generating diff file info for diffset id 58
2012-01-09 17:26:56,331 - DEBUG - End: Generating diff file info for diffset id 58
2012-01-09 17:26:56,332 - DEBUG - Generating diff file info for diffset id 58 took 0.22316 seconds
2012-01-09 17:26:56,333 - DEBUG - Begin: Generating diff file info for diffset id 58, filediff 103
2012-01-09 17:26:56,355 - INFO - Cache miss for key gerrit.am.freescale.net:diff-sidebyside-hl-103.
2012-01-09 17:26:56,383 - DEBUG - Begin: Patching file arch/powerpc/kernel/setup_64.c
2012-01-09 17:26:56,405 - DEBUG - End: Patching file arch/powerpc/kernel/setup_64.c
2012-01-09 17:26:56,406 - DEBUG - Patching file arch/powerpc/kernel/setup_64.c took 0.22071 seconds

But exactly, some diff could be view successfully.
2012-01-09 17:33:27,518 - DEBUG - Generating diff viewer page for filediff id 38
2012-01-09 17:33:27,520 - DEBUG - Begin: Generating diff file info for diffset id 38
2012-01-09 17:33:27,544 - DEBUG - End: Generating diff file info for diffset id 38
2012-01-09 17:33:27,545 - DEBUG - Generating diff file info for diffset id 38 took 0.24039 seconds
2012-01-09 17:33:27,547 - DEBUG - Begin: Generating diff file info for diffset id 38, filediff 79
2012-01-09 17:33:27,579 - DEBUG - End: Generating diff file info for diffset id 38, filediff 79
2012-01-09 17:33:27,580 - DEBUG - Generating diff file info for diffset id 38, filediff 79 took 0.31687 seconds
2012-01-09 17:33:27,765 - DEBUG - Done generating diff viewer page for filediff id 38
#6 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
I tried to increase cache size up to 128MB and 2GB, but the issue still happen.
# memcached -u www-data -d -m 128 -l 127.0.0.1 -p 11211
# memcached -u www-data -d -m 2048 -l 127.0.0.1 -p 11211
david
#7 david
I'm pretty sure the cache miss isn't related. If there's a miss, it will then go and fetch the file from the source repository.
#8 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
Thank you for the comments.
Then what do you think cause the exception that patch didn't apply cleanly?
It seemed that a small project works well. But it happen when 'view diff' of a big project like u-boot or linux.
#9 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
I also checked the administrator's dashboard.

Server Cache
Cache backend: django.core.cache.backends.memcached
Statistics
127.0.0.1:11211 
Memory usage: 	6.1 KB
Keys in cache: 	6 of 242
Cache hits: 	325 of 325: 100%
Cache misses: 	141 of 325: 43%
Cache evictions: 	0
Cache traffic: 	48.6 KB in, 33.8 KB out
Uptime: 	71990
david
#10 david
It looks like, from the contents of /tmp/reviewboard.4NIpTN/tmpf8d2eE_, that the server isn't returning the right data. In particular, it says "Bad commit reference: 66648ccdba49bf63cc112f40cd35b50d9240273f", which suggests that the server is treating tho SHA1 as a commit ID instead of a blob ID. Can you explain how your repository is configured in RB?
#11 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
Exactly if I add a new file and post the commit, 'View Diff' is OK.
If I change an existed file, the issue happen again.

Please refer to the repository configuration:
General Information
Name:            sdk/u-boot.git

Repository Hosting
Hosting service: Custom
Repository type: Git
Path:            /home/reviewboard/sdk/u-boot.git/.git
#12 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
It's interesting that if I change another file under the same or different directory, there's no problem. Even I changed another file bigger than this one.
#13 hongh******@gmai***** (Google Code) (Is this you? Claim this profile.)
The change to both file is to add following sentence.
/* test post-review */

But one is fail and the other is OK.
#14 sympho******@gmai***** (Google Code) (Is this you? Claim this profile.)
We have a similar issue. Looking at the failed diffs, we noticed that source file being pulled from the git repo occasionally (when there is a failure) includes html that looks like an error page instead of the actual file contents.
david
#15 david
My guess here is that the diffs are being generated against revisions which are not present in the remote repository. Please look into the --tracking-branch and --parent options and make sure that the parent revision for the diff is always something which has been pushed to the remote.
  • +UserError