# HG changeset patch
# User Angel Ezquerra <
angel.e...@gmail.com>
# Date 1381344134 -7200
# Wed Oct 09 20:42:14 2013 +0200
# Node ID 7bf3715d98a4564f4fe2299096660ebdc30e84e4
# Parent a9b7bcd86ac1937ffd825c9fb63ecf89f994e266
revpanel: add linkpattern config to customize the target of cset links (fixes #3373)
Issue #3373 suggests that it would be nice to be able to customize the changeset
link on the revpanel so that it takes you go a web page for example.
In order to do so, we introduce a tortoisehg/linkpattern config setting, which
is a "pattern string" that serves as a pattern to generate the actual link URL.
The linkpattern uses a mercurial "template like" syntax that currently accepts
two template variables: {node}, which is replaced by the 40 digit revision id,
and {rev} which is the revision number.
For example:
linkpattern =
https://bitbucket.org/tortoisehg/thg/commits/{node}
can be used to link cset links to their corresponding bitbucket commit page.
Currently there is no GUI for this configuration option. The best settings panel
for this seems to be the Workbench panel, but it is quite crowded already.
diff --git a/tortoisehg/hgqt/revpanel.py b/tortoisehg/hgqt/revpanel.py
--- a/tortoisehg/hgqt/revpanel.py
+++ b/tortoisehg/hgqt/revpanel.py
@@ -101,15 +101,17 @@
raise csinfo.UnknownItem(item)
-def markup_func(widget, item, value):
- def link_markup(revnum, revid, enable=True):
+def create_markup_func(ui):
+ def link_markup(revnum, revid, enable=True, linkpattern=None):
mrevid = revid_markup('%s (%s)' % (revnum, revid))
if not enable:
return mrevid
- link = 'cset:%s' % revid
+ if not linkpattern:
+ linkpattern = 'cset:{node}'
+ link = linkpattern.replace('{node}', revid).replace('{revnum}', revnum)
return '<a href="%s">%s</a>' % (link, mrevid)
def revline_markup(revnum, revid, summary, highlight=None,
- branch=None, link=True):
+ branch=None, link=True, linkpattern=None):
def branch_markup(branch):
opts = dict(fg='black', bg='#aaffaa')
return qtlib.markup(' %s ' % branch, **opts)
@@ -117,7 +119,7 @@
if branch:
branch = branch_markup(branch)
if revid:
- rev = link_markup(revnum, revid, link)
+ rev = link_markup(revnum, revid, link, linkpattern=linkpattern)
if branch:
return '%s %s %s' % (rev, branch, summary)
return '%s %s' % (rev, summary)
@@ -126,26 +128,33 @@
if branch:
return '%s - %s %s' % (revnum, branch, summary)
return '%s - %s' % (revnum, summary)
- if item in ('cset', 'graft', 'transplant', 'mqoriginalparent',
- 'p4', 'svn', 'converted'):
- link = item != 'cset'
- if isinstance(value, basestring):
- return revid_markup(value)
- return revline_markup(link=link, *value)
- elif item in ('parents', 'children', 'precursors', 'successors'):
- csets = []
- for cset in value:
- if isinstance(cset, basestring):
- csets.append(revid_markup(cset))
+ def markup_func(widget, item, value):
+ if item in ('cset', 'graft', 'transplant', 'mqoriginalparent',
+ 'p4', 'svn', 'converted'):
+ if item == 'cset':
+ linkpattern = ui.config('tortoisehg', 'linkpattern', None)
+ link = linkpattern is not None
else:
- csets.append(revline_markup(*cset))
- return csets
- raise csinfo.UnknownItem(item)
+ linkpattern = None
+ link = True
+ if isinstance(value, basestring):
+ return revid_markup(value)
+ return revline_markup(link=link, linkpattern=linkpattern, *value)
+ elif item in ('parents', 'children', 'precursors', 'successors'):
+ csets = []
+ for cset in value:
+ if isinstance(cset, basestring):
+ csets.append(revid_markup(cset))
+ else:
+ csets.append(revline_markup(*cset))
+ return csets
+ raise csinfo.UnknownItem(item)
+ return markup_func
def RevPanelWidget(repo):
'''creates a rev panel widget and returns it'''
custom = csinfo.custom(data=data_func, label=label_func,
- markup=markup_func)
+ markup=create_markup_func(repo.ui))
style = csinfo.panelstyle(contents=('cset', 'branch', 'obsolete', 'close', 'user',
'dateage', 'parents', 'children', 'tags', 'graft', 'transplant',
'mqoriginalparent',