diff options
author | Peter Bex <peter@more-magic.net> | 2011-03-29 22:33:16 +0200 |
---|---|---|
committer | Peter Bex <peter@more-magic.net> | 2011-03-29 22:33:16 +0200 |
commit | 99fd3c030b8064225ed8738d655151c7f9f4bd13 (patch) | |
tree | 9a5bca7a70b8ffe9fc7b589fdd45ec659c1839f2 | |
download | hg-egg-author-99fd3c030b8064225ed8738d655151c7f9f4bd13.tar.gz |
Add initial hack job to implement hg 'eggtag' command
-rw-r--r-- | egg-author.py | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/egg-author.py b/egg-author.py new file mode 100644 index 0000000..c897f04 --- /dev/null +++ b/egg-author.py @@ -0,0 +1,92 @@ +# egg-authors.py +# +# Just drop this file in your ~/.hg directory and add +# the following lines to your .hgrc: +# +# [extensions] +# egg-author=~/.hg/egg-author.py +# +# 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 http://mercurial.selenic.com/wiki/License 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!')) + else: + 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.') + % 'http://wiki.call-cc.org/releasing-your-egg') + + 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))) + fp.seek(0, 2) # to the end + for n in allnames: + fp.write("(release \"%s\")\n" % _clean_scheme_string(n)) + fp.close() + + 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...") +} |