環境:
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相應位置。
于是,世界又一片清凈了。。。。。