aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago@cassini.local.lan>2007-12-24 00:44:01 -0200
committerThiago Macieira <thiago@cassini.local.lan>2007-12-24 00:45:23 -0200
commitb6ba9639a3c908aedb76954a575641c56a76714c (patch)
treeb4f39c68a43a314c817b911025beb04e51391cbf
parentc7d45e66be31b72663e3a5a13a60eef31d458e0a (diff)
downloadsvn2git-b6ba9639a3c908aedb76954a575641c56a76714c.tar
svn2git-b6ba9639a3c908aedb76954a575641c56a76714c.tar.gz
svn2git-b6ba9639a3c908aedb76954a575641c56a76714c.tar.bz2
svn2git-b6ba9639a3c908aedb76954a575641c56a76714c.tar.xz
svn2git-b6ba9639a3c908aedb76954a575641c56a76714c.zip
Fix crashes and improve behaviour
-rw-r--r--src/main.cpp2
-rw-r--r--src/repository.cpp11
-rw-r--r--src/repository.h1
-rw-r--r--src/svn.cpp31
4 files changed, 28 insertions, 17 deletions
diff --git a/src/main.cpp b/src/main.cpp
index ba6f2f5..4415bca 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -49,7 +49,7 @@ int main(int argc, char **argv)
svn.setRepositories(repositories);
int max_rev = svn.youngestRevision();
- for (int i = 1; i < max_rev; ++i)
+ for (int i = 1; i <= max_rev; ++i)
if (!svn.exportRevision(i))
break;
diff --git a/src/repository.cpp b/src/repository.cpp
index bd229f0..8a5f4f0 100644
--- a/src/repository.cpp
+++ b/src/repository.cpp
@@ -17,8 +17,10 @@
#include "repository.h"
#include <QTextStream>
+#include <QDebug>
Repository::Repository(const Rules::Repository &rule)
+ : name(rule.name)
{
foreach (Rules::Repository::Branch branchRule, rule.branches) {
Branch branch;
@@ -28,6 +30,9 @@ Repository::Repository(const Rules::Repository &rule)
branches.insert(branchRule.name, branch);
}
+ // create the default branch
+ branches["master"].isCreated = true;
+
fastImport.setWorkingDirectory(rule.name);
fastImport.setProcessChannelMode(QProcess::ForwardedChannels);
}
@@ -43,8 +48,10 @@ Repository::~Repository()
Repository::Transaction *Repository::newTransaction(const QString &branch, const QString &svnprefix,
int revnum)
{
- if (!branches.contains(branch))
+ if (!branches.contains(branch)) {
+ qCritical() << branch << "is not known in repository" << name;
return 0;
+ }
Transaction *txn = new Transaction;
txn->repository = this;
@@ -125,7 +132,7 @@ void Repository::Transaction::commit()
QTextStream s(&repository->fastImport);
s << "commit " << branchRef << endl;
s << "mark :" << revnum << endl;
- s << "committer " << author << ' ' << datetime << "-0000" << endl;
+ s << "committer " << author << ' ' << datetime << " -0000" << endl;
Branch &br = repository->branches[branch];
if (!br.isCreated) {
diff --git a/src/repository.h b/src/repository.h
index c0556c7..60c2aed 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -72,6 +72,7 @@ private:
};
QHash<QString, Branch> branches;
+ QString name;
QProcess fastImport;
Q_DISABLE_COPY(Repository)
diff --git a/src/svn.cpp b/src/svn.cpp
index 84ce3af..18666a3 100644
--- a/src/svn.cpp
+++ b/src/svn.cpp
@@ -57,12 +57,15 @@ typedef QHash<QByteArray, QByteArray> IdentityHash;
class AprAutoPool
{
apr_pool_t *pool;
+ AprAutoPool(const AprAutoPool &);
+ AprAutoPool &operator=(const AprAutoPool &);
public:
inline AprAutoPool(apr_pool_t *parent = NULL)
{ pool = svn_pool_create(parent); }
inline ~AprAutoPool()
{ svn_pool_destroy(pool); }
+ inline void clear() { svn_pool_clear(pool); }
inline apr_pool_t *data() const { return pool; }
inline operator apr_pool_t *() const { return pool; }
};
@@ -167,7 +170,7 @@ static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *po
// maybe it's a symlink?
SVN_ERR(svn_fs_node_prop(&propvalue, fs_root, pathname, "svn:special", pool));
- if (strcmp(propvalue->data, "symlink") == 0)
+ if (propvalue && strcmp(propvalue->data, "symlink") == 0)
mode = 0120000;
return mode;
@@ -192,7 +195,7 @@ static svn_stream_t *streamForDevice(QIODevice *device, apr_pool_t *pool)
}
static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
- const char *pathname, apr_pool_t *pool)
+ const char *pathname, const QString &finalPathName, apr_pool_t *pool)
{
// what type is it?
int mode = pathMode(fs_root, pathname, pool);
@@ -200,7 +203,7 @@ static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
svn_filesize_t stream_length;
SVN_ERR(svn_fs_file_length(&stream_length, fs_root, pathname, pool));
- QIODevice *io = txn->addFile(pathname, mode, stream_length);
+ QIODevice *io = txn->addFile(finalPathName, mode, stream_length);
#ifndef DRY_RUN
// open the file
@@ -229,21 +232,20 @@ time_t get_epoch(char *svn_date)
int SvnPrivate::exportRevision(int revnum)
{
- AprAutoPool pool(global_pool);
+ AprAutoPool pool(global_pool.data());
// open this revision:
+ qDebug() << "Exporting revision" << revnum;
svn_fs_root_t *fs_root;
SVN_ERR(svn_fs_revision_root(&fs_root, fs, revnum, pool));
- qDebug() << "Exporting revision" << revnum;
// find out what was changed in this revision:
QHash<QString, Repository::Transaction *> transactions;
apr_hash_t *changes;
SVN_ERR(svn_fs_paths_changed(&changes, fs_root, pool));
- AprAutoPool revpool(pool);
+ AprAutoPool revpool(pool.data());
for (apr_hash_index_t *i = apr_hash_first(pool, changes); i; i = apr_hash_next(i)) {
- svn_pool_clear(revpool);
-
+ revpool.clear();
const void *vkey;
void *value;
apr_hash_this(i, &vkey, NULL, &value);
@@ -259,7 +261,7 @@ int SvnPrivate::exportRevision(int revnum)
// find the first rule that matches this pathname
bool foundMatch = false;
- foreach (Rules::Match rule, matchRules)
+ foreach (Rules::Match rule, matchRules) {
if (rule.rx.exactMatch(current)) {
foundMatch = true;
QString repository = current;
@@ -271,7 +273,7 @@ int SvnPrivate::exportRevision(int revnum)
branch.replace(rule.rx, rule.branch);
path.replace(rule.rx, rule.path);
- qDebug() << "..." << current << "->"
+ qDebug() << "..." << current << "rev" << revnum << "->"
<< repository << branch << path;
Repository::Transaction *txn = transactions.value(repository, 0);
@@ -284,8 +286,8 @@ int SvnPrivate::exportRevision(int revnum)
}
QString svnprefix = current;
- if (current.endsWith(path))
- current.chop(path.length());
+ if (svnprefix.endsWith(path))
+ svnprefix.chop(path.length());
txn = repo->newTransaction(branch, svnprefix, revnum);
if (!txn)
@@ -298,17 +300,18 @@ int SvnPrivate::exportRevision(int revnum)
if (change->change_kind == svn_fs_path_change_delete)
txn->deleteFile(path);
else
- dumpBlob(txn, fs_root, key, revpool);
+ dumpBlob(txn, fs_root, key, path, revpool);
break;
}
+ }
if (!foundMatch) {
qCritical() << current << "did not match any rules; cannot continue";
return EXIT_FAILURE;
}
}
- svn_pool_clear(revpool);
+ revpool.clear();
if (transactions.isEmpty())
return EXIT_SUCCESS; // no changes?