[viewvc-dev] Patch: permit additional short- and long-format log post-processing.
Jan Grant <[email protected]>
| Newsgroups | gmane.comp.version-control.cvs.viewcvs.devel |
|---|---|
| Message-ID | <[email protected]> |
Attached is a small patch that scratches an itch I've had for a while. We run a ticketting system here and log messages often arrive with references to a particular ticket in them, eg: [[[ changes to foo() and bar(), see rtbaz#9876 ]]] I hacked a local version that identifies strings of the appropriate format and turns them into links to the appropriate ticket detail in the issue tracker. Thought this might be useful so here's a version that is customisable by deployers without changing the main viewvc codebase during deployment. You use it like this: viewvc.conf: [[[ # The name of a module which can htmlify and otherwise # post-process log messages for display. log_post_process = vclog.example ]]] In lib/vclog/example.py (or elsewhere on your python path), two functions: [[[ import viewvc.htmlify def format_short_log(message, request): pass def format_long_log(message, request): pass ]]] which override the format_short_log and format_long_log calls in viewvc.py. Typically these can call htmlify as per usual and then follow that up with something that looks for additional regexps. I think I've found every instance of log message formatting and shoved it through one of format_short_log or format_long_log as appropriate, rather than the direct calls to htmlify. Let me know what you think. Cheers, jan -- jan grant, ISYS, University of Bristol. http://www.bris.ac.uk/ Tel +44 (0)117 3317661 http://ioctl.org/jan/ Bolstered by my success with vi, I proceeded to learn C with 'learn c'. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
viewvc.diff
(text/plain, 4.8 KB)
Index: viewvc-svn/lib/viewvc.py
===================================================================
--- viewvc-svn/lib/viewvc.py (revision 1734)
+++ viewvc-svn/lib/viewvc.py (working copy)
@@ -144,6 +144,15 @@
self.pathrev = None # current path revision or tag
self.auth = None # authorizer module in use
+ # If one was specified, set up the log post-processing function.
+ self.format_log = None
+ if cfg.options.log_post_process:
+ format_log = __import__(cfg.options.log_post_process)
+ components = cfg.options.log_post_process.split('.')
+ for comp in components[1:]:
+ format_log = getattr(format_log, comp)
+ self.format_log = format_log
+
# setup the default authorizer (until we have a root)
self.auth = vcauth.ViewVCAuthorizer()
@@ -1050,15 +1059,22 @@
r'<a href="mailto:\1@\2">\1@\2</a>', html)
return html
-def format_log(log, cfg):
+def format_short_log(log, request):
if not log:
return log
- s = htmlify(log[:cfg.options.short_log_len],
- cfg.options.mangle_email_addresses)
- if len(log) > cfg.options.short_log_len:
- s = s + '...'
- return s
+ if not request.format_log:
+ s = htmlify(log[:request.cfg.options.short_log_len],
+ request.cfg.options.mangle_email_addresses)
+ if len(log) > request.cfg.options.short_log_len:
+ s = s + '...'
+ return s
+ return request.format_log.format_short_log(log, request)
+def format_long_log(log, request):
+ if not request.format_log:
+ return htmlify(log, request.cfg.options.mangle_email_addresses)
+ return request.format_log.format_long_log(log, request)
+
_time_desc = {
1 : 'second',
60 : 'minute',
@@ -1514,7 +1530,7 @@
'date' : make_time_string(entry.date, cfg),
'author' : entry.author,
'changed' : entry.changed,
- 'log' : htmlify(entry.log, cfg.options.mangle_email_addresses),
+ 'log' : format_long_log(entry.log, request),
'size' : entry.size,
})
@@ -1737,8 +1753,8 @@
row.date = make_time_string(file.date, cfg)
row.ago = html_time(request, file.date)
if cfg.options.show_logs:
- row.short_log = format_log(file.log, cfg)
- row.log = htmlify(file.log, cfg.options.mangle_email_addresses)
+ row.short_log = format_short_log(file.log, request)
+ row.log = format_long_log(file.log, request)
row.anchor = request.server.escape(file.name)
row.name = request.server.escape(file.name)
@@ -2047,7 +2063,7 @@
entry.ago = None
if rev.date is not None:
entry.ago = html_time(request, rev.date, 1)
- entry.log = htmlify(rev.log or "", cfg.options.mangle_email_addresses)
+ entry.log = format_long_log(rev.log, request)
entry.size = rev.size
entry.branch_point = None
entry.next_main = None
@@ -2351,7 +2367,7 @@
'date' : make_time_string(entry.date, cfg),
'author' : entry.author,
'changed' : entry.changed,
- 'log' : htmlify(entry.log, cfg.options.mangle_email_addresses),
+ 'log' : format_long_log(entry.log, request),
'size' : entry.size,
})
@@ -3351,7 +3367,7 @@
'rev' : str(rev),
'author' : author,
'date' : date_str,
- 'log' : msg and htmlify(msg, cfg.options.mangle_email_addresses) or None,
+ 'log' : format_long_log(msg, request),
'ago' : None,
'changes' : changes,
'prev_href' : prev_rev_href,
@@ -3510,8 +3526,8 @@
commit = _item(num_files=len(files), files=[])
commit.limited_files = ezt.boolean(limited_files)
desc = files[0].GetDescription()
- commit.log = htmlify(desc, cfg.options.mangle_email_addresses)
- commit.short_log = format_log(desc, cfg)
+ commit.log = format_long_log(desc, request)
+ commit.short_log = format_short_log(desc, request)
commit.author = request.server.escape(files[0].GetAuthor())
commit.rss_date = make_rss_time_string(files[0].GetTime(), cfg)
if request.roottype == 'svn':
@@ -3911,6 +3927,8 @@
cvsroot = os.path.exists(os.path.join(pp, "CVSROOT", "config"))
for subpath in subpaths:
+ if subpath == '.svn':
+ continue
if os.path.exists(os.path.join(pp, subpath)):
if (repo_type == 'cvs'
and (os.path.exists(os.path.join(pp, subpath, "CVSROOT", "config"))
Index: viewvc-svn/lib/config.py
===================================================================
--- viewvc-svn/lib/config.py (revision 1734)
+++ viewvc-svn/lib/config.py (working copy)
@@ -247,6 +247,7 @@
self.options.use_re_search = 0
self.options.use_pagesize = 0
self.options.limit_changes = 100
+ self.options.log_post_process = None
self.templates.annotate = None
self.templates.diff = None