From e1bebdeb498dcfd772303a8e193f2ca989f67d92 Mon Sep 17 00:00:00 2001 From: Torgny Nyblom Date: Mon, 13 Sep 2010 12:19:04 +0200 Subject: Make the fastImport into a logging instance, logging is enabled when the "--debug-rules" flag is active. --- src/repository.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/src/repository.cpp b/src/repository.cpp index fc8da5e..cb48b71 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -21,12 +21,72 @@ #include #include #include +#include #include static const int maxSimultaneousProcesses = 100; static const int maxMark = (1 << 20) - 1; // some versions of git-fast-import are buggy for larger values of maxMark +class LoggingQProcess : public QProcess +{ + QFile log; + bool logging; +public: + LoggingQProcess(const QString filename) : QProcess(), log() { + if(CommandLineParser::instance()->contains("debug-rules")) { + logging = true; + QString name = filename; + name.replace('/', '_'); + name.prepend("gitlog-"); + log.setFileName(name); + log.open(QIODevice::WriteOnly); + } else { + logging = false; + } + }; + ~LoggingQProcess() { + if(logging) { + log.close(); + } + }; + + qint64 write(const char *data) { + if(logging) { + log.write(data); + } + return QProcess::write(data); + } + qint64 write(const char *data, qint64 length) { + if(logging) { + log.write(data); + } + return QProcess::write(data, length); + } + qint64 write(const QByteArray &data) { + if(logging) { + log.write(data); + } + return QProcess::write(data); + } + qint64 writeNoLog(const char *data) { + return QProcess::write(data); + } + qint64 writeNoLog(const char *data, qint64 length) { + return QProcess::write(data, length); + } + qint64 writeNoLog(const QByteArray &data) { + return QProcess::write(data); + } + bool putChar( char c) { + if(logging) { + log.putChar(c); + } + return QProcess::putChar(c); + } +}; + + class FastImportRepository : public Repository { public: @@ -98,7 +158,7 @@ private: QHash branches; QHash annotatedTags; QString name; - QProcess fastImport; + LoggingQProcess fastImport; int commitCount; int outstandingTransactions; @@ -222,7 +282,7 @@ static QString marksFileName(QString name) } FastImportRepository::FastImportRepository(const Rules::Repository &rule) - : name(rule.name), commitCount(0), outstandingTransactions(0), last_commit_mark(0), next_file_mark(maxMark), processHasStarted(false) + : name(rule.name), fastImport(name), commitCount(0), outstandingTransactions(0), last_commit_mark(0), next_file_mark(maxMark), processHasStarted(false) { foreach (Rules::Repository::Branch branchRule, rule.branches) { Branch branch; @@ -733,11 +793,11 @@ QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int m modifiedFiles.append("\n"); if (!CommandLineParser::instance()->contains("dry-run")) { - repository->fastImport.write("blob\nmark :"); - repository->fastImport.write(QByteArray::number(mark)); - repository->fastImport.write("\ndata "); - repository->fastImport.write(QByteArray::number(length)); - repository->fastImport.write("\n", 1); + repository->fastImport.writeNoLog("blob\nmark :"); + repository->fastImport.writeNoLog(QByteArray::number(mark)); + repository->fastImport.writeNoLog("\ndata "); + repository->fastImport.writeNoLog(QByteArray::number(length)); + repository->fastImport.writeNoLog("\n", 1); } return &repository->fastImport; -- cgit v1.2.1