Peter Bex avatar Peter Bex committed d79623f

Add initial hack job to implement hg 'eggtag' command

Comments (0)

Files changed (1)

+# 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...")
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.