Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

changeset: add changeset and issue tracker links

Closes #315
Refs #369

Every word-boundary delimited string of 12 or 40 characters from the
range [0-9a-f] is considered a changeset link. Clicking on it in the
repository explorer, will jump to the given changeset if possible.

Issue tracker links are enabled when configured in the tortoisehg
section of the configuration files. There are two keys: issue.regex
and issue.link. The first defines the regex to match when picking up
issue numbers, while the second defines the command to run when an
issue number is recognized.

You may include groups in issue.regex, and corresponding {n} tokens
in issue.link (where n is a non-negative integer). {0} refers to the
entire string matched by issue.regex, while {1} refers to the first
group and so on. If no {n} tokens are found in issue.link, the entire
matched string is appended instead.

Examples:

BitBucket:
issue.regex = #(\d+)\b
issue.link = http://bitbucket.org/<your project and repo>/issue/{1}/

Mercurial:
issue.regex = \bissue\d+\b
issue.link = http://mercurial.selenic.com/bts/

Changeset 529de39db722

Parent 8542ac67763d

by Sune Foldager

Changes to one file · Browse files at 529de39db722 Showing diff from parent 8542ac67763d Diff from another changeset...

 
6
7
8
 
9
10
11
 
16
17
18
19
 
20
21
22
 
26
27
28
 
 
 
 
 
 
 
 
29
30
31
 
261
262
263
264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
266
267
 
726
727
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
730
731
 
6
7
8
9
10
11
12
 
17
18
19
 
20
21
22
23
 
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
270
271
272
 
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
 
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
@@ -6,6 +6,7 @@
 # GNU General Public License version 2, incorporated herein by reference.    import os +import re  import gtk  import gobject  import pango @@ -16,7 +17,7 @@
 from tortoisehg.util.i18n import _  from tortoisehg.util import shlib, hglib   -from tortoisehg.hgtk import csinfo, gdialog, gtklib, hgcmd, statusbar +from tortoisehg.hgtk import csinfo, gdialog, gtklib, hgcmd, statusbar, about    class ChangeSet(gdialog.GDialog):   'GTK+ based dialog for displaying repository logs' @@ -26,6 +27,14 @@
  self.glog_parent = None   self.bfile = None   + # initialize changeset/issue tracker link regex and dict + match = r'(\b[0-9a-f]{12}(?:[0-9a-f]{28})?\b)' + issue = repo.ui.config('tortoisehg', 'issue.regex') + if issue: + match = r'%s|(%s)' % (match, issue) + self.bodyre = re.compile(match) + self.issuedict = dict() +   def get_title(self):   title = _('%s changeset ') % self.get_reponame()   rev = self.opts['rev'] @@ -261,7 +270,26 @@
  buf = self._buffer   buf.set_text('')   eob = buf.get_end_iter() - buf.insert(eob, desc + '\n\n') + + pos = 0 + self.issuedict.clear() + for m in self.bodyre.finditer(desc): + a, b = m.span() + if a > pos: + buf.insert(eob, desc[pos:a]) + pos = b + groups = m.groups() + link = groups[0] + if link: + buf.insert_with_tags_by_name(eob, link, 'csetlink') + else: + link = groups[1] + if len(groups) > 2: + self.issuedict[link] = groups[1:] + buf.insert_with_tags_by_name(eob, link, 'issuelink') + if pos < len(desc): + buf.insert(eob, desc[pos:]) + buf.insert(eob, '\n\n')     def append_diff(self, wfile):   if not wfile: @@ -726,6 +754,56 @@
  weight=pango.WEIGHT_BOLD))   tag_table.add(make_texttag('yellowbg', background='yellow'))   + issuelink_tag = make_texttag('issuelink', foreground='blue', + underline=pango.UNDERLINE_SINGLE) + issuelink_tag.connect('event', self.issuelink_event) + tag_table.add(issuelink_tag) + csetlink_tag = make_texttag('csetlink', foreground='blue', + underline=pango.UNDERLINE_SINGLE) + csetlink_tag.connect('event', self.csetlink_event) + tag_table.add(csetlink_tag) + + def issuelink_event(self, tag, widget, event, liter): + if event.type != gtk.gdk.BUTTON_RELEASE: + return + text = self.get_link_text(tag, widget, liter) + if not text: + return + link = self.repo.ui.config('tortoisehg', 'issue.link') + if link: + groups = self.issuedict.get(text, [text]) + link, num = re.subn(r'\{(\d+)\}', lambda m: + groups[int(m.group(1))], link) + if not num: + link += text + about.browse_url(link) + + def csetlink_event(self, tag, widget, event, liter): + if event.type != gtk.gdk.BUTTON_RELEASE: + return + text = self.get_link_text(tag, widget, liter) + if not text: + return + try: + rev = self.repo[text].rev() + if self.graphview: + self.graphview.set_revision_id(rev, load=True) + else: + self.load_details(rev) + except RepoError: + pass + + def get_link_text(self, tag, widget, liter): + text_buffer = widget.get_buffer() + beg = liter.copy() + while not beg.begins_tag(tag): + beg.backward_char() + end = liter.copy() + while not end.ends_tag(tag): + end.forward_char() + text = text_buffer.get_text(beg, end) + return text +   def file_button_release(self, widget, event):   if event.button == 3 and not (event.state & (gtk.gdk.SHIFT_MASK |   gtk.gdk.CONTROL_MASK)):