egg-author /

Full commit
# Just drop this file in your ~/.hg directory and add
# the following lines to your .hgrc:
# [extensions]
# egg-author=~/.hg/
# This silly file may be used and distributed according to the terms of
# the GNU General Public License, version 2 or later "(at your option)".
# See for more info, including
# a link to the license text.
# TODO: Add automatic meta-file updates when tagging tip?  Or perhaps
# based on a repo-specific setting, since people using the tarball method
# might not want their meta-files cluttered with long lists of files...

'''Tools to help make egg authors' lives easier'''

import fnmatch, re
from mercurial.i18n import _
from mercurial import cmdutil, commands, util
import mercurial.match as matchmod

# This is probably really really dumb code. I don't know python
def _find_release_info_file(repo):
    stat = repo.status(clean=True)
    for x in stat[:5]:
        for fn in x:
            if fnmatch.fnmatch(fn, '*.release-info'):
                raise util.Abort(_('%s is modified (please commit or revert '
                                   'and retry)') % fn)
    release_info_file = None
    for x in stat[5:]:
        for fn in x:
            if fnmatch.fnmatch(fn, "*.release-info"):
                if release_info_file:
                    raise util.Abort(_('Found more than one release-info file!'))
                    release_info_file = fn

    if not release_info_file:
        raise util.Abort(_('Could not find release-info file. You need to '
                           'create one first. See %s for more info.')
                         % '')
    return release_info_file

def _clean_scheme_string(s):
    # This is a pathetic attempt at being safe. You shouldn't be using
    # these names anywway, and the user should be already be trusted when
    # they're allowed to commit.
    return re.sub(r'\\', r'\\\\', re.sub(r'"', r'\\"', s))

def eggtag(ui, repo, name1, *names, **opts):
    '''Tag a Chicken egg for release.

    The syntax is identical to "hg tag", which it executes
    automatically.  This command just adds a (release ..) entry to
    your .release-info file for each tag.
    allnames = [t.strip() for t in (name1,) + names]

    release_info_file = _find_release_info_file(repo)
    fp = repo.wfile(release_info_file, 'r+')
    commands.tag(ui, repo, name1, *names, **opts)
    # if hg's original tag command succeeded, we can do our stuff
    relinfo_message = ('Updated release-info file for release tag %s' % (', '.join(allnames))), 2) # to the end
    for n in allnames:
        fp.write("(release \"%s\")\n" % _clean_scheme_string(n))

    m = matchmod.exact(repo.root, '', [release_info_file])
    repo.commit(text=relinfo_message, user=opts.get('user'), date=opts.get('date'), match=m)

cmdtable = {
    "eggtag": (eggtag,
               [('r', 'rev', '',
                 _('revision to tag'), _('REV')),
                ('', 'remove', None, _('remove a tag')),
                ('e', 'edit', None, _('edit commit message')),
                ('m', 'message', '',
                 _('use <text> as commit message'), _('TEXT')),
               "hg eggtag [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME...")