]> andersk Git - svn-all-fast-export.git/blobdiff - src/svn.cpp
Ignore any directories that didn't match any rules, including those with history
[svn-all-fast-export.git] / src / svn.cpp
index 18666a3badd32068130dfbb73faf7d53c40970f1..8d5836b1c3e810930b4aff4e2b6b657b8e034076 100644 (file)
@@ -221,6 +221,49 @@ static int dumpBlob(Repository::Transaction *txn, svn_fs_root_t *fs_root,
     return EXIT_SUCCESS;
 }
 
+static int recursiveDumpDir(Repository::Transaction *txn, svn_fs_root_t *fs_root,
+                            const QByteArray &pathname, const QString &finalPathName,
+                            apr_pool_t *pool)
+{
+    // get the dir listing
+    apr_hash_t *entries;
+    SVN_ERR(svn_fs_dir_entries(&entries, fs_root, pathname, pool));
+    AprAutoPool dirpool(pool);
+
+    for (apr_hash_index_t *i = apr_hash_first(pool, entries); i; i = apr_hash_next(i)) {
+        dirpool.clear();
+        const void *vkey;
+        void *value;
+        apr_hash_this(i, &vkey, NULL, &value);
+
+        svn_fs_dirent_t *dirent = reinterpret_cast<svn_fs_dirent_t *>(value);
+        QByteArray entryName = pathname + '/' + dirent->name;
+        QString 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) {
+            if (dumpBlob(txn, fs_root, entryName, entryFinalName, dirpool) == EXIT_FAILURE)
+                return EXIT_FAILURE;
+        }
+    }
+}
+
+static bool wasDir(svn_fs_t *fs, int revnum, const char *pathname, apr_pool_t *pool)
+{
+    AprAutoPool subpool(pool);
+    svn_fs_root_t *fs_root;
+    if (svn_fs_revision_root(&fs_root, fs, revnum, subpool) != SVN_NO_ERROR)
+        return false;
+
+    svn_boolean_t is_dir;
+    if (svn_fs_is_dir(&is_dir, fs_root, pathname, subpool) != SVN_NO_ERROR)
+        return false;
+
+    return is_dir;
+}
+
 time_t get_epoch(char *svn_date)
 {
     struct tm tm;
@@ -246,6 +289,7 @@ int SvnPrivate::exportRevision(int revnum)
     AprAutoPool revpool(pool.data());
     for (apr_hash_index_t *i = apr_hash_first(pool, changes); i; i = apr_hash_next(i)) {
         revpool.clear();
+
         const void *vkey;
         void *value;
         apr_hash_this(i, &vkey, NULL, &value);
@@ -254,16 +298,35 @@ int SvnPrivate::exportRevision(int revnum)
         // is this a directory?
         svn_boolean_t is_dir;
         SVN_ERR(svn_fs_is_dir(&is_dir, fs_root, key, revpool));
-        if (is_dir)
-            continue;           // Git doesn't handle directories, so we don't either
+        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)
+                // no, it's a new directory being added
+                // Git doesn't handle directories, so we don't either
+                continue;
+
+            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
+                    break;
+
                 QString repository = current;
                 QString branch = current;
                 QString path = current;
@@ -273,8 +336,8 @@ int SvnPrivate::exportRevision(int revnum)
                 branch.replace(rule.rx, rule.branch);
                 path.replace(rule.rx, rule.path);
 
-                qDebug() << "..." << current << "rev" << revnum << "->"
-                         << repository << branch << path;
+                qDebug() << "..." << qPrintable(current) << "rev" << revnum << "->"
+                         << qPrintable(repository) << qPrintable(branch) << qPrintable(path);
 
                 Repository::Transaction *txn = transactions.value(repository, 0);
                 if (!txn) {
@@ -299,16 +362,24 @@ int SvnPrivate::exportRevision(int revnum)
                 svn_fs_path_change_t *change = reinterpret_cast<svn_fs_path_change_t *>(value);
                 if (change->change_kind == svn_fs_path_change_delete)
                     txn->deleteFile(path);
-                else
+                else if (!is_dir)
                     dumpBlob(txn, fs_root, key, path, revpool);
+                else
+                    recursiveDumpDir(txn, fs_root, key, path, revpool);
 
                 break;
             }
         }
 
         if (!foundMatch) {
-            qCritical() << current << "did not match any rules; cannot continue";
-            return EXIT_FAILURE;
+            if (is_dir) {
+                qDebug() << current << "is a 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();
This page took 0.142658 seconds and 4 git commands to generate.