Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>mata's answer is clever, but there's actually a built in way to do this if you're willing to write your own extension (it's <a href="http://mercurial.selenic.com/wiki/WritingExtensions">really easy</a>, little more than just writing the hook functionality you wanted to write anyway).</p> <p>The "right" way to do this is to subclass the repository in <code>reposetup</code>, as shown in the docstring of <code>mercurial.extensions.wrapfunction</code> (because it turns out <code>wrapfunction</code> is not the right way to do it for repos:</p> <blockquote> <pre><code>Wrapping methods of the repository object is not recommended since it conflicts with extensions that extend the repository by subclassing. All extensions that need to extend methods of localrepository should use this subclassing trick: namely, reposetup() should look like def reposetup(ui, repo): class myrepo(repo.__class__): def whatever(self, *args, **kwargs): [...extension stuff...] super(myrepo, self).whatever(*args, **kwargs) [...extension stuff...] repo.__class__ = myrepo </code></pre> </blockquote> <p>So for instance, your extension would look like this (stripped down):</p> <pre><code>#!/usr/bin/python import re import mercurial, sys, os _branch_regex = re.compile('(feature|bug|case|bugid|fogbugz)_(\d+)') _commit_regex = re.compile(r'\b(?P&lt;case&gt;(review|case|bug[zs]?(\s| )*(id)?:?)s?(\s| )*([#:; ]| )+)((([ ,:;#]|and)*)(?P&lt;bugid&gt;\d+))+',re.I) #One of mercurial's callbacks for extensions. This is where you # you want to subclass repo to add your functionality. def reposetup(ui, repo): #Create a derived class that actually does what you want. class myrepo(repo.__class__): def commitctx(self, ctx, *args, **kwargs): match = _branch_regex.match(ctx.branch()) if match: ctx._text += ' BugID:'+ match.groups()[1] #Make sure to actually use the new subclass. repo.__class__ = myrepo ### Finish off the extensions stuff # We aren't adding any commands to hg. cmdtables = {} #List of known compatible versions of hg. testedwith = '2.7.1' </code></pre> <p>I have tested this and it works fine. You can use the extension by saving it in a python file, say <code>/some-path/fogbugz.py</code>, and adding it under the <code>extensions</code> group in your hgrc:</p> <pre><code>[extensions] fogbugz = /some-path/fogbugz.py </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload