# HG changeset patch # User Teemu Piippo # Date 1439031640 -10800 # Node ID 4a72fb181a43fb6683ecd9fa1519ffce8dc0c3aa # Parent c17b82b1f573995d4aa69897fd8f365b01aa3199 Fix .cset Fix 'moredata' usage in announce_ticket_resolved diff -r c17b82b1f573 -r 4a72fb181a43 hgpoll.py --- a/hgpoll.py Tue Aug 04 22:39:22 2015 +0300 +++ b/hgpoll.py Sat Aug 08 14:00:40 2015 +0300 @@ -123,9 +123,6 @@ email='author|email', message='desc') - if len (moredata) != 2: - raise HgProcessError ('Received invalid hg data while processing %s' % cset) - diffstat = repo.hg ('diff', '--change', cset, '--stat') try: diff -r c17b82b1f573 -r 4a72fb181a43 mod_hg.py --- a/mod_hg.py Tue Aug 04 22:39:22 2015 +0300 +++ b/mod_hg.py Sat Aug 08 14:00:40 2015 +0300 @@ -28,11 +28,12 @@ from __future__ import print_function from datetime import datetime -import hgpoll as HgPoll +import hgpoll import re import subprocess from configfile import Config from modulecore import command_error +from hgdb import HgCommitsDatabase ModuleData = { 'commands': @@ -71,7 +72,7 @@ return '' if a == 1 else 's' def cmd_checkhg (bot, **rest): - HgPoll.force_poll() + hgpoll.force_poll() def is_dateversion (key): try: @@ -81,17 +82,20 @@ return False def resolve_node (node): - reponame = None + repo = None + db = HgCommitsDatabase() if '/' in node: - reponame, node = node.split ('/')[0:2] + reponame, node = node.split ('/')[:2] - if reponame not in HgPoll.all_repo_names(): + try: + repo = hgpoll.RepositoriesByName[reponame] + except KeyError: command_error ('''unknown repository %s''' % reponame) # Possibly we're passed a date version instead. Try find the node for this. if is_dateversion (node): - node = HgPoll.g_CommitsDb.find_commit_by_dateversion (node) + node = db.find_commit_by_dateversion (node) if node == None: command_error ('''couldn't find changeset for date %s''' % node) @@ -99,15 +103,15 @@ node = node[0:7] - noderepos = HgPoll.g_CommitsDb.get_commit_repos (node) + noderepos = db.get_commit_repos (node) - if reponame == None: + if repo == None: if not noderepos: command_error ('''couldn't find changeset %s''' % node) - reponame = noderepos[0] + repo = noderepos[0] - return (node, reponame) + return (node, repo) def get_version_string (reponame, node): try: @@ -135,56 +139,42 @@ def cmd_cset (bot, args, reply, **rest): data = "" - node, reponame = resolve_node (args['key']) - repourl = HgPoll.get_repo_info (reponame).get_value ('url') - delim = '@@@@@@@@@@@@' + node, repo = resolve_node (args['key']) try: - data = subprocess.check_output (['hg', '--cwd', reponame, "log", "-l1", "-r", node, - "--template", delim.join (["{node|short}", - "{desc}", - "{author|person}", - "{diffstat}", - "{date|hgdate}", - "{bookmarks}", - "{latesttagdistance}", - "{latesttag}", - "{author|email}"] - ) - ]).split (delim) + data = repo.get_commit_data (rev=node, + node='node|short', + message='desc', + author='author', + diffstat='diffstat', + time='date|hgdate', + bookmarks='bookmarks', + latesttagdistance='latesttagdistance', + latesttag='latesttag', + email='author|email') except Subprocess.CalledProcessError: command_error ('''couldn't find changeset %s in %s''' % (node, reponame)) - node = data[0] - message = data[1] - author = data[2] - diffstat = data[3] - date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) - bookmarks = data[5] - latesttagdistance = int (data[6]) - latesttag = data[7] - email = data[8] - delta = datetime.utcnow() - date - datestring = '' - - if bookmarks: - bookmarks = HgPoll.prettify_bookmarks (bookmarks) + del node + commit['date'] = datetime.utcfromtimestamp (int (commit['time'].split (' ')[0])) + commit['latesttagdistance'] = int (commit['latesttagdistance']) + commit['bookmarks'] = hgpoll.prettify_bookmarks (commit['bookmarks']) # Find out the version string of this changeset - versionstring = get_version_string (reponame, node) - - subprocess.call (['hg', '--cwd', reponame, 'revert', '--all']) + versionstring = get_version_string (reponame, commit['node']) username = Config.find_developer_by_email (email) - if username != '': - author = username + if username: + commit['author'] = username # Try prettify the diffstat - match = re.match (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$', diffstat) + match = re.match (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$', commit['diffstat']) if match: - diffstat = "%s\003:\0033 +%s\003/\0034-%s\003" % (match.group (1), match.group (2), match.group (3)) + commit['diffstat'] = "%s\003:\0033 +%s\003/\0034-%s\003" % \ + (match.group (1), match.group (2), match.group (3)) + delta = datetime.utcnow() - date if delta.days < 4: if delta.days == 0: if delta.seconds < 60: @@ -198,9 +188,9 @@ else: datestring = '%d day%s ago' % (delta.days, plural (delta.days)) else: - datestring = 'on %s' % (str (date)) + datestring = 'on %s' % (str (commit['date'])) - if latesttagdistance != 0: + if commit['latesttagdistance'] != 0: versionblurb = "" if versionstring: @@ -212,12 +202,13 @@ versionblurb = latesttag reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ - (node, bookmarks, versionblurb, author, datestring, diffstat)) + (commit['node'], commit['bookmarks'], versionblurb, commit['author'], datestring, + commit['diffstat'])) for line in message.split ('\n'): reply (' ' + line) - reply ('url: %s/commits/%s' % (repourl, node)) + reply ('url: %s/commits/%s' % (repo.url, commit['node'])) def cmd_hg (bot, args, reply, **rest): try: @@ -227,4 +218,4 @@ command_error (str (e)) def cmd_resolves (bot, args, **rest): - HgPoll.announce_ticket_resolved (args['ticket'], args['changeset']) \ No newline at end of file + hgpoll.announce_ticket_resolved (args['ticket'], args['changeset']) \ No newline at end of file