# HG changeset patch # User Teemu Piippo # Date 1415109560 -7200 # Node ID 441a04262cb4cbc6d5524b7383263f3aeaa455f8 # Parent 180ae24d46f2636c986b52f4ca2b5e9288c12dad - added the .changeset (aka .cset or .rev) command to get revision info diff -r 180ae24d46f2 -r 441a04262cb4 cobalt.py --- a/cobalt.py Sat Nov 01 15:29:45 2014 +0200 +++ b/cobalt.py Tue Nov 04 15:59:20 2014 +0200 @@ -40,6 +40,7 @@ import os import suds import math +from datetime import datetime try: uid = os.geteuid() @@ -282,6 +283,8 @@ #fi #done #done + + return '' #enddef ' Retrieves and processes commits for zandronum repositories ' @@ -530,6 +533,9 @@ return num_commits > 0 #enddef +def plural (a): + return '' if a == 1 else 's' + # # Main IRC client class # @@ -1047,8 +1053,82 @@ self.privmsg (replyto, 'error: %s' % `e`) #fi #tried + elif command == 'changeset' or command == 'cset' or command == 'rev': + if len(args) != 1: + raise logical_exception ('usage: %s ' % command) + + repo = None + data = "" + + # The sandboxes contain all revisions in zandronum and zandronum-stable. + # Thus we only need to try find the revision in the sandbox repos. + for reponame in ['zandronum-sandbox', 'zandronum-sandbox-stable']: + try: + repo = hgapi.Repo (reponame) + repo.hg_command ("log", "-r", args[0], "--template", " ") + break + except hgapi.hgapi.HgException: + pass + #done + + if repo == None: + self.privmsg (replyto, 'couldn\'t find changeset %s' % (args[0])) + else: + try: + data = repo.hg_command ("log", "-r", args[0], "--template", + "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%s')}") + data = data.split ('@@@@@@@') + + node = data[0] + message = data[1] + author = data[2] + diffstat = data[3] + date = datetime.fromtimestamp (int (data[4])) + delta = datetime.now() - date + datestring = '' + + # Remove the email address from the author if possible + match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) + if match: + author = match.group (1) + email = match.group (2) + + username = find_developer_by_email (email) + + if username != '': + author = username + + if delta.days < 4: + if delta.days == 0: + if delta.seconds < 60: + datestring = 'just now' + elif delta.seconds < 3600: + minutes = delta.seconds / 60 + datestring = '%d minute%s ago' % (minutes, plural (minutes)) + else: + hours = delta.seconds / 3600 + datestring = '%d hour%s ago' % (hours, plural (hours)) + else: + datestring = '%d day%s ago' % (delta.days, plural (delta.days)) + else: + datestring = 'on %s' % (str (date)) + #fi + + self.privmsg (replyto, 'changeset %s: committed by %s %s (%s)' % (node, author, datestring, diffstat)) + + for line in message.split ('\n'): + self.privmsg (replyto, ' ' + line) + except hgapi.hgapi.HgException as e: + result = decipher_hgapi_error (e) + + if result[0]: + self.privmsg (replyto, 'error: %s' % result[1]) + else: + self.privmsg (replyto, 'error: %s' % `e`) + #tried + #fi # else: -# raiee logical_exception ("unknown command `.%s`" % command) +# raise logical_exception ("unknown command `.%s`" % command) # # Print a ticket announce to appropriate channels