Support darcs-style diff output.
Wed Sep 7 06:25:28 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Support darcs-style diff output.
{
hunk ./darcsweb.cgi 287
- if action in ("commitdiff", "filediff", "headdiff", "headfilediff"):
+ efaction = action
+ if '_' in action:
+ # action is composed as "format_action", like
+ # "darcs_commitdiff"; so we get the "effective action" to
+ # decide if we need to present the "alternative formats" menu
+ pos = action.find('_')
+ fmt = action[:pos]
+ efaction = action[pos + 1:]
+ if efaction in ("commitdiff", "filediff", "headdiff", "headfilediff"):
hunk ./darcsweb.cgi 301
- # plain first
+ # normal (unified)
+ print """
+<a class="link" href="%(myreponame)s;a=%(act)s;%(params)s">unified</a>
+ """ % { "myreponame": config.myreponame, "act": efaction,
+ "params": params }
+
+ # plain
hunk ./darcsweb.cgi 309
-<a class="link" href="%(myreponame)s;a=plain_%(act)s;%(params)s">plain</a>
- """ % { "myreponame": config.myreponame, "act": action,
+| <a class="link" href="%(myreponame)s;a=plain_%(act)s;%(params)s">plain</a>
+ """ % { "myreponame": config.myreponame, "act": efaction,
hunk ./darcsweb.cgi 314
- # TODO: not yet
-# print """
-#| <a class="link" href="%(myreponame)s;a=darcs_%(act)s;%(params)s">darcs</a>
-# """ % { "myreponame": config.myreponame, "act": action,
-# "params": params }
+ print """
+| <a class="link" href="%(myreponame)s;a=darcs_%(act)s;%(params)s">darcs</a>
+ """ % { "myreponame": config.myreponame, "act": efaction,
+ "params": params }
hunk ./darcsweb.cgi 325
- "act": action, "params": params }
+ "act": efaction, "params": params }
hunk ./darcsweb.cgi 603
+
+def get_darcs_diff(hash, fname = None):
+ cmd = 'changes -v --matches "hash %s"' % hash
+ if fname:
+ cmd += ' "%s"' % fname
+ return run_darcs(cmd)
hunk ./darcsweb.cgi 610
+def get_darcs_headdiff(hash, fname = None):
+ cmd = 'changes -v --from-match "hash %s"' % hash
+ if fname:
+ cmd += ' "%s"' % fname
+ return run_darcs(cmd)
hunk ./darcsweb.cgi 630
- print '<div class="diff_info">%s</div>' % l
+ print '<div class="diff_info">%s</div>' % escape(l)
hunk ./darcsweb.cgi 644
+
+
+def print_darcs_diff(dsrc):
+ for l in dsrc:
+ l = l.decode(config.repoencoding, 'replace').encode('utf-8')
+
+ if not l.startswith(" "):
+ # comments and normal stuff
+ print '<div class="pre">' + escape(l) + "</div>"
+ continue
+
+ l = l.strip()
+
+ if l[0] == '+':
+ cl = 'class="pre" style="color:#008800;"'
+ elif l[0] == '-':
+ cl = 'class="pre" style="color:#cc0000;"'
+ else:
+ cl = 'class="diff_info"'
+ print '<div %s>' % cl + escape(l) + '</div>'
hunk ./darcsweb.cgi 867
- print_plain_header()
- print "Not yet implemented"
+ print_header()
+ print_navbar(h = phash)
+ p = get_patch(phash)
+ print """
+<div>
+ <a class="title" href="%(myreponame)s;a=commit;h=%(hash)s">%(name)s</a>
+</div>
+ """ % {
+ 'myreponame': config.myreponame,
+ 'hash': p.hash,
+ 'name': p.name,
+ }
+
+ dsrc = get_darcs_diff(phash)
+ print_darcs_diff(dsrc)
+ print_footer()
hunk ./darcsweb.cgi 920
+ print_header()
+ print_navbar(h = phash)
+ p = get_patch(phash)
+ print """
+<div>
+ <a class="title" href="%(myreponame)s;a=commit;h=%(hash)s">
+ %(name)s --&gt; to head</a>
+</div>
+ """ % {
+ 'myreponame': config.myreponame,
+ 'hash': p.hash,
+ 'name': p.name,
+ }
+
+ dsrc = get_darcs_headdiff(phash)
+ print_darcs_diff(dsrc)
+ print_footer()
+
+def do_raw_headdiff(phash):
hunk ./darcsweb.cgi 940
- print "Not yet implemented"
+ dsrc = get_darcs_headdiff(phash)
+ for l in dsrc:
+ sys.stdout.write(l)
hunk ./darcsweb.cgi 972
- print_plain_header()
- print "Not yet implemented"
+ print_header()
+ print_navbar(h = phash)
+ p = get_patch(phash)
+ print """
+<div>
+ <a class="title" href="%(myreponame)s;a=commit;h=%(hash)s">%(name)s</a>
+</div>
+<div class="page_path"><b>%(fname)s</b></div>
+ """ % {
+ 'myreponame': config.myreponame,
+ 'hash': p.hash,
+ 'name': p.name,
+ 'fname': fname,
+ }
+
+ dsrc = get_darcs_diff(phash, fname)
+ print_darcs_diff(dsrc)
+ print_footer()
hunk ./darcsweb.cgi 1020
+ print_header()
+ print_navbar(h = phash)
+ p = get_patch(phash)
+ print """
+<div>
+ <a class="title" href="%(myreponame)s;a=commit;h=%(hash)s">
+ %(name)s --&gt; to head</a>
+</div>
+<div class="page_path"><b>%(fname)s</b></div>
+ """ % {
+ 'myreponame': config.myreponame,
+ 'hash': p.hash,
+ 'name': p.name,
+ 'fname': fname,
+ }
+
+ dsrc = get_darcs_headdiff(phash, fname)
+ print_darcs_diff(dsrc)
+ print_footer()
+
hunk ./darcsweb.cgi 1552
- do_darcs_filediff(phash)
+ fname = filter_file(form["f"].value)
+ do_darcs_filediff(phash, fname)
hunk ./darcsweb.cgi 1565
- do_darcs_fileheaddiff(phash)
+ fname = filter_file(form["f"].value)
+ do_darcs_fileheaddiff(phash, fname)
}