aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorgny Nyblom <kde@nyblom.org>2010-12-04 20:53:43 +0100
committerTorgny Nyblom <kde@nyblom.org>2010-12-04 20:53:43 +0100
commitce56750e8a47e3be86cf0c0964a145c7d7f943e5 (patch)
tree53f1f80707fc7f147a111a85593ecb92e72a67d5
parent6e13e426db84b9137b98ba80552b91e3684085cd (diff)
downloadsvn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.gz
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.bz2
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.tar.xz
svn2git-ce56750e8a47e3be86cf0c0964a145c7d7f943e5.zip
Add an option to print some stats after a run.
-rw-r--r--src/main.cpp4
-rw-r--r--src/ruleparser.cpp88
-rw-r--r--src/ruleparser.h22
-rw-r--r--src/svn.cpp2
4 files changed, 112 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ad6cde3..d6a5a6b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -105,6 +105,7 @@ static const CommandLineOption options[] = {
{"--dry-run", "don't actually write anything"},
{"--debug-rules", "print what rule is being used for each file"},
{"--commit-interval NUMBER", "if passed the cache will be flushed to git every NUMBER of commits"},
+ {"--stats", "after a run print some statistics about the rules"},
{"-h, --help", "show help"},
{"-v, --version", "show version"},
CommandLineLastOption
@@ -113,6 +114,7 @@ static const CommandLineOption options[] = {
int main(int argc, char **argv)
{
CommandLineParser::init(argc, argv);
+ Stats::init();
CommandLineParser::addOptionDefinitions(options);
CommandLineParser *args = CommandLineParser::instance();
if (args->contains(QLatin1String("help")) || args->arguments().count() != 1) {
@@ -230,6 +232,6 @@ int main(int argc, char **argv)
repo->finalizeTags();
delete repo;
}
-
+ Stats::instance()->printStats();
return errors ? EXIT_FAILURE : EXIT_SUCCESS;
}
diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp
index 27ab0ca..f7d201c 100644
--- a/src/ruleparser.cpp
+++ b/src/ruleparser.cpp
@@ -21,6 +21,7 @@
#include <QDebug>
#include "ruleparser.h"
+#include "CommandLineParser.h"
RulesList::RulesList(const QString &filenames)
: m_filenames(filenames)
@@ -193,6 +194,7 @@ void Rules::load(const QString &filename)
if (!match.repository.isEmpty())
match.action = Match::Export;
m_matchRules += match;
+ Stats::instance()->addRule(match);
state = ReadingNone;
continue;
}
@@ -232,6 +234,92 @@ void Rules::load(const QString &filename)
}
}
+Stats *Stats::self = 0;
+
+class Stats::Private
+{
+public:
+ Private();
+
+ void printStats() const;
+ void ruleMatched(const Rules::Match &rule, const int rev);
+ void addRule(const Rules::Match &rule);
+private:
+ QMap<QString,int> m_usedRules;
+};
+
+Stats::Stats() : d(new Private())
+{
+ use = CommandLineParser::instance()->contains("stats");
+}
+
+Stats::~Stats()
+{
+ delete d;
+}
+
+void Stats::init()
+{
+ if(self)
+ delete self;
+ self = new Stats();
+}
+
+Stats* Stats::instance()
+{
+ return self;
+}
+
+void Stats::printStats() const
+{
+ if(use)
+ d->printStats();
+}
+
+void Stats::ruleMatched(const Rules::Match &rule, const int rev)
+{
+ if(use)
+ d->ruleMatched(rule, rev);
+}
+
+void Stats::addRule( const Rules::Match &rule)
+{
+ if(use)
+ d->addRule(rule);
+}
+
+Stats::Private::Private()
+{
+}
+
+void Stats::Private::printStats() const
+{
+ printf("\nRule stats\n");
+ foreach(const QString name, m_usedRules.keys()) {
+ printf("%s was matched %i times\n", qPrintable(name), m_usedRules[name]);
+ }
+}
+
+void Stats::Private::ruleMatched(const Rules::Match &rule, const int rev)
+{
+ Q_UNUSED(rev);
+ const QString name = rule.info();
+ if(!m_usedRules.contains(name)) {
+ m_usedRules.insert(name, 1);
+ qWarning() << "New match rule, should have been added when created.";
+ } else {
+ m_usedRules[name]++;
+ }
+}
+
+void Stats::Private::addRule( const Rules::Match &rule)
+{
+ const QString name = rule.info();
+ if(m_usedRules.contains(name))
+ qWarning() << "Rule" << name << "was added multiple times.";
+ m_usedRules.insert(name, 0);
+}
+
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug s, const Rules::Match &rule)
{
diff --git a/src/ruleparser.h b/src/ruleparser.h
index f3f6c6a..9d21937 100644
--- a/src/ruleparser.h
+++ b/src/ruleparser.h
@@ -73,7 +73,7 @@ public:
Match() : minRevision(-1), maxRevision(-1), annotate(false), action(Ignore) { }
const QString info() const {
- const QString info = rx.pattern() % " (" % Rule::filename % ":" % QByteArray::number(Rule::lineNumber) % ")";
+ const QString info = Rule::filename % ":" % QByteArray::number(Rule::lineNumber) % " " % rx.pattern();
return info;
}
};
@@ -83,12 +83,10 @@ public:
const QList<Repository> repositories() const;
const QList<Match> matchRules() const;
-
void load();
private:
void load(const QString &filename);
-
QString filename;
QList<Repository> m_repositories;
QList<Match> m_matchRules;
@@ -113,6 +111,24 @@ private:
QList<QList<Rules::Match> > m_allMatchRules;
};
+class Stats
+{
+public:
+ static Stats *instance();
+ void printStats() const;
+ void ruleMatched(const Rules::Match &rule, const int rev = -1);
+ void addRule( const Rules::Match &rule);
+ static void init();
+ ~Stats();
+
+private:
+ Stats();
+ class Private;
+ Private * const d;
+ static Stats *self;
+ bool use;
+};
+
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
QDebug operator<<(QDebug, const Rules::Match &);
diff --git a/src/svn.cpp b/src/svn.cpp
index 5026f45..38e21dc 100644
--- a/src/svn.cpp
+++ b/src/svn.cpp
@@ -190,6 +190,7 @@ findMatchRule(const MatchRuleList &matchRules, int revnum, const QString &curren
if (it->action == Rules::Match::Recurse && ruleMask & NoRecurseRule)
continue;
if (it->rx.indexIn(current) == 0) {
+ Stats::instance()->ruleMatched(*it, revnum);
return it;
}
}
@@ -664,6 +665,7 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *cha
if (prevmatch != matchRules.constEnd()) {
splitPathName(*prevmatch, previous, &prevsvnprefix, &prevrepository,
&prevbranch, &prevpath);
+
} else {
qWarning() << "SVN reports a \"copy from\" @" << revnum << "from" << path_from << "@" << rev_from << "but no matching rules found! Ignoring copy, treating as a modification";
path_from = NULL;