Support darcs-style diff output.
Wed Sep 7 06:25:28 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Support darcs-style diff output.
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-10-18 11:45:41.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-10-18 11:45:41.000000000 +0000
@@ -284,24 +284,37 @@
print "<br/>"
- 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 """
-<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=%(act)s;%(params)s">unified</a>
+ """ % { "myreponame": config.myreponame, "act": efaction,
+ "params": params }
+
+ # plain
+ print """
+| <a class="link" href="%(myreponame)s;a=plain_%(act)s;%(params)s">plain</a>
+ """ % { "myreponame": config.myreponame, "act": efaction,
"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 }
+ print """
+| <a class="link" href="%(myreponame)s;a=darcs_%(act)s;%(params)s">darcs</a>
+ """ % { "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 """
| <a class="link" href="%(myreponame)s;a=raw_%(act)s;%(params)s">raw</a>
""" % { "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 '<div class="diff_info">%s</div>' % l
+ print '<div class="diff_info">%s</div>' % escape(l)
continue
color = ""
@@ -619,6 +643,26 @@
print '<div class="pre" %s>' % color + escape(l) + '</div>'
+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>'
+
+
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 """
+<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()
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 """
+<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):
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 """
+<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()
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 """
+<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()
+
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":