@@ -20,10 +20,12 @@
from mercurial.i18n import _
from mercurial import (
+ config,
error,
minirst,
registrar,
scmutil,
+ util,
)
cmdtable = {}
@@ -111,9 +113,15 @@
self.addnontitleditem(section, paragraphs)
class releasenotessections(object):
- def __init__(self, ui):
- # TODO support defining custom sections from config.
- self._sections = list(DEFAULT_SECTIONS)
+ def __init__(self, ui, repo=None):
+ if repo:
+ sections = util.sortdict(DEFAULT_SECTIONS)
+ custom_sections = getcustomadmonitions(repo)
+ if custom_sections:
+ sections.update(custom_sections)
+ self._sections = list(sections.iteritems())
+ else:
+ self._sections = list(DEFAULT_SECTIONS)
def __iter__(self):
return iter(self._sections)
@@ -128,6 +136,22 @@
return None
+def getcustomadmonitions(repo):
+ ctx = repo['.']
+ p = config.config()
+
+ def read(f, sections=None, remap=None):
+ if f in ctx:
+ data = ctx[f].data()
+ p.parse(f, data, sections, remap, read)
+ else:
+ raise error.Abort(_(".hgreleasenotes file \'%s\' not found") %
+ repo.pathto(f))
+
+ if '.hgreleasenotes' in ctx:
+ read('.hgreleasenotes')
+ return p['sections']
+
def parsenotesfromrevisions(repo, directives, revs):
notes = parsedreleasenotes()
@@ -396,7 +420,7 @@
that file. A particular use case for this is to tweak the wording of a
release note after it has been added to the release notes file.
"""
- sections = releasenotessections(ui)
+ sections = releasenotessections(ui, repo)
revs = scmutil.revrange(repo, [rev or 'not public()'])
incoming = parsenotesfromrevisions(repo, sections.names(), revs)
@@ -416,7 +440,7 @@
fh.write(serializenotes(sections, notes))
@command('debugparsereleasenotes', norepo=True)
-def debugparsereleasenotes(ui, path):
+def debugparsereleasenotes(ui, path, repo=None):
"""parse release notes and print resulting data structure"""
if path == '-':
text = sys.stdin.read()
@@ -424,7 +448,7 @@
with open(path, 'rb') as fh:
text = fh.read()
- sections = releasenotessections(ui)
+ sections = releasenotessections(ui, repo)
notes = parsereleasenotesfile(sections, text)
@@ -255,6 +255,8 @@
* Short summary of fix 3
+ $ cd ..
+
Multiple 'Other Changes' sub-sections for every section
$ hg init multiple-otherchanges
@@ -324,3 +326,53 @@
* Short summary of fix 2
+ $ cd ..
+
+Using custom sections in notes
+
+ $ hg init custom-section
+ $ cd custom-section
+ $ cat >> .hgreleasenotes << EOF
+ > [sections]
+ > testsection=Name of Section
+ > EOF
+
+ $ touch a
+ $ hg -q commit -A -l - << EOF
+ > commit 1
+ >
+ > .. testsection::
+ >
+ > First paragraph under this admonition.
+ > EOF
+
+ $ hg releasenotes -r . $TESTTMP/relnotes-custom-section
+ $ cat $TESTTMP/relnotes-custom-section
+ Name of Section
+ ===============
+
+ * First paragraph under this admonition.
+
+Overriding default sections (For eg. by default feature = New Features)
+
+ $ cat >> .hgreleasenotes << EOF
+ > [sections]
+ > feature=Feature Additions
+ > EOF
+
+ $ touch b
+ $ hg -q commit -A -l - << EOF
+ > commit 2
+ >
+ > .. feature::
+ >
+ > Adds a new feature.
+ > EOF
+
+ $ hg releasenotes -r . $TESTTMP/relnotes-override-section
+ $ cat $TESTTMP/relnotes-override-section
+ Feature Additions
+ =================
+
+ * Adds a new feature.
+