From 3a59e8f266545b86c251bbc8e6f769be522f810c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 8 Jun 2017 09:46:54 +0200 Subject: [PATCH] Fix changelog generator script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Correctly exclude merge commits (there's a git log option for it) * Stop mangling log lines with @ symbol. This should only be cut for author of a change. * Fix PEP8 issues * Remove unused code * Port to argparse (optparse is deprecated) Signed-off-by: Lubomír Sedlář --- git-changelog | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/git-changelog b/git-changelog index 093d1ed6..ff4ffea8 100755 --- a/git-changelog +++ b/git-changelog @@ -20,20 +20,15 @@ # Author: David Cantrell # Author: Brian C. Lane -import os -import re import subprocess -import sys import textwrap -from optparse import OptionParser - +from argparse import ArgumentParser class ChangeLog: def __init__(self, name, version): self.name = name self.version = version - self.ignore = None def _getCommitDetail(self, commit, field): proc = subprocess.Popen(['git', 'log', '-1', @@ -43,7 +38,7 @@ class ChangeLog: ret = proc[0].strip('\n').split('\n') - if len(ret) == 1 and ret[0].find('@') != -1: + if field == '%aE' and len(ret) == 1 and ret[0].find('@') != -1: ret = ret[0].split('@')[0] elif len(ret) == 1: ret = ret[0] @@ -57,25 +52,19 @@ class ChangeLog: range = "%s.." % (self.version) else: range = "%s-%s.." % (self.name, self.version) - proc = subprocess.Popen(['git', 'log', '--pretty=oneline', range], + proc = subprocess.Popen(['git', 'log', '--pretty=oneline', + '--no-merges', range], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - lines = filter(lambda x: x.find('l10n: ') != 41 and \ - x.find('Merge commit') != 41 and \ - x.find('Merge branch') != 41, + lines = filter(lambda x: x.find('l10n: ') != 41, proc[0].strip('\n').split('\n')) - if self.ignore and self.ignore != '': - for commit in self.ignore.split(','): - lines = filter(lambda x: not x.startswith(commit), lines) - log = [] for line in lines: fields = line.split(' ') commit = fields[0] summary = self._getCommitDetail(commit, "%s") - long = self._getCommitDetail(commit, "%b") author = self._getCommitDetail(commit, "%aE") log.append(("%s (%s)" % (summary.strip(), author))) @@ -94,18 +83,17 @@ class ChangeLog: return s -def main(): - parser = OptionParser() - parser.add_option("-n", "--name", dest="name", - help="Name of package used in tags") - parser.add_option("-v", "--version", dest="version", - help="Last version, changelog is commits after this tag") - (options, args) = parser.parse_args() - cl = ChangeLog(options.name, options.version) +def main(): + parser = ArgumentParser() + parser.add_argument("-n", "--name", + help="Name of package used in tags") + parser.add_argument("-v", "--version", + help="Last version, changelog is commits after this tag") + args = parser.parse_args() + + cl = ChangeLog(args.name, args.version) print cl.formatLog() if __name__ == "__main__": main() - -