From 4a17edbe0d0265bf2039efde9ccb324b7d1f5a29 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Fri, 4 Jul 2008 22:58:19 +0200 Subject: [PATCH] gitstats: Added a simple 'stats.py bug' command Currently it examines a specific commit using the appropriate metrics. With the use of flags it is possible to specify how to use these sub-metrics, and what arguments to run them with. --- src/git_stats/bug.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/stats.py | 2 + 2 files changed, 126 insertions(+) create mode 100644 src/git_stats/bug.py diff --git a/src/git_stats/bug.py b/src/git_stats/bug.py new file mode 100644 index 0000000..51a049c --- /dev/null +++ b/src/git_stats/bug.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python + +import os +import sys + +from optparse import OptionParser, OptionValueError +from git import Repo + +from git_stats import parse + +def aggregateType(debug): + """ + """ + + result = [] + + # TODO, implement + + return result + +def determineType(commit, + debug=False, + branchFilter=None, + msgFilter=None, + diffFilter=None): + """Determines the type of the specified commit + + Args: + commit: The commit to determine the type of. + debug: Whether to include debug information. + branchFilter: Type=fix if a commit belongs to any of these branches. + msgFilter: Type=fix if the commit log msg matches this filter. + diffFilter: Type=fix if the commit diff matches this filter. + """ + + branches = branch.belongsTo(commit) + reverts = commit.findRevert(commit) + msg_matches = msgFilter and commitmsgMatches(commit, msgFilter) + diff_matches = diffFilter and commitdiffMatches(commit, diffFilter) + + result = [] + + if branchFilter in branches: + result.append("In maintenance branch!") + + if reverts: + result.append("Reverts a previous commit!") + + if msg_matches: + result.append("Message matches!") + + if diff_matches: + result.append("Diff matches!") + + return result + +def _checkOptions(parser, options): + """Checks the specified options and uses the parser to indicate errors + + Args: + parser: The parser to use to signal when the options are bad. + options: The options to check. + """ + + opts = [options.aggregate, options.type] + + if not parse.isUnique(opts): + parser.error("Please choose exactly one mode") + +def dispatch(*args): + """Dispatches index related commands + """ + + progname = os.path.basename(sys.argv[0]) + " bug" + + parser = OptionParser(option_class=parse.GitOption, prog=progname) + + parser.add_option( + "-d", "--debug", + action="store_true", + help="show debug information") + + parser.add_option( + "-a", "--aggregate", + action="store_true", + help="aggregate bug information of all commits") + + parser.add_option( + "-t", "--type", + type="commit", + help="shows which type the specified commit is") + + parser.add_option( + "-m", "--message-filter", + help="mark the commit as a fix if it's log matches this filter") + + parser.add_option( + "-f", "--diff-filter", + help="mark the commit as a fix if it's diff matches this filter") + + parser.add_option( + "-b", "--branch-filter", + help="mark the commit as a fix if it belongs to this branch") + + # Default to True for now, until there is another option + parser.set_default("debug", False) + parser.set_default("aggregate", False) + + (options, args) = parser.parse_args(list(args)) + + _checkOptions(parser, options) + + if options.aggregate: + result = aggregateType(options.debug) + elif options.type: + result = determineType( options.type, + debug=options.debug, + msgFilter=options.msg_filter, + diffFilter=options.diff_filter, + branchFilter=options.branch_filter) + + for line in result: + print(line) + diff --git a/src/stats.py b/src/stats.py index 284cd7b..c5397ce 100755 --- a/src/stats.py +++ b/src/stats.py @@ -20,6 +20,7 @@ os.sys.path.insert(0, dir) from git import Git from git_stats import author +from git_stats import bug from git_stats import branch from git_stats import commit from git_stats import diff @@ -85,6 +86,7 @@ class Dispatcher(): commands = { "author" : author.dispatch, + "bug" : bug.dispatch, "branch" : branch.dispatch, "commit" : commit.dispatch, "diff" : diff.dispatch, -- 2.11.4.GIT