]> andersk Git - svn-all-fast-export.git/blobdiff - src/svn.cpp
more information at the end of the revision export
[svn-all-fast-export.git] / src / svn.cpp
index 6333877cc794134dcd8543f0f67296580d652ee2..8892cdc70acb8606e7400568d671a0d4da4b0f9b 100644 (file)
@@ -160,6 +160,46 @@ 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 void splitPathName(const Rules::Match &rule, const QString &pathName, QString *svnprefix_p,
+                          QString *repository_p, QString *branch_p, QString *path_p)
+{
+    QString svnprefix = pathName;
+    svnprefix.truncate(rule.rx.matchedLength());
+    if (svnprefix_p)
+        *svnprefix_p = svnprefix;
+
+    if (repository_p) {
+        *repository_p = svnprefix;
+        repository_p->replace(rule.rx, rule.repository);
+    }
+
+    if (branch_p) {
+        *branch_p = svnprefix;
+        branch_p->replace(rule.rx, rule.branch);
+    }
+
+    if (path_p)
+        *path_p = pathName.mid(svnprefix.length());
+}
+
 static int pathMode(svn_fs_root_t *fs_root, const char *pathname, apr_pool_t *pool)
 {
     svn_string_t *propvalue;
@@ -238,12 +278,18 @@ static int recursiveDumpDir(Repository::Transaction *txn, svn_fs_root_t *fs_root
 
         svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
         QByteArray entryName = pathname + '/' + dirent->name;
-        QString entryFinalName = finalPathName + '/' + dirent->name;
+        QString entryFinalName;
+        if (finalPathName.isEmpty())
+            entryFinalName = dirent->name;
+        else
+            entryFinalName = finalPathName + '/' + dirent->name;
 
         if (dirent->kind == svn_node_dir) {
             if (recursiveDumpDir(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
                 return EXIT_FAILURE;
         } else if (dirent->kind == svn_node_file) {
+            printf("+");
+            fflush(stdout);
             if (dumpBlob(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
                 return EXIT_FAILURE;
         }
@@ -276,14 +322,15 @@ 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;
+    printf("Exporting revision %d ", revnum);
+    fflush(stdout);
     svn_fs_root_t *fs_root;
     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());
@@ -294,64 +341,100 @@ int SvnPrivate::exportRevision(int revnum)
         void *value;
         apr_hash_this(i, &vkey, NULL, &value);
         const char *key = reinterpret_cast<const char *>(vkey);
+        QString current = QString::fromUtf8(key);
+
+        // 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;
+            current += '/';
+            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)
+        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 << ")";
                 continue;
-            if (rule.rx.exactMatch(current)) {
-                foundMatch = true;
-                if (rule.repository.isEmpty())
-                    // ignore rule
-                    break;
-
-                QString repository = current;
-                QString branch = current;
-                QString path = current;
-
-                // do the replacement
-                repository.replace(rule.rx, rule.repository);
-                branch.replace(rule.rx, rule.branch);
-                path.replace(rule.rx, rule.path);
+            } else {
+                QString svnprefix, repository, branch, path;
+                splitPathName(rule, current, &svnprefix, &repository, &branch, &path);
+
+                if (path.isEmpty() && path_from != NULL) {
+                    QString previous = QString::fromUtf8(path_from) + '/';
+                    MatchRuleList::ConstIterator prevmatch =
+                        findMatchRule(matchRules, rev_from, previous);
+                    if (prevmatch != matchRules.constEnd()) {
+                        QString prevsvnprefix, prevrepository, prevbranch, prevpath;
+                        splitPathName(*prevmatch, previous, &prevsvnprefix, &prevrepository,
+                                      &prevbranch, &prevpath);
+
+                        if (!prevpath.isEmpty()) {
+                            qDebug() << qPrintable(current) << "is a partial branch of repository"
+                                     << qPrintable(prevrepository) << "branch"
+                                     << qPrintable(prevbranch) << "subdir"
+                                     << qPrintable(prevpath);
+                        } else if (prevrepository != repository) {
+                            qWarning() << qPrintable(current) << "rev" << revnum
+                                       << "is a cross-repository copy (from repository"
+                                       << qPrintable(prevrepository) << "branch"
+                                       << qPrintable(prevbranch) << "path"
+                                       << qPrintable(prevpath) << "rev" << rev_from << ")";
+                        } else if (prevbranch == branch) {
+                            // same branch and same repository
+                            qDebug() << qPrintable(current) << "rev" << revnum
+                                     << "is an SVN rename from"
+                                     << qPrintable(previous) << "rev" << rev_from;
+                            continue;
+                        } else {
+                            // same repository but not same branch
+                            // this means this is a plain branch
+                            qDebug() << qPrintable(repository) << ": branch"
+                                     << qPrintable(branch) << "is branching from"
+                                     << qPrintable(prevbranch);
+
+                            Repository *repo = repositories.value(repository, 0);
+                            if (!repo) {
+                                qCritical() << "Rule" << rule.rx.pattern() << "line" << rule.lineNumber
+                                            << "references unknown repository" << repository;
+                                return EXIT_FAILURE;
+                            }
+
+                            repo->createBranch(branch, revnum, prevbranch, rev_from);
+                        }
+                    }
+                }
 
-                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) {
                     Repository *repo = repositories.value(repository, 0);
                     if (!repo) {
-                        qCritical() << "Rule" << rule.rx.pattern()
+                        qCritical() << "Rule" << rule.rx.pattern() << "line" << rule.lineNumber
                                     << "references unknown repository" << repository;
                         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;
@@ -367,23 +450,25 @@ int SvnPrivate::exportRevision(int revnum)
                 else
                     recursiveDumpDir(txn, fs_root, key, path, revpool);
 
-                break;
+                continue;
             }
         }
 
-        if (!foundMatch) {
-            if (wasDir(fs, revnum - 1, key, pool)) {
-                qDebug() << current << "was a directory; ignoring";
-            } else {
-                qCritical() << current << "did not match any rules; cannot continue";
-                return EXIT_FAILURE;
-            }
+        if (is_dir) {
+            qDebug() << current << "is a new directory; ignoring";
+        } else if (wasDir(fs, revnum - 1, key, pool)) {
+            qDebug() << current << "was a directory; ignoring";
+        } else {
+            qCritical() << current << "did not match any rules; cannot continue";
+            return EXIT_FAILURE;
         }
     }
     revpool.clear();
 
-    if (transactions.isEmpty())
+    if (transactions.isEmpty()) {
+        printf("nothing to do\n");
         return EXIT_SUCCESS;    // no changes?
+    }
 
     // now create the commit
     apr_hash_t *revprops;
@@ -393,7 +478,7 @@ int SvnPrivate::exportRevision(int revnum)
     svn_string_t *svnlog = (svn_string_t*)apr_hash_get(revprops, "svn:log", APR_HASH_KEY_STRING);
 
     QByteArray log = (char *)svnlog->data;
-    QByteArray authorident = identities.value((char *)svnauthor->data);
+    QByteArray authorident = svnauthor ? identities.value((char *)svnauthor->data) : QByteArray();
     time_t epoch = get_epoch((char*)svndate->data);
     if (authorident.isEmpty()) {
         if (!svnauthor || svn_string_isempty(svnauthor))
@@ -412,5 +497,6 @@ int SvnPrivate::exportRevision(int revnum)
         delete txn;
     }
 
+    printf("done\n");
     return EXIT_SUCCESS;
 }
This page took 0.038881 seconds and 4 git commands to generate.