Created
March 19, 2017 11:06
-
-
Save tuxillo/495990dd62757a6191a037aec0916e70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import os | |
import re | |
import git | |
categories = [ | |
'usertools', # bin, usr.bin | |
'kernel', # sys | |
'systemtool', # sbin, usr.sbin, libexec | |
'contrib', # contrib | |
'crypto', # crypto | |
'doc', # doc | |
'etc', # etc, share | |
'games', # games | |
'gnu', # gnu | |
'lib', # lib | |
'nrelease', # nrelease | |
'tools' # test, tools | |
] | |
changelog = dict() | |
previous = 'origin/DragonFly_RELEASE_4_6' | |
current = 'origin/DragonFly_RELEASE_4_8' | |
# | |
# Set a commit in a specific category and add it to the | |
# changelog dictionary | |
# | |
def parse_commit(commit): | |
global categories | |
catg = dict.fromkeys(categories, 0) | |
topcat = dict() | |
assert commit.message != '' | |
for files, changes in commit.stats.files.iteritems(): | |
if files.startswith('bin/') or files.startswith('usr.bin/'): | |
catg['usertools'] += 1 | |
elif files.startswith('sys/'): | |
catg['kernel'] += 1 | |
elif files.startswith('sbin/') or files.startswith('usr.sbin/'): | |
catg['systemtool'] += 1 | |
elif files.startswith('contrib/'): | |
catg['contrib'] += 1 | |
elif files.startswith('crypto/'): | |
catg['crypto'] += 1 | |
elif files.startswith('doc/'): | |
catg['doc'] += 1 | |
elif files.startswith('etc/') or files.startswith('share/') and 'man' not in files: | |
catg['etc'] += 1 | |
elif files.startswith('games/'): | |
catg['games'] += 1 | |
elif files.startswith('gnu/'): | |
catg['gnu'] += 1 | |
elif files.startswith('lib/'): | |
catg['lib'] += 1 | |
elif files.startswith('nrelease/'): | |
catg['nrelease'] += 1 | |
elif files.startswith('test/') or files.startswith('tools/'): | |
catg['tools'] += 1 | |
for cat, occur in catg.iteritems(): | |
if not topcat: | |
topcat = { cat: occur } | |
else: | |
key = topcat.iteritems().next()[0] | |
if topcat[key] < catg[cat]: | |
del topcat[key] | |
topcat.update({ cat: occur }) | |
key = topcat.iteritems().next()[0] | |
if not key in changelog: | |
changelog[key] = dict() | |
changelog[key].update({ commit.hexsha: commit.message.splitlines()[0] }) | |
# -------------------------- | |
repo = git.Repo('/home/antonioh/s/dragonfly') | |
for commit in repo.iter_commits('%s..%s' %(previous, current)): | |
parse_commit(commit) | |
for category, msg in sorted(changelog.iteritems()): | |
print 'Category:', category | |
for commitid, cmsg in changelog[category].iteritems(): | |
print '\t ', commitid, cmsg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment