]> andersk Git - svn-all-fast-export.git/commitdiff
Add a process cache to keep the number of processes under 100
authorThiago Macieira <thiago.macieira@trolltech.com>
Sat, 23 Aug 2008 20:48:34 +0000 (22:48 +0200)
committerThiago Macieira <thiago.macieira@trolltech.com>
Sat, 23 Aug 2008 20:48:34 +0000 (22:48 +0200)
src/repository.cpp
src/repository.h

index be24ed4c48d1ce471fcf74706e59f4e2543d097b..e74ab207f4304ba592a2d476c5863a6b505bc1d2 100644 (file)
 #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)
@@ -36,6 +61,11 @@ Repository::Repository(const Rules::Repository &rule)
 }
 
 Repository::~Repository()
+{
+    closeFastImport();
+}
+
+void Repository::closeFastImport()
 {
     if (fastImport.state() != QProcess::NotRunning) {
         fastImport.write("checkpoint\n");
@@ -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'))
index 4692080a2f5c077b6c823165e2f25d5d75c046b1..d837599fcf53fc474126a42795e4447e36780a82 100644 (file)
@@ -80,7 +80,9 @@ private:
     bool processHasStarted;
 
     void startFastImport();
+    void closeFastImport();
 
+    friend class ProcessCache;
     Q_DISABLE_COPY(Repository)
 };
 
This page took 0.06279 seconds and 5 git commands to generate.