Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9.2, 1.9.3, and 2.0

qtlib, revmessage: migrate issue.link feature from hgtk.changeset

Changeset 8bb85c4c2c0b

Parent c5ce70af9811

by Yuya Nishihara

Changes to 3 files · Browse files at 8bb85c4c2c0b Showing diff from parent c5ce70af9811 Diff from another changeset...

 
146
147
148
149
 
150
151
152
 
 
 
153
154
155
 
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170
171
172
173
174
175
 
 
 
 
 
 
 
 
 
176
177
178
 
191
192
193
 
 
 
 
 
 
 
 
 
 
 
194
195
196
 
146
147
148
 
149
150
151
 
152
153
154
155
156
157
 
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
 
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
 
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@@ -146,10 +146,12 @@
  msg = msg.replace('\n', '<br />')   return '<span style="%s">%s</span>' % (style, msg)   -def descriptionhtmlizer(): +def descriptionhtmlizer(ui):   """Return a function to mark up ctx.description() as an HTML   - >>> htmlize = descriptionhtmlizer() + >>> from mercurial import ui + >>> u = ui.ui() + >>> htmlize = descriptionhtmlizer(u)   >>> htmlize('foo <bar> \\n& <baz>')   u'foo &lt;bar&gt; \\n&amp; &lt;baz&gt;'   @@ -166,13 +168,48 @@
  u'http://example.com:8000/foo?bar=baz&amp;bax#blah</a>')   >>> htmlize('https://example/')   u'<a href="https://example/">https://example/</a>' + + issue links: + >>> u.setconfig('tortoisehg', 'issue.regex', r'#(\\d+)\\b') + >>> u.setconfig('tortoisehg', 'issue.link', 'http://example/issue/{1}/') + >>> htmlize = descriptionhtmlizer(u) + >>> htmlize('foo #123') + u'foo <a href="http://example/issue/123/">#123</a>' + + missing issue.link setting: + >>> u.setconfig('tortoisehg', 'issue.link', '') + >>> htmlize = descriptionhtmlizer(u) + >>> htmlize('foo #123') + u'foo #123' + + too many replacements in issue.link: + >>> u.setconfig('tortoisehg', 'issue.link', 'http://example/issue/{1}/{2}') + >>> htmlize = descriptionhtmlizer(u) + >>> htmlize('foo #123') + u'foo #123' + + invalid regexp in issue.regex: + >>> u.setconfig('tortoisehg', 'issue.regex', '(') + >>> htmlize = descriptionhtmlizer(u) + >>> htmlize('foo #123') + u'foo #123' + >>> htmlize('http://example/') + u'<a href="http://example/">http://example/</a>'   """ - # TODO: support tortoisehg.issue.regex and issue.link   csmatch = r'(\b[0-9a-f]{12}(?:[0-9a-f]{28})?\b)'   httpmatch = r'(\b(http|https)://([-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]))'   regexp = r'%s|%s' % (csmatch, httpmatch)   bodyre = re.compile(regexp)   + issuematch = ui.config('tortoisehg', 'issue.regex') + issuerepl = ui.config('tortoisehg', 'issue.link') + if issuematch and issuerepl: + regexp += '|(%s)' % issuematch + try: + bodyre = re.compile(regexp) + except re.error: + pass +   def htmlize(desc):   """Mark up ctx.description() [localstr] as an HTML [unicode]"""   desc = unicode(Qt.escape(hglib.tounicode(desc))) @@ -191,6 +228,17 @@
  if groups[1]:   urllink = groups[1]   buf += '<a href="%s">%s</a>' % (urllink, urllink) + if len(groups) > 4 and groups[4]: + issue = groups[4] + issueparams = groups[4:] + try: + link = re.sub(r'\{(\d+)\}', + lambda m: issueparams[int(m.group(1))], + issuerepl) + buf += '<a href="%s">%s</a>' % (link, issue) + except IndexError: + buf += issue +   if pos < len(desc):   buf += desc[pos:]  
 
130
131
132
133
 
134
135
136
 
130
131
132
 
133
134
135
136
@@ -130,7 +130,7 @@
  self.message_splitter.setMidLineWidth(0)   self.message_splitter.setOrientation(Qt.Vertical)   self.message_splitter.setOpaqueResize(True) - self.message = RevMessage(self.message_splitter) + self.message = RevMessage(self.repo.ui, self.message_splitter)   self.message.linkActivated.connect(self.linkActivated)     sp = SP(SP.Expanding, SP.Expanding)
 
22
23
24
25
 
26
27
28
 
39
40
41
42
 
43
44
45
 
22
23
24
 
25
26
27
28
 
39
40
41
 
42
43
44
45
@@ -22,7 +22,7 @@
 class RevMessage(QWidget):   linkActivated = pyqtSignal(unicode)   - def __init__(self, parent): + def __init__(self, ui, parent):   QWidget.__init__(self, parent)     vb = QVBoxLayout() @@ -39,7 +39,7 @@
    self.setLayout(vb)   - self._htmlize = qtlib.descriptionhtmlizer() + self._htmlize = qtlib.descriptionhtmlizer(ui)     self._message.anchorClicked.connect(   lambda url: self.linkActivated.emit(url.toString()))