25
25
# run from the trampoline by the Diff application.
27
27
from common import cgirequest
28
from cgi import parse_qs
34
33
def htmlfy_diff(difftext):
35
34
"""Adds HTML markup to a udiff string"""
36
35
output = cgi.escape(difftext)
37
match_file = re.compile(r'^([\+\-]{3})\s(\S+)\s\((.+)\)$',re.MULTILINE)
38
match_range = re.compile(r'^\@\@ (.*) \@\@$',re.MULTILINE)
39
match_add = re.compile(r'^\+(.*)$',re.MULTILINE)
40
match_sub = re.compile(r'^\-(.*)$',re.MULTILINE)
41
match_special = re.compile(r'^\\(.*)$',re.MULTILINE)
42
output = match_file.sub(
43
r'<span class="diff-files">\1 \2 <em>(\3)</em></span>', output)
44
output = match_range.sub(
45
r'<span class="diff-range">@@ \1 @@</span>', output)
46
output = match_add.sub(
47
r'<span class="diff-add">+\1</span>', output)
48
output = match_sub.sub(
49
r'<span class="diff-sub">-\1</span>', output)
50
output = match_special.sub(
51
r'<span class="diff-special">\\\1</span>', output)
37
r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
38
r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
40
r'<span class="diff-range">@@ \1 @@</span>',
42
r'<span class="diff-add">+\1</span>',
44
r'<span class="diff-sub">-\1</span>',
46
r'<span class="diff-special">\\\1</span>'
50
output = re.compile(match, re.MULTILINE).sub(subs[match], output)
54
54
def get_revision(r_str):
70
70
# IVLE handler environment.
72
72
req = cgirequest.CGIRequest()
73
req.install_error_handler()
73
74
req.content_type = "text/html"
75
76
# Beginning of the page
76
77
req.write('<div id="ivle_padding">\n')
77
78
req.write('<h1>Diff</h1>\n')
79
# Work out the revisions from query
81
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
82
pysvn.opt_revision_kind.working]]
83
# Override revisions from query string
80
84
fields = req.get_fieldstorage()
81
85
field_r = fields.getlist("r")
83
rev1=pysvn.Revision( pysvn.opt_revision_kind.base )
84
rev2=pysvn.Revision( pysvn.opt_revision_kind.working )
85
# Override revisions from query string
87
r1 = get_revision(field_r[0])
91
r2 = get_revision(field_r[1])
86
for ri in range(len(field_r)):
87
r = get_revision(field_r[ri])
95
91
# Attempt to get the diff for these revisons
97
93
svnclient = pysvn.Client()
98
94
diff = svnclient.diff
99
95
diff_text = diff( '/tmp/svndiff',
100
path.join('/home/', req.path),
102
#revision1=pysvn.Revision( pysvn.opt_revision_kind.base ),
103
#url_or_path2=url_or_path,
105
#revision2=pysvn.Revision( opt_revision_kind.working ),
107
#ignore_ancestry=False,
109
#ignore_content_type=False,
96
os.path.join('/home', req.path),
114
101
# Split up the udiff into individual files
128
115
except pysvn._pysvn_2_5.ClientError, e:
129
116
req.write('<p><b>Error:</b></p>\n')
130
req.write('<pre class="diff">%s</pre>\n' % cgi.escape(e))
117
req.write('<pre class="diff">%s</pre>\n' % cgi.escape(str(e)))
132
119
req.write('</div>\n')