Wed Sep 7 06:25:28 UTC 2005 Alberto Bertogli * Support darcs-style diff output. diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi --- old-darcsweb/darcsweb.cgi 2015-10-27 15:24:08.000000000 +0000 +++ new-darcsweb/darcsweb.cgi 2015-10-27 15:24:08.000000000 +0000 @@ -284,24 +284,37 @@ print "
" - 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"): # show the alternative patch formats params = 'h=%s;' % h if f: params += 'f=%s;' % f - # plain first + # normal (unified) print """ -plain - """ % { "myreponame": config.myreponame, "act": action, +unified + """ % { "myreponame": config.myreponame, "act": efaction, + "params": params } + + # plain + print """ +| plain + """ % { "myreponame": config.myreponame, "act": efaction, "params": params } # darcs, htmlized - # TODO: not yet -# print """ -#| darcs -# """ % { "myreponame": config.myreponame, "act": action, -# "params": params } + print """ +| darcs + """ % { "myreponame": config.myreponame, "act": efaction, + "params": params } # darcs, raw, if available; and only for commitdiff realf = filter_file(config.repodir + '/_darcs/patches/' + h) @@ -309,7 +322,7 @@ print """ | raw """ % { "myreponame": config.myreponame, - "act": action, "params": params } + "act": efaction, "params": params } elif f and action == "headblob": # show the only alternative format: plain @@ -588,6 +601,17 @@ dsrc = gzip.open(realf) return dsrc +def get_darcs_diff(hash, fname = None): + cmd = 'changes -v --matches "hash %s"' % hash + if fname: + cmd += ' "%s"' % fname + return run_darcs(cmd) + +def get_darcs_headdiff(hash, fname = None): + cmd = 'changes -v --from-match "hash %s"' % hash + if fname: + cmd += ' "%s"' % fname + return run_darcs(cmd) # # specific html functions @@ -603,7 +627,7 @@ if l.startswith('diff'): # file lines, they have their own class - print '
%s
' % l + print '
%s
' % escape(l) continue color = "" @@ -619,6 +643,26 @@ print '
' % color + escape(l) + '
' +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 '
' + escape(l) + "
" + 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 '
' % cl + escape(l) + '
' + + def print_shortlog(last = 50, topi = 0, fname = None): ps = get_last_patches(last, topi, fname) @@ -820,8 +864,22 @@ sys.stdout.write(l) def do_darcs_commitdiff(phash): - print_plain_header() - print "Not yet implemented" + print_header() + print_navbar(h = phash) + p = get_patch(phash) + print """ +
+ %(name)s +
+ """ % { + 'myreponame': config.myreponame, + 'hash': p.hash, + 'name': p.name, + } + + dsrc = get_darcs_diff(phash) + print_darcs_diff(dsrc) + print_footer() def do_raw_commitdiff(phash): print_plain_header() @@ -859,8 +917,29 @@ sys.stdout.write(l) def do_darcs_headdiff(phash): + print_header() + print_navbar(h = phash) + p = get_patch(phash) + print """ +
+ + %(name)s --> to head +
+ """ % { + '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): print_plain_header() - print "Not yet implemented" + dsrc = get_darcs_headdiff(phash) + for l in dsrc: + sys.stdout.write(l) def do_filediff(phash, fname): @@ -890,8 +969,24 @@ sys.stdout.write(l) def do_darcs_filediff(phash, fname): - print_plain_header() - print "Not yet implemented" + print_header() + print_navbar(h = phash) + p = get_patch(phash) + print """ +
+ %(name)s +
+
%(fname)s
+ """ % { + 'myreponame': config.myreponame, + 'hash': p.hash, + 'name': p.name, + 'fname': fname, + } + + dsrc = get_darcs_diff(phash, fname) + print_darcs_diff(dsrc) + print_footer() def do_file_headdiff(phash, fname): @@ -922,6 +1017,26 @@ sys.stdout.write(l) def do_darcs_fileheaddiff(phash, fname): + print_header() + print_navbar(h = phash) + p = get_patch(phash) + print """ +
+ + %(name)s --> to head +
+
%(fname)s
+ """ % { + 'myreponame': config.myreponame, + 'hash': p.hash, + 'name': p.name, + 'fname': fname, + } + + dsrc = get_darcs_headdiff(phash, fname) + print_darcs_diff(dsrc) + print_footer() + print_plain_header() print "Not yet implemented" @@ -1434,7 +1549,8 @@ do_plain_filediff(phash, fname) elif action == "darcs_filediff": phash = filter_hash(form["h"].value) - do_darcs_filediff(phash) + fname = filter_file(form["f"].value) + do_darcs_filediff(phash, fname) elif action == 'headfilediff': phash = filter_hash(form["h"].value) @@ -1446,7 +1562,8 @@ do_plain_fileheaddiff(phash, fname) elif action == "darcs_headfilediff": phash = filter_hash(form["h"].value) - do_darcs_fileheaddiff(phash) + fname = filter_file(form["f"].value) + do_darcs_fileheaddiff(phash, fname) elif action == "shortlog":