Sat Jul 23 22:54:35 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Implement file history (a "focused" version of shortlog).
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-10-08 15:33:00.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-10-08 15:33:01.000000000 +0000
@@ -273,8 +273,12 @@
| <a href="%(myreponame)s;a=headfilediff;h=%(hash)s;f=%(fname)s">headfilediff</a>
""" % { "myreponame": config.myreponame, 'hash': h, 'fname': f }
- print '<br/><br/></div>'
+ if f:
+ print """
+| <a class="link" href="%(myreponame)s;a=filehistory;f=%(fname)s">filehistory</a>
+ """ % { "myreponame": config.myreponame, 'fname': f }
+ print '<br/><br/></div>'
def print_plain_header():
print "Content-type: text/plain\n"
@@ -475,13 +479,26 @@
return handler
-def get_last_patches(last = 15, topi = 0):
+def get_last_patches(last = 15, topi = 0, fname = None):
"""Gets the last N patches from the repo, returns a patch list. If
"topi" is specified, then it will return the N patches that preceeded
the patch number topi in the list. It sounds messy but it's quite
- simple. FIXME: there's probably a more efficient way of doing this."""
+ simple. You can optionally pass a filename and only changes that
+ affect it will be returned. FIXME: there's probably a more efficient
+ way of doing this."""
+
+ # darcs calculate last first, and then filters the filename,
+ # so it's not so simple to combine them; that's why we do so much
+ # special casing here
toget = last + topi
- handler = get_changes_handler("-s --last=%d" % toget)
+
+ if fname:
+ if fname[0] == '/': fname = fname[1:]
+ s = "-s " + fname
+ else:
+ s = "-s --last=%d" % toget
+
+ handler = get_changes_handler(s)
# return the list of all the patch objects
return handler.get_list()[topi:toget]
@@ -531,10 +548,19 @@
print '<div class="pre" %s>' % color + escape(l) + '</div>'
-def print_shortlog(last = 50, topi = 0):
- ps = get_last_patches(last, topi)
- print '<div><a class="title" href="%s;a=shortlog">shortlog</a></div>' \
- % config.myreponame
+def print_shortlog(last = 50, topi = 0, fname = None):
+ ps = get_last_patches(last, topi, fname)
+
+ if fname:
+ title = '<a class="title" href="%s;a=filehistory;f=%s">' % \
+ (config.myreponame, fname)
+ title += 'history for file %s' % fname
+ title += '</a>'
+ else:
+ title = '<a class="title" href="%s;a=shortlog">shortlog</a>' \
+ % config.myreponame
+
+ print '<div>%s</div>' % title
print '<table cellspacing="0">'
if topi != 0:
@@ -542,8 +568,14 @@
ntopi = topi - last
if ntopi < 0:
ntopi = 0
- print '<td><a href="%s;a=shortlog;topi=%d">...</a></td>' % \
- (config.myreponame, ntopi)
+ print '<tr><td>'
+ if fname:
+ print '<a href="%s;a=filehistory;topi=%d;f=%s">...</a>' \
+ % (config.myreponame, ntopi, fname)
+ else:
+ print '<a href="%s;a=shortlog;topi=%d">...</a>' \
+ % (config.myreponame, ntopi)
+ print '</td></tr>'
alt = False
for p in ps:
@@ -574,11 +606,14 @@
if len(ps) >= last:
# only show if we've not shown them all already
- print """
-<tr><td>
- <a href="%s;a=shortlog;topi=%d">...</a>
-</td></tr>
- """ % (config.myreponame, topi + last)
+ print '<tr><td>'
+ if fname:
+ print '<a href="%s;a=filehistory;topi=%d;f=%s">...</a>' \
+ % (config.myreponame, topi + last, fname)
+ else:
+ print '<a href="%s;a=shortlog;topi=%d">...</a>' \
+ % (config.myreponame, topi + last)
+ print '</td></tr>'
print "</table>"
@@ -878,9 +913,11 @@
if show_diff:
print """
-<td><a class="link" href="%(myreponame)s;a=filediff;h=%(hash)s;f=%(file)s">
- diff
-</a></td>
+<td>
+ <a class="link" href="%(myreponame)s;a=filediff;h=%(hash)s;f=%(file)s">
+ diff</a> |
+ <a class="link" href="%(myreponame)s;a=filehistory;f=%(file)s">history</a>
+</td>
""" % {
'myreponame': config.myreponame,
'hash': p.hash,
@@ -946,7 +983,10 @@
if f in dlist:
print """
<td><a class="list" href="%(myrname)s;a=tree;f=%(newf)s">%(f)s</a></td>
- <td><a class="link" href="%(myrname)s;a=tree;f=%(newf)s">tree</a></td>
+ <td>
+ <a class="link" href="%(myrname)s;a=filehistory;f=%(newf)s">history</a> |
+ <a class="link" href="%(myrname)s;a=tree;f=%(newf)s">tree</a>
+ </td>
""" % {
'myrname': config.myreponame,
'f': f,
@@ -955,7 +995,10 @@
else:
print """
<td><a class="list" href="%(myrname)s;a=headblob;f=%(fullf)s">%(f)s</a></td>
- <td><a class="link" href="%(myrname)s;a=headblob;f=%(fullf)s">headblob</a></td>
+ <td>
+ <a class="link" href="%(myrname)s;a=filehistory;f=%(fullf)s">history</a> |
+ <a class="link" href="%(myrname)s;a=headblob;f=%(fullf)s">headblob</a>
+ </td>
""" % {
'myrname': config.myreponame,
'f': f,
@@ -1004,6 +1047,11 @@
print_shortlog(topi = topi)
print_footer()
+def do_filehistory(topi, f):
+ print_header()
+ print_navbar(f = fname)
+ print_shortlog(topi = topi, fname = fname)
+ print_footer()
def do_log(topi):
print_header()
@@ -1223,6 +1271,13 @@
else:
topi = 0
do_shortlog(topi)
+elif action == "filehistory":
+ if form.has_key("topi"):
+ topi = int(filter_num(form["topi"].value))
+ else:
+ 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))