[PATCH 1 of 1] mq: add functions to attach information items to patches
Ingo Proetel
proetel at aicas.de
Thu Aug 11 11:56:46 CDT 2011
# HG changeset patch
# User Ingo Proetel <proetel at aicas.de>
# Date 1313081661 -7200
# Node ID 7f36cb5749a614fc32defa25ba96842f4c7d195e
# Parent 3ab40477ce60e1757ceeaa49e2c9d2790fbb47e0
mq: add functions to attach information items to patches
Allow programmers to attach some information such as bug ids or review ids to a patch.
Usage:
repo.mq.attachinfo(index,'posted',[reviewID])
...
existing = repo.mq.getattachedinfo(index,'posted')
if existing:
print('patch is in review (#%s)' % existing[0])
diff -r 3ab40477ce60 -r 7f36cb5749a6 hgext/mq.py
--- a/hgext/mq.py Thu Aug 11 09:05:09 2011 +0200
+++ b/hgext/mq.py Thu Aug 11 18:54:21 2011 +0200
@@ -489,6 +489,30 @@
write(_('skipping %s - no matching guards\n') %
self.series[idx])
+
+ def attachinfo(self, idx, name, values):
+ '''Attach some information items with a patch. The items get stored in
+ the series file as comments in the form '#name:item0 #name:item1 ...'.
+ If values is None the named items are cleared.
+ '''
+ if name.find(':') != -1:
+ raise util.Abort(_('attach name %s contains(:)') % name)
+ for v in values or []:
+ if not v.isalnum() or '#' in v:
+ raise util.Abort(_('attach value must be only alphanumeric'
+ ' and not contain(#): %s') % v)
+
+ pattern = '\s?#' + name + ':[^\s#]*'
+ drop = re.sub(pattern, '', self.fullseries[idx])
+ self.fullseries[idx] = drop + ''.join(' #' + name + ':' + v for v in values or [])
+ self.parseseries()
+ self.seriesdirty = True
+
+ def getattachedinfo(self, idx, name):
+ '''Retrieve information items attached to the patch.'''
+ pattern = r'\s?#' + name + r':([^\s#]*)'
+ return re.findall(pattern, self.fullseries[idx])
+
def savedirty(self):
def writelist(items, path):
fp = self.opener(path, 'w')
More information about the Mercurial-devel
mailing list