Sun, 12 Oct 2014 16:33:44 +0300
- now with a more detailed diffstat, in color!
cobalt.py | file | annotate | diff | comparison | revisions |
--- a/cobalt.py Mon Oct 06 00:18:23 2014 +0300 +++ b/cobalt.py Sun Oct 12 16:33:44 2014 +0300 @@ -247,6 +247,31 @@ #endtry #enddef +def bbcodify(commit_diffstat): + result='' + for line in commit_diffstat.split('\n'): + # Add green color-tags for the ++++++++++ stream + rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$') + match = rex.match (line) + if match: + line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \ + % (match.group (1), match.group (2), match.group (3), match.group (4), match.group (5)) + + # Tracker doesn't seem to like empty color tags + line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '') + #else: + #rex = re.compile (r'^(.*) ([0-9]+) insertions\(\+\), ([0-9]+) deletions\(\-\)$') + #match = rex.match (line) + #if match: + #line = '%s [b][color=green]%s[/color][/b] insertions, [b][color=red]%s[/color][/b] deletions\n' \ + #% (match.group (1), match.group (2), match.group (3)) + + result += line + #done + + return result +#enddef + ' Retrieves and processes commits for zandronum repositories ' ' Ensure both repositories are OK before using this! ' def process_zan_repo_updates (repo_name): @@ -341,16 +366,15 @@ # Acquire additional data moredata = get_commit_data (zanrepo, commit_node, - '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}\n{diffstat|nonempty}').split('\n') + '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}').split('\n') - if len (moredata) != 3: + if len (moredata) != 2: chanlog ('error while processing %s: malformed hg data' % commit_node) continue #fi commit_author = moredata[0] commit_date = moredata[1] - commit_diffstat = moredata[2] commit_email = "" try: @@ -369,26 +393,13 @@ commit_email = match.group (2) #fi - # Try parse and prettify the diffstat - rex = re.compile (r'([0-9]+): \+([0-9]+)/-([0-9]+)') - match = rex.match (commit_diffstat) + commit_diffstat = zanrepo.hg_command ('diff', '--change', commit_node, '--stat') - if match: - modded = int (match.group (1)) - added = int (match.group (2)) - deleted = int (match.group (3)) - commit_diffstat = "%s file%s modified, %s line%s added, %s line%s removed" % \ - (modded if modded != 0 else 'no', - 's' if modded != 1 else '', - added if added != 0 else 'no', - 's' if added != 1 else '', - deleted if deleted != 0 else 'no', - 's' if deleted != 1 else '') - #fi - - files_added = filter (None, get_commit_data (zanrepo, commit_node, '{file_adds}').split (' ')) - files_removed = filter (None, get_commit_data (zanrepo, commit_node, '{file_dels}').split (' ')) - files_changed = filter (None, get_commit_data (zanrepo, commit_node, '{file_mods}').split (' ')) + if len(commit_diffstat) > 0: + # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]' + commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat) + else: + commit_diffstat = 'No changes in files.' # Compare the email addresses against known developer usernames commit_trackeruser = '' @@ -414,18 +425,6 @@ message += "\nCommitted by %s on %s\n\n%s" \ % (commit_author, commit_date, commit_diffstat) - if len (files_added) > 0: - message += "\nFiles added: %s" % ', '.join (files_added) - #fi - - if len (files_removed) > 0: - message += "\nFiles removed: %s" % ', '.join (files_removed) - #fi - - if len (files_changed) > 0: - message += "\nFiles changed: %s" % ', '.join (files_changed) - #fi - need_update = False # If not already set, set handler