Tue Aug 23 23:04:30 UTC 2005 Alberto Bertogli * 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). diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi --- old-darcsweb/darcsweb.cgi 2015-10-09 09:11:21.000000000 +0000 +++ new-darcsweb/darcsweb.cgi 2015-10-09 09:11:21.000000000 +0000 @@ -283,7 +283,43 @@ | filehistory """ % { "myreponame": config.myreponame, 'fname': f } - print '

' + print "
" + + 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 """ +plain + """ % { "myreponame": config.myreponame, "act": action, + "params": params } + + # darcs, htmlized + # TODO: not yet +# print """ +#| darcs +# """ % { "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 """ +| raw + """ % { "myreponame": config.myreponame, + "act": action, "params": params } + + elif f and action == "headblob": + # show the only alternative format: plain + print """ +plain + """ % { "myreponame": config.myreponame, "fname": f } + + print '
' + print '' def print_plain_header(): print "Content-type: text/plain\n" @@ -533,6 +569,9 @@ patch = handler.db[handler.list[0]] return patch +def get_diff(hash): + return run_darcs("diff -u --match 'hash %s'" % hash) + def get_file_diff(hash, fname): return run_darcs("diff -u --match 'hash %s' '%s'" % (hash, fname)) @@ -542,6 +581,14 @@ def get_patch_headdiff(hash): return run_darcs("diff -u --from-match 'hash %s'" % hash) +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 + # # specific html functions @@ -767,6 +814,25 @@ print_diff(dsrc) print_footer() +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) + def do_headdiff(phash): print_header() @@ -787,6 +853,16 @@ print_diff(dsrc) print_footer() +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" + def do_filediff(phash, fname): print_header() @@ -808,6 +884,16 @@ print_diff(dsrc) print_footer() +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" + def do_file_headdiff(phash, fname): print_header() @@ -830,13 +916,16 @@ print_diff(dsrc) print_footer() - -def do_plainfilediff(phash, fname): +def do_plain_fileheaddiff(phash, fname): print_plain_header() - dsrc = get_file_diff(phash, fname) + dsrc = get_file_headdiff(phash, fname) for l in dsrc: sys.stdout.write(l) +def do_darcs_fileheaddiff(phash, fname): + print_plain_header() + print "Not yet implemented" + def do_commit(phash): print_header() @@ -1268,33 +1357,65 @@ # see what should we do according to the received action if action == "summary": do_summary() + elif action == "commit": phash = filter_hash(form["h"].value) do_commit(phash) elif action == "commitdiff": phash = filter_hash(form["h"].value) do_commitdiff(phash) +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) + elif action == 'headdiff': phash = filter_hash(form["h"].value) do_headdiff(phash) +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) + elif action == "filediff": phash = filter_hash(form["h"].value) fname = filter_file(form["f"].value) do_filediff(phash, fname) +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) + elif action == 'headfilediff': phash = filter_hash(form["h"].value) fname = filter_file(form["f"].value) do_file_headdiff(phash, fname) -elif action == "plainfilediff": +elif action == "plain_headfilediff": phash = filter_hash(form["h"].value) fname = filter_file(form["f"].value) - do_plainfilediff(phash, fname) + do_plain_fileheaddiff(phash, fname) +elif action == "darcs_headfilediff": + phash = filter_hash(form["h"].value) + do_darcs_fileheaddiff(phash) + + elif action == "shortlog": if form.has_key("topi"): topi = int(filter_num(form["topi"].value)) else: topi = 0 do_shortlog(topi) + elif action == "filehistory": if form.has_key("topi"): topi = int(filter_num(form["topi"].value)) @@ -1302,26 +1423,32 @@ topi = 0 fname = filter_file(form["f"].value) do_filehistory(topi, fname) + elif action == "log": if form.has_key("topi"): topi = int(filter_num(form["topi"].value)) else: topi = 0 do_log(topi) + elif action == 'headblob': fname = filter_file(form["f"].value) do_headblob(fname) + elif action == 'plainblob': fname = filter_file(form["f"].value) do_plainblob(fname) + elif action == 'tree': if form.has_key('f'): fname = filter_file(form["f"].value) else: fname = '/' do_tree(fname) + elif action == 'rss': do_rss() + else: action = "invalid query" do_die()