Tue Aug 23 23:04:30 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Implement alternative views.
This patch adds support for alternative patch views for all the different
patch displays (commitdiff, filediff, headdiff and headfilediff), supporting
currently a plain output and, for commitdiff, a raw one.
A darcs output is included but commented out, since I'm not familiar with
darcs' native output enough to make a syntax highlighter for it.
Besides, it also includes an alternative view for headblob (I was too lazy to
split up the patch =). Thanks to Zachary P. Landau who sent a patch to do this
(although I did it in a slightly different way).
{
hunk ./darcsweb.cgi 286
- print '<br/><br/></div>'
+ print "<br/>"
+
+ if action in ("commitdiff", "filediff", "headdiff", "headfilediff"):
+ # show the alternative patch formats
+ params = 'h=%s;' % h
+ if f:
+ params += 'f=%s;' % f
+
+ # plain first
+ print """
+<a class="link" href="%(myreponame)s;a=plain_%(act)s;%(params)s">plain</a>
+ """ % { "myreponame": config.myreponame, "act": action,
+ "params": params }
+
+ # darcs, htmlized
+ # 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 }
+
+ # darcs, raw, if available; and only for commitdiff
+ realf = filter_file(config.repodir + '/_darcs/patches/' + h)
+ if action == "commitdiff" and os.path.isfile(realf):
+ print """
+| <a class="link" href="%(myreponame)s;a=raw_%(act)s;%(params)s">raw</a>
+ """ % { "myreponame": config.myreponame,
+ "act": action, "params": params }
+
+ elif f and action == "headblob":
+ # show the only alternative format: plain
+ print """
+<a class="link" href="%(myreponame)s;a=plainblob;f=%(fname)s">plain</a>
+ """ % { "myreponame": config.myreponame, "fname": f }
+
+ print '<br/>'
+ print '</div>'
hunk ./darcsweb.cgi 571
+
+def get_diff(hash):
+ return run_darcs("diff -u --match 'hash %s'" % hash)
hunk ./darcsweb.cgi 583
+
+def get_raw_diff(hash):
+ import gzip
+ realf = filter_file(config.repodir + '/_darcs/patches/' + hash)
+ if not os.path.isfile(realf):
+ return None
+ dsrc = gzip.open(realf)
+ return dsrc
hunk ./darcsweb.cgi 816
+
+def do_plain_commitdiff(phash):
+ print_plain_header()
+ dsrc = get_diff(phash)
+ for l in dsrc:
+ sys.stdout.write(l)
+
+def do_darcs_commitdiff(phash):
+ print_plain_header()
+ print "Not yet implemented"
+
+def do_raw_commitdiff(phash):
+ print_plain_header()
+ dsrc = get_raw_diff(phash)
+ if not dsrc:
+ print "Error opening file!"
+ return
+ for l in dsrc:
+ sys.stdout.write(l)
hunk ./darcsweb.cgi 855
+
+def do_plain_headdiff(phash):
+ print_plain_header()
+ dsrc = get_patch_headdiff(phash)
+ for l in dsrc:
+ sys.stdout.write(l)
+
+def do_darcs_headdiff(phash):
+ print_plain_header()
+ print "Not yet implemented"
hunk ./darcsweb.cgi 886
+
+def do_plain_filediff(phash, fname):
+ print_plain_header()
+ dsrc = get_file_diff(phash, fname)
+ for l in dsrc:
+ sys.stdout.write(l)
+
+def do_darcs_filediff(phash, fname):
+ print_plain_header()
+ print "Not yet implemented"
hunk ./darcsweb.cgi 918
-
hunk ./darcsweb.cgi 919
-def do_plainfilediff(phash, fname):
+def do_plain_fileheaddiff(phash, fname):
hunk ./darcsweb.cgi 921
- dsrc = get_file_diff(phash, fname)
+ dsrc = get_file_headdiff(phash, fname)
hunk ./darcsweb.cgi 924
+
+def do_darcs_fileheaddiff(phash, fname):
+ print_plain_header()
+ print "Not yet implemented"
hunk ./darcsweb.cgi 1360
+
hunk ./darcsweb.cgi 1367
+elif action == "plain_commitdiff":
+ phash = filter_hash(form["h"].value)
+ do_plain_commitdiff(phash)
+elif action == "darcs_commitdiff":
+ phash = filter_hash(form["h"].value)
+ do_darcs_commitdiff(phash)
+elif action == "raw_commitdiff":
+ phash = filter_hash(form["h"].value)
+ do_raw_commitdiff(phash)
+
hunk ./darcsweb.cgi 1380
+elif action == "plain_headdiff":
+ phash = filter_hash(form["h"].value)
+ do_plain_headdiff(phash)
+elif action == "darcs_headdiff":
+ phash = filter_hash(form["h"].value)
+ do_darcs_headdiff(phash)
+
hunk ./darcsweb.cgi 1391
+elif action == "plain_filediff":
+ phash = filter_hash(form["h"].value)
+ fname = filter_file(form["f"].value)
+ do_plain_filediff(phash, fname)
+elif action == "darcs_filediff":
+ phash = filter_hash(form["h"].value)
+ do_darcs_filediff(phash)
+
hunk ./darcsweb.cgi 1403
-elif action == "plainfilediff":
+elif action == "plain_headfilediff":
hunk ./darcsweb.cgi 1406
- do_plainfilediff(phash, fname)
+ do_plain_fileheaddiff(phash, fname)
+elif action == "darcs_headfilediff":
+ phash = filter_hash(form["h"].value)
+ do_darcs_fileheaddiff(phash)
+
+
hunk ./darcsweb.cgi 1418
+
hunk ./darcsweb.cgi 1426
+
hunk ./darcsweb.cgi 1433
+
hunk ./darcsweb.cgi 1437
+
hunk ./darcsweb.cgi 1441
+
hunk ./darcsweb.cgi 1448
+
hunk ./darcsweb.cgi 1451
+
}