diff -r 9880bb697149 -r ac07779f788d mod_hg.py --- a/mod_hg.py Mon Jan 19 16:42:36 2015 -0500 +++ b/mod_hg.py Sat Apr 11 21:02:09 2015 +0300 @@ -36,13 +36,6 @@ 'args': ' ', 'level': 'admin', # TODO }, - - { - 'name': 'compress', - 'description': 'Compresses a head on the sandbox repositories.', - 'args': '', - 'level': 'admin', # TODO - } ] } @@ -52,45 +45,64 @@ def cmd_checkhg (bot, **rest): HgPoll.force_poll() -def cmd_cset (bot, args, reply, **rest): - repo = Repo ('zandronum-everything') - data = "" - node = args['key'] +def is_dateversion (key): + try: + datetime.strptime (key, '%y%m%d-%H%M') + return True + except ValueError: + return False + +def resolve_node (node): + reponame = None + + if '/' in node: + reponame, node = node.split ('/')[0:2] + + if reponame not in HgPoll.all_repo_names(): + command_error ('''unknown repository %s''' % reponame) # Possibly we're passed a date version instead. Try find the node for this. - try: - datetime.strptime (args['key'], '%y%m%d-%H%M') - HgPoll.make_commits_txt() - commits_txt = open ('commits.txt', 'r') + if is_dateversion (node): + node = HgPoll.g_CommitsDb.find_commit_by_dateversion (node) + + if node == None: + command_error ('''couldn't find changeset for date %s''' % node) + return + + node = node[0:7] + + noderepos = HgPoll.g_CommitsDb.get_commit_repos (node) - for line in commits_txt: - data = line.replace ('\n', '').split (' ') - if data[1] == args['key']: - node = data[0] - break - else: - command_error ('couldn\'t find changeset for date %s' % args['key']) - return - except ValueError: - pass + if reponame == None: + if not noderepos: + command_error ('''couldn't find changeset %s''' % node) + + reponame = noderepos[0] + + return (node, reponame) - # zandronum-everything contains all zandronum changesets, so look for changesets in that. +def cmd_cset (bot, args, reply, **rest): + data = "" + node, reponame = resolve_node (args['key']) + repourl = HgPoll.get_repo_info (reponame).get_value ('url') + repo = Repo (reponame) + delim = '@@@@@@@@@@@@' + try: data = repo.hg_command ("log", "-l1", "-r", node, "--template", - "{node|short}@@@@@@@" + - "{desc}@@@@@@@" + - "{author}@@@@@@@" + - "{diffstat}@@@@@@@" + - "{date|hgdate}@@@@@@@" + - "{bookmarks}@@@@@@@" + - "{latesttagdistance}@@@@@@@" + - "{latesttag}") + delim.join (["{node|short}", + "{desc}", + "{author}", + "{diffstat}", + "{date|hgdate}", + "{bookmarks}", + "{latesttagdistance}", + "{latesttag}"])).split (delim) except hgapi.HgException: - command_error ('couldn\'t find changeset %s' % (node)) + command_error ('''couldn't find changeset %s in %s''' % (node, reponame)) return try: - data = data.split ('@@@@@@@') node = data[0] message = data[1] author = data[2] @@ -107,23 +119,26 @@ # Find out the Zandronum version of this changeset repo.hg_command ('revert', '-r', node, 'src/version.h') - zanversion = '' + zanversion = '' - with open ('zandronum-everything/src/version.h') as version_file: - regexps = [ \ - re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ - re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ - re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] + try: + with open (reponame + '/src/version.h') as version_file: + regexps = [ \ + re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ + re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ + re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] - for line in version_file: - for rex in regexps: - match = rex.match (line) + for line in version_file: + for rex in regexps: + match = rex.match (line) + if match != None: + zanversion = match.group (1) + break + if match != None: - zanversion = match.group (1) break - - if match != None: - break + except IOError: + pass repo.hg_command ('revert', '--all') @@ -172,6 +187,8 @@ for line in message.split ('\n'): reply (' ' + line) + + reply ('url: %s/commits/%s' % (repourl, node)) except hgapi.HgException as e: result = HgPoll.decipher_hgapi_error (e)