aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago@cassini.local.lan>2007-12-24 14:06:33 -0200
committerThiago Macieira <thiago@cassini.local.lan>2007-12-24 14:06:33 -0200
commitf97a8dff0675251aadc60d1c06ce5315eae2c36b (patch)
treeeca97cc72ac2b5d8e43c7f46c569f36b9d66afbb
parent9fa82b403b5fef362b36d9f3ad199fd016c2ee96 (diff)
downloadsvn2git-f97a8dff0675251aadc60d1c06ce5315eae2c36b.tar
svn2git-f97a8dff0675251aadc60d1c06ce5315eae2c36b.tar.gz
svn2git-f97a8dff0675251aadc60d1c06ce5315eae2c36b.tar.bz2
svn2git-f97a8dff0675251aadc60d1c06ce5315eae2c36b.tar.xz
svn2git-f97a8dff0675251aadc60d1c06ce5315eae2c36b.zip
Support for pathless rules
-rw-r--r--src/ruleparser.cpp4
-rw-r--r--src/ruleparser.h1
-rw-r--r--src/svn.cpp86
3 files changed, 52 insertions, 39 deletions
diff --git a/src/ruleparser.cpp b/src/ruleparser.cpp
index 6d3e417..da05749 100644
--- a/src/ruleparser.cpp
+++ b/src/ruleparser.cpp
@@ -53,7 +53,6 @@ void Rules::load()
QRegExp matchLine("match\\s+(.*)", Qt::CaseInsensitive);
QRegExp matchRepoLine("repository\\s+(\\S+)", Qt::CaseInsensitive);
QRegExp matchBranchLine("branch\\s+(\\S+)", Qt::CaseInsensitive);
- QRegExp matchPathLine("path\\s+(.*)", Qt::CaseInsensitive);
QRegExp matchRevLine("(min|max) revision (\\d+)", Qt::CaseInsensitive);
QTextStream s(&file);
@@ -93,9 +92,6 @@ void Rules::load()
} else if (matchBranchLine.exactMatch(line)) {
match.branch = matchBranchLine.cap(1);
continue;
- } else if (matchPathLine.exactMatch(line)) {
- match.path = matchPathLine.cap(1);
- continue;
} else if (matchRevLine.exactMatch(line)) {
if (matchRevLine.cap(1) == "min")
match.minRevision = matchRevLine.cap(2).toInt();
diff --git a/src/ruleparser.h b/src/ruleparser.h
index e0e3116..f882289 100644
--- a/src/ruleparser.h
+++ b/src/ruleparser.h
@@ -45,7 +45,6 @@ public:
QRegExp rx;
QString repository;
QString branch;
- QString path;
int minRevision;
int maxRevision;
int lineNumber;
diff --git a/src/svn.cpp b/src/svn.cpp
index dcbd40c..3611713 100644
--- a/src/svn.cpp
+++ b/src/svn.cpp
@@ -160,6 +160,25 @@ int SvnPrivate::openRepository(const QString &pathToRepository)
return EXIT_SUCCESS;
}
+static MatchRuleList::ConstIterator
+findMatchRule(const MatchRuleList &matchRules, int revnum, const QString &current)
+{
+ MatchRuleList::ConstIterator it = matchRules.constBegin(),
+ end = matchRules.constEnd();
+ for ( ; it != end; ++it) {
+ if (it->minRevision > revnum)
+ continue;
+ if (it->maxRevision != -1 && it->maxRevision < revnum)
+ continue;
+ if (it->rx.indexIn(current) == 0)
+ return it;
+ }
+
+ // no match
+ return end;
+}
+
+
static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *pool)
{
svn_string_t *propvalue;
@@ -276,6 +295,7 @@ time_t get_epoch(char *svn_date)
int SvnPrivate::exportRevision(int revnum)
{
AprAutoPool pool(global_pool.data());
+ QHash<QString, Repository::Transaction *> transactions;
// open this revision:
qDebug() << "Exporting revision" << revnum;
@@ -283,7 +303,6 @@ int SvnPrivate::exportRevision(int revnum)
SVN_ERR(svn_fs_revision_root(&fs_root, fs, revnum, pool));
// 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.data());
@@ -295,52 +314,52 @@ int SvnPrivate::exportRevision(int revnum)
apr_hash_this(i, &vkey, NULL, &value);
const char *key = reinterpret_cast<const char *>(vkey);
+ // was this copied from somewhere?
+ svn_revnum_t rev_from;
+ const char *path_from;
+ SVN_ERR(svn_fs_copied_from(&rev_from, &path_from, fs_root, key, revpool));
+
// is this a directory?
svn_boolean_t is_dir;
SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool));
if (is_dir) {
- // was this directory copied from somewhere?
- svn_revnum_t rev_from;
- const char *path_from;
- SVN_ERR(svn_fs_copied_from(&rev_from, &path_from, fs_root, key, revpool));
-
- if (path_from == NULL)
+ if (path_from == NULL) {
// no, it's a new directory being added
// Git doesn't handle directories, so we don't either
+ qDebug() << " mkdir ignored:" << key;
continue;
+ }
- qDebug() << "..." << key << "was copied from" << path_from;
+ qDebug() << " " << key << "was copied from" << path_from;
}
QString current = QString::fromUtf8(key);
// find the first rule that matches this pathname
- bool foundMatch = false;
- foreach (Rules::Match rule, matchRules) {
- if (rule.minRevision > revnum)
- continue;
- if (rule.maxRevision != -1 && rule.maxRevision < revnum)
- continue;
- if (rule.rx.exactMatch(current)) {
- foundMatch = true;
- if (rule.repository.isEmpty()) {
- // ignore rule
- qDebug() << "..." << qPrintable(current) << "rev" << revnum
- << "-> ignored";
- break;
- }
+ MatchRuleList::ConstIterator match = findMatchRule(matchRules, revnum, current);
+ if (match != matchRules.constEnd()) {
+ const Rules::Match &rule = *match;
+ if (rule.repository.isEmpty()) {
+ // ignore rule
+ qDebug() << " " << qPrintable(current) << "rev" << revnum
+ << "-> ignored (rule line" << rule.lineNumber << ")";
+ break;
+ } else {
+ QString svnprefix = current;
+ svnprefix.truncate(rule.rx.matchedLength());
- QString repository = current;
- QString branch = current;
- QString path = current;
+ QString repository = svnprefix;
+ QString branch = svnprefix;
+ QString path = current.mid(rule.rx.matchedLength());
// do the replacement
repository.replace(rule.rx, rule.repository);
branch.replace(rule.rx, rule.branch);
- path.replace(rule.rx, rule.path);
- qDebug() << "..." << qPrintable(current) << "rev" << revnum << "->"
- << qPrintable(repository) << qPrintable(branch) << qPrintable(path);
+ printf(".");
+ fflush(stdout);
+// qDebug() << " " << qPrintable(current) << "rev" << revnum << "->"
+// << qPrintable(repository) << qPrintable(branch) << qPrintable(path);
Repository::Transaction *txn = transactions.value(repository, 0);
if (!txn) {
@@ -351,10 +370,6 @@ int SvnPrivate::exportRevision(int revnum)
return EXIT_FAILURE;
}
- QString svnprefix = current;
- if (svnprefix.endsWith(path))
- svnprefix.chop(path.length());
-
txn = repo->newTransaction(branch, svnprefix, revnum);
if (!txn)
return EXIT_FAILURE;
@@ -372,11 +387,13 @@ int SvnPrivate::exportRevision(int revnum)
break;
}
+ } else if (is_dir && path_from != NULL) {
+ qDebug() << current << "is probably a new branch";
}
- if (!foundMatch) {
+ if (match == matchRules.constEnd()) {
if (is_dir) {
- qDebug() << current << "is a directory; ignoring";
+ qDebug() << current << "is a new directory; ignoring";
} else if (wasDir(fs, revnum - 1, key, pool)) {
qDebug() << current << "was a directory; ignoring";
} else {
@@ -417,5 +434,6 @@ int SvnPrivate::exportRevision(int revnum)
delete txn;
}
+ printf("\n");
return EXIT_SUCCESS;
}