aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@trolltech.com>2008-08-23 22:48:34 +0200
committerThiago Macieira <thiago.macieira@trolltech.com>2008-08-23 22:48:34 +0200
commit374d4cd6fe492af4bcb0adf46e380f55be737d01 (patch)
treee946bc11604b7a07a226c9cab3febcd4cbae76c9
parent25e6c28e0da95faa8bd6644cebf3f20d0afb6f53 (diff)
downloadsvn2git-374d4cd6fe492af4bcb0adf46e380f55be737d01.tar
svn2git-374d4cd6fe492af4bcb0adf46e380f55be737d01.tar.gz
svn2git-374d4cd6fe492af4bcb0adf46e380f55be737d01.tar.bz2
svn2git-374d4cd6fe492af4bcb0adf46e380f55be737d01.tar.xz
svn2git-374d4cd6fe492af4bcb0adf46e380f55be737d01.zip
Add a process cache to keep the number of processes under 100
-rw-r--r--src/repository.cpp34
-rw-r--r--src/repository.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/src/repository.cpp b/src/repository.cpp
index be24ed4..e74ab20 100644
--- a/src/repository.cpp
+++ b/src/repository.cpp
@@ -18,6 +18,31 @@
#include "repository.h"
#include <QTextStream>
#include <QDebug>
+#include <QLinkedList>
+
+static const int maxSimultaneousProcesses = 100;
+
+class ProcessCache: QLinkedList<Repository *>
+{
+public:
+ void touch(Repository *repo)
+ {
+ remove(repo);
+
+ // if the cache is too big, remove from the front
+ while (size() >= maxSimultaneousProcesses)
+ takeFirst()->closeFastImport();
+
+ // append to the end
+ append(repo);
+ }
+
+ inline void remove(Repository *repo)
+ {
+ removeOne(repo);
+ }
+};
+static ProcessCache processCache;
Repository::Repository(const Rules::Repository &rule)
: name(rule.name), commitCount(0), processHasStarted(false)
@@ -37,6 +62,11 @@ Repository::Repository(const Rules::Repository &rule)
Repository::~Repository()
{
+ closeFastImport();
+}
+
+void Repository::closeFastImport()
+{
if (fastImport.state() != QProcess::NotRunning) {
fastImport.write("checkpoint\n");
fastImport.waitForBytesWritten(-1);
@@ -47,6 +77,8 @@ Repository::~Repository()
qWarning() << "git-fast-import for repository" << name << "did not die";
}
}
+ processHasStarted = false;
+ processCache.remove(this);
}
void Repository::reloadBranches()
@@ -198,6 +230,8 @@ QIODevice *Repository::Transaction::addFile(const QString &path, int mode, qint6
void Repository::Transaction::commit()
{
+ processCache.touch(repository);
+
// create the commit message
QByteArray message = log;
if (!message.endsWith('\n'))
diff --git a/src/repository.h b/src/repository.h
index 4692080..d837599 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -80,7 +80,9 @@ private:
bool processHasStarted;
void startFastImport();
+ void closeFastImport();
+ friend class ProcessCache;
Q_DISABLE_COPY(Repository)
};