diff options
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/repository.cpp | 23 | ||||
-rw-r--r-- | src/repository.h | 2 | ||||
-rw-r--r-- | src/svn.cpp | 33 | ||||
-rw-r--r-- | src/svn.h | 2 |
5 files changed, 48 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp index ec969c5..225ae5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -245,7 +245,7 @@ int main(int argc, char **argv) Svn::initialize(); Svn svn(args->arguments().first()); svn.setMatchRules(rulesList.allMatchRules()); - svn.setRepositories(repositories); + svn.setRepositories(&repositories); svn.setIdentityMap(loadIdentityMapFile(args->optionArgument("identity-map"))); // Massage user input a little, no guarantees that input makes sense. QString domain = args->optionArgument("identity-domain").simplified().remove(QChar('@')); diff --git a/src/repository.cpp b/src/repository.cpp index 154dc93..d33e218 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -72,6 +72,23 @@ Repository::Repository(const Rules::Repository &rule) branches.insert(branchRule.name, branch); } + init(rule.description); +} + +Repository::Repository(const QString &name, const QString &branchName, int revision) + : name(name), prefix(""), fastImport(name), commitCount(0), outstandingTransactions(0), + last_commit_mark(0), next_file_mark(maxMark), processHasStarted(false) +{ + Branch branch; + branch.created = revision; + + branches.insert(branchName, branch); + + init(""); +} + +void Repository::init(const QString &description) +{ // create the default branch branches["master"].created = 1; @@ -85,10 +102,10 @@ Repository::Repository(const Rules::Repository &rule) init.start("git", QStringList() << "--bare" << "init"); init.waitForFinished(-1); // Write description - if (!rule.description.isEmpty()) { + if (!description.isEmpty()) { QFile fDesc(QDir(name).filePath("description")); if (fDesc.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { - fDesc.write(rule.description.toUtf8()); + fDesc.write(description.toUtf8()); fDesc.putChar('\n'); fDesc.close(); } @@ -102,6 +119,7 @@ Repository::Repository(const Rules::Repository &rule) } } + static QString logFileName(QString name) { name.replace('/', '_'); @@ -302,7 +320,6 @@ int Repository::markFrom(const QString &branchFrom, int branchRevNum, QByteArray Branch &brFrom = branches[branchFrom]; if (!brFrom.created) return -1; - if (brFrom.commits.isEmpty()) { return -1; } diff --git a/src/repository.h b/src/repository.h index 4716ced..c5a289b 100644 --- a/src/repository.h +++ b/src/repository.h @@ -131,6 +131,7 @@ public: const QByteArray &commit = QByteArray()); }; Repository(const Rules::Repository &rule); + Repository(const QString &name, const QString &branchName, int revision); int setupIncremental(int &cutoff); void restoreLog(); ~Repository(); @@ -190,6 +191,7 @@ private: bool processHasStarted; + void init(const QString &description); void startFastImport(); void closeFastImport(); diff --git a/src/svn.cpp b/src/svn.cpp index b2fe2a2..f63219b 100644 --- a/src/svn.cpp +++ b/src/svn.cpp @@ -75,7 +75,7 @@ class SvnPrivate { public: QList<MatchRuleList> allMatchRules; - RepositoryHash repositories; + RepositoryHash *repositories; IdentityHash identities; QString userdomain; @@ -119,7 +119,7 @@ void Svn::setMatchRules(const QList<MatchRuleList> &allMatchRules) d->allMatchRules = allMatchRules; } -void Svn::setRepositories(const RepositoryHash &repositories) +void Svn::setRepositories(RepositoryHash *repositories) { d->repositories = repositories; } @@ -145,7 +145,7 @@ bool Svn::exportRevision(int revnum) } SvnPrivate::SvnPrivate(const QString &pathToRepository) - : global_pool(NULL) + : repositories(NULL), global_pool(NULL) { if( openRepository(pathToRepository) != EXIT_SUCCESS) { qCritical() << "Failed to open repository"; @@ -398,7 +398,7 @@ public: AprAutoPool pool; QHash<QString, Repository::Transaction *> transactions; QList<MatchRuleList> allMatchRules; - RepositoryHash repositories; + RepositoryHash *repositories; IdentityHash identities; QString userdomain; @@ -415,7 +415,7 @@ public: bool needCommit; SvnRevision(int revision, svn_fs_t *f, apr_pool_t *parent_pool) - : pool(parent_pool), fs(f), fs_root(0), revnum(revision), propsFetched(false) + : repositories(NULL), pool(parent_pool), fs(f), fs_root(0), revnum(revision), propsFetched(false) { ruledebug = CommandLineParser::instance()->contains( QLatin1String("debug-rules")); } @@ -542,7 +542,7 @@ int SvnRevision::commit() // now create the commit if (fetchRevProps() != EXIT_SUCCESS) return EXIT_FAILURE; - foreach (Repository *repo, repositories.values()) { + foreach (Repository *repo, repositories->values()) { repo->commit(); } @@ -686,12 +686,27 @@ int SvnRevision::exportInternal(const char *key, const svn_fs_path_change_t *cha QString svnprefix, repository, branch, path; splitPathName(rule, current, &svnprefix, &repository, &branch, &path); - Repository *repo = repositories.value(repository, 0); + Repository *repo = repositories->value(repository, 0); if (!repo) { - if (change->change_kind != svn_fs_path_change_delete) + if (change->change_kind != svn_fs_path_change_delete) { + // Attempt to auto create the repo + qWarning() << "Auto-creating repository" << repository << "with branch" + << branch << "at revision" << revnum << "due to rule match"; + + repo = new Repository(repository, branch, revnum); + if (!repo) + return EXIT_FAILURE; + repositories->insert(repository, repo); + + //repo->setupIncremental(INT_MAX); + } + + if (!repo) { qCritical() << "Rule" << rule << "references unknown repository" << repository; - return EXIT_FAILURE; + + return EXIT_FAILURE; + } } printf("."); @@ -34,7 +34,7 @@ public: ~Svn(); void setMatchRules(const QList<QList<Rules::Match> > &matchRules); - void setRepositories(const QHash<QString, Repository *> &repositories); + void setRepositories(QHash<QString, Repository *> *repositories); void setIdentityMap(const QHash<QByteArray, QByteArray> &identityMap); void setIdentityDomain(const QString &identityDomain); |