2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "CommitsMatcher.h"
20 #include "../CommandLineParser.h"
22 CommitsMatcher::CommitsMatcher()
23 : useRegExp(false), useRegExpTo(false), useMatcher(false), useMatcherTo(false)
25 CommandLineParser
*args
= CommandLineParser::instance();
27 if (args
->contains("to-match")) {
28 m_matcherTo
= QStringMatcher(args
->optionArgument("to-match"), Qt::CaseInsensitive
);
31 else if (args
->contains("to-patch")) {
32 m_regExpTo
= QRegExp(args
->optionArgument("to-patch"), Qt::CaseInsensitive
, QRegExp::RegExp2
);
37 if (args
->contains("from-match")) {
38 m_matcher
= QStringMatcher(args
->optionArgument("from-match"), Qt::CaseInsensitive
);
41 else if (args
->contains("from-patch")) {
42 m_regExp
= QRegExp(args
->optionArgument("from-patch"), Qt::CaseInsensitive
, QRegExp::RegExp2
);
46 m_state
= MatchingPerItem
;
51 CommitsMatcher::ExpectedAction
CommitsMatcher::match(const Commit
&commit
)
54 case AllClear
: return ShowPatch
;
56 if ((useMatcher
&& m_matcher
.indexIn(commit
.author()) == -1
57 && m_matcher
.indexIn(commit
.logMessage()) == -1)
58 || (useRegExp
&& m_regExp
.indexIn(commit
.author()) == -1
59 && m_regExp
.indexIn(commit
.logMessage()) == -1))
61 m_state
= MatchingPerItem
;
65 if ((useMatcher
&& m_matcher
.indexIn(commit
.author()) == -1
66 && m_matcher
.indexIn(commit
.logMessage()) == -1)
67 || (useRegExp
&& m_regExp
.indexIn(commit
.author()) == -1
68 && m_regExp
.indexIn(commit
.logMessage()) == -1))
70 if (!useMatcherTo
&& !useRegExpTo
)
73 if ((useMatcherTo
&& m_matcherTo
.indexIn(commit
.author()) == -1
74 && m_matcherTo
.indexIn(commit
.logMessage()) == -1)
75 || (useRegExpTo
&& m_regExpTo
.indexIn(commit
.author()) == -1
76 && m_regExpTo
.indexIn(commit
.logMessage()) == -1))
86 void CommitsMatcher::findNormalMatchers()
88 CommandLineParser
*args
= CommandLineParser::instance();
89 if (args
->contains("match")) {
90 m_matcher
= QStringMatcher(args
->optionArgument("match"), Qt::CaseInsensitive
);
93 else if (args
->contains("patches")) {
94 m_regExp
= QRegExp(args
->optionArgument("patches"), Qt::CaseInsensitive
, QRegExp::RegExp2
);
97 else if (useMatcherTo
|| useRegExpTo
)
98 m_state
= SearchingForTo
;