Reviewboard (http://reviews.review-board.org/#) comes with a tool called post-review. post-review uploads diffs to the reviewboard server. Unfortunately post-review drops certain lines during upload. This patch fixes that - mostly. See http://reviews.review-board.org/r/624/ and http://groups.google.com/group/reviewboard/browse_thread/thread/cb96afc6064bbf7b# for details. coded by Maximillian Dornseif Index: post-review =================================================================== --- post-review (revision 4065) +++ post-review (working copy) @@ -9,6 +9,8 @@ import socket import subprocess import sys +import md5 +import base64 import urllib import urllib2 from optparse import OptionParser @@ -399,7 +401,8 @@ content_type, body = self._encode_multipart_formdata(fields, files) headers = { 'Content-Type': content_type, - 'Content-Length': str(len(body)) + 'Content-Length': str(len(body)), + 'Content-MD5': base64.b64encode(md5.new(body).digest()) } try: @@ -710,33 +713,47 @@ # svn diff against a repository URL on two revisions appears to # handle moved files properly, so only adjust the diff file names # if they were created using a working copy. + + # we want to catch: + # Index: produktpass/scoring.py + # =================================================================== + # --- produktpass/scoring.py (revision 4065) + # +++ produktpass/scoring.py (working copy) + # @@ -29,7 +29,7 @@ + # to be really reliable we would have to implement a state machine here. + if self.diff_against_url: return diff_content result = [] - from_line = "" + previous_line = "" + line_before_previous_line = '' for line in diff_content: - if line.startswith('---'): + if (line_before_previous_line.startswith('Index: ') + and previous_line.startswith('===========================') + and line.startswith('--- ') and line.strip().endswith(')')): from_line = line - continue + else: + # This is where we decide how mangle the previous '---' + if line.startswith('+++ ') and from_line: + to_file, _ = self.parse_filename_header(line[4:]) + info = self.svn_info(to_file) + if info.has_key("Copied From URL"): + url = info["Copied From URL"] + root = info["Repository Root"] + from_file = urllib.unquote(url[len(root):]) + result.append(from_line.replace(to_file, from_file)) + else: + result.append(from_line) #as is, no copy performed + + # We only mangle '---' lines. All others get added straight to + # the output. + result.append(line) + + line_before_previous_line = previous_line + previous_line = line - # This is where we decide how mangle the previous '---' - if line.startswith('+++'): - to_file, _ = self.parse_filename_header(line[4:]) - info = self.svn_info(to_file) - if info.has_key("Copied From URL"): - url = info["Copied From URL"] - root = info["Repository Root"] - from_file = urllib.unquote(url[len(root):]) - result.append(from_line.replace(to_file, from_file)) - else: - result.append(from_line) #as is, no copy performed - - # We only mangle '---' lines. All others get added straight to - # the output. - result.append(line) - return result