Skip to content

Instantly share code, notes, and snippets.

@tuxillo
Created March 20, 2017 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxillo/43d65a02fbfb9f76d2759617f7f29eba to your computer and use it in GitHub Desktop.
Save tuxillo/43d65a02fbfb9f76d2759617f7f29eba to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import os
import re
import git
categories = (
( 'User utilities', lambda x: x.startswith("bin/"), 1 ),
( 'User utilities', lambda x: x.startswith("usr.bin/"), 1 ),
( 'Kernel', lambda x: x.startswith("sys/"), 1 ),
( 'Filesystems', lambda x: x.startswith("sys/vfs"), 2 ),
( 'Devices', lambda x: x.startswith("sys/dev/"), 2 ),
( 'Networking', lambda x: x.startswith("sys/netinet/"), 2 ),
( 'System utilities', lambda x: x.startswith("sbin/"), 1 ),
( 'System utilities', lambda x: x.startswith("libexec/"), 1 ),
( 'System utilities', lambda x: x.startswith("usr.sbin/"), 1 ),
( 'Contributed software', lambda x: x.startswith("contrib/"), 1 ),
( 'Cryptography', lambda x: x.startswith("crypto/"), 1 ),
( 'Documentation', lambda x: x.startswith("doc/"), 1 ),
( 'System configuration files and scripts', lambda x: x.startswith("etc/"), 1 ),
( 'System configuration files and scripts', lambda x: x.startswith("share/"), 1 ),
( 'Manual pages', lambda x: x.startswith("share/man/"), 2 ),
( 'Games', lambda x: x.startswith("games/"), 1 ),
( 'GNU', lambda x: x.startswith("gnu/"), 1 ),
( 'Libraries', lambda x: x.startswith("lib/"), 1 ),
( 'nrelease', lambda x: x.startswith("nrelease/"), 1 ),
( 'Tools', lambda x: x.startswith("tools/"), 1 ),
( 'Tools', lambda x: x.startswith("test/"), 1 )
)
changelog = dict()
previous = 'origin/DragonFly_RELEASE_4_6'
current = 'origin/DragonFly_RELEASE_4_8'
def check_weight(key1, key2):
for key, func, weight in categories:
if key == key1:
w1 = categories[2]
if key == key2:
w2 = categories[2]
if w1 >= w2:
return key1
elif w2 > w1:
return key2
#
# Set a commit in a specific category and add it to the
# changelog dictionary
#
def parse_commit(commit):
catg = dict()
maxvalue = -1
maxcatg = 'other'
assert commit.message != ''
for elem in commit.stats.files:
for key, func, weight in categories:
if func(elem):
if not key in catg:
catg[key] = 0
catg[key] += 1
for key in catg:
if catg[key] > maxvalue:
maxvalue = catg[key]
maxcatg = key
elif catg[key] == maxvalue:
maxcatg = check_weight(key, maxcatg)
return maxcatg
# --------------------------
if __name__ == '__main__':
repo = git.Repo('/home/antonioh/s/dragonfly')
for commit in repo.iter_commits('%s..%s' %(previous, current)):
catg = parse_commit(commit)
if not catg in changelog:
changelog[catg] = dict()
changelog[catg].update({ commit.hexsha: commit.message.splitlines()[0] })
# Produce output in Markdown syntax
print '## Changelog: From', previous, 'to', current
for category in sorted(changelog):
print '###', category
for commitid, cmsg in changelog[category].iteritems():
print '* [[' + commitid + '|https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/' + commitid + ']] -', cmsg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment