aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaja R Harinath <harinath@hurrynot.org>2010-07-22 17:37:07 +0530
committerRaja R Harinath <harinath@hurrynot.org>2010-07-22 17:37:07 +0530
commitf0b31cfe9d31421b83507316d1274d191336a1f7 (patch)
tree456f8b2266607a1c337d9f9218c358cfde05815b
parent37b289b98200f0e054a97485b56a0b643536cad4 (diff)
downloadsvn2git-f0b31cfe9d31421b83507316d1274d191336a1f7.tar
svn2git-f0b31cfe9d31421b83507316d1274d191336a1f7.tar.gz
svn2git-f0b31cfe9d31421b83507316d1274d191336a1f7.tar.bz2
svn2git-f0b31cfe9d31421b83507316d1274d191336a1f7.tar.xz
svn2git-f0b31cfe9d31421b83507316d1274d191336a1f7.zip
Extract out public methods of Repository into an abstract base class
Rename Repository to FastImportRepository. We will be introducing new types soon.
-rw-r--r--src/main.cpp2
-rw-r--r--src/repository.cpp153
-rw-r--r--src/repository.h109
3 files changed, 154 insertions, 110 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 1982627..ff11255 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
retry:
int min_rev = 1;
foreach (Rules::Repository rule, rules.repositories()) {
- Repository *repo = new Repository(rule);
+ Repository *repo = makeRepository(rule, repositories);
repositories.insert(rule.name, repo);
int repo_next = repo->setupIncremental(cutoff);
diff --git a/src/repository.cpp b/src/repository.cpp
index a53d206..f5b7a50 100644
--- a/src/repository.cpp
+++ b/src/repository.cpp
@@ -27,10 +27,106 @@ 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 ProcessCache: QLinkedList<Repository *>
+class FastImportRepository : public Repository
{
public:
- void touch(Repository *repo)
+ class Transaction : public Repository::Transaction
+ {
+ Q_DISABLE_COPY(Transaction)
+ friend class FastImportRepository;
+
+ FastImportRepository *repository;
+ QByteArray branch;
+ QByteArray svnprefix;
+ QByteArray author;
+ QByteArray log;
+ uint datetime;
+ int revnum;
+
+ QVector<int> merges;
+
+ QStringList deletedFiles;
+ QByteArray modifiedFiles;
+
+ inline Transaction() {}
+ public:
+ ~Transaction();
+ void commit();
+
+ void setAuthor(const QByteArray &author);
+ void setDateTime(uint dt);
+ void setLog(const QByteArray &log);
+
+ void noteCopyFromBranch (const QString &prevbranch, int revFrom);
+
+ void deleteFile(const QString &path);
+ QIODevice *addFile(const QString &path, int mode, qint64 length);
+ };
+ FastImportRepository(const Rules::Repository &rule);
+ int setupIncremental(int &cutoff);
+ void restoreLog();
+ ~FastImportRepository();
+
+ void reloadBranches();
+ int createBranch(const QString &branch, int revnum,
+ const QString &branchFrom, int revFrom);
+ int deleteBranch(const QString &branch, int revnum);
+ Repository::Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum);
+
+ void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum,
+ const QByteArray &author, uint dt,
+ const QByteArray &log);
+ void finalizeTags();
+
+private:
+ struct Branch
+ {
+ int created;
+ QVector<int> commits;
+ QVector<int> marks;
+ };
+ struct AnnotatedTag
+ {
+ QString supportingRef;
+ QByteArray svnprefix;
+ QByteArray author;
+ QByteArray log;
+ uint dt;
+ int revnum;
+ };
+
+ QHash<QString, Branch> branches;
+ QHash<QString, AnnotatedTag> annotatedTags;
+ QString name;
+ QProcess fastImport;
+ int commitCount;
+ int outstandingTransactions;
+
+ /* starts at 0, and counts up. */
+ int last_commit_mark;
+
+ /* starts at maxMark and counts down. Reset after each SVN revision */
+ int next_file_mark;
+
+ bool processHasStarted;
+
+ void startFastImport();
+ void closeFastImport();
+
+ // called when a transaction is deleted
+ void forgetTransaction(Transaction *t);
+
+ int resetBranch(const QString &branch, int revnum, int mark, const QByteArray &resetTo, const QByteArray &comment);
+ int markFrom(const QString &branchFrom, int branchRevNum, QByteArray &desc);
+
+ friend class ProcessCache;
+ Q_DISABLE_COPY(FastImportRepository)
+};
+
+class ProcessCache: QLinkedList<FastImportRepository *>
+{
+public:
+ void touch(FastImportRepository *repo)
{
remove(repo);
@@ -42,7 +138,7 @@ public:
append(repo);
}
- inline void remove(Repository *repo)
+ inline void remove(FastImportRepository *repo)
{
#if QT_VERSION >= 0x040400
removeOne(repo);
@@ -53,7 +149,12 @@ public:
};
static ProcessCache processCache;
-Repository::Repository(const Rules::Repository &rule)
+Repository *makeRepository(const Rules::Repository &rule, const QHash<QString, Repository *> &repositories)
+{
+ return new FastImportRepository(rule);
+}
+
+FastImportRepository::FastImportRepository(const Rules::Repository &rule)
: name(rule.name), commitCount(0), outstandingTransactions(0), last_commit_mark(0), next_file_mark(maxMark), processHasStarted(false)
{
foreach (Rules::Repository::Branch branchRule, rule.branches) {
@@ -140,7 +241,7 @@ static int lastValidMark(QString name)
return prev_mark;
}
-int Repository::setupIncremental(int &cutoff)
+int FastImportRepository::setupIncremental(int &cutoff)
{
QFile logfile(logFileName(name));
if (!logfile.exists())
@@ -220,7 +321,7 @@ int Repository::setupIncremental(int &cutoff)
return cutoff;
}
-void Repository::restoreLog()
+void FastImportRepository::restoreLog()
{
QString file = logFileName(name);
QString bkup = file + ".old";
@@ -230,13 +331,13 @@ void Repository::restoreLog()
QFile::rename(bkup, file);
}
-Repository::~Repository()
+FastImportRepository::~FastImportRepository()
{
Q_ASSERT(outstandingTransactions == 0);
closeFastImport();
}
-void Repository::closeFastImport()
+void FastImportRepository::closeFastImport()
{
if (fastImport.state() != QProcess::NotRunning) {
fastImport.write("checkpoint\n");
@@ -252,7 +353,7 @@ void Repository::closeFastImport()
processCache.remove(this);
}
-void Repository::reloadBranches()
+void FastImportRepository::reloadBranches()
{
foreach (QString branch, branches.keys()) {
Branch &br = branches[branch];
@@ -270,7 +371,7 @@ void Repository::reloadBranches()
}
}
-int Repository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray &branchFromDesc)
+int FastImportRepository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray &branchFromDesc)
{
Branch &brFrom = branches[branchFrom];
if (!brFrom.created)
@@ -294,7 +395,7 @@ int Repository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray
return brFrom.marks[it - brFrom.commits.begin()];
}
-int Repository::createBranch(const QString &branch, int revnum,
+int FastImportRepository::createBranch(const QString &branch, int revnum,
const QString &branchFrom, int branchRevNum)
{
startFastImport();
@@ -326,7 +427,7 @@ int Repository::createBranch(const QString &branch, int revnum,
return resetBranch(branch, revnum, mark, branchFromRef, branchFromDesc);
}
-int Repository::deleteBranch(const QString &branch, int revnum)
+int FastImportRepository::deleteBranch(const QString &branch, int revnum)
{
startFastImport();
@@ -334,7 +435,7 @@ int Repository::deleteBranch(const QString &branch, int revnum)
return resetBranch(branch, revnum, 0, null_sha, "delete");
}
-int Repository::resetBranch(const QString &branch, int revnum, int mark, const QByteArray &resetTo, const QByteArray &comment)
+int FastImportRepository::resetBranch(const QString &branch, int revnum, int mark, const QByteArray &resetTo, const QByteArray &comment)
{
QByteArray branchRef = branch.toUtf8();
if (!branchRef.startsWith("refs/"))
@@ -360,7 +461,7 @@ int Repository::resetBranch(const QString &branch, int revnum, int mark, const Q
return EXIT_SUCCESS;
}
-Repository::Transaction *Repository::newTransaction(const QString &branch, const QString &svnprefix,
+Repository::Transaction *FastImportRepository::newTransaction(const QString &branch, const QString &svnprefix,
int revnum)
{
startFastImport();
@@ -383,13 +484,13 @@ Repository::Transaction *Repository::newTransaction(const QString &branch, const
return txn;
}
-void Repository::forgetTransaction(Transaction *)
+void FastImportRepository::forgetTransaction(Transaction *)
{
if (!--outstandingTransactions)
next_file_mark = maxMark;
}
-void Repository::createAnnotatedTag(const QString &ref, const QString &svnprefix,
+void FastImportRepository::createAnnotatedTag(const QString &ref, const QString &svnprefix,
int revnum,
const QByteArray &author, uint dt,
const QByteArray &log)
@@ -412,7 +513,7 @@ void Repository::createAnnotatedTag(const QString &ref, const QString &svnprefix
tag.dt = dt;
}
-void Repository::finalizeTags()
+void FastImportRepository::finalizeTags()
{
if (annotatedTags.isEmpty())
return;
@@ -459,7 +560,7 @@ void Repository::finalizeTags()
printf("\n");
}
-void Repository::startFastImport()
+void FastImportRepository::startFastImport()
{
if (fastImport.state() == QProcess::NotRunning) {
if (processHasStarted)
@@ -480,27 +581,27 @@ void Repository::startFastImport()
}
}
-Repository::Transaction::~Transaction()
+FastImportRepository::Transaction::~Transaction()
{
repository->forgetTransaction(this);
}
-void Repository::Transaction::setAuthor(const QByteArray &a)
+void FastImportRepository::Transaction::setAuthor(const QByteArray &a)
{
author = a;
}
-void Repository::Transaction::setDateTime(uint dt)
+void FastImportRepository::Transaction::setDateTime(uint dt)
{
datetime = dt;
}
-void Repository::Transaction::setLog(const QByteArray &l)
+void FastImportRepository::Transaction::setLog(const QByteArray &l)
{
log = l;
}
-void Repository::Transaction::noteCopyFromBranch(const QString &branchFrom, int branchRevNum)
+void FastImportRepository::Transaction::noteCopyFromBranch(const QString &branchFrom, int branchRevNum)
{
static QByteArray dummy;
int mark = repository->markFrom(branchFrom, branchRevNum, dummy);
@@ -520,7 +621,7 @@ void Repository::Transaction::noteCopyFromBranch(const QString &branchFrom, int
}
}
-void Repository::Transaction::deleteFile(const QString &path)
+void FastImportRepository::Transaction::deleteFile(const QString &path)
{
QString pathNoSlash = path;
if(pathNoSlash.endsWith('/'))
@@ -528,7 +629,7 @@ void Repository::Transaction::deleteFile(const QString &path)
deletedFiles.append(pathNoSlash);
}
-QIODevice *Repository::Transaction::addFile(const QString &path, int mode, qint64 length)
+QIODevice *FastImportRepository::Transaction::addFile(const QString &path, int mode, qint64 length)
{
int mark = repository->next_file_mark--;
@@ -556,7 +657,7 @@ QIODevice *Repository::Transaction::addFile(const QString &path, int mode, qint6
return &repository->fastImport;
}
-void Repository::Transaction::commit()
+void FastImportRepository::Transaction::commit()
{
processCache.touch(repository);
diff --git a/src/repository.h b/src/repository.h
index 0240043..590ef0e 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -30,94 +30,37 @@ public:
class Transaction
{
Q_DISABLE_COPY(Transaction)
- friend class Repository;
-
- Repository *repository;
- QByteArray branch;
- QByteArray svnprefix;
- QByteArray author;
- QByteArray log;
- uint datetime;
- int revnum;
-
- QVector<int> merges;
-
- QStringList deletedFiles;
- QByteArray modifiedFiles;
-
- inline Transaction() {}
+ protected:
+ Transaction() {}
public:
- ~Transaction();
- void commit();
-
- void setAuthor(const QByteArray &author);
- void setDateTime(uint dt);
- void setLog(const QByteArray &log);
+ virtual ~Transaction() {}
+ virtual void commit() = 0;
- void noteCopyFromBranch (const QString &prevbranch, int revFrom);
+ virtual void setAuthor(const QByteArray &author) = 0;
+ virtual void setDateTime(uint dt) = 0;
+ virtual void setLog(const QByteArray &log) = 0;
- void deleteFile(const QString &path);
- QIODevice *addFile(const QString &path, int mode, qint64 length);
- };
- Repository(const Rules::Repository &rule);
- int setupIncremental(int &cutoff);
- void restoreLog();
- ~Repository();
-
- void reloadBranches();
- int createBranch(const QString &branch, int revnum,
- const QString &branchFrom, int revFrom);
- int deleteBranch(const QString &branch, int revnum);
- Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum);
-
- void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum,
- const QByteArray &author, uint dt,
- const QByteArray &log);
- void finalizeTags();
+ virtual void noteCopyFromBranch (const QString &prevbranch, int revFrom) = 0;
-private:
- struct Branch
- {
- int created;
- QVector<int> commits;
- QVector<int> marks;
- };
- struct AnnotatedTag
- {
- QString supportingRef;
- QByteArray svnprefix;
- QByteArray author;
- QByteArray log;
- uint dt;
- int revnum;
+ virtual void deleteFile(const QString &path) = 0;
+ virtual QIODevice *addFile(const QString &path, int mode, qint64 length) = 0;
};
-
- QHash<QString, Branch> branches;
- QHash<QString, AnnotatedTag> annotatedTags;
- QString name;
- QProcess fastImport;
- int commitCount;
- int outstandingTransactions;
-
- /* starts at 0, and counts up. */
- int last_commit_mark;
-
- /* starts at maxMark and counts down. Reset after each SVN revision */
- int next_file_mark;
-
- bool processHasStarted;
-
- void startFastImport();
- void closeFastImport();
-
- // called when a transaction is deleted
- void forgetTransaction(Transaction *t);
-
- int resetBranch(const QString &branch, int revnum, int mark, const QByteArray &resetTo, const QByteArray &comment);
- int markFrom(const QString &branchFrom, int branchRevNum, QByteArray &desc);
-
- friend class ProcessCache;
- Q_DISABLE_COPY(Repository)
+ virtual int setupIncremental(int &cutoff) = 0;
+ virtual void restoreLog() = 0;
+ virtual ~Repository() {}
+
+ virtual void reloadBranches() = 0;
+ virtual int createBranch(const QString &branch, int revnum,
+ const QString &branchFrom, int revFrom) = 0;
+ virtual int deleteBranch(const QString &branch, int revnum) = 0;
+ virtual Transaction *newTransaction(const QString &branch, const QString &svnprefix, int revnum) = 0;
+
+ virtual void createAnnotatedTag(const QString &name, const QString &svnprefix, int revnum,
+ const QByteArray &author, uint dt,
+ const QByteArray &log) = 0;
+ virtual void finalizeTags() = 0;
};
+Repository *makeRepository(const Rules::Repository &rule, const QHash<QString, Repository *> &repositories);
+
#endif