环境:
Windows XP
RBTools 0.4.2
ReviewBoard 1.7.1
之前搭建了reviewboard,一开始是在动态视图下测试的,一切顺利。
当切换到静态视图下,用post-review提交所有checkedout文件时,命令显示似乎也一切正常,最后也输出了提交成功的提示信息“Review request #10 posted”。
但到reviewboard上打开该request,进行view diff时,出现如下异常:
Traceback (most recent call last):
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\views.py", line 383, in view_diff_fragment
file = get_requested_diff_file()
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\views.py", line 309, in get_requested_diff_file
populate_diff_chunks(files, highlighting)
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\diffutils.py", line 1197, in populate_diff_chunks
large_data=True)
File "F:\CodeReview\Python27\lib\site-packages\djblets-0.7.8-py2.7.egg\djblets\util\misc.py", line 156, in cache_memoize
data = lookup_callable()
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\diffutils.py", line 1196, in <lambda>
enable_syntax_highlighting)),
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\diffutils.py", line 599, in get_chunks
new = get_patched_file(old, filediff)
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\diffutils.py", line 392, in get_patched_file
return patch(diff, buffer, filediff.dest_file)
File "F:\CodeReview\Python27\lib\site-packages\reviewboard-1.7.2-py2.7.egg\reviewboard\diffviewer\diffutils.py", line 251, in patch
(filename, tempdir, patch_output))
Exception: The patch to '{clearcase file path}' didn't apply cleanly. The temporary files have been left in 'e:\temp\reviewboard.yoegta' for debugging purposes.
`patch` returned: patching file e:\temp\reviewboard.yoegta\tmpmvzzpi
Patch attempted to create file e:\temp\reviewboard.yoegta\tmpmvzzpi, which already exists.
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file e:\temp\reviewboard.yoegta\tmpmvzzpi-new.rej
把该文件在动态视图下也post-review一下,比较了一下,发现静态视图下生成的diff文件不对。
直接用diff、cat命令测试,却是因为在CC静态视图下,带版本信息的文件是无法访问的。这样的话只得先用cleartool get命令把文件拷贝一份临时文件,再用diff去比较临时文件。
在eclipse装上python插件,post-review调试,逐步跟进,找到了diff代码的位置:
def diff_files(self, old_file, new_file):
"C:\Python27\Lib\site-packages\RBTools-0.4.2-py2.7\rbtools\clients\clearcase.py" 262行
代码改动如下:
def diff_files(self, old_file, new_file):
# in snapshot view, diff command can't access clearcase file which with version path
# create temporary file backup instead of clearcase file according by 'cleartool get' command
if self.viewtype == "snapshot":
temp_old_file = make_tempfile()
temp_new_file = make_tempfile()
if cpath.exists(temp_old_file):
os.unlink(temp_old_file)
if cpath.exists(temp_new_file):
os.unlink(temp_new_file)
execute(["cleartool", "get" , "-to", temp_old_file, old_file])
execute(["cleartool", "get" , "-to", temp_new_file, new_file])
diff_cmd = ["diff", "-uN", temp_old_file, temp_new_file]
else:
diff_cmd = ["diff", "-uN", old_file, new_file]
"""Return unified diff for file.
Most effective and reliable way is use gnu diff.
"""
dl = execute(diff_cmd, extra_ignore_errors=(1, 2),
translate_newlines=False)
# replace temporary file in snapshot view
if self.viewtype == "snapshot":
dl = dl.replace(temp_old_file, old_file)
dl = dl.replace(temp_new_file, new_file)
改动后重新编译一下,塞回到RBTools相应位置。
于是,世界又一片清净了。。。。。