25
25
# run from the trampoline by the Diff application.
27
27
from common import cgirequest
28
from cgi import parse_qs
34
34
def htmlfy_diff(difftext):
35
35
"""Adds HTML markup to a udiff string"""
36
36
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)
38
r'^([\+\-]{3})\s(\S+)\s\((.+)\)$':
39
r'<span class="diff-files">\1 \2 <em>(\3)</em></span>',
41
r'<span class="diff-range">@@ \1 @@</span>',
43
r'<span class="diff-add">+\1</span>',
45
r'<span class="diff-sub">-\1</span>',
47
r'<span class="diff-special">\\\1</span>'
51
output = re.compile(match, re.MULTILINE).sub(subs[match], output)
54
def get_revision(r_str):
55
""" Returns a Revison object for pysvn from a r query string """
57
return pysvn.Revision( pysvn.opt_revision_kind.head )
58
elif r_str == "WORKING":
59
return pysvn.Revision( pysvn.opt_revision_kind.working )
61
return pysvn.Revision( pysvn.opt_revision_kind.base )
65
return pysvn.Revision( pysvn.opt_revision_kind.number, r)
69
55
# Use a CGIRequest object to make the CGI environment look like the normal
70
56
# IVLE handler environment.
72
58
req = cgirequest.CGIRequest()
59
req.install_error_handler()
73
60
req.content_type = "text/html"
75
62
# Beginning of the page
76
63
req.write('<div id="ivle_padding">\n')
77
64
req.write('<h1>Diff</h1>\n')
79
# Work out the revisions from query
67
revs = [pysvn.Revision(x) for x in [pysvn.opt_revision_kind.base,
68
pysvn.opt_revision_kind.working]]
69
# Override revisions from query string
80
70
fields = req.get_fieldstorage()
81
71
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])
72
for ri in range(len(field_r)):
73
r = common.svn.revision_from_string(field_r[ri])
95
77
# Attempt to get the diff for these revisons
97
79
svnclient = pysvn.Client()
98
80
diff = svnclient.diff
99
81
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,
82
os.path.join('/home', req.path),
114
87
# Split up the udiff into individual files