6 from optparse
import OptionParser
, OptionValueError
9 from git_stats
import branch
10 from git_stats
import commit
11 from git_stats
import config
12 from git_stats
import parse
14 def aggregateType(debug
):
24 def determineType(target
,
29 """Determines the type of the specified commit
32 commit: The commit to determine the type of.
33 debug: Whether to include debug information.
34 branchFilter: Type=fix if a commit belongs to any of these branches.
35 msgFilter: Type=fix if the commit log msg matches this filter.
36 diffFilter: Type=fix if the commit diff matches this filter.
39 branches
= branch
.belongsTo(target
)
40 reverts
= commit
.findReverts(target
)
41 msg_matches
= msgFilter
and commit
.commitmsgMatches(target
, msgFilter
)
42 diff_matches
= diffFilter
and commit
.commitdiffMatches(target
, diffFilter
)
46 if branchFilter
in branches
:
47 result
.append("In maintenance branch!")
50 result
.append("Reverts a previous commit!")
53 result
.append("Message matches: '" + msgFilter
+ "'.")
56 result
.append("Diff matches: '" + diffFilter
+ "'.")
60 def _checkOptions(parser
, options
):
61 """Checks the specified options and uses the parser to indicate errors
64 parser: The parser to use to signal when the options are bad.
65 options: The options to check.
68 opts
= [options
.aggregate
, options
.type]
70 if not parse
.isUnique(opts
):
71 parser
.error("Please choose exactly one mode")
74 """Dispatches index related commands
77 progname
= os
.path
.basename(sys
.argv
[0]) + " bug"
79 parser
= OptionParser(option_class
=parse
.GitOption
, prog
=progname
)
84 help="show debug information")
89 help="aggregate bug information of all commits")
94 help="shows which type the specified commit is")
97 "-m", "--message-filter",
98 help="mark the commit as a fix if it's log matches this filter")
101 "-f", "--diff-filter",
102 help="mark the commit as a fix if it's diff matches this filter")
105 "-b", "--branch-filter",
106 help="mark the commit as a fix if it belongs to this branch")
108 # Default to True for now, until there is another option
109 parser
.set_default("debug", False)
110 parser
.set_default("aggregate", False)
112 (options
, args
) = parser
.parse_args(list(args
))
114 _checkOptions(parser
, options
)
116 if options
.aggregate
:
117 result
= aggregateType(options
.debug
)
120 result
= determineType(
122 debug
=options
.debug
or opts
.get("debug", False),
123 msgFilter
=options
.message_filter
or opts
["msgFilter"],
124 diffFilter
=options
.diff_filter
or opts
["diffFilter"],
125 branchFilter
=options
.branch_filter
or opts
["branchFilter"])